diff options
Diffstat (limited to 'arch/um/kernel/skas')
-rw-r--r-- | arch/um/kernel/skas/Makefile | 9 | ||||
-rw-r--r-- | arch/um/kernel/skas/clone.c | 44 | ||||
-rw-r--r-- | arch/um/kernel/skas/exec_kern.c | 2 | ||||
-rw-r--r-- | arch/um/kernel/skas/include/mm_id.h | 17 | ||||
-rw-r--r-- | arch/um/kernel/skas/include/mmu-skas.h | 7 | ||||
-rw-r--r-- | arch/um/kernel/skas/include/mode-skas.h | 1 | ||||
-rw-r--r-- | arch/um/kernel/skas/include/skas.h | 16 | ||||
-rw-r--r-- | arch/um/kernel/skas/include/stub-data.h | 18 | ||||
-rw-r--r-- | arch/um/kernel/skas/mem.c | 6 | ||||
-rw-r--r-- | arch/um/kernel/skas/mem_user.c | 225 | ||||
-rw-r--r-- | arch/um/kernel/skas/mmu.c | 141 | ||||
-rw-r--r-- | arch/um/kernel/skas/process.c | 216 | ||||
-rw-r--r-- | arch/um/kernel/skas/process_kern.c | 46 | ||||
-rw-r--r-- | arch/um/kernel/skas/syscall_user.c | 4 | ||||
-rw-r--r-- | arch/um/kernel/skas/time.c | 30 | ||||
-rw-r--r-- | arch/um/kernel/skas/tlb.c | 29 |
16 files changed, 609 insertions, 202 deletions
diff --git a/arch/um/kernel/skas/Makefile b/arch/um/kernel/skas/Makefile index d37d1bfcd6f7..d296d55ade4b 100644 --- a/arch/um/kernel/skas/Makefile +++ b/arch/um/kernel/skas/Makefile | |||
@@ -3,11 +3,14 @@ | |||
3 | # Licensed under the GPL | 3 | # Licensed under the GPL |
4 | # | 4 | # |
5 | 5 | ||
6 | obj-y := exec_kern.o mem.o mem_user.o mmu.o process.o process_kern.o \ | 6 | obj-y := clone.o exec_kern.o mem.o mem_user.o mmu.o process.o process_kern.o \ |
7 | syscall_kern.o syscall_user.o time.o tlb.o trap_user.o uaccess.o \ | 7 | syscall_kern.o syscall_user.o tlb.o trap_user.o uaccess.o \ |
8 | 8 | ||
9 | subdir- := util | 9 | subdir- := util |
10 | 10 | ||
11 | USER_OBJS := process.o time.o | 11 | USER_OBJS := process.o clone.o |
12 | 12 | ||
13 | include arch/um/scripts/Makefile.rules | 13 | include arch/um/scripts/Makefile.rules |
14 | |||
15 | # clone.o is in the stub, so it can't be built with profiling | ||
16 | $(obj)/clone.o : c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS)) | ||
diff --git a/arch/um/kernel/skas/clone.c b/arch/um/kernel/skas/clone.c new file mode 100644 index 000000000000..4dc55f10cd18 --- /dev/null +++ b/arch/um/kernel/skas/clone.c | |||
@@ -0,0 +1,44 @@ | |||
1 | #include <sched.h> | ||
2 | #include <signal.h> | ||
3 | #include <sys/mman.h> | ||
4 | #include <sys/time.h> | ||
5 | #include <asm/unistd.h> | ||
6 | #include <asm/page.h> | ||
7 | #include "ptrace_user.h" | ||
8 | #include "skas.h" | ||
9 | #include "stub-data.h" | ||
10 | #include "uml-config.h" | ||
11 | #include "sysdep/stub.h" | ||
12 | |||
13 | /* This is in a separate file because it needs to be compiled with any | ||
14 | * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled | ||
15 | */ | ||
16 | void __attribute__ ((__section__ (".__syscall_stub"))) | ||
17 | stub_clone_handler(void) | ||
18 | { | ||
19 | long err; | ||
20 | struct stub_data *from = (struct stub_data *) UML_CONFIG_STUB_DATA; | ||
21 | |||
22 | err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD, | ||
23 | UML_CONFIG_STUB_DATA + PAGE_SIZE / 2 - | ||
24 | sizeof(void *)); | ||
25 | if(err != 0) | ||
26 | goto out; | ||
27 | |||
28 | err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0); | ||
29 | if(err) | ||
30 | goto out; | ||
31 | |||
32 | err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL, | ||
33 | (long) &from->timer, 0); | ||
34 | if(err) | ||
35 | goto out; | ||
36 | |||
37 | err = stub_syscall6(STUB_MMAP_NR, UML_CONFIG_STUB_DATA, PAGE_SIZE, | ||
38 | PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, | ||
39 | from->fd, from->offset); | ||
40 | out: | ||
41 | /* save current result. Parent: pid; child: retcode of mmap */ | ||
42 | from->err = err; | ||
43 | trap_myself(); | ||
44 | } | ||
diff --git a/arch/um/kernel/skas/exec_kern.c b/arch/um/kernel/skas/exec_kern.c index c6b4d5dba789..77ed7bbab219 100644 --- a/arch/um/kernel/skas/exec_kern.c +++ b/arch/um/kernel/skas/exec_kern.c | |||
@@ -18,7 +18,7 @@ | |||
18 | void flush_thread_skas(void) | 18 | void flush_thread_skas(void) |
19 | { | 19 | { |
20 | force_flush_all(); | 20 | force_flush_all(); |
21 | switch_mm_skas(current->mm->context.skas.mm_fd); | 21 | switch_mm_skas(¤t->mm->context.skas.id); |
22 | } | 22 | } |
23 | 23 | ||
24 | void start_thread_skas(struct pt_regs *regs, unsigned long eip, | 24 | void start_thread_skas(struct pt_regs *regs, unsigned long eip, |
diff --git a/arch/um/kernel/skas/include/mm_id.h b/arch/um/kernel/skas/include/mm_id.h new file mode 100644 index 000000000000..48dd0989ddaa --- /dev/null +++ b/arch/um/kernel/skas/include/mm_id.h | |||
@@ -0,0 +1,17 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2005 Jeff Dike (jdike@karaya.com) | ||
3 | * Licensed under the GPL | ||
4 | */ | ||
5 | |||
6 | #ifndef __MM_ID_H | ||
7 | #define __MM_ID_H | ||
8 | |||
9 | struct mm_id { | ||
10 | union { | ||
11 | int mm_fd; | ||
12 | int pid; | ||
13 | } u; | ||
14 | unsigned long stack; | ||
15 | }; | ||
16 | |||
17 | #endif | ||
diff --git a/arch/um/kernel/skas/include/mmu-skas.h b/arch/um/kernel/skas/include/mmu-skas.h index 4cd60d7213f3..278b72f1d9ad 100644 --- a/arch/um/kernel/skas/include/mmu-skas.h +++ b/arch/um/kernel/skas/include/mmu-skas.h | |||
@@ -6,10 +6,15 @@ | |||
6 | #ifndef __SKAS_MMU_H | 6 | #ifndef __SKAS_MMU_H |
7 | #define __SKAS_MMU_H | 7 | #define __SKAS_MMU_H |
8 | 8 | ||
9 | #include "mm_id.h" | ||
10 | |||
9 | struct mmu_context_skas { | 11 | struct mmu_context_skas { |
10 | int mm_fd; | 12 | struct mm_id id; |
13 | unsigned long last_page_table; | ||
11 | }; | 14 | }; |
12 | 15 | ||
16 | extern void switch_mm_skas(struct mm_id * mm_idp); | ||
17 | |||
13 | #endif | 18 | #endif |
14 | 19 | ||
15 | /* | 20 | /* |
diff --git a/arch/um/kernel/skas/include/mode-skas.h b/arch/um/kernel/skas/include/mode-skas.h index c1e33bd788db..bcd26a6a3888 100644 --- a/arch/um/kernel/skas/include/mode-skas.h +++ b/arch/um/kernel/skas/include/mode-skas.h | |||
@@ -13,7 +13,6 @@ extern unsigned long exec_fp_regs[]; | |||
13 | extern unsigned long exec_fpx_regs[]; | 13 | extern unsigned long exec_fpx_regs[]; |
14 | extern int have_fpx_regs; | 14 | extern int have_fpx_regs; |
15 | 15 | ||
16 | extern void user_time_init_skas(void); | ||
17 | extern void sig_handler_common_skas(int sig, void *sc_ptr); | 16 | extern void sig_handler_common_skas(int sig, void *sc_ptr); |
18 | extern void halt_skas(void); | 17 | extern void halt_skas(void); |
19 | extern void reboot_skas(void); | 18 | extern void reboot_skas(void); |
diff --git a/arch/um/kernel/skas/include/skas.h b/arch/um/kernel/skas/include/skas.h index 96b51dba3471..d983ea842547 100644 --- a/arch/um/kernel/skas/include/skas.h +++ b/arch/um/kernel/skas/include/skas.h | |||
@@ -6,9 +6,11 @@ | |||
6 | #ifndef __SKAS_H | 6 | #ifndef __SKAS_H |
7 | #define __SKAS_H | 7 | #define __SKAS_H |
8 | 8 | ||
9 | #include "mm_id.h" | ||
9 | #include "sysdep/ptrace.h" | 10 | #include "sysdep/ptrace.h" |
10 | 11 | ||
11 | extern int userspace_pid[]; | 12 | extern int userspace_pid[]; |
13 | extern int proc_mm, ptrace_faultinfo; | ||
12 | 14 | ||
13 | extern void switch_threads(void *me, void *next); | 15 | extern void switch_threads(void *me, void *next); |
14 | extern void thread_wait(void *sw, void *fb); | 16 | extern void thread_wait(void *sw, void *fb); |
@@ -22,16 +24,18 @@ extern void new_thread_proc(void *stack, void (*handler)(int sig)); | |||
22 | extern void remove_sigstack(void); | 24 | extern void remove_sigstack(void); |
23 | extern void new_thread_handler(int sig); | 25 | extern void new_thread_handler(int sig); |
24 | extern void handle_syscall(union uml_pt_regs *regs); | 26 | extern void handle_syscall(union uml_pt_regs *regs); |
25 | extern void map(int fd, unsigned long virt, unsigned long len, int r, int w, | 27 | extern int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len, |
26 | int x, int phys_fd, unsigned long long offset); | 28 | int r, int w, int x, int phys_fd, unsigned long long offset); |
27 | extern int unmap(int fd, void *addr, unsigned long len); | 29 | extern int unmap(struct mm_id * mm_idp, void *addr, unsigned long len); |
28 | extern int protect(int fd, unsigned long addr, unsigned long len, | 30 | extern int protect(struct mm_id * mm_idp, unsigned long addr, |
29 | int r, int w, int x); | 31 | unsigned long len, int r, int w, int x); |
30 | extern void user_signal(int sig, union uml_pt_regs *regs, int pid); | 32 | extern void user_signal(int sig, union uml_pt_regs *regs, int pid); |
31 | extern int new_mm(int from); | 33 | extern int new_mm(int from); |
32 | extern void start_userspace(int cpu); | 34 | extern int start_userspace(unsigned long stub_stack); |
35 | extern int copy_context_skas0(unsigned long stack, int pid); | ||
33 | extern void get_skas_faultinfo(int pid, struct faultinfo * fi); | 36 | extern void get_skas_faultinfo(int pid, struct faultinfo * fi); |
34 | extern long execute_syscall_skas(void *r); | 37 | extern long execute_syscall_skas(void *r); |
38 | extern unsigned long current_stub_stack(void); | ||
35 | 39 | ||
36 | #endif | 40 | #endif |
37 | 41 | ||
diff --git a/arch/um/kernel/skas/include/stub-data.h b/arch/um/kernel/skas/include/stub-data.h new file mode 100644 index 000000000000..f6ed92c3727d --- /dev/null +++ b/arch/um/kernel/skas/include/stub-data.h | |||
@@ -0,0 +1,18 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2005 Jeff Dike (jdike@karaya.com) | ||
3 | * Licensed under the GPL | ||
4 | */ | ||
5 | |||
6 | #ifndef __STUB_DATA_H | ||
7 | #define __STUB_DATA_H | ||
8 | |||
9 | #include <sys/time.h> | ||
10 | |||
11 | struct stub_data { | ||
12 | long offset; | ||
13 | int fd; | ||
14 | struct itimerval timer; | ||
15 | long err; | ||
16 | }; | ||
17 | |||
18 | #endif | ||
diff --git a/arch/um/kernel/skas/mem.c b/arch/um/kernel/skas/mem.c index 438db2f43456..147466d7ff4f 100644 --- a/arch/um/kernel/skas/mem.c +++ b/arch/um/kernel/skas/mem.c | |||
@@ -5,7 +5,9 @@ | |||
5 | 5 | ||
6 | #include "linux/config.h" | 6 | #include "linux/config.h" |
7 | #include "linux/mm.h" | 7 | #include "linux/mm.h" |
8 | #include "asm/pgtable.h" | ||
8 | #include "mem_user.h" | 9 | #include "mem_user.h" |
10 | #include "skas.h" | ||
9 | 11 | ||
10 | unsigned long set_task_sizes_skas(int arg, unsigned long *host_size_out, | 12 | unsigned long set_task_sizes_skas(int arg, unsigned long *host_size_out, |
11 | unsigned long *task_size_out) | 13 | unsigned long *task_size_out) |
@@ -18,7 +20,9 @@ unsigned long set_task_sizes_skas(int arg, unsigned long *host_size_out, | |||
18 | *task_size_out = CONFIG_HOST_TASK_SIZE; | 20 | *task_size_out = CONFIG_HOST_TASK_SIZE; |
19 | #else | 21 | #else |
20 | *host_size_out = top; | 22 | *host_size_out = top; |
21 | *task_size_out = top; | 23 | if (proc_mm && ptrace_faultinfo) |
24 | *task_size_out = top; | ||
25 | else *task_size_out = CONFIG_STUB_START & PGDIR_MASK; | ||
22 | #endif | 26 | #endif |
23 | return(((unsigned long) set_task_sizes_skas) & ~0xffffff); | 27 | return(((unsigned long) set_task_sizes_skas) & ~0xffffff); |
24 | } | 28 | } |
diff --git a/arch/um/kernel/skas/mem_user.c b/arch/um/kernel/skas/mem_user.c index 1310bf1e88d1..b0980ff3bd95 100644 --- a/arch/um/kernel/skas/mem_user.c +++ b/arch/um/kernel/skas/mem_user.c | |||
@@ -3,100 +3,171 @@ | |||
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <signal.h> | ||
6 | #include <errno.h> | 7 | #include <errno.h> |
7 | #include <sys/mman.h> | 8 | #include <sys/mman.h> |
9 | #include <sys/wait.h> | ||
10 | #include <asm/page.h> | ||
11 | #include <asm/unistd.h> | ||
8 | #include "mem_user.h" | 12 | #include "mem_user.h" |
9 | #include "mem.h" | 13 | #include "mem.h" |
14 | #include "mm_id.h" | ||
10 | #include "user.h" | 15 | #include "user.h" |
11 | #include "os.h" | 16 | #include "os.h" |
12 | #include "proc_mm.h" | 17 | #include "proc_mm.h" |
13 | 18 | #include "ptrace_user.h" | |
14 | void map(int fd, unsigned long virt, unsigned long len, int r, int w, | 19 | #include "user_util.h" |
15 | int x, int phys_fd, unsigned long long offset) | 20 | #include "kern_util.h" |
21 | #include "task.h" | ||
22 | #include "registers.h" | ||
23 | #include "uml-config.h" | ||
24 | #include "sysdep/ptrace.h" | ||
25 | #include "sysdep/stub.h" | ||
26 | #include "skas.h" | ||
27 | |||
28 | extern unsigned long syscall_stub, __syscall_stub_start; | ||
29 | |||
30 | extern void wait_stub_done(int pid, int sig, char * fname); | ||
31 | |||
32 | static long run_syscall_stub(struct mm_id * mm_idp, int syscall, | ||
33 | unsigned long *args) | ||
16 | { | 34 | { |
17 | struct proc_mm_op map; | 35 | int n, pid = mm_idp->u.pid; |
18 | int prot, n; | 36 | unsigned long regs[MAX_REG_NR]; |
19 | 37 | ||
20 | prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | | 38 | get_safe_registers(regs); |
21 | (x ? PROT_EXEC : 0); | 39 | regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE + |
22 | 40 | ((unsigned long) &syscall_stub - | |
23 | map = ((struct proc_mm_op) { .op = MM_MMAP, | 41 | (unsigned long) &__syscall_stub_start); |
24 | .u = | 42 | /* XXX Don't have a define for starting a syscall */ |
25 | { .mmap = | 43 | regs[REGS_SYSCALL_NR] = syscall; |
26 | { .addr = virt, | 44 | regs[REGS_SYSCALL_ARG1] = args[0]; |
27 | .len = len, | 45 | regs[REGS_SYSCALL_ARG2] = args[1]; |
28 | .prot = prot, | 46 | regs[REGS_SYSCALL_ARG3] = args[2]; |
29 | .flags = MAP_SHARED | | 47 | regs[REGS_SYSCALL_ARG4] = args[3]; |
30 | MAP_FIXED, | 48 | regs[REGS_SYSCALL_ARG5] = args[4]; |
31 | .fd = phys_fd, | 49 | regs[REGS_SYSCALL_ARG6] = args[5]; |
32 | .offset = offset | 50 | n = ptrace_setregs(pid, regs); |
33 | } } } ); | 51 | if(n < 0){ |
34 | n = os_write_file(fd, &map, sizeof(map)); | 52 | printk("run_syscall_stub : PTRACE_SETREGS failed, " |
35 | if(n != sizeof(map)) | 53 | "errno = %d\n", n); |
36 | printk("map : /proc/mm map failed, err = %d\n", -n); | 54 | return(n); |
55 | } | ||
56 | |||
57 | wait_stub_done(pid, 0, "run_syscall_stub"); | ||
58 | |||
59 | return(*((unsigned long *) mm_idp->stack)); | ||
37 | } | 60 | } |
38 | 61 | ||
39 | int unmap(int fd, void *addr, unsigned long len) | 62 | int map(struct mm_id *mm_idp, unsigned long virt, unsigned long len, |
63 | int r, int w, int x, int phys_fd, unsigned long long offset) | ||
40 | { | 64 | { |
41 | struct proc_mm_op unmap; | 65 | int prot, n; |
42 | int n; | 66 | |
43 | 67 | prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | | |
44 | unmap = ((struct proc_mm_op) { .op = MM_MUNMAP, | 68 | (x ? PROT_EXEC : 0); |
45 | .u = | 69 | |
46 | { .munmap = | 70 | if(proc_mm){ |
47 | { .addr = (unsigned long) addr, | 71 | struct proc_mm_op map; |
48 | .len = len } } } ); | 72 | int fd = mm_idp->u.mm_fd; |
49 | n = os_write_file(fd, &unmap, sizeof(unmap)); | 73 | map = ((struct proc_mm_op) { .op = MM_MMAP, |
50 | if(n != sizeof(unmap)) { | 74 | .u = |
51 | if(n < 0) | 75 | { .mmap = |
52 | return(n); | 76 | { .addr = virt, |
53 | else if(n > 0) | 77 | .len = len, |
54 | return(-EIO); | 78 | .prot = prot, |
55 | } | 79 | .flags = MAP_SHARED | |
56 | 80 | MAP_FIXED, | |
57 | return(0); | 81 | .fd = phys_fd, |
82 | .offset= offset | ||
83 | } } } ); | ||
84 | n = os_write_file(fd, &map, sizeof(map)); | ||
85 | if(n != sizeof(map)) | ||
86 | printk("map : /proc/mm map failed, err = %d\n", -n); | ||
87 | } | ||
88 | else { | ||
89 | long res; | ||
90 | unsigned long args[] = { virt, len, prot, | ||
91 | MAP_SHARED | MAP_FIXED, phys_fd, | ||
92 | MMAP_OFFSET(offset) }; | ||
93 | |||
94 | res = run_syscall_stub(mm_idp, STUB_MMAP_NR, args); | ||
95 | if((void *) res == MAP_FAILED) | ||
96 | printk("mmap stub failed, errno = %d\n", res); | ||
97 | } | ||
98 | |||
99 | return 0; | ||
58 | } | 100 | } |
59 | 101 | ||
60 | int protect(int fd, unsigned long addr, unsigned long len, int r, int w, | 102 | int unmap(struct mm_id *mm_idp, void *addr, unsigned long len) |
61 | int x, int must_succeed) | ||
62 | { | 103 | { |
63 | struct proc_mm_op protect; | 104 | int n; |
64 | int prot, n; | 105 | |
65 | 106 | if(proc_mm){ | |
66 | prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | | 107 | struct proc_mm_op unmap; |
67 | (x ? PROT_EXEC : 0); | 108 | int fd = mm_idp->u.mm_fd; |
68 | 109 | unmap = ((struct proc_mm_op) { .op = MM_MUNMAP, | |
69 | protect = ((struct proc_mm_op) { .op = MM_MPROTECT, | 110 | .u = |
70 | .u = | 111 | { .munmap = |
71 | { .mprotect = | 112 | { .addr = |
72 | { .addr = (unsigned long) addr, | 113 | (unsigned long) addr, |
73 | .len = len, | 114 | .len = len } } } ); |
74 | .prot = prot } } } ); | 115 | n = os_write_file(fd, &unmap, sizeof(unmap)); |
75 | 116 | if(n != sizeof(unmap)) { | |
76 | n = os_write_file(fd, &protect, sizeof(protect)); | 117 | if(n < 0) |
77 | if(n != sizeof(protect)) { | 118 | return(n); |
78 | if(n == 0) return(0); | 119 | else if(n > 0) |
79 | 120 | return(-EIO); | |
80 | if(must_succeed) | 121 | } |
81 | panic("protect failed, err = %d", -n); | 122 | } |
82 | 123 | else { | |
83 | return(-EIO); | 124 | int res; |
84 | } | 125 | unsigned long args[] = { (unsigned long) addr, len, 0, 0, 0, |
126 | 0 }; | ||
127 | |||
128 | res = run_syscall_stub(mm_idp, __NR_munmap, args); | ||
129 | if(res < 0) | ||
130 | printk("munmap stub failed, errno = %d\n", res); | ||
131 | } | ||
132 | |||
133 | return(0); | ||
134 | } | ||
85 | 135 | ||
86 | return(0); | 136 | int protect(struct mm_id *mm_idp, unsigned long addr, unsigned long len, |
137 | int r, int w, int x) | ||
138 | { | ||
139 | struct proc_mm_op protect; | ||
140 | int prot, n; | ||
141 | |||
142 | prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | | ||
143 | (x ? PROT_EXEC : 0); | ||
144 | |||
145 | if(proc_mm){ | ||
146 | int fd = mm_idp->u.mm_fd; | ||
147 | protect = ((struct proc_mm_op) { .op = MM_MPROTECT, | ||
148 | .u = | ||
149 | { .mprotect = | ||
150 | { .addr = | ||
151 | (unsigned long) addr, | ||
152 | .len = len, | ||
153 | .prot = prot } } } ); | ||
154 | |||
155 | n = os_write_file(fd, &protect, sizeof(protect)); | ||
156 | if(n != sizeof(protect)) | ||
157 | panic("protect failed, err = %d", -n); | ||
158 | } | ||
159 | else { | ||
160 | int res; | ||
161 | unsigned long args[] = { addr, len, prot, 0, 0, 0 }; | ||
162 | |||
163 | res = run_syscall_stub(mm_idp, __NR_mprotect, args); | ||
164 | if(res < 0) | ||
165 | panic("mprotect stub failed, errno = %d\n", res); | ||
166 | } | ||
167 | |||
168 | return(0); | ||
87 | } | 169 | } |
88 | 170 | ||
89 | void before_mem_skas(unsigned long unused) | 171 | void before_mem_skas(unsigned long unused) |
90 | { | 172 | { |
91 | } | 173 | } |
92 | |||
93 | /* | ||
94 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
95 | * Emacs will notice this stuff at the end of the file and automatically | ||
96 | * adjust the settings for this buffer only. This must remain at the end | ||
97 | * of the file. | ||
98 | * --------------------------------------------------------------------------- | ||
99 | * Local variables: | ||
100 | * c-file-style: "linux" | ||
101 | * End: | ||
102 | */ | ||
diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c index 6cb9a6d028a9..d232daa42c31 100644 --- a/arch/um/kernel/skas/mmu.c +++ b/arch/um/kernel/skas/mmu.c | |||
@@ -3,46 +3,143 @@ | |||
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "linux/config.h" | ||
6 | #include "linux/sched.h" | 7 | #include "linux/sched.h" |
7 | #include "linux/list.h" | 8 | #include "linux/list.h" |
8 | #include "linux/spinlock.h" | 9 | #include "linux/spinlock.h" |
9 | #include "linux/slab.h" | 10 | #include "linux/slab.h" |
11 | #include "linux/errno.h" | ||
12 | #include "linux/mm.h" | ||
10 | #include "asm/current.h" | 13 | #include "asm/current.h" |
11 | #include "asm/segment.h" | 14 | #include "asm/segment.h" |
12 | #include "asm/mmu.h" | 15 | #include "asm/mmu.h" |
16 | #include "asm/pgalloc.h" | ||
17 | #include "asm/pgtable.h" | ||
13 | #include "os.h" | 18 | #include "os.h" |
14 | #include "skas.h" | 19 | #include "skas.h" |
15 | 20 | ||
21 | extern int __syscall_stub_start; | ||
22 | |||
23 | static int init_stub_pte(struct mm_struct *mm, unsigned long proc, | ||
24 | unsigned long kernel) | ||
25 | { | ||
26 | pgd_t *pgd; | ||
27 | pud_t *pud; | ||
28 | pmd_t *pmd; | ||
29 | pte_t *pte; | ||
30 | |||
31 | spin_lock(&mm->page_table_lock); | ||
32 | pgd = pgd_offset(mm, proc); | ||
33 | pud = pud_alloc(mm, pgd, proc); | ||
34 | if (!pud) | ||
35 | goto out; | ||
36 | |||
37 | pmd = pmd_alloc(mm, pud, proc); | ||
38 | if (!pmd) | ||
39 | goto out_pmd; | ||
40 | |||
41 | pte = pte_alloc_map(mm, pmd, proc); | ||
42 | if (!pte) | ||
43 | goto out_pte; | ||
44 | |||
45 | /* There's an interaction between the skas0 stub pages, stack | ||
46 | * randomization, and the BUG at the end of exit_mmap. exit_mmap | ||
47 | * checks that the number of page tables freed is the same as had | ||
48 | * been allocated. If the stack is on the last page table page, | ||
49 | * then the stack pte page will be freed, and if not, it won't. To | ||
50 | * avoid having to know where the stack is, or if the process mapped | ||
51 | * something at the top of its address space for some other reason, | ||
52 | * we set TASK_SIZE to end at the start of the last page table. | ||
53 | * This keeps exit_mmap off the last page, but introduces a leak | ||
54 | * of that page. So, we hang onto it here and free it in | ||
55 | * destroy_context_skas. | ||
56 | */ | ||
57 | |||
58 | mm->context.skas.last_page_table = pmd_page_kernel(*pmd); | ||
59 | |||
60 | *pte = mk_pte(virt_to_page(kernel), __pgprot(_PAGE_PRESENT)); | ||
61 | *pte = pte_mkexec(*pte); | ||
62 | *pte = pte_wrprotect(*pte); | ||
63 | spin_unlock(&mm->page_table_lock); | ||
64 | return(0); | ||
65 | |||
66 | out_pmd: | ||
67 | pud_free(pud); | ||
68 | out_pte: | ||
69 | pmd_free(pmd); | ||
70 | out: | ||
71 | spin_unlock(&mm->page_table_lock); | ||
72 | return(-ENOMEM); | ||
73 | } | ||
74 | |||
16 | int init_new_context_skas(struct task_struct *task, struct mm_struct *mm) | 75 | int init_new_context_skas(struct task_struct *task, struct mm_struct *mm) |
17 | { | 76 | { |
18 | int from; | 77 | struct mm_struct *cur_mm = current->mm; |
78 | struct mm_id *cur_mm_id = &cur_mm->context.skas.id; | ||
79 | struct mm_id *mm_id = &mm->context.skas.id; | ||
80 | unsigned long stack; | ||
81 | int from, ret; | ||
19 | 82 | ||
20 | if((current->mm != NULL) && (current->mm != &init_mm)) | 83 | if(proc_mm){ |
21 | from = current->mm->context.skas.mm_fd; | 84 | if((cur_mm != NULL) && (cur_mm != &init_mm)) |
22 | else from = -1; | 85 | from = cur_mm->context.skas.id.u.mm_fd; |
86 | else from = -1; | ||
23 | 87 | ||
24 | mm->context.skas.mm_fd = new_mm(from); | 88 | ret = new_mm(from); |
25 | if(mm->context.skas.mm_fd < 0){ | 89 | if(ret < 0){ |
26 | printk("init_new_context_skas - new_mm failed, errno = %d\n", | 90 | printk("init_new_context_skas - new_mm failed, " |
27 | mm->context.skas.mm_fd); | 91 | "errno = %d\n", ret); |
28 | return(mm->context.skas.mm_fd); | 92 | return ret; |
93 | } | ||
94 | mm_id->u.mm_fd = ret; | ||
29 | } | 95 | } |
96 | else { | ||
97 | /* This zeros the entry that pgd_alloc didn't, needed since | ||
98 | * we are about to reinitialize it, and want mm.nr_ptes to | ||
99 | * be accurate. | ||
100 | */ | ||
101 | mm->pgd[USER_PTRS_PER_PGD] = __pgd(0); | ||
30 | 102 | ||
31 | return(0); | 103 | ret = init_stub_pte(mm, CONFIG_STUB_CODE, |
104 | (unsigned long) &__syscall_stub_start); | ||
105 | if(ret) | ||
106 | goto out; | ||
107 | |||
108 | ret = -ENOMEM; | ||
109 | stack = get_zeroed_page(GFP_KERNEL); | ||
110 | if(stack == 0) | ||
111 | goto out; | ||
112 | mm_id->stack = stack; | ||
113 | |||
114 | ret = init_stub_pte(mm, CONFIG_STUB_DATA, stack); | ||
115 | if(ret) | ||
116 | goto out_free; | ||
117 | |||
118 | mm->nr_ptes--; | ||
119 | |||
120 | if((cur_mm != NULL) && (cur_mm != &init_mm)) | ||
121 | mm_id->u.pid = copy_context_skas0(stack, | ||
122 | cur_mm_id->u.pid); | ||
123 | else mm_id->u.pid = start_userspace(stack); | ||
124 | } | ||
125 | |||
126 | return 0; | ||
127 | |||
128 | out_free: | ||
129 | free_page(mm_id->stack); | ||
130 | out: | ||
131 | return ret; | ||
32 | } | 132 | } |
33 | 133 | ||
34 | void destroy_context_skas(struct mm_struct *mm) | 134 | void destroy_context_skas(struct mm_struct *mm) |
35 | { | 135 | { |
36 | os_close_file(mm->context.skas.mm_fd); | 136 | struct mmu_context_skas *mmu = &mm->context.skas; |
37 | } | ||
38 | 137 | ||
39 | /* | 138 | if(proc_mm) |
40 | * Overrides for Emacs so that we follow Linus's tabbing style. | 139 | os_close_file(mmu->id.u.mm_fd); |
41 | * Emacs will notice this stuff at the end of the file and automatically | 140 | else { |
42 | * adjust the settings for this buffer only. This must remain at the end | 141 | os_kill_ptraced_process(mmu->id.u.pid, 1); |
43 | * of the file. | 142 | free_page(mmu->id.stack); |
44 | * --------------------------------------------------------------------------- | 143 | free_page(mmu->last_page_table); |
45 | * Local variables: | 144 | } |
46 | * c-file-style: "linux" | 145 | } |
47 | * End: | ||
48 | */ | ||
diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c index 773cd2b525fc..ba671dab8878 100644 --- a/arch/um/kernel/skas/process.c +++ b/arch/um/kernel/skas/process.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) | 2 | * Copyright (C) 2002- 2004 Jeff Dike (jdike@addtoit.com) |
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
@@ -13,7 +13,9 @@ | |||
13 | #include <sys/wait.h> | 13 | #include <sys/wait.h> |
14 | #include <sys/mman.h> | 14 | #include <sys/mman.h> |
15 | #include <sys/user.h> | 15 | #include <sys/user.h> |
16 | #include <sys/time.h> | ||
16 | #include <asm/unistd.h> | 17 | #include <asm/unistd.h> |
18 | #include <asm/types.h> | ||
17 | #include "user.h" | 19 | #include "user.h" |
18 | #include "ptrace_user.h" | 20 | #include "ptrace_user.h" |
19 | #include "time_user.h" | 21 | #include "time_user.h" |
@@ -21,13 +23,18 @@ | |||
21 | #include "user_util.h" | 23 | #include "user_util.h" |
22 | #include "kern_util.h" | 24 | #include "kern_util.h" |
23 | #include "skas.h" | 25 | #include "skas.h" |
26 | #include "stub-data.h" | ||
27 | #include "mm_id.h" | ||
24 | #include "sysdep/sigcontext.h" | 28 | #include "sysdep/sigcontext.h" |
29 | #include "sysdep/stub.h" | ||
25 | #include "os.h" | 30 | #include "os.h" |
26 | #include "proc_mm.h" | 31 | #include "proc_mm.h" |
27 | #include "skas_ptrace.h" | 32 | #include "skas_ptrace.h" |
28 | #include "chan_user.h" | 33 | #include "chan_user.h" |
29 | #include "signal_user.h" | 34 | #include "signal_user.h" |
30 | #include "registers.h" | 35 | #include "registers.h" |
36 | #include "mem.h" | ||
37 | #include "uml-config.h" | ||
31 | #include "process.h" | 38 | #include "process.h" |
32 | 39 | ||
33 | int is_skas_winch(int pid, int fd, void *data) | 40 | int is_skas_winch(int pid, int fd, void *data) |
@@ -39,20 +46,55 @@ int is_skas_winch(int pid, int fd, void *data) | |||
39 | return(1); | 46 | return(1); |
40 | } | 47 | } |
41 | 48 | ||
42 | void get_skas_faultinfo(int pid, struct faultinfo * fi) | 49 | void wait_stub_done(int pid, int sig, char * fname) |
43 | { | 50 | { |
44 | int err; | 51 | int n, status, err; |
45 | 52 | ||
46 | err = ptrace(PTRACE_FAULTINFO, pid, 0, fi); | 53 | do { |
47 | if(err) | 54 | if ( sig != -1 ) { |
48 | panic("get_skas_faultinfo - PTRACE_FAULTINFO failed, " | 55 | err = ptrace(PTRACE_CONT, pid, 0, sig); |
49 | "errno = %d\n", errno); | 56 | if(err) |
57 | panic("%s : continue failed, errno = %d\n", | ||
58 | fname, errno); | ||
59 | } | ||
60 | sig = 0; | ||
61 | |||
62 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); | ||
63 | } while((n >= 0) && WIFSTOPPED(status) && | ||
64 | (WSTOPSIG(status) == SIGVTALRM)); | ||
65 | |||
66 | if((n < 0) || !WIFSTOPPED(status) || | ||
67 | (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status != SIGTRAP))){ | ||
68 | panic("%s : failed to wait for SIGUSR1/SIGTRAP, " | ||
69 | "pid = %d, n = %d, errno = %d, status = 0x%x\n", | ||
70 | fname, pid, n, errno, status); | ||
71 | } | ||
72 | } | ||
50 | 73 | ||
51 | /* Special handling for i386, which has different structs */ | 74 | void get_skas_faultinfo(int pid, struct faultinfo * fi) |
52 | if (sizeof(struct ptrace_faultinfo) < sizeof(struct faultinfo)) | 75 | { |
53 | memset((char *)fi + sizeof(struct ptrace_faultinfo), 0, | 76 | int err; |
54 | sizeof(struct faultinfo) - | 77 | |
55 | sizeof(struct ptrace_faultinfo)); | 78 | if(ptrace_faultinfo){ |
79 | err = ptrace(PTRACE_FAULTINFO, pid, 0, fi); | ||
80 | if(err) | ||
81 | panic("get_skas_faultinfo - PTRACE_FAULTINFO failed, " | ||
82 | "errno = %d\n", errno); | ||
83 | |||
84 | /* Special handling for i386, which has different structs */ | ||
85 | if (sizeof(struct ptrace_faultinfo) < sizeof(struct faultinfo)) | ||
86 | memset((char *)fi + sizeof(struct ptrace_faultinfo), 0, | ||
87 | sizeof(struct faultinfo) - | ||
88 | sizeof(struct ptrace_faultinfo)); | ||
89 | } | ||
90 | else { | ||
91 | wait_stub_done(pid, SIGSEGV, "get_skas_faultinfo"); | ||
92 | |||
93 | /* faultinfo is prepared by the stub-segv-handler at start of | ||
94 | * the stub stack page. We just have to copy it. | ||
95 | */ | ||
96 | memcpy(fi, (void *)current_stub_stack(), sizeof(*fi)); | ||
97 | } | ||
56 | } | 98 | } |
57 | 99 | ||
58 | static void handle_segv(int pid, union uml_pt_regs * regs) | 100 | static void handle_segv(int pid, union uml_pt_regs * regs) |
@@ -91,11 +133,56 @@ static void handle_trap(int pid, union uml_pt_regs *regs, int local_using_sysemu | |||
91 | handle_syscall(regs); | 133 | handle_syscall(regs); |
92 | } | 134 | } |
93 | 135 | ||
94 | static int userspace_tramp(void *arg) | 136 | extern int __syscall_stub_start; |
137 | |||
138 | static int userspace_tramp(void *stack) | ||
95 | { | 139 | { |
96 | init_new_thread_signals(0); | 140 | void *addr; |
97 | enable_timer(); | 141 | |
98 | ptrace(PTRACE_TRACEME, 0, 0, 0); | 142 | ptrace(PTRACE_TRACEME, 0, 0, 0); |
143 | |||
144 | init_new_thread_signals(1); | ||
145 | enable_timer(); | ||
146 | |||
147 | if(!proc_mm){ | ||
148 | /* This has a pte, but it can't be mapped in with the usual | ||
149 | * tlb_flush mechanism because this is part of that mechanism | ||
150 | */ | ||
151 | int fd; | ||
152 | __u64 offset; | ||
153 | |||
154 | fd = phys_mapping(to_phys(&__syscall_stub_start), &offset); | ||
155 | addr = mmap64((void *) UML_CONFIG_STUB_CODE, page_size(), | ||
156 | PROT_EXEC, MAP_FIXED | MAP_PRIVATE, fd, offset); | ||
157 | if(addr == MAP_FAILED){ | ||
158 | printk("mapping mmap stub failed, errno = %d\n", | ||
159 | errno); | ||
160 | exit(1); | ||
161 | } | ||
162 | |||
163 | if(stack != NULL){ | ||
164 | fd = phys_mapping(to_phys(stack), &offset); | ||
165 | addr = mmap((void *) UML_CONFIG_STUB_DATA, page_size(), | ||
166 | PROT_READ | PROT_WRITE, | ||
167 | MAP_FIXED | MAP_SHARED, fd, offset); | ||
168 | if(addr == MAP_FAILED){ | ||
169 | printk("mapping segfault stack failed, " | ||
170 | "errno = %d\n", errno); | ||
171 | exit(1); | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | if(!ptrace_faultinfo && (stack != NULL)){ | ||
176 | unsigned long v = UML_CONFIG_STUB_CODE + | ||
177 | (unsigned long) stub_segv_handler - | ||
178 | (unsigned long) &__syscall_stub_start; | ||
179 | |||
180 | set_sigstack((void *) UML_CONFIG_STUB_DATA, page_size()); | ||
181 | set_handler(SIGSEGV, (void *) v, SA_ONSTACK, | ||
182 | SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, | ||
183 | SIGUSR1, -1); | ||
184 | } | ||
185 | |||
99 | os_stop_process(os_getpid()); | 186 | os_stop_process(os_getpid()); |
100 | return(0); | 187 | return(0); |
101 | } | 188 | } |
@@ -105,11 +192,11 @@ static int userspace_tramp(void *arg) | |||
105 | #define NR_CPUS 1 | 192 | #define NR_CPUS 1 |
106 | int userspace_pid[NR_CPUS]; | 193 | int userspace_pid[NR_CPUS]; |
107 | 194 | ||
108 | void start_userspace(int cpu) | 195 | int start_userspace(unsigned long stub_stack) |
109 | { | 196 | { |
110 | void *stack; | 197 | void *stack; |
111 | unsigned long sp; | 198 | unsigned long sp; |
112 | int pid, status, n; | 199 | int pid, status, n, flags; |
113 | 200 | ||
114 | stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, | 201 | stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, |
115 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 202 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
@@ -117,8 +204,9 @@ void start_userspace(int cpu) | |||
117 | panic("start_userspace : mmap failed, errno = %d", errno); | 204 | panic("start_userspace : mmap failed, errno = %d", errno); |
118 | sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *); | 205 | sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *); |
119 | 206 | ||
120 | pid = clone(userspace_tramp, (void *) sp, | 207 | flags = CLONE_FILES | SIGCHLD; |
121 | CLONE_FILES | CLONE_VM | SIGCHLD, NULL); | 208 | if(proc_mm) flags |= CLONE_VM; |
209 | pid = clone(userspace_tramp, (void *) sp, flags, (void *) stub_stack); | ||
122 | if(pid < 0) | 210 | if(pid < 0) |
123 | panic("start_userspace : clone failed, errno = %d", errno); | 211 | panic("start_userspace : clone failed, errno = %d", errno); |
124 | 212 | ||
@@ -140,7 +228,7 @@ void start_userspace(int cpu) | |||
140 | if(munmap(stack, PAGE_SIZE) < 0) | 228 | if(munmap(stack, PAGE_SIZE) < 0) |
141 | panic("start_userspace : munmap failed, errno = %d\n", errno); | 229 | panic("start_userspace : munmap failed, errno = %d\n", errno); |
142 | 230 | ||
143 | userspace_pid[cpu] = pid; | 231 | return(pid); |
144 | } | 232 | } |
145 | 233 | ||
146 | void userspace(union uml_pt_regs *regs) | 234 | void userspace(union uml_pt_regs *regs) |
@@ -174,7 +262,9 @@ void userspace(union uml_pt_regs *regs) | |||
174 | if(WIFSTOPPED(status)){ | 262 | if(WIFSTOPPED(status)){ |
175 | switch(WSTOPSIG(status)){ | 263 | switch(WSTOPSIG(status)){ |
176 | case SIGSEGV: | 264 | case SIGSEGV: |
177 | handle_segv(pid, regs); | 265 | if(PTRACE_FULL_FAULTINFO || !ptrace_faultinfo) |
266 | user_signal(SIGSEGV, regs, pid); | ||
267 | else handle_segv(pid, regs); | ||
178 | break; | 268 | break; |
179 | case SIGTRAP + 0x80: | 269 | case SIGTRAP + 0x80: |
180 | handle_trap(pid, regs, local_using_sysemu); | 270 | handle_trap(pid, regs, local_using_sysemu); |
@@ -194,6 +284,7 @@ void userspace(union uml_pt_regs *regs) | |||
194 | printk("userspace - child stopped with signal " | 284 | printk("userspace - child stopped with signal " |
195 | "%d\n", WSTOPSIG(status)); | 285 | "%d\n", WSTOPSIG(status)); |
196 | } | 286 | } |
287 | pid = userspace_pid[0]; | ||
197 | interrupt_end(); | 288 | interrupt_end(); |
198 | 289 | ||
199 | /* Avoid -ERESTARTSYS handling in host */ | 290 | /* Avoid -ERESTARTSYS handling in host */ |
@@ -207,6 +298,67 @@ void userspace(union uml_pt_regs *regs) | |||
207 | #define INIT_JMP_HALT 3 | 298 | #define INIT_JMP_HALT 3 |
208 | #define INIT_JMP_REBOOT 4 | 299 | #define INIT_JMP_REBOOT 4 |
209 | 300 | ||
301 | |||
302 | int copy_context_skas0(unsigned long new_stack, int pid) | ||
303 | { | ||
304 | int err; | ||
305 | unsigned long regs[MAX_REG_NR]; | ||
306 | unsigned long current_stack = current_stub_stack(); | ||
307 | struct stub_data *data = (struct stub_data *) current_stack; | ||
308 | struct stub_data *child_data = (struct stub_data *) new_stack; | ||
309 | __u64 new_offset; | ||
310 | int new_fd = phys_mapping(to_phys((void *)new_stack), &new_offset); | ||
311 | |||
312 | /* prepare offset and fd of child's stack as argument for parent's | ||
313 | * and child's mmap2 calls | ||
314 | */ | ||
315 | *data = ((struct stub_data) { .offset = MMAP_OFFSET(new_offset), | ||
316 | .fd = new_fd, | ||
317 | .timer = ((struct itimerval) | ||
318 | { { 0, 1000000 / hz() }, | ||
319 | { 0, 1000000 / hz() }})}); | ||
320 | get_safe_registers(regs); | ||
321 | |||
322 | /* Set parent's instruction pointer to start of clone-stub */ | ||
323 | regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE + | ||
324 | (unsigned long) stub_clone_handler - | ||
325 | (unsigned long) &__syscall_stub_start; | ||
326 | regs[REGS_SP_INDEX] = UML_CONFIG_STUB_DATA + PAGE_SIZE - | ||
327 | sizeof(void *); | ||
328 | err = ptrace_setregs(pid, regs); | ||
329 | if(err < 0) | ||
330 | panic("copy_context_skas0 : PTRACE_SETREGS failed, " | ||
331 | "pid = %d, errno = %d\n", pid, errno); | ||
332 | |||
333 | /* set a well known return code for detection of child write failure */ | ||
334 | child_data->err = 12345678; | ||
335 | |||
336 | /* Wait, until parent has finished its work: read child's pid from | ||
337 | * parent's stack, and check, if bad result. | ||
338 | */ | ||
339 | wait_stub_done(pid, 0, "copy_context_skas0"); | ||
340 | |||
341 | pid = data->err; | ||
342 | if(pid < 0) | ||
343 | panic("copy_context_skas0 - stub-parent reports error %d\n", | ||
344 | pid); | ||
345 | |||
346 | /* Wait, until child has finished too: read child's result from | ||
347 | * child's stack and check it. | ||
348 | */ | ||
349 | wait_stub_done(pid, -1, "copy_context_skas0"); | ||
350 | if (child_data->err != UML_CONFIG_STUB_DATA) | ||
351 | panic("copy_context_skas0 - stub-child reports error %d\n", | ||
352 | child_data->err); | ||
353 | |||
354 | if (ptrace(PTRACE_OLDSETOPTIONS, pid, NULL, | ||
355 | (void *)PTRACE_O_TRACESYSGOOD) < 0) | ||
356 | panic("copy_context_skas0 : PTRACE_SETOPTIONS failed, " | ||
357 | "errno = %d\n", errno); | ||
358 | |||
359 | return pid; | ||
360 | } | ||
361 | |||
210 | void new_thread(void *stack, void **switch_buf_ptr, void **fork_buf_ptr, | 362 | void new_thread(void *stack, void **switch_buf_ptr, void **fork_buf_ptr, |
211 | void (*handler)(int)) | 363 | void (*handler)(int)) |
212 | { | 364 | { |
@@ -334,21 +486,19 @@ void reboot_skas(void) | |||
334 | siglongjmp(initial_jmpbuf, INIT_JMP_REBOOT); | 486 | siglongjmp(initial_jmpbuf, INIT_JMP_REBOOT); |
335 | } | 487 | } |
336 | 488 | ||
337 | void switch_mm_skas(int mm_fd) | 489 | void switch_mm_skas(struct mm_id *mm_idp) |
338 | { | 490 | { |
339 | int err; | 491 | int err; |
340 | 492 | ||
341 | #warning need cpu pid in switch_mm_skas | 493 | #warning need cpu pid in switch_mm_skas |
342 | err = ptrace(PTRACE_SWITCH_MM, userspace_pid[0], 0, mm_fd); | 494 | if(proc_mm){ |
343 | if(err) | 495 | err = ptrace(PTRACE_SWITCH_MM, userspace_pid[0], 0, |
344 | panic("switch_mm_skas - PTRACE_SWITCH_MM failed, errno = %d\n", | 496 | mm_idp->u.mm_fd); |
345 | errno); | 497 | if(err) |
346 | } | 498 | panic("switch_mm_skas - PTRACE_SWITCH_MM failed, " |
347 | 499 | "errno = %d\n", errno); | |
348 | void kill_off_processes_skas(void) | 500 | } |
349 | { | 501 | else userspace_pid[0] = mm_idp->u.pid; |
350 | #warning need to loop over userspace_pids in kill_off_processes_skas | ||
351 | os_kill_ptraced_process(userspace_pid[0], 1); | ||
352 | } | 502 | } |
353 | 503 | ||
354 | /* | 504 | /* |
diff --git a/arch/um/kernel/skas/process_kern.c b/arch/um/kernel/skas/process_kern.c index fc71ef295782..cbabab104ac3 100644 --- a/arch/um/kernel/skas/process_kern.c +++ b/arch/um/kernel/skas/process_kern.c | |||
@@ -111,8 +111,7 @@ int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp, | |||
111 | void (*handler)(int); | 111 | void (*handler)(int); |
112 | 112 | ||
113 | if(current->thread.forking){ | 113 | if(current->thread.forking){ |
114 | memcpy(&p->thread.regs.regs.skas, | 114 | memcpy(&p->thread.regs.regs.skas, ®s->regs.skas, |
115 | ¤t->thread.regs.regs.skas, | ||
116 | sizeof(p->thread.regs.regs.skas)); | 115 | sizeof(p->thread.regs.regs.skas)); |
117 | REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0); | 116 | REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0); |
118 | if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp; | 117 | if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp; |
@@ -176,12 +175,14 @@ static int start_kernel_proc(void *unused) | |||
176 | return(0); | 175 | return(0); |
177 | } | 176 | } |
178 | 177 | ||
178 | extern int userspace_pid[]; | ||
179 | |||
179 | int start_uml_skas(void) | 180 | int start_uml_skas(void) |
180 | { | 181 | { |
181 | start_userspace(0); | 182 | if(proc_mm) |
183 | userspace_pid[0] = start_userspace(0); | ||
182 | 184 | ||
183 | init_new_thread_signals(1); | 185 | init_new_thread_signals(1); |
184 | uml_idle_timer(); | ||
185 | 186 | ||
186 | init_task.thread.request.u.thread.proc = start_kernel_proc; | 187 | init_task.thread.request.u.thread.proc = start_kernel_proc; |
187 | init_task.thread.request.u.thread.arg = NULL; | 188 | init_task.thread.request.u.thread.arg = NULL; |
@@ -202,13 +203,30 @@ int thread_pid_skas(struct task_struct *task) | |||
202 | return(userspace_pid[0]); | 203 | return(userspace_pid[0]); |
203 | } | 204 | } |
204 | 205 | ||
205 | /* | 206 | void kill_off_processes_skas(void) |
206 | * Overrides for Emacs so that we follow Linus's tabbing style. | 207 | { |
207 | * Emacs will notice this stuff at the end of the file and automatically | 208 | if(proc_mm) |
208 | * adjust the settings for this buffer only. This must remain at the end | 209 | #warning need to loop over userspace_pids in kill_off_processes_skas |
209 | * of the file. | 210 | os_kill_ptraced_process(userspace_pid[0], 1); |
210 | * --------------------------------------------------------------------------- | 211 | else { |
211 | * Local variables: | 212 | struct task_struct *p; |
212 | * c-file-style: "linux" | 213 | int pid, me; |
213 | * End: | 214 | |
214 | */ | 215 | me = os_getpid(); |
216 | for_each_process(p){ | ||
217 | if(p->mm == NULL) | ||
218 | continue; | ||
219 | |||
220 | pid = p->mm->context.skas.id.u.pid; | ||
221 | os_kill_ptraced_process(pid, 1); | ||
222 | } | ||
223 | } | ||
224 | } | ||
225 | |||
226 | unsigned long current_stub_stack(void) | ||
227 | { | ||
228 | if(current->mm == NULL) | ||
229 | return(0); | ||
230 | |||
231 | return(current->mm->context.skas.id.stack); | ||
232 | } | ||
diff --git a/arch/um/kernel/skas/syscall_user.c b/arch/um/kernel/skas/syscall_user.c index 2828e6e37721..6b0664970147 100644 --- a/arch/um/kernel/skas/syscall_user.c +++ b/arch/um/kernel/skas/syscall_user.c | |||
@@ -15,7 +15,7 @@ | |||
15 | void handle_syscall(union uml_pt_regs *regs) | 15 | void handle_syscall(union uml_pt_regs *regs) |
16 | { | 16 | { |
17 | long result; | 17 | long result; |
18 | #if UML_CONFIG_SYSCALL_DEBUG | 18 | #ifdef UML_CONFIG_SYSCALL_DEBUG |
19 | int index; | 19 | int index; |
20 | 20 | ||
21 | index = record_syscall_start(UPT_SYSCALL_NR(regs)); | 21 | index = record_syscall_start(UPT_SYSCALL_NR(regs)); |
@@ -27,7 +27,7 @@ void handle_syscall(union uml_pt_regs *regs) | |||
27 | REGS_SET_SYSCALL_RETURN(regs->skas.regs, result); | 27 | REGS_SET_SYSCALL_RETURN(regs->skas.regs, result); |
28 | 28 | ||
29 | syscall_trace(regs, 1); | 29 | syscall_trace(regs, 1); |
30 | #if UML_CONFIG_SYSCALL_DEBUG | 30 | #ifdef UML_CONFIG_SYSCALL_DEBUG |
31 | record_syscall_end(index, result); | 31 | record_syscall_end(index, result); |
32 | #endif | 32 | #endif |
33 | } | 33 | } |
diff --git a/arch/um/kernel/skas/time.c b/arch/um/kernel/skas/time.c deleted file mode 100644 index 98091494b897..000000000000 --- a/arch/um/kernel/skas/time.c +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) | ||
3 | * Licensed under the GPL | ||
4 | */ | ||
5 | |||
6 | #include <sys/signal.h> | ||
7 | #include <sys/time.h> | ||
8 | #include "time_user.h" | ||
9 | #include "process.h" | ||
10 | #include "user.h" | ||
11 | |||
12 | void user_time_init_skas(void) | ||
13 | { | ||
14 | if(signal(SIGALRM, (__sighandler_t) alarm_handler) == SIG_ERR) | ||
15 | panic("Couldn't set SIGALRM handler"); | ||
16 | if(signal(SIGVTALRM, (__sighandler_t) alarm_handler) == SIG_ERR) | ||
17 | panic("Couldn't set SIGVTALRM handler"); | ||
18 | set_interval(ITIMER_VIRTUAL); | ||
19 | } | ||
20 | |||
21 | /* | ||
22 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
23 | * Emacs will notice this stuff at the end of the file and automatically | ||
24 | * adjust the settings for this buffer only. This must remain at the end | ||
25 | * of the file. | ||
26 | * --------------------------------------------------------------------------- | ||
27 | * Local variables: | ||
28 | * c-file-style: "linux" | ||
29 | * End: | ||
30 | */ | ||
diff --git a/arch/um/kernel/skas/tlb.c b/arch/um/kernel/skas/tlb.c index b8c5e71763d1..6230999c672c 100644 --- a/arch/um/kernel/skas/tlb.c +++ b/arch/um/kernel/skas/tlb.c | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | #include "linux/stddef.h" | 7 | #include "linux/stddef.h" |
8 | #include "linux/sched.h" | 8 | #include "linux/sched.h" |
9 | #include "linux/config.h" | ||
9 | #include "linux/mm.h" | 10 | #include "linux/mm.h" |
10 | #include "asm/page.h" | 11 | #include "asm/page.h" |
11 | #include "asm/pgtable.h" | 12 | #include "asm/pgtable.h" |
@@ -17,7 +18,7 @@ | |||
17 | #include "os.h" | 18 | #include "os.h" |
18 | #include "tlb.h" | 19 | #include "tlb.h" |
19 | 20 | ||
20 | static void do_ops(int fd, struct host_vm_op *ops, int last) | 21 | static void do_ops(union mm_context *mmu, struct host_vm_op *ops, int last) |
21 | { | 22 | { |
22 | struct host_vm_op *op; | 23 | struct host_vm_op *op; |
23 | int i; | 24 | int i; |
@@ -26,18 +27,18 @@ static void do_ops(int fd, struct host_vm_op *ops, int last) | |||
26 | op = &ops[i]; | 27 | op = &ops[i]; |
27 | switch(op->type){ | 28 | switch(op->type){ |
28 | case MMAP: | 29 | case MMAP: |
29 | map(fd, op->u.mmap.addr, op->u.mmap.len, | 30 | map(&mmu->skas.id, op->u.mmap.addr, op->u.mmap.len, |
30 | op->u.mmap.r, op->u.mmap.w, op->u.mmap.x, | 31 | op->u.mmap.r, op->u.mmap.w, op->u.mmap.x, |
31 | op->u.mmap.fd, op->u.mmap.offset); | 32 | op->u.mmap.fd, op->u.mmap.offset); |
32 | break; | 33 | break; |
33 | case MUNMAP: | 34 | case MUNMAP: |
34 | unmap(fd, (void *) op->u.munmap.addr, | 35 | unmap(&mmu->skas.id, (void *) op->u.munmap.addr, |
35 | op->u.munmap.len); | 36 | op->u.munmap.len); |
36 | break; | 37 | break; |
37 | case MPROTECT: | 38 | case MPROTECT: |
38 | protect(fd, op->u.mprotect.addr, op->u.mprotect.len, | 39 | protect(&mmu->skas.id, op->u.mprotect.addr, |
39 | op->u.mprotect.r, op->u.mprotect.w, | 40 | op->u.mprotect.len, op->u.mprotect.r, |
40 | op->u.mprotect.x); | 41 | op->u.mprotect.w, op->u.mprotect.x); |
41 | break; | 42 | break; |
42 | default: | 43 | default: |
43 | printk("Unknown op type %d in do_ops\n", op->type); | 44 | printk("Unknown op type %d in do_ops\n", op->type); |
@@ -46,12 +47,15 @@ static void do_ops(int fd, struct host_vm_op *ops, int last) | |||
46 | } | 47 | } |
47 | } | 48 | } |
48 | 49 | ||
50 | extern int proc_mm; | ||
51 | |||
49 | static void fix_range(struct mm_struct *mm, unsigned long start_addr, | 52 | static void fix_range(struct mm_struct *mm, unsigned long start_addr, |
50 | unsigned long end_addr, int force) | 53 | unsigned long end_addr, int force) |
51 | { | 54 | { |
52 | int fd = mm->context.skas.mm_fd; | 55 | if(!proc_mm && (end_addr > CONFIG_STUB_START)) |
56 | end_addr = CONFIG_STUB_START; | ||
53 | 57 | ||
54 | fix_range_common(mm, start_addr, end_addr, force, fd, do_ops); | 58 | fix_range_common(mm, start_addr, end_addr, force, do_ops); |
55 | } | 59 | } |
56 | 60 | ||
57 | void __flush_tlb_one_skas(unsigned long addr) | 61 | void __flush_tlb_one_skas(unsigned long addr) |
@@ -69,17 +73,20 @@ void flush_tlb_range_skas(struct vm_area_struct *vma, unsigned long start, | |||
69 | 73 | ||
70 | void flush_tlb_mm_skas(struct mm_struct *mm) | 74 | void flush_tlb_mm_skas(struct mm_struct *mm) |
71 | { | 75 | { |
76 | unsigned long end; | ||
77 | |||
72 | /* Don't bother flushing if this address space is about to be | 78 | /* Don't bother flushing if this address space is about to be |
73 | * destroyed. | 79 | * destroyed. |
74 | */ | 80 | */ |
75 | if(atomic_read(&mm->mm_users) == 0) | 81 | if(atomic_read(&mm->mm_users) == 0) |
76 | return; | 82 | return; |
77 | 83 | ||
78 | fix_range(mm, 0, host_task_size, 0); | 84 | end = proc_mm ? task_size : CONFIG_STUB_START; |
79 | flush_tlb_kernel_range_common(start_vm, end_vm); | 85 | fix_range(mm, 0, end, 0); |
80 | } | 86 | } |
81 | 87 | ||
82 | void force_flush_all_skas(void) | 88 | void force_flush_all_skas(void) |
83 | { | 89 | { |
84 | fix_range(current->mm, 0, host_task_size, 1); | 90 | unsigned long end = proc_mm ? task_size : CONFIG_STUB_START; |
91 | fix_range(current->mm, 0, end, 1); | ||
85 | } | 92 | } |