diff options
author | Gennady Sharapov <Gennady.V.Sharapov@intel.com> | 2006-01-18 20:42:41 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-18 22:20:19 -0500 |
commit | 4fef0c10fa174b57a10854b8b4b2b90d155706e0 (patch) | |
tree | 02cfcc989114da9a6d46484753937cc0e3a60b52 /arch/um/os-Linux | |
parent | 12919aa6e015dd85170fc3b1a3e10a5dfd116c72 (diff) |
[PATCH] uml: move libc-dependent utility procedures
The serial UML OS-abstraction layer patch (um/kernel dir).
This moves all systemcalls from user_util.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 'Blaisorblade' 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/os-Linux')
-rw-r--r-- | arch/um/os-Linux/Makefile | 4 | ||||
-rw-r--r-- | arch/um/os-Linux/tt.c | 48 | ||||
-rw-r--r-- | arch/um/os-Linux/util.c | 116 |
3 files changed, 166 insertions, 2 deletions
diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index 40c7d6b1df68..08a4e628b24c 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile | |||
@@ -5,12 +5,12 @@ | |||
5 | 5 | ||
6 | obj-y = aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \ | 6 | obj-y = aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \ |
7 | start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o user_syms.o \ | 7 | start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o user_syms.o \ |
8 | drivers/ sys-$(SUBARCH)/ | 8 | util.o drivers/ sys-$(SUBARCH)/ |
9 | 9 | ||
10 | obj-$(CONFIG_MODE_SKAS) += skas/ | 10 | obj-$(CONFIG_MODE_SKAS) += skas/ |
11 | 11 | ||
12 | USER_OBJS := aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \ | 12 | USER_OBJS := aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \ |
13 | start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o | 13 | start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o util.o |
14 | 14 | ||
15 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h | 15 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h |
16 | CFLAGS_elf_aux.o += -I$(objtree)/arch/um | 16 | CFLAGS_elf_aux.o += -I$(objtree)/arch/um |
diff --git a/arch/um/os-Linux/tt.c b/arch/um/os-Linux/tt.c index cb2648b79d0f..404bb63a74a9 100644 --- a/arch/um/os-Linux/tt.c +++ b/arch/um/os-Linux/tt.c | |||
@@ -63,6 +63,54 @@ void kill_child_dead(int pid) | |||
63 | } while(1); | 63 | } while(1); |
64 | } | 64 | } |
65 | 65 | ||
66 | void stop(void) | ||
67 | { | ||
68 | while(1) sleep(1000000); | ||
69 | } | ||
70 | |||
71 | int wait_for_stop(int pid, int sig, int cont_type, void *relay) | ||
72 | { | ||
73 | sigset_t *relay_signals = relay; | ||
74 | int status, ret; | ||
75 | |||
76 | while(1){ | ||
77 | CATCH_EINTR(ret = waitpid(pid, &status, WUNTRACED)); | ||
78 | if((ret < 0) || | ||
79 | !WIFSTOPPED(status) || (WSTOPSIG(status) != sig)){ | ||
80 | if(ret < 0){ | ||
81 | printk("wait failed, errno = %d\n", | ||
82 | errno); | ||
83 | } | ||
84 | else if(WIFEXITED(status)) | ||
85 | printk("process %d exited with status %d\n", | ||
86 | pid, WEXITSTATUS(status)); | ||
87 | else if(WIFSIGNALED(status)) | ||
88 | printk("process %d exited with signal %d\n", | ||
89 | pid, WTERMSIG(status)); | ||
90 | else if((WSTOPSIG(status) == SIGVTALRM) || | ||
91 | (WSTOPSIG(status) == SIGALRM) || | ||
92 | (WSTOPSIG(status) == SIGIO) || | ||
93 | (WSTOPSIG(status) == SIGPROF) || | ||
94 | (WSTOPSIG(status) == SIGCHLD) || | ||
95 | (WSTOPSIG(status) == SIGWINCH) || | ||
96 | (WSTOPSIG(status) == SIGINT)){ | ||
97 | ptrace(cont_type, pid, 0, WSTOPSIG(status)); | ||
98 | continue; | ||
99 | } | ||
100 | else if((relay_signals != NULL) && | ||
101 | sigismember(relay_signals, WSTOPSIG(status))){ | ||
102 | ptrace(cont_type, pid, 0, WSTOPSIG(status)); | ||
103 | continue; | ||
104 | } | ||
105 | else printk("process %d stopped with signal %d\n", | ||
106 | pid, WSTOPSIG(status)); | ||
107 | panic("wait_for_stop failed to wait for %d to stop " | ||
108 | "with %d\n", pid, sig); | ||
109 | } | ||
110 | return(status); | ||
111 | } | ||
112 | } | ||
113 | |||
66 | /* | 114 | /* |
67 | *------------------------- | 115 | *------------------------- |
68 | * only for tt mode (will be deleted in future...) | 116 | * only for tt mode (will be deleted in future...) |
diff --git a/arch/um/os-Linux/util.c b/arch/um/os-Linux/util.c new file mode 100644 index 000000000000..d224434d5610 --- /dev/null +++ b/arch/um/os-Linux/util.c | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2000, 2001, 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 <limits.h> | ||
10 | #include <setjmp.h> | ||
11 | #include <sys/mman.h> | ||
12 | #include <sys/stat.h> | ||
13 | #include <sys/utsname.h> | ||
14 | #include <sys/param.h> | ||
15 | #include <sys/time.h> | ||
16 | #include "asm/types.h" | ||
17 | #include <ctype.h> | ||
18 | #include <signal.h> | ||
19 | #include <wait.h> | ||
20 | #include <errno.h> | ||
21 | #include <stdarg.h> | ||
22 | #include <sched.h> | ||
23 | #include <termios.h> | ||
24 | #include <string.h> | ||
25 | #include "user_util.h" | ||
26 | #include "kern_util.h" | ||
27 | #include "user.h" | ||
28 | #include "mem_user.h" | ||
29 | #include "init.h" | ||
30 | #include "ptrace_user.h" | ||
31 | #include "uml-config.h" | ||
32 | #include "os.h" | ||
33 | |||
34 | void stack_protections(unsigned long address) | ||
35 | { | ||
36 | int prot = PROT_READ | PROT_WRITE | PROT_EXEC; | ||
37 | |||
38 | if(mprotect((void *) address, page_size(), prot) < 0) | ||
39 | panic("protecting stack failed, errno = %d", errno); | ||
40 | } | ||
41 | |||
42 | void task_protections(unsigned long address) | ||
43 | { | ||
44 | unsigned long guard = address + page_size(); | ||
45 | unsigned long stack = guard + page_size(); | ||
46 | int prot = 0, pages; | ||
47 | |||
48 | #ifdef notdef | ||
49 | if(mprotect((void *) stack, page_size(), prot) < 0) | ||
50 | panic("protecting guard page failed, errno = %d", errno); | ||
51 | #endif | ||
52 | pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER) - 2; | ||
53 | prot = PROT_READ | PROT_WRITE | PROT_EXEC; | ||
54 | if(mprotect((void *) stack, pages * page_size(), prot) < 0) | ||
55 | panic("protecting stack failed, errno = %d", errno); | ||
56 | } | ||
57 | |||
58 | int raw(int fd) | ||
59 | { | ||
60 | struct termios tt; | ||
61 | int err; | ||
62 | |||
63 | CATCH_EINTR(err = tcgetattr(fd, &tt)); | ||
64 | if(err < 0) | ||
65 | return -errno; | ||
66 | |||
67 | cfmakeraw(&tt); | ||
68 | |||
69 | CATCH_EINTR(err = tcsetattr(fd, TCSADRAIN, &tt)); | ||
70 | if(err < 0) | ||
71 | return -errno; | ||
72 | |||
73 | /* XXX tcsetattr could have applied only some changes | ||
74 | * (and cfmakeraw() is a set of changes) */ | ||
75 | return(0); | ||
76 | } | ||
77 | |||
78 | void setup_machinename(char *machine_out) | ||
79 | { | ||
80 | struct utsname host; | ||
81 | |||
82 | uname(&host); | ||
83 | #if defined(UML_CONFIG_UML_X86) && !defined(UML_CONFIG_64BIT) | ||
84 | if (!strcmp(host.machine, "x86_64")) { | ||
85 | strcpy(machine_out, "i686"); | ||
86 | return; | ||
87 | } | ||
88 | #endif | ||
89 | strcpy(machine_out, host.machine); | ||
90 | } | ||
91 | |||
92 | char host_info[(_UTSNAME_LENGTH + 1) * 4 + _UTSNAME_NODENAME_LENGTH + 1]; | ||
93 | |||
94 | void setup_hostinfo(void) | ||
95 | { | ||
96 | struct utsname host; | ||
97 | |||
98 | uname(&host); | ||
99 | sprintf(host_info, "%s %s %s %s %s", host.sysname, host.nodename, | ||
100 | host.release, host.version, host.machine); | ||
101 | } | ||
102 | |||
103 | int setjmp_wrapper(void (*proc)(void *, void *), ...) | ||
104 | { | ||
105 | va_list args; | ||
106 | sigjmp_buf buf; | ||
107 | int n; | ||
108 | |||
109 | n = sigsetjmp(buf, 1); | ||
110 | if(n == 0){ | ||
111 | va_start(args, proc); | ||
112 | (*proc)(&buf, &args); | ||
113 | } | ||
114 | va_end(args); | ||
115 | return(n); | ||
116 | } | ||