aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2007-07-16 02:38:56 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-16 12:05:38 -0400
commitc43990162fc7f9d2f15a12797fdc6f9c0905f704 (patch)
tree64f8b776c4807da48971f3c24ca157c5e6ab921f
parent42a359e31a0e438b5b978a8f0fecdbd3c86bb033 (diff)
uml: simplify helper stack handling
run_helper and run_helper_thread had arguments which were the same in all callers. run_helper's stack_out was always NULL and run_helper_thread's stack_order was always 0. These are now gone, and the constants folded into the code. Also fixed leaks of the helper stack in the AIO and SIGIO code. Signed-off-by: Jeff Dike <jdike@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/um/drivers/chan_user.c2
-rw-r--r--arch/um/drivers/harddog_user.c2
-rw-r--r--arch/um/drivers/net_user.c2
-rw-r--r--arch/um/drivers/port_user.c2
-rw-r--r--arch/um/drivers/slip_user.c2
-rw-r--r--arch/um/drivers/slirp_user.c2
-rw-r--r--arch/um/drivers/xterm.c2
-rw-r--r--arch/um/include/os.h6
-rw-r--r--arch/um/os-Linux/aio.c11
-rw-r--r--arch/um/os-Linux/drivers/ethertap_user.c2
-rw-r--r--arch/um/os-Linux/drivers/tuntap_user.c2
-rw-r--r--arch/um/os-Linux/helper.c19
-rw-r--r--arch/um/os-Linux/sigio.c19
13 files changed, 36 insertions, 37 deletions
diff --git a/arch/um/drivers/chan_user.c b/arch/um/drivers/chan_user.c
index 8b81bd5f20f..4d438f36ea2 100644
--- a/arch/um/drivers/chan_user.c
+++ b/arch/um/drivers/chan_user.c
@@ -161,7 +161,7 @@ static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out,
161 * problem with /dev/net/tun, which if held open by this 161 * problem with /dev/net/tun, which if held open by this
162 * thread, prevents the TUN/TAP device from being reused. 162 * thread, prevents the TUN/TAP device from being reused.
163 */ 163 */
164 err = run_helper_thread(winch_thread, &data, CLONE_FILES, stack_out, 0); 164 err = run_helper_thread(winch_thread, &data, CLONE_FILES, stack_out);
165 if(err < 0){ 165 if(err < 0){
166 printk("fork of winch_thread failed - errno = %d\n", -err); 166 printk("fork of winch_thread failed - errno = %d\n", -err);
167 goto out_close; 167 goto out_close;
diff --git a/arch/um/drivers/harddog_user.c b/arch/um/drivers/harddog_user.c
index 5eeecf8917c..1171790f742 100644
--- a/arch/um/drivers/harddog_user.c
+++ b/arch/um/drivers/harddog_user.c
@@ -68,7 +68,7 @@ int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock)
68 args = pid_args; 68 args = pid_args;
69 } 69 }
70 70
71 pid = run_helper(pre_exec, &data, args, NULL); 71 pid = run_helper(pre_exec, &data, args);
72 72
73 os_close_file(out_fds[0]); 73 os_close_file(out_fds[0]);
74 os_close_file(in_fds[1]); 74 os_close_file(in_fds[1]);
diff --git a/arch/um/drivers/net_user.c b/arch/um/drivers/net_user.c
index 3503cff867c..6fa948ba969 100644
--- a/arch/um/drivers/net_user.c
+++ b/arch/um/drivers/net_user.c
@@ -187,7 +187,7 @@ static int change_tramp(char **argv, char *output, int output_len)
187 } 187 }
188 pe_data.close_me = fds[0]; 188 pe_data.close_me = fds[0];
189 pe_data.stdout = fds[1]; 189 pe_data.stdout = fds[1];
190 pid = run_helper(change_pre_exec, &pe_data, argv, NULL); 190 pid = run_helper(change_pre_exec, &pe_data, argv);
191 191
192 if (pid > 0) /* Avoid hang as we won't get data in failure case. */ 192 if (pid > 0) /* Avoid hang as we won't get data in failure case. */
193 read_output(fds[0], output, output_len); 193 read_output(fds[0], output, output_len);
diff --git a/arch/um/drivers/port_user.c b/arch/um/drivers/port_user.c
index 3f6357d24be..29250beba42 100644
--- a/arch/um/drivers/port_user.c
+++ b/arch/um/drivers/port_user.c
@@ -188,7 +188,7 @@ int port_connection(int fd, int *socket, int *pid_out)
188 { .sock_fd = new, 188 { .sock_fd = new,
189 .pipe_fd = socket[1] }); 189 .pipe_fd = socket[1] });
190 190
191 err = run_helper(port_pre_exec, &data, argv, NULL); 191 err = run_helper(port_pre_exec, &data, argv);
192 if(err < 0) 192 if(err < 0)
193 goto out_shutdown; 193 goto out_shutdown;
194 194
diff --git a/arch/um/drivers/slip_user.c b/arch/um/drivers/slip_user.c
index 78f0e515da8..edc2de3ee2f 100644
--- a/arch/um/drivers/slip_user.c
+++ b/arch/um/drivers/slip_user.c
@@ -85,7 +85,7 @@ static int slip_tramp(char **argv, int fd)
85 pe_data.stdin = fd; 85 pe_data.stdin = fd;
86 pe_data.stdout = fds[1]; 86 pe_data.stdout = fds[1];
87 pe_data.close_me = fds[0]; 87 pe_data.close_me = fds[0];
88 err = run_helper(slip_pre_exec, &pe_data, argv, NULL); 88 err = run_helper(slip_pre_exec, &pe_data, argv);
89 if(err < 0) 89 if(err < 0)
90 goto out_close; 90 goto out_close;
91 pid = err; 91 pid = err;
diff --git a/arch/um/drivers/slirp_user.c b/arch/um/drivers/slirp_user.c
index 39f889fe994..0e462f64f22 100644
--- a/arch/um/drivers/slirp_user.c
+++ b/arch/um/drivers/slirp_user.c
@@ -42,7 +42,7 @@ static int slirp_tramp(char **argv, int fd)
42 42
43 pe_data.stdin = fd; 43 pe_data.stdin = fd;
44 pe_data.stdout = fd; 44 pe_data.stdout = fd;
45 pid = run_helper(slirp_pre_exec, &pe_data, argv, NULL); 45 pid = run_helper(slirp_pre_exec, &pe_data, argv);
46 46
47 return(pid); 47 return(pid);
48} 48}
diff --git a/arch/um/drivers/xterm.c b/arch/um/drivers/xterm.c
index 35912846ed2..fd817e54154 100644
--- a/arch/um/drivers/xterm.c
+++ b/arch/um/drivers/xterm.c
@@ -132,7 +132,7 @@ static int xterm_open(int input, int output, int primary, void *d,
132 } 132 }
133 133
134 sprintf(title, data->title, data->device); 134 sprintf(title, data->title, data->device);
135 pid = run_helper(NULL, NULL, argv, NULL); 135 pid = run_helper(NULL, NULL, argv);
136 if (pid < 0) { 136 if (pid < 0) {
137 err = pid; 137 err = pid;
138 printk(UM_KERN_ERR "xterm_open : run_helper failed, " 138 printk(UM_KERN_ERR "xterm_open : run_helper failed, "
diff --git a/arch/um/include/os.h b/arch/um/include/os.h
index 4d9fb26387d..930b261ea48 100644
--- a/arch/um/include/os.h
+++ b/arch/um/include/os.h
@@ -239,11 +239,9 @@ extern unsigned long __do_user_copy(void *to, const void *from, int n,
239/* execvp.c */ 239/* execvp.c */
240extern int execvp_noalloc(char *buf, const char *file, char *const argv[]); 240extern int execvp_noalloc(char *buf, const char *file, char *const argv[]);
241/* helper.c */ 241/* helper.c */
242extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv, 242extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv);
243 unsigned long *stack_out);
244extern int run_helper_thread(int (*proc)(void *), void *arg, 243extern int run_helper_thread(int (*proc)(void *), void *arg,
245 unsigned int flags, unsigned long *stack_out, 244 unsigned int flags, unsigned long *stack_out);
246 int stack_order);
247extern int helper_wait(int pid); 245extern int helper_wait(int pid);
248 246
249 247
diff --git a/arch/um/os-Linux/aio.c b/arch/um/os-Linux/aio.c
index 9bf944f6a1d..b126df4ea16 100644
--- a/arch/um/os-Linux/aio.c
+++ b/arch/um/os-Linux/aio.c
@@ -177,6 +177,7 @@ static int do_not_aio(struct aio_thread_req *req)
177static int aio_req_fd_r = -1; 177static int aio_req_fd_r = -1;
178static int aio_req_fd_w = -1; 178static int aio_req_fd_w = -1;
179static int aio_pid = -1; 179static int aio_pid = -1;
180static unsigned long aio_stack;
180 181
181static int not_aio_thread(void *arg) 182static int not_aio_thread(void *arg)
182{ 183{
@@ -212,7 +213,6 @@ static int not_aio_thread(void *arg)
212 213
213static int init_aio_24(void) 214static int init_aio_24(void)
214{ 215{
215 unsigned long stack;
216 int fds[2], err; 216 int fds[2], err;
217 217
218 err = os_pipe(fds, 1, 1); 218 err = os_pipe(fds, 1, 1);
@@ -227,7 +227,7 @@ static int init_aio_24(void)
227 goto out_close_pipe; 227 goto out_close_pipe;
228 228
229 err = run_helper_thread(not_aio_thread, NULL, 229 err = run_helper_thread(not_aio_thread, NULL,
230 CLONE_FILES | CLONE_VM | SIGCHLD, &stack, 0); 230 CLONE_FILES | CLONE_VM | SIGCHLD, &aio_stack);
231 if(err < 0) 231 if(err < 0)
232 goto out_close_pipe; 232 goto out_close_pipe;
233 233
@@ -252,7 +252,6 @@ out:
252#define DEFAULT_24_AIO 0 252#define DEFAULT_24_AIO 0
253static int init_aio_26(void) 253static int init_aio_26(void)
254{ 254{
255 unsigned long stack;
256 int err; 255 int err;
257 256
258 if(io_setup(256, &ctx)){ 257 if(io_setup(256, &ctx)){
@@ -263,7 +262,7 @@ static int init_aio_26(void)
263 } 262 }
264 263
265 err = run_helper_thread(aio_thread, NULL, 264 err = run_helper_thread(aio_thread, NULL,
266 CLONE_FILES | CLONE_VM | SIGCHLD, &stack, 0); 265 CLONE_FILES | CLONE_VM | SIGCHLD, &aio_stack);
267 if(err < 0) 266 if(err < 0)
268 return err; 267 return err;
269 268
@@ -365,8 +364,10 @@ __initcall(init_aio);
365 364
366static void exit_aio(void) 365static void exit_aio(void)
367{ 366{
368 if(aio_pid != -1) 367 if (aio_pid != -1) {
369 os_kill_process(aio_pid, 1); 368 os_kill_process(aio_pid, 1);
369 free_stack(aio_stack, 0);
370 }
370} 371}
371 372
372__uml_exitcall(exit_aio); 373__uml_exitcall(exit_aio);
diff --git a/arch/um/os-Linux/drivers/ethertap_user.c b/arch/um/os-Linux/drivers/ethertap_user.c
index acba3016128..cac01b31ea9 100644
--- a/arch/um/os-Linux/drivers/ethertap_user.c
+++ b/arch/um/os-Linux/drivers/ethertap_user.c
@@ -117,7 +117,7 @@ static int etap_tramp(char *dev, char *gate, int control_me,
117 pe_data.control_remote = control_remote; 117 pe_data.control_remote = control_remote;
118 pe_data.control_me = control_me; 118 pe_data.control_me = control_me;
119 pe_data.data_me = data_me; 119 pe_data.data_me = data_me;
120 pid = run_helper(etap_pre_exec, &pe_data, args, NULL); 120 pid = run_helper(etap_pre_exec, &pe_data, args);
121 121
122 if(pid < 0) 122 if(pid < 0)
123 err = pid; 123 err = pid;
diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/arch/um/os-Linux/drivers/tuntap_user.c
index 11a9779dc9f..f848b4ea934 100644
--- a/arch/um/os-Linux/drivers/tuntap_user.c
+++ b/arch/um/os-Linux/drivers/tuntap_user.c
@@ -83,7 +83,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
83 data.stdout = remote; 83 data.stdout = remote;
84 data.close_me = me; 84 data.close_me = me;
85 85
86 pid = run_helper(tuntap_pre_exec, &data, argv, NULL); 86 pid = run_helper(tuntap_pre_exec, &data, argv);
87 87
88 if(pid < 0) 88 if(pid < 0)
89 return -pid; 89 return -pid;
diff --git a/arch/um/os-Linux/helper.c b/arch/um/os-Linux/helper.c
index 97bed16bf4c..9cf48d0577c 100644
--- a/arch/um/os-Linux/helper.c
+++ b/arch/um/os-Linux/helper.c
@@ -44,17 +44,13 @@ static int helper_child(void *arg)
44/* Returns either the pid of the child process we run or -E* on failure. 44/* Returns either the pid of the child process we run or -E* on failure.
45 * XXX The alloc_stack here breaks if this is called in the tracing thread, so 45 * XXX The alloc_stack here breaks if this is called in the tracing thread, so
46 * we need to receive a preallocated stack (a local buffer is ok). */ 46 * we need to receive a preallocated stack (a local buffer is ok). */
47int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv, 47int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
48 unsigned long *stack_out)
49{ 48{
50 struct helper_data data; 49 struct helper_data data;
51 unsigned long stack, sp; 50 unsigned long stack, sp;
52 int pid, fds[2], ret, n; 51 int pid, fds[2], ret, n;
53 52
54 if ((stack_out != NULL) && (*stack_out != 0)) 53 stack = alloc_stack(0, __cant_sleep());
55 stack = *stack_out;
56 else
57 stack = alloc_stack(0, __cant_sleep());
58 if (stack == 0) 54 if (stack == 0)
59 return -ENOMEM; 55 return -ENOMEM;
60 56
@@ -113,22 +109,21 @@ out_close:
113 close(fds[1]); 109 close(fds[1]);
114 close(fds[0]); 110 close(fds[0]);
115out_free: 111out_free:
116 if ((stack_out == NULL) || (*stack_out == 0)) 112 free_stack(stack, 0);
117 free_stack(stack, 0);
118 return ret; 113 return ret;
119} 114}
120 115
121int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags, 116int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags,
122 unsigned long *stack_out, int stack_order) 117 unsigned long *stack_out)
123{ 118{
124 unsigned long stack, sp; 119 unsigned long stack, sp;
125 int pid, status, err; 120 int pid, status, err;
126 121
127 stack = alloc_stack(stack_order, __cant_sleep()); 122 stack = alloc_stack(0, __cant_sleep());
128 if (stack == 0) 123 if (stack == 0)
129 return -ENOMEM; 124 return -ENOMEM;
130 125
131 sp = stack + (UM_KERN_PAGE_SIZE << stack_order) - sizeof(void *); 126 sp = stack + UM_KERN_PAGE_SIZE - sizeof(void *);
132 pid = clone(proc, (void *) sp, flags | SIGCHLD, arg); 127 pid = clone(proc, (void *) sp, flags | SIGCHLD, arg);
133 if (pid < 0) { 128 if (pid < 0) {
134 err = -errno; 129 err = -errno;
@@ -147,7 +142,7 @@ int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags,
147 if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) 142 if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
148 printk("run_helper_thread - thread returned status " 143 printk("run_helper_thread - thread returned status "
149 "0x%x\n", status); 144 "0x%x\n", status);
150 free_stack(stack, stack_order); 145 free_stack(stack, 0);
151 } else 146 } else
152 *stack_out = stack; 147 *stack_out = stack;
153 return pid; 148 return pid;
diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c
index 8d4e0c6b8c9..2c23cb26118 100644
--- a/arch/um/os-Linux/sigio.c
+++ b/arch/um/os-Linux/sigio.c
@@ -26,6 +26,7 @@
26 * exitcall. 26 * exitcall.
27 */ 27 */
28static int write_sigio_pid = -1; 28static int write_sigio_pid = -1;
29static unsigned long write_sigio_stack;
29 30
30/* These arrays are initialized before the sigio thread is started, and 31/* These arrays are initialized before the sigio thread is started, and
31 * the descriptors closed after it is killed. So, it can't see them change. 32 * the descriptors closed after it is killed. So, it can't see them change.
@@ -144,8 +145,10 @@ static void update_thread(void)
144 return; 145 return;
145 fail: 146 fail:
146 /* Critical section start */ 147 /* Critical section start */
147 if(write_sigio_pid != -1) 148 if (write_sigio_pid != -1) {
148 os_kill_process(write_sigio_pid, 1); 149 os_kill_process(write_sigio_pid, 1);
150 free_stack(write_sigio_stack, 0);
151 }
149 write_sigio_pid = -1; 152 write_sigio_pid = -1;
150 close(sigio_private[0]); 153 close(sigio_private[0]);
151 close(sigio_private[1]); 154 close(sigio_private[1]);
@@ -243,7 +246,6 @@ static struct pollfd *setup_initial_poll(int fd)
243 246
244static void write_sigio_workaround(void) 247static void write_sigio_workaround(void)
245{ 248{
246 unsigned long stack;
247 struct pollfd *p; 249 struct pollfd *p;
248 int err; 250 int err;
249 int l_write_sigio_fds[2]; 251 int l_write_sigio_fds[2];
@@ -293,7 +295,8 @@ static void write_sigio_workaround(void)
293 memcpy(sigio_private, l_sigio_private, sizeof(l_sigio_private)); 295 memcpy(sigio_private, l_sigio_private, sizeof(l_sigio_private));
294 296
295 write_sigio_pid = run_helper_thread(write_sigio_thread, NULL, 297 write_sigio_pid = run_helper_thread(write_sigio_thread, NULL,
296 CLONE_FILES | CLONE_VM, &stack, 0); 298 CLONE_FILES | CLONE_VM,
299 &write_sigio_stack);
297 300
298 if (write_sigio_pid < 0) 301 if (write_sigio_pid < 0)
299 goto out_clear; 302 goto out_clear;
@@ -356,10 +359,12 @@ out:
356 359
357static void sigio_cleanup(void) 360static void sigio_cleanup(void)
358{ 361{
359 if(write_sigio_pid != -1){ 362 if (write_sigio_pid == -1)
360 os_kill_process(write_sigio_pid, 1); 363 return;
361 write_sigio_pid = -1; 364
362 } 365 os_kill_process(write_sigio_pid, 1);
366 free_stack(write_sigio_stack, 0);
367 write_sigio_pid = -1;
363} 368}
364 369
365__uml_exitcall(sigio_cleanup); 370__uml_exitcall(sigio_cleanup);