aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux/helper.c
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 /arch/um/os-Linux/helper.c
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>
Diffstat (limited to 'arch/um/os-Linux/helper.c')
-rw-r--r--arch/um/os-Linux/helper.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/arch/um/os-Linux/helper.c b/arch/um/os-Linux/helper.c
index 97bed16bf4c7..9cf48d0577cc 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;