aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux/skas/mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/os-Linux/skas/mem.c')
-rw-r--r--arch/um/os-Linux/skas/mem.c94
1 files changed, 47 insertions, 47 deletions
diff --git a/arch/um/os-Linux/skas/mem.c b/arch/um/os-Linux/skas/mem.c
index ae7685710c46..d58d11179bb7 100644
--- a/arch/um/os-Linux/skas/mem.c
+++ b/arch/um/os-Linux/skas/mem.c
@@ -1,30 +1,25 @@
1/* 1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
5 5
6#include <signal.h> 6#include <stddef.h>
7#include <unistd.h>
7#include <errno.h> 8#include <errno.h>
8#include <string.h> 9#include <string.h>
9#include <unistd.h>
10#include <sys/mman.h> 10#include <sys/mman.h>
11#include <sys/wait.h> 11#include "init.h"
12#include <asm/unistd.h> 12#include "kern_constants.h"
13#include "mem_user.h" 13#include "mm_id.h"
14#include "mem.h"
15#include "skas.h"
16#include "user.h"
17#include "os.h" 14#include "os.h"
18#include "proc_mm.h" 15#include "proc_mm.h"
19#include "ptrace_user.h" 16#include "ptrace_user.h"
20#include "kern_util.h"
21#include "task.h"
22#include "registers.h" 17#include "registers.h"
23#include "uml-config.h" 18#include "skas.h"
19#include "user.h"
24#include "sysdep/ptrace.h" 20#include "sysdep/ptrace.h"
25#include "sysdep/stub.h" 21#include "sysdep/stub.h"
26#include "init.h" 22#include "uml-config.h"
27#include "kern_constants.h"
28 23
29extern unsigned long batch_syscall_stub, __syscall_stub_start; 24extern unsigned long batch_syscall_stub, __syscall_stub_start;
30 25
@@ -33,7 +28,7 @@ extern void wait_stub_done(int pid);
33static inline unsigned long *check_init_stack(struct mm_id * mm_idp, 28static inline unsigned long *check_init_stack(struct mm_id * mm_idp,
34 unsigned long *stack) 29 unsigned long *stack)
35{ 30{
36 if(stack == NULL) { 31 if (stack == NULL) {
37 stack = (unsigned long *) mm_idp->stack + 2; 32 stack = (unsigned long *) mm_idp->stack + 2;
38 *stack = 0; 33 *stack = 0;
39 } 34 }
@@ -67,29 +62,30 @@ static inline long do_syscall_stub(struct mm_id * mm_idp, void **addr)
67 unsigned long * syscall; 62 unsigned long * syscall;
68 int err, pid = mm_idp->u.pid; 63 int err, pid = mm_idp->u.pid;
69 64
70 if(proc_mm) 65 if (proc_mm)
71 /* FIXME: Need to look up userspace_pid by cpu */ 66 /* FIXME: Need to look up userspace_pid by cpu */
72 pid = userspace_pid[0]; 67 pid = userspace_pid[0];
73 68
74 multi_count++; 69 multi_count++;
75 70
76 n = ptrace_setregs(pid, syscall_regs); 71 n = ptrace_setregs(pid, syscall_regs);
77 if(n < 0){ 72 if (n < 0) {
78 printk("Registers - \n"); 73 printk(UM_KERN_ERR "Registers - \n");
79 for(i = 0; i < MAX_REG_NR; i++) 74 for (i = 0; i < MAX_REG_NR; i++)
80 printk("\t%d\t0x%lx\n", i, syscall_regs[i]); 75 printk(UM_KERN_ERR "\t%d\t0x%lx\n", i, syscall_regs[i]);
81 panic("do_syscall_stub : PTRACE_SETREGS failed, errno = %d\n", 76 panic("do_syscall_stub : PTRACE_SETREGS failed, errno = %d\n",
82 -n); 77 -n);
83 } 78 }
84 79
85 err = ptrace(PTRACE_CONT, pid, 0, 0); 80 err = ptrace(PTRACE_CONT, pid, 0, 0);
86 if(err) 81 if (err)
87 panic("Failed to continue stub, pid = %d, errno = %d\n", pid, 82 panic("Failed to continue stub, pid = %d, errno = %d\n", pid,
88 errno); 83 errno);
89 84
90 wait_stub_done(pid); 85 wait_stub_done(pid);
91 86
92 /* When the stub stops, we find the following values on the 87 /*
88 * When the stub stops, we find the following values on the
93 * beginning of the stack: 89 * beginning of the stack:
94 * (long )return_value 90 * (long )return_value
95 * (long )offset to failed sycall-data (0, if no error) 91 * (long )offset to failed sycall-data (0, if no error)
@@ -99,24 +95,25 @@ static inline long do_syscall_stub(struct mm_id * mm_idp, void **addr)
99 if (offset) { 95 if (offset) {
100 data = (unsigned long *)(mm_idp->stack + 96 data = (unsigned long *)(mm_idp->stack +
101 offset - UML_CONFIG_STUB_DATA); 97 offset - UML_CONFIG_STUB_DATA);
102 printk("do_syscall_stub : ret = %ld, offset = %ld, " 98 printk(UM_KERN_ERR "do_syscall_stub : ret = %ld, offset = %ld, "
103 "data = %p\n", ret, offset, data); 99 "data = %p\n", ret, offset, data);
104 syscall = (unsigned long *)((unsigned long)data + data[0]); 100 syscall = (unsigned long *)((unsigned long)data + data[0]);
105 printk("do_syscall_stub: syscall %ld failed, return value = " 101 printk(UM_KERN_ERR "do_syscall_stub: syscall %ld failed, "
106 "0x%lx, expected return value = 0x%lx\n", 102 "return value = 0x%lx, expected return value = 0x%lx\n",
107 syscall[0], ret, syscall[7]); 103 syscall[0], ret, syscall[7]);
108 printk(" syscall parameters: " 104 printk(UM_KERN_ERR " syscall parameters: "
109 "0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n", 105 "0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
110 syscall[1], syscall[2], syscall[3], 106 syscall[1], syscall[2], syscall[3],
111 syscall[4], syscall[5], syscall[6]); 107 syscall[4], syscall[5], syscall[6]);
112 for(n = 1; n < data[0]/sizeof(long); n++) { 108 for (n = 1; n < data[0]/sizeof(long); n++) {
113 if(n == 1) 109 if (n == 1)
114 printk(" additional syscall data:"); 110 printk(UM_KERN_ERR " additional syscall "
115 if(n % 4 == 1) 111 "data:");
116 printk("\n "); 112 if (n % 4 == 1)
113 printk("\n" UM_KERN_ERR " ");
117 printk(" 0x%lx", data[n]); 114 printk(" 0x%lx", data[n]);
118 } 115 }
119 if(n > 1) 116 if (n > 1)
120 printk("\n"); 117 printk("\n");
121 } 118 }
122 else ret = 0; 119 else ret = 0;
@@ -132,7 +129,7 @@ long run_syscall_stub(struct mm_id * mm_idp, int syscall,
132{ 129{
133 unsigned long *stack = check_init_stack(mm_idp, *addr); 130 unsigned long *stack = check_init_stack(mm_idp, *addr);
134 131
135 if(done && *addr == NULL) 132 if (done && *addr == NULL)
136 single_count++; 133 single_count++;
137 134
138 *stack += sizeof(long); 135 *stack += sizeof(long);
@@ -149,8 +146,8 @@ long run_syscall_stub(struct mm_id * mm_idp, int syscall,
149 *stack = 0; 146 *stack = 0;
150 multi_op_count++; 147 multi_op_count++;
151 148
152 if(!done && ((((unsigned long) stack) & ~UM_KERN_PAGE_MASK) < 149 if (!done && ((((unsigned long) stack) & ~UM_KERN_PAGE_MASK) <
153 UM_KERN_PAGE_SIZE - 10 * sizeof(long))){ 150 UM_KERN_PAGE_SIZE - 10 * sizeof(long))) {
154 *addr = stack; 151 *addr = stack;
155 return 0; 152 return 0;
156 } 153 }
@@ -165,14 +162,15 @@ long syscall_stub_data(struct mm_id * mm_idp,
165 unsigned long *stack; 162 unsigned long *stack;
166 int ret = 0; 163 int ret = 0;
167 164
168 /* If *addr still is uninitialized, it *must* contain NULL. 165 /*
166 * If *addr still is uninitialized, it *must* contain NULL.
169 * Thus in this case do_syscall_stub correctly won't be called. 167 * Thus in this case do_syscall_stub correctly won't be called.
170 */ 168 */
171 if((((unsigned long) *addr) & ~UM_KERN_PAGE_MASK) >= 169 if ((((unsigned long) *addr) & ~UM_KERN_PAGE_MASK) >=
172 UM_KERN_PAGE_SIZE - (10 + data_count) * sizeof(long)) { 170 UM_KERN_PAGE_SIZE - (10 + data_count) * sizeof(long)) {
173 ret = do_syscall_stub(mm_idp, addr); 171 ret = do_syscall_stub(mm_idp, addr);
174 /* in case of error, don't overwrite data on stack */ 172 /* in case of error, don't overwrite data on stack */
175 if(ret) 173 if (ret)
176 return ret; 174 return ret;
177 } 175 }
178 176
@@ -194,7 +192,7 @@ int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len, int prot,
194{ 192{
195 int ret; 193 int ret;
196 194
197 if(proc_mm){ 195 if (proc_mm) {
198 struct proc_mm_op map; 196 struct proc_mm_op map;
199 int fd = mm_idp->u.mm_fd; 197 int fd = mm_idp->u.mm_fd;
200 198
@@ -210,9 +208,10 @@ int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len, int prot,
210 .offset= offset 208 .offset= offset
211 } } } ); 209 } } } );
212 CATCH_EINTR(ret = write(fd, &map, sizeof(map))); 210 CATCH_EINTR(ret = write(fd, &map, sizeof(map)));
213 if(ret != sizeof(map)){ 211 if (ret != sizeof(map)) {
214 ret = -errno; 212 ret = -errno;
215 printk("map : /proc/mm map failed, err = %d\n", -ret); 213 printk(UM_KERN_ERR "map : /proc/mm map failed, "
214 "err = %d\n", -ret);
216 } 215 }
217 else ret = 0; 216 else ret = 0;
218 } 217 }
@@ -233,7 +232,7 @@ int unmap(struct mm_id * mm_idp, unsigned long addr, unsigned long len,
233{ 232{
234 int ret; 233 int ret;
235 234
236 if(proc_mm){ 235 if (proc_mm) {
237 struct proc_mm_op unmap; 236 struct proc_mm_op unmap;
238 int fd = mm_idp->u.mm_fd; 237 int fd = mm_idp->u.mm_fd;
239 238
@@ -244,9 +243,10 @@ int unmap(struct mm_id * mm_idp, unsigned long addr, unsigned long len,
244 (unsigned long) addr, 243 (unsigned long) addr,
245 .len = len } } } ); 244 .len = len } } } );
246 CATCH_EINTR(ret = write(fd, &unmap, sizeof(unmap))); 245 CATCH_EINTR(ret = write(fd, &unmap, sizeof(unmap)));
247 if(ret != sizeof(unmap)){ 246 if (ret != sizeof(unmap)) {
248 ret = -errno; 247 ret = -errno;
249 printk("unmap - proc_mm write returned %d\n", ret); 248 printk(UM_KERN_ERR "unmap - proc_mm write returned "
249 "%d\n", ret);
250 } 250 }
251 else ret = 0; 251 else ret = 0;
252 } 252 }
@@ -267,7 +267,7 @@ int protect(struct mm_id * mm_idp, unsigned long addr, unsigned long len,
267 struct proc_mm_op protect; 267 struct proc_mm_op protect;
268 int ret; 268 int ret;
269 269
270 if(proc_mm){ 270 if (proc_mm) {
271 int fd = mm_idp->u.mm_fd; 271 int fd = mm_idp->u.mm_fd;
272 272
273 protect = ((struct proc_mm_op) { .op = MM_MPROTECT, 273 protect = ((struct proc_mm_op) { .op = MM_MPROTECT,
@@ -279,9 +279,9 @@ int protect(struct mm_id * mm_idp, unsigned long addr, unsigned long len,
279 .prot = prot } } } ); 279 .prot = prot } } } );
280 280
281 CATCH_EINTR(ret = write(fd, &protect, sizeof(protect))); 281 CATCH_EINTR(ret = write(fd, &protect, sizeof(protect)));
282 if(ret != sizeof(protect)){ 282 if (ret != sizeof(protect)) {
283 ret = -errno; 283 ret = -errno;
284 printk("protect failed, err = %d", -ret); 284 printk(UM_KERN_ERR "protect failed, err = %d", -ret);
285 } 285 }
286 else ret = 0; 286 else ret = 0;
287 } 287 }