diff options
Diffstat (limited to 'arch/um')
-rw-r--r-- | arch/um/drivers/cow.h | 2 | ||||
-rw-r--r-- | arch/um/drivers/cow_sys.h | 6 | ||||
-rw-r--r-- | arch/um/drivers/cow_user.c | 24 | ||||
-rw-r--r-- | arch/um/drivers/net_user.c | 34 | ||||
-rw-r--r-- | arch/um/drivers/ubd_kern.c | 2 | ||||
-rw-r--r-- | arch/um/include/init.h | 2 | ||||
-rw-r--r-- | arch/um/include/os.h | 3 | ||||
-rw-r--r-- | arch/um/os-Linux/file.c | 19 | ||||
-rw-r--r-- | arch/um/os-Linux/process.c | 16 | ||||
-rw-r--r-- | arch/um/sys-i386/ldt.c | 9 |
10 files changed, 78 insertions, 39 deletions
diff --git a/arch/um/drivers/cow.h b/arch/um/drivers/cow.h index dc36b222100b..04e3958266e0 100644 --- a/arch/um/drivers/cow.h +++ b/arch/um/drivers/cow.h | |||
@@ -46,7 +46,7 @@ extern int file_reader(__u64 offset, char *buf, int len, void *arg); | |||
46 | extern int read_cow_header(int (*reader)(__u64, char *, int, void *), | 46 | extern int read_cow_header(int (*reader)(__u64, char *, int, void *), |
47 | void *arg, __u32 *version_out, | 47 | void *arg, __u32 *version_out, |
48 | char **backing_file_out, time_t *mtime_out, | 48 | char **backing_file_out, time_t *mtime_out, |
49 | unsigned long long *size_out, int *sectorsize_out, | 49 | __u64 *size_out, int *sectorsize_out, |
50 | __u32 *align_out, int *bitmap_offset_out); | 50 | __u32 *align_out, int *bitmap_offset_out); |
51 | 51 | ||
52 | extern int write_cow_header(char *cow_file, int fd, char *backing_file, | 52 | extern int write_cow_header(char *cow_file, int fd, char *backing_file, |
diff --git a/arch/um/drivers/cow_sys.h b/arch/um/drivers/cow_sys.h index c83fc5d68936..94de4ead4f7a 100644 --- a/arch/um/drivers/cow_sys.h +++ b/arch/um/drivers/cow_sys.h | |||
@@ -23,17 +23,17 @@ static inline char *cow_strdup(char *str) | |||
23 | return(uml_strdup(str)); | 23 | return(uml_strdup(str)); |
24 | } | 24 | } |
25 | 25 | ||
26 | static inline int cow_seek_file(int fd, unsigned long long offset) | 26 | static inline int cow_seek_file(int fd, __u64 offset) |
27 | { | 27 | { |
28 | return(os_seek_file(fd, offset)); | 28 | return(os_seek_file(fd, offset)); |
29 | } | 29 | } |
30 | 30 | ||
31 | static inline int cow_file_size(char *file, unsigned long long *size_out) | 31 | static inline int cow_file_size(char *file, __u64 *size_out) |
32 | { | 32 | { |
33 | return(os_file_size(file, size_out)); | 33 | return(os_file_size(file, size_out)); |
34 | } | 34 | } |
35 | 35 | ||
36 | static inline int cow_write_file(int fd, char *buf, int size) | 36 | static inline int cow_write_file(int fd, void *buf, int size) |
37 | { | 37 | { |
38 | return(os_write_file(fd, buf, size)); | 38 | return(os_write_file(fd, buf, size)); |
39 | } | 39 | } |
diff --git a/arch/um/drivers/cow_user.c b/arch/um/drivers/cow_user.c index fbe2217db5dd..61951b721268 100644 --- a/arch/um/drivers/cow_user.c +++ b/arch/um/drivers/cow_user.c | |||
@@ -176,7 +176,7 @@ int write_cow_header(char *cow_file, int fd, char *backing_file, | |||
176 | err = -ENOMEM; | 176 | err = -ENOMEM; |
177 | header = cow_malloc(sizeof(*header)); | 177 | header = cow_malloc(sizeof(*header)); |
178 | if(header == NULL){ | 178 | if(header == NULL){ |
179 | cow_printf("Failed to allocate COW V3 header\n"); | 179 | cow_printf("write_cow_header - failed to allocate COW V3 header\n"); |
180 | goto out; | 180 | goto out; |
181 | } | 181 | } |
182 | header->magic = htonl(COW_MAGIC); | 182 | header->magic = htonl(COW_MAGIC); |
@@ -196,15 +196,17 @@ int write_cow_header(char *cow_file, int fd, char *backing_file, | |||
196 | 196 | ||
197 | err = os_file_modtime(header->backing_file, &modtime); | 197 | err = os_file_modtime(header->backing_file, &modtime); |
198 | if(err < 0){ | 198 | if(err < 0){ |
199 | cow_printf("Backing file '%s' mtime request failed, " | 199 | cow_printf("write_cow_header - backing file '%s' mtime " |
200 | "err = %d\n", header->backing_file, -err); | 200 | "request failed, err = %d\n", header->backing_file, |
201 | -err); | ||
201 | goto out_free; | 202 | goto out_free; |
202 | } | 203 | } |
203 | 204 | ||
204 | err = cow_file_size(header->backing_file, size); | 205 | err = cow_file_size(header->backing_file, size); |
205 | if(err < 0){ | 206 | if(err < 0){ |
206 | cow_printf("Couldn't get size of backing file '%s', " | 207 | cow_printf("write_cow_header - couldn't get size of " |
207 | "err = %d\n", header->backing_file, -err); | 208 | "backing file '%s', err = %d\n", |
209 | header->backing_file, -err); | ||
208 | goto out_free; | 210 | goto out_free; |
209 | } | 211 | } |
210 | 212 | ||
@@ -214,10 +216,11 @@ int write_cow_header(char *cow_file, int fd, char *backing_file, | |||
214 | header->alignment = htonl(alignment); | 216 | header->alignment = htonl(alignment); |
215 | header->cow_format = COW_BITMAP; | 217 | header->cow_format = COW_BITMAP; |
216 | 218 | ||
217 | err = os_write_file(fd, header, sizeof(*header)); | 219 | err = cow_write_file(fd, header, sizeof(*header)); |
218 | if(err != sizeof(*header)){ | 220 | if(err != sizeof(*header)){ |
219 | cow_printf("Write of header to new COW file '%s' failed, " | 221 | cow_printf("write_cow_header - write of header to " |
220 | "err = %d\n", cow_file, -err); | 222 | "new COW file '%s' failed, err = %d\n", cow_file, |
223 | -err); | ||
221 | goto out_free; | 224 | goto out_free; |
222 | } | 225 | } |
223 | err = 0; | 226 | err = 0; |
@@ -299,7 +302,7 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg, | |||
299 | } | 302 | } |
300 | else if(version == 3){ | 303 | else if(version == 3){ |
301 | if(n < sizeof(header->v3)){ | 304 | if(n < sizeof(header->v3)){ |
302 | cow_printf("read_cow_header - failed to read V2 " | 305 | cow_printf("read_cow_header - failed to read V3 " |
303 | "header\n"); | 306 | "header\n"); |
304 | goto out; | 307 | goto out; |
305 | } | 308 | } |
@@ -359,7 +362,8 @@ int init_cow_file(int fd, char *cow_file, char *backing_file, int sectorsize, | |||
359 | if(err != sizeof(zero)){ | 362 | if(err != sizeof(zero)){ |
360 | cow_printf("Write of bitmap to new COW file '%s' failed, " | 363 | cow_printf("Write of bitmap to new COW file '%s' failed, " |
361 | "err = %d\n", cow_file, -err); | 364 | "err = %d\n", cow_file, -err); |
362 | err = -EINVAL; | 365 | if (err >= 0) |
366 | err = -EINVAL; | ||
363 | goto out; | 367 | goto out; |
364 | } | 368 | } |
365 | 369 | ||
diff --git a/arch/um/drivers/net_user.c b/arch/um/drivers/net_user.c index 098fa65981ab..0e2f06187ea7 100644 --- a/arch/um/drivers/net_user.c +++ b/arch/um/drivers/net_user.c | |||
@@ -47,10 +47,12 @@ void tap_check_ips(char *gate_addr, unsigned char *eth_addr) | |||
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | /* Do reliable error handling as this fails frequently enough. */ | ||
50 | void read_output(int fd, char *output, int len) | 51 | void read_output(int fd, char *output, int len) |
51 | { | 52 | { |
52 | int remain, n, actual; | 53 | int remain, ret, expected; |
53 | char c; | 54 | char c; |
55 | char *str; | ||
54 | 56 | ||
55 | if(output == NULL){ | 57 | if(output == NULL){ |
56 | output = &c; | 58 | output = &c; |
@@ -58,23 +60,31 @@ void read_output(int fd, char *output, int len) | |||
58 | } | 60 | } |
59 | 61 | ||
60 | *output = '\0'; | 62 | *output = '\0'; |
61 | n = os_read_file(fd, &remain, sizeof(remain)); | 63 | ret = os_read_file(fd, &remain, sizeof(remain)); |
62 | if(n != sizeof(remain)){ | 64 | |
63 | printk("read_output - read of length failed, err = %d\n", -n); | 65 | if (ret != sizeof(remain)) { |
64 | return; | 66 | expected = sizeof(remain); |
67 | str = "length"; | ||
68 | goto err; | ||
65 | } | 69 | } |
66 | 70 | ||
67 | while(remain != 0){ | 71 | while(remain != 0){ |
68 | n = (remain < len) ? remain : len; | 72 | expected = (remain < len) ? remain : len; |
69 | actual = os_read_file(fd, output, n); | 73 | ret = os_read_file(fd, output, expected); |
70 | if(actual != n){ | 74 | if (ret != expected) { |
71 | printk("read_output - read of data failed, " | 75 | str = "data"; |
72 | "err = %d\n", -actual); | 76 | goto err; |
73 | return; | ||
74 | } | 77 | } |
75 | remain -= actual; | 78 | remain -= ret; |
76 | } | 79 | } |
80 | |||
77 | return; | 81 | return; |
82 | |||
83 | err: | ||
84 | if (ret < 0) | ||
85 | printk("read_output - read of %s failed, errno = %d\n", str, -ret); | ||
86 | else | ||
87 | printk("read_output - read of %s failed, read only %d of %d bytes\n", str, ret, expected); | ||
78 | } | 88 | } |
79 | 89 | ||
80 | int net_read(int fd, void *buf, int len) | 90 | int net_read(int fd, void *buf, int len) |
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 101efd26d467..fa617e0719ab 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c | |||
@@ -1135,7 +1135,7 @@ static int path_requires_switch(char *from_cmdline, char *from_cow, char *cow) | |||
1135 | static int backing_file_mismatch(char *file, __u64 size, time_t mtime) | 1135 | static int backing_file_mismatch(char *file, __u64 size, time_t mtime) |
1136 | { | 1136 | { |
1137 | unsigned long modtime; | 1137 | unsigned long modtime; |
1138 | long long actual; | 1138 | unsigned long long actual; |
1139 | int err; | 1139 | int err; |
1140 | 1140 | ||
1141 | err = os_file_modtime(file, &modtime); | 1141 | err = os_file_modtime(file, &modtime); |
diff --git a/arch/um/include/init.h b/arch/um/include/init.h index cbd79a8d213d..d4de7c0120ce 100644 --- a/arch/um/include/init.h +++ b/arch/um/include/init.h | |||
@@ -122,7 +122,7 @@ extern struct uml_param __uml_setup_start, __uml_setup_end; | |||
122 | 122 | ||
123 | #define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn | 123 | #define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn |
124 | 124 | ||
125 | #define __init_call __attribute__ ((unused,__section__ (".initcall.init"))) | 125 | #define __init_call __attribute_used__ __attribute__ ((__section__ (".initcall.init"))) |
126 | 126 | ||
127 | #endif | 127 | #endif |
128 | 128 | ||
diff --git a/arch/um/include/os.h b/arch/um/include/os.h index eb1710b81255..2a1c64d8d0bf 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h | |||
@@ -179,8 +179,11 @@ extern void os_stop_process(int pid); | |||
179 | extern void os_kill_process(int pid, int reap_child); | 179 | extern void os_kill_process(int pid, int reap_child); |
180 | extern void os_kill_ptraced_process(int pid, int reap_child); | 180 | extern void os_kill_ptraced_process(int pid, int reap_child); |
181 | extern void os_usr1_process(int pid); | 181 | extern void os_usr1_process(int pid); |
182 | extern long os_ptrace_ldt(long pid, long addr, long data); | ||
183 | |||
182 | extern int os_getpid(void); | 184 | extern int os_getpid(void); |
183 | extern int os_getpgrp(void); | 185 | extern int os_getpgrp(void); |
186 | |||
184 | extern void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)); | 187 | extern void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)); |
185 | extern void init_new_thread_signals(int altstack); | 188 | extern void init_new_thread_signals(int altstack); |
186 | extern int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr); | 189 | extern int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr); |
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c index f55773c819e6..3bd10deea280 100644 --- a/arch/um/os-Linux/file.c +++ b/arch/um/os-Linux/file.c | |||
@@ -272,14 +272,23 @@ int os_connect_socket(char *name) | |||
272 | snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name); | 272 | snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name); |
273 | 273 | ||
274 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | 274 | fd = socket(AF_UNIX, SOCK_STREAM, 0); |
275 | if(fd < 0) | 275 | if(fd < 0) { |
276 | return(fd); | 276 | err = -errno; |
277 | goto out; | ||
278 | } | ||
277 | 279 | ||
278 | err = connect(fd, (struct sockaddr *) &sock, sizeof(sock)); | 280 | err = connect(fd, (struct sockaddr *) &sock, sizeof(sock)); |
279 | if(err) | 281 | if(err) { |
280 | return(-errno); | 282 | err = -errno; |
283 | goto out_close; | ||
284 | } | ||
281 | 285 | ||
282 | return(fd); | 286 | return fd; |
287 | |||
288 | out_close: | ||
289 | close(fd); | ||
290 | out: | ||
291 | return err; | ||
283 | } | 292 | } |
284 | 293 | ||
285 | void os_close_file(int fd) | 294 | void os_close_file(int fd) |
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 7f5e2dac2a35..d261888f39c4 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include "irq_user.h" | 19 | #include "irq_user.h" |
20 | #include "kern_util.h" | 20 | #include "kern_util.h" |
21 | #include "longjmp.h" | 21 | #include "longjmp.h" |
22 | #include "skas_ptrace.h" | ||
22 | 23 | ||
23 | #define ARBITRARY_ADDR -1 | 24 | #define ARBITRARY_ADDR -1 |
24 | #define FAILURE_PID -1 | 25 | #define FAILURE_PID -1 |
@@ -100,6 +101,21 @@ void os_kill_process(int pid, int reap_child) | |||
100 | 101 | ||
101 | } | 102 | } |
102 | 103 | ||
104 | /* This is here uniquely to have access to the userspace errno, i.e. the one | ||
105 | * used by ptrace in case of error. | ||
106 | */ | ||
107 | |||
108 | long os_ptrace_ldt(long pid, long addr, long data) | ||
109 | { | ||
110 | int ret; | ||
111 | |||
112 | ret = ptrace(PTRACE_LDT, pid, addr, data); | ||
113 | |||
114 | if (ret < 0) | ||
115 | return -errno; | ||
116 | return ret; | ||
117 | } | ||
118 | |||
103 | /* Kill off a ptraced child by all means available. kill it normally first, | 119 | /* Kill off a ptraced child by all means available. kill it normally first, |
104 | * then PTRACE_KILL it, then PTRACE_CONT it in case it's in a run state from | 120 | * then PTRACE_KILL it, then PTRACE_CONT it in case it's in a run state from |
105 | * which it can't exit directly. | 121 | * which it can't exit directly. |
diff --git a/arch/um/sys-i386/ldt.c b/arch/um/sys-i386/ldt.c index 1fa09a79a10b..fe0877b3509c 100644 --- a/arch/um/sys-i386/ldt.c +++ b/arch/um/sys-i386/ldt.c | |||
@@ -107,7 +107,7 @@ long write_ldt_entry(struct mm_id * mm_idp, int func, struct user_desc * desc, | |||
107 | * So we need to switch child's mm into our userspace, then | 107 | * So we need to switch child's mm into our userspace, then |
108 | * later switch back. | 108 | * later switch back. |
109 | * | 109 | * |
110 | * Note: I'm unshure: should interrupts be disabled here? | 110 | * Note: I'm unsure: should interrupts be disabled here? |
111 | */ | 111 | */ |
112 | if(!current->active_mm || current->active_mm == &init_mm || | 112 | if(!current->active_mm || current->active_mm == &init_mm || |
113 | mm_idp != ¤t->active_mm->context.skas.id) | 113 | mm_idp != ¤t->active_mm->context.skas.id) |
@@ -129,9 +129,7 @@ long write_ldt_entry(struct mm_id * mm_idp, int func, struct user_desc * desc, | |||
129 | pid = userspace_pid[cpu]; | 129 | pid = userspace_pid[cpu]; |
130 | } | 130 | } |
131 | 131 | ||
132 | res = ptrace(PTRACE_LDT, pid, 0, (unsigned long) &ldt_op); | 132 | res = os_ptrace_ldt(pid, 0, (unsigned long) &ldt_op); |
133 | if(res) | ||
134 | res = errno; | ||
135 | 133 | ||
136 | if(proc_mm) | 134 | if(proc_mm) |
137 | put_cpu(); | 135 | put_cpu(); |
@@ -181,8 +179,7 @@ static long read_ldt_from_host(void __user * ptr, unsigned long bytecount) | |||
181 | */ | 179 | */ |
182 | 180 | ||
183 | cpu = get_cpu(); | 181 | cpu = get_cpu(); |
184 | res = ptrace(PTRACE_LDT, userspace_pid[cpu], 0, | 182 | res = os_ptrace_ldt(userspace_pid[cpu], 0, (unsigned long) &ptrace_ldt); |
185 | (unsigned long) &ptrace_ldt); | ||
186 | put_cpu(); | 183 | put_cpu(); |
187 | if(res < 0) | 184 | if(res < 0) |
188 | goto out; | 185 | goto out; |