aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/kernel
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2005-11-07 03:58:51 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-07 10:53:31 -0500
commitff5c6ff54215fe284e515032878111de5d8a5ce1 (patch)
treeecf5e2eaacc9f45f5227b50d8bfaaf82e15b9647 /arch/um/kernel
parent52c653b3bed323df9006c06cdfb4548ec44b3109 (diff)
[PATCH] uml: separate libc-dependent helper code
The serial UML OS-abstraction layer patch (um/kernel dir). This moves all systemcalls from helper.c file under os-Linux dir Signed-off-by: Gennady Sharapov <Gennady.V.Sharapov@intel.com> Signed-off-by: Jeff Dike <jdike@addtoit.com> Cc: Paolo Giarrusso <blaisorblade@yahoo.it> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/kernel')
-rw-r--r--arch/um/kernel/Makefile5
-rw-r--r--arch/um/kernel/helper.c165
-rw-r--r--arch/um/kernel/ksyms.c1
-rw-r--r--arch/um/kernel/sigio_user.c1
-rw-r--r--arch/um/kernel/user_util.c1
5 files changed, 2 insertions, 171 deletions
diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile
index f9858583863a..3de9d21e36bf 100644
--- a/arch/um/kernel/Makefile
+++ b/arch/um/kernel/Makefile
@@ -7,7 +7,7 @@ extra-y := vmlinux.lds
7clean-files := 7clean-files :=
8 8
9obj-y = config.o exec_kern.o exitcode.o \ 9obj-y = config.o exec_kern.o exitcode.o \
10 helper.o init_task.o irq.o irq_user.o ksyms.o mem.o physmem.o \ 10 init_task.o irq.o irq_user.o ksyms.o mem.o physmem.o \
11 process_kern.o ptrace.o reboot.o resource.o sigio_user.o sigio_kern.o \ 11 process_kern.o ptrace.o reboot.o resource.o sigio_user.o sigio_kern.o \
12 signal_kern.o signal_user.o smp.o syscall_kern.o sysrq.o time.o \ 12 signal_kern.o signal_user.o smp.o syscall_kern.o sysrq.o time.o \
13 time_kern.o tlb.o trap_kern.o trap_user.o uaccess.o um_arch.o \ 13 time_kern.o tlb.o trap_kern.o trap_user.o uaccess.o um_arch.o \
@@ -24,8 +24,7 @@ obj-$(CONFIG_MODE_SKAS) += skas/
24 24
25user-objs-$(CONFIG_TTY_LOG) += tty_log.o 25user-objs-$(CONFIG_TTY_LOG) += tty_log.o
26 26
27USER_OBJS := $(user-objs-y) config.o helper.o time.o tty_log.o umid.o \ 27USER_OBJS := $(user-objs-y) config.o time.o tty_log.o umid.o user_util.o
28 user_util.o
29 28
30include arch/um/scripts/Makefile.rules 29include arch/um/scripts/Makefile.rules
31 30
diff --git a/arch/um/kernel/helper.c b/arch/um/kernel/helper.c
deleted file mode 100644
index 33fb0bd3b11a..000000000000
--- a/arch/um/kernel/helper.c
+++ /dev/null
@@ -1,165 +0,0 @@
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <unistd.h>
9#include <errno.h>
10#include <sched.h>
11#include <sys/signal.h>
12#include <sys/wait.h>
13#include "user.h"
14#include "kern_util.h"
15#include "user_util.h"
16#include "helper.h"
17#include "os.h"
18
19struct helper_data {
20 void (*pre_exec)(void*);
21 void *pre_data;
22 char **argv;
23 int fd;
24};
25
26/* Debugging aid, changed only from gdb */
27int helper_pause = 0;
28
29static void helper_hup(int sig)
30{
31}
32
33static int helper_child(void *arg)
34{
35 struct helper_data *data = arg;
36 char **argv = data->argv;
37 int errval;
38
39 if(helper_pause){
40 signal(SIGHUP, helper_hup);
41 pause();
42 }
43 if(data->pre_exec != NULL)
44 (*data->pre_exec)(data->pre_data);
45 execvp(argv[0], argv);
46 errval = errno;
47 printk("execvp of '%s' failed - errno = %d\n", argv[0], errno);
48 os_write_file(data->fd, &errval, sizeof(errval));
49 os_kill_process(os_getpid(), 0);
50 return(0);
51}
52
53/* Returns either the pid of the child process we run or -E* on failure.
54 * XXX The alloc_stack here breaks if this is called in the tracing thread */
55int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv,
56 unsigned long *stack_out)
57{
58 struct helper_data data;
59 unsigned long stack, sp;
60 int pid, fds[2], ret, n;
61
62 if((stack_out != NULL) && (*stack_out != 0))
63 stack = *stack_out;
64 else stack = alloc_stack(0, um_in_interrupt());
65 if(stack == 0)
66 return(-ENOMEM);
67
68 ret = os_pipe(fds, 1, 0);
69 if(ret < 0){
70 printk("run_helper : pipe failed, ret = %d\n", -ret);
71 goto out_free;
72 }
73
74 ret = os_set_exec_close(fds[1], 1);
75 if(ret < 0){
76 printk("run_helper : setting FD_CLOEXEC failed, ret = %d\n",
77 -ret);
78 goto out_close;
79 }
80
81 sp = stack + page_size() - sizeof(void *);
82 data.pre_exec = pre_exec;
83 data.pre_data = pre_data;
84 data.argv = argv;
85 data.fd = fds[1];
86 pid = clone(helper_child, (void *) sp, CLONE_VM | SIGCHLD, &data);
87 if(pid < 0){
88 ret = -errno;
89 printk("run_helper : clone failed, errno = %d\n", errno);
90 goto out_close;
91 }
92
93 os_close_file(fds[1]);
94 fds[1] = -1;
95
96 /*Read the errno value from the child.*/
97 n = os_read_file(fds[0], &ret, sizeof(ret));
98 if(n < 0){
99 printk("run_helper : read on pipe failed, ret = %d\n", -n);
100 ret = n;
101 os_kill_process(pid, 1);
102 }
103 else if(n != 0){
104 CATCH_EINTR(n = waitpid(pid, NULL, 0));
105 ret = -errno;
106 } else {
107 ret = pid;
108 }
109
110out_close:
111 if (fds[1] != -1)
112 os_close_file(fds[1]);
113 os_close_file(fds[0]);
114out_free:
115 if(stack_out == NULL)
116 free_stack(stack, 0);
117 else *stack_out = stack;
118 return(ret);
119}
120
121int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags,
122 unsigned long *stack_out, int stack_order)
123{
124 unsigned long stack, sp;
125 int pid, status, err;
126
127 stack = alloc_stack(stack_order, um_in_interrupt());
128 if(stack == 0) return(-ENOMEM);
129
130 sp = stack + (page_size() << stack_order) - sizeof(void *);
131 pid = clone(proc, (void *) sp, flags | SIGCHLD, arg);
132 if(pid < 0){
133 err = -errno;
134 printk("run_helper_thread : clone failed, errno = %d\n",
135 errno);
136 return err;
137 }
138 if(stack_out == NULL){
139 CATCH_EINTR(pid = waitpid(pid, &status, 0));
140 if(pid < 0){
141 err = -errno;
142 printk("run_helper_thread - wait failed, errno = %d\n",
143 errno);
144 pid = err;
145 }
146 if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
147 printk("run_helper_thread - thread returned status "
148 "0x%x\n", status);
149 free_stack(stack, stack_order);
150 }
151 else *stack_out = stack;
152 return(pid);
153}
154
155int helper_wait(int pid)
156{
157 int ret;
158
159 CATCH_EINTR(ret = waitpid(pid, NULL, WNOHANG));
160 if(ret < 0){
161 ret = -errno;
162 printk("helper_wait : waitpid failed, errno = %d\n", errno);
163 }
164 return(ret);
165}
diff --git a/arch/um/kernel/ksyms.c b/arch/um/kernel/ksyms.c
index a97a72e516aa..7713e7a6f476 100644
--- a/arch/um/kernel/ksyms.c
+++ b/arch/um/kernel/ksyms.c
@@ -20,7 +20,6 @@
20#include "user_util.h" 20#include "user_util.h"
21#include "mem_user.h" 21#include "mem_user.h"
22#include "os.h" 22#include "os.h"
23#include "helper.h"
24 23
25EXPORT_SYMBOL(stop); 24EXPORT_SYMBOL(stop);
26EXPORT_SYMBOL(uml_physmem); 25EXPORT_SYMBOL(uml_physmem);
diff --git a/arch/um/kernel/sigio_user.c b/arch/um/kernel/sigio_user.c
index a52751108aa1..3fbfd956bfe7 100644
--- a/arch/um/kernel/sigio_user.c
+++ b/arch/um/kernel/sigio_user.c
@@ -18,7 +18,6 @@
18#include "kern_util.h" 18#include "kern_util.h"
19#include "user_util.h" 19#include "user_util.h"
20#include "sigio.h" 20#include "sigio.h"
21#include "helper.h"
22#include "os.h" 21#include "os.h"
23 22
24/* Changed during early boot */ 23/* Changed during early boot */
diff --git a/arch/um/kernel/user_util.c b/arch/um/kernel/user_util.c
index 41d17c71511c..4c231161f257 100644
--- a/arch/um/kernel/user_util.c
+++ b/arch/um/kernel/user_util.c
@@ -27,7 +27,6 @@
27#include "user.h" 27#include "user.h"
28#include "mem_user.h" 28#include "mem_user.h"
29#include "init.h" 29#include "init.h"
30#include "helper.h"
31#include "ptrace_user.h" 30#include "ptrace_user.h"
32#include "uml-config.h" 31#include "uml-config.h"
33 32