diff options
Diffstat (limited to 'arch/um/os-Linux')
| -rw-r--r-- | arch/um/os-Linux/Makefile | 9 | ||||
| -rw-r--r-- | arch/um/os-Linux/aio.c | 1 | ||||
| -rw-r--r-- | arch/um/os-Linux/drivers/ethertap_user.c | 1 | ||||
| -rw-r--r-- | arch/um/os-Linux/drivers/tuntap_user.c | 1 | ||||
| -rw-r--r-- | arch/um/os-Linux/helper.c | 165 | ||||
| -rw-r--r-- | arch/um/os-Linux/main.c | 259 | ||||
| -rw-r--r-- | arch/um/os-Linux/mem.c | 6 | ||||
| -rw-r--r-- | arch/um/os-Linux/start_up.c | 77 | ||||
| -rw-r--r-- | arch/um/os-Linux/uaccess.c | 32 |
9 files changed, 535 insertions, 16 deletions
diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index d15ec2af6a22..b83ac8e21c35 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile | |||
| @@ -3,11 +3,12 @@ | |||
| 3 | # Licensed under the GPL | 3 | # Licensed under the GPL |
| 4 | # | 4 | # |
| 5 | 5 | ||
| 6 | obj-y = aio.o elf_aux.o file.o mem.o process.o signal.o start_up.o time.o \ | 6 | obj-y = aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \ |
| 7 | tt.o tty.o user_syms.o drivers/ sys-$(SUBARCH)/ | 7 | start_up.o time.o tt.o tty.o uaccess.o user_syms.o drivers/ \ |
| 8 | sys-$(SUBARCH)/ | ||
| 8 | 9 | ||
| 9 | USER_OBJS := aio.o elf_aux.o file.o mem.o process.o signal.o start_up.o \ | 10 | USER_OBJS := aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \ |
| 10 | time.o tt.o tty.o | 11 | start_up.o time.o tt.o tty.o uaccess.o |
| 11 | 12 | ||
| 12 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h | 13 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h |
| 13 | CFLAGS_elf_aux.o += -I$(objtree)/arch/um | 14 | CFLAGS_elf_aux.o += -I$(objtree)/arch/um |
diff --git a/arch/um/os-Linux/aio.c b/arch/um/os-Linux/aio.c index 41cfb0944201..ffa759addd3c 100644 --- a/arch/um/os-Linux/aio.c +++ b/arch/um/os-Linux/aio.c | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | #include <sched.h> | 10 | #include <sched.h> |
| 11 | #include <sys/syscall.h> | 11 | #include <sys/syscall.h> |
| 12 | #include "os.h" | 12 | #include "os.h" |
| 13 | #include "helper.h" | ||
| 14 | #include "aio.h" | 13 | #include "aio.h" |
| 15 | #include "init.h" | 14 | #include "init.h" |
| 16 | #include "user.h" | 15 | #include "user.h" |
diff --git a/arch/um/os-Linux/drivers/ethertap_user.c b/arch/um/os-Linux/drivers/ethertap_user.c index cd4d6544da71..901b85e8a1c6 100644 --- a/arch/um/os-Linux/drivers/ethertap_user.c +++ b/arch/um/os-Linux/drivers/ethertap_user.c | |||
| @@ -19,7 +19,6 @@ | |||
| 19 | #include "user_util.h" | 19 | #include "user_util.h" |
| 20 | #include "net_user.h" | 20 | #include "net_user.h" |
| 21 | #include "etap.h" | 21 | #include "etap.h" |
| 22 | #include "helper.h" | ||
| 23 | #include "os.h" | 22 | #include "os.h" |
| 24 | 23 | ||
| 25 | #define MAX_PACKET ETH_MAX_PACKET | 24 | #define MAX_PACKET ETH_MAX_PACKET |
diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/arch/um/os-Linux/drivers/tuntap_user.c index 4ba9b17adf13..52945338b64d 100644 --- a/arch/um/os-Linux/drivers/tuntap_user.c +++ b/arch/um/os-Linux/drivers/tuntap_user.c | |||
| @@ -20,7 +20,6 @@ | |||
| 20 | #include "kern_util.h" | 20 | #include "kern_util.h" |
| 21 | #include "user_util.h" | 21 | #include "user_util.h" |
| 22 | #include "user.h" | 22 | #include "user.h" |
| 23 | #include "helper.h" | ||
| 24 | #include "os.h" | 23 | #include "os.h" |
| 25 | 24 | ||
| 26 | #define MAX_PACKET ETH_MAX_PACKET | 25 | #define MAX_PACKET ETH_MAX_PACKET |
diff --git a/arch/um/os-Linux/helper.c b/arch/um/os-Linux/helper.c new file mode 100644 index 000000000000..36cc8475bcda --- /dev/null +++ b/arch/um/os-Linux/helper.c | |||
| @@ -0,0 +1,165 @@ | |||
| 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 "os.h" | ||
| 17 | |||
| 18 | struct helper_data { | ||
| 19 | void (*pre_exec)(void*); | ||
| 20 | void *pre_data; | ||
| 21 | char **argv; | ||
| 22 | int fd; | ||
| 23 | }; | ||
| 24 | |||
| 25 | /* Debugging aid, changed only from gdb */ | ||
| 26 | int helper_pause = 0; | ||
| 27 | |||
| 28 | static void helper_hup(int sig) | ||
| 29 | { | ||
| 30 | } | ||
| 31 | |||
| 32 | static int helper_child(void *arg) | ||
| 33 | { | ||
| 34 | struct helper_data *data = arg; | ||
| 35 | char **argv = data->argv; | ||
| 36 | int errval; | ||
| 37 | |||
| 38 | if(helper_pause){ | ||
| 39 | signal(SIGHUP, helper_hup); | ||
| 40 | pause(); | ||
| 41 | } | ||
| 42 | if(data->pre_exec != NULL) | ||
| 43 | (*data->pre_exec)(data->pre_data); | ||
| 44 | execvp(argv[0], argv); | ||
| 45 | errval = errno; | ||
| 46 | printk("execvp of '%s' failed - errno = %d\n", argv[0], errno); | ||
| 47 | os_write_file(data->fd, &errval, sizeof(errval)); | ||
| 48 | kill(os_getpid(), SIGKILL); | ||
| 49 | return(0); | ||
| 50 | } | ||
| 51 | |||
| 52 | /* Returns either the pid of the child process we run or -E* on failure. | ||
| 53 | * XXX The alloc_stack here breaks if this is called in the tracing thread */ | ||
| 54 | int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv, | ||
| 55 | unsigned long *stack_out) | ||
| 56 | { | ||
| 57 | struct helper_data data; | ||
| 58 | unsigned long stack, sp; | ||
| 59 | int pid, fds[2], ret, n; | ||
| 60 | |||
| 61 | if((stack_out != NULL) && (*stack_out != 0)) | ||
| 62 | stack = *stack_out; | ||
| 63 | else stack = alloc_stack(0, um_in_interrupt()); | ||
| 64 | if(stack == 0) | ||
| 65 | return(-ENOMEM); | ||
| 66 | |||
| 67 | ret = os_pipe(fds, 1, 0); | ||
| 68 | if(ret < 0){ | ||
| 69 | printk("run_helper : pipe failed, ret = %d\n", -ret); | ||
| 70 | goto out_free; | ||
| 71 | } | ||
| 72 | |||
| 73 | ret = os_set_exec_close(fds[1], 1); | ||
| 74 | if(ret < 0){ | ||
| 75 | printk("run_helper : setting FD_CLOEXEC failed, ret = %d\n", | ||
| 76 | -ret); | ||
| 77 | goto out_close; | ||
| 78 | } | ||
| 79 | |||
| 80 | sp = stack + page_size() - sizeof(void *); | ||
| 81 | data.pre_exec = pre_exec; | ||
| 82 | data.pre_data = pre_data; | ||
| 83 | data.argv = argv; | ||
| 84 | data.fd = fds[1]; | ||
| 85 | pid = clone(helper_child, (void *) sp, CLONE_VM | SIGCHLD, &data); | ||
| 86 | if(pid < 0){ | ||
| 87 | ret = -errno; | ||
| 88 | printk("run_helper : clone failed, errno = %d\n", errno); | ||
| 89 | goto out_close; | ||
| 90 | } | ||
| 91 | |||
| 92 | close(fds[1]); | ||
| 93 | fds[1] = -1; | ||
| 94 | |||
| 95 | /*Read the errno value from the child.*/ | ||
| 96 | n = os_read_file(fds[0], &ret, sizeof(ret)); | ||
| 97 | if(n < 0){ | ||
| 98 | printk("run_helper : read on pipe failed, ret = %d\n", -n); | ||
| 99 | ret = n; | ||
| 100 | kill(pid, SIGKILL); | ||
| 101 | CATCH_EINTR(waitpid(pid, NULL, 0)); | ||
| 102 | } | ||
| 103 | else if(n != 0){ | ||
| 104 | CATCH_EINTR(n = waitpid(pid, NULL, 0)); | ||
| 105 | ret = -errno; | ||
| 106 | } else { | ||
| 107 | ret = pid; | ||
| 108 | } | ||
| 109 | |||
| 110 | out_close: | ||
| 111 | if (fds[1] != -1) | ||
| 112 | close(fds[1]); | ||
| 113 | close(fds[0]); | ||
| 114 | out_free: | ||
| 115 | if(stack_out == NULL) | ||
| 116 | free_stack(stack, 0); | ||
| 117 | else *stack_out = stack; | ||
| 118 | return(ret); | ||
| 119 | } | ||
| 120 | |||
| 121 | int 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 | |||
| 155 | int 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/os-Linux/main.c b/arch/um/os-Linux/main.c new file mode 100644 index 000000000000..23da27d22569 --- /dev/null +++ b/arch/um/os-Linux/main.c | |||
| @@ -0,0 +1,259 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) | ||
| 3 | * Licensed under the GPL | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <unistd.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <signal.h> | ||
| 11 | #include <errno.h> | ||
| 12 | #include <sys/resource.h> | ||
| 13 | #include <sys/mman.h> | ||
| 14 | #include <sys/user.h> | ||
| 15 | #include <asm/page.h> | ||
| 16 | #include "user_util.h" | ||
| 17 | #include "kern_util.h" | ||
| 18 | #include "mem_user.h" | ||
| 19 | #include "signal_user.h" | ||
| 20 | #include "time_user.h" | ||
| 21 | #include "irq_user.h" | ||
| 22 | #include "user.h" | ||
| 23 | #include "init.h" | ||
| 24 | #include "mode.h" | ||
| 25 | #include "choose-mode.h" | ||
| 26 | #include "uml-config.h" | ||
| 27 | #include "os.h" | ||
| 28 | |||
| 29 | /* Set in set_stklim, which is called from main and __wrap_malloc. | ||
| 30 | * __wrap_malloc only calls it if main hasn't started. | ||
| 31 | */ | ||
| 32 | unsigned long stacksizelim; | ||
| 33 | |||
| 34 | /* Set in main */ | ||
| 35 | char *linux_prog; | ||
| 36 | |||
| 37 | #define PGD_BOUND (4 * 1024 * 1024) | ||
| 38 | #define STACKSIZE (8 * 1024 * 1024) | ||
| 39 | #define THREAD_NAME_LEN (256) | ||
| 40 | |||
| 41 | static void set_stklim(void) | ||
| 42 | { | ||
| 43 | struct rlimit lim; | ||
| 44 | |||
| 45 | if(getrlimit(RLIMIT_STACK, &lim) < 0){ | ||
| 46 | perror("getrlimit"); | ||
| 47 | exit(1); | ||
| 48 | } | ||
| 49 | if((lim.rlim_cur == RLIM_INFINITY) || (lim.rlim_cur > STACKSIZE)){ | ||
| 50 | lim.rlim_cur = STACKSIZE; | ||
| 51 | if(setrlimit(RLIMIT_STACK, &lim) < 0){ | ||
| 52 | perror("setrlimit"); | ||
| 53 | exit(1); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | stacksizelim = (lim.rlim_cur + PGD_BOUND - 1) & ~(PGD_BOUND - 1); | ||
| 57 | } | ||
| 58 | |||
| 59 | static __init void do_uml_initcalls(void) | ||
| 60 | { | ||
| 61 | initcall_t *call; | ||
| 62 | |||
| 63 | call = &__uml_initcall_start; | ||
| 64 | while (call < &__uml_initcall_end){; | ||
| 65 | (*call)(); | ||
| 66 | call++; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | static void last_ditch_exit(int sig) | ||
| 71 | { | ||
| 72 | signal(SIGINT, SIG_DFL); | ||
| 73 | signal(SIGTERM, SIG_DFL); | ||
| 74 | signal(SIGHUP, SIG_DFL); | ||
| 75 | uml_cleanup(); | ||
| 76 | exit(1); | ||
| 77 | } | ||
| 78 | |||
| 79 | extern int uml_exitcode; | ||
| 80 | |||
| 81 | extern void scan_elf_aux( char **envp); | ||
| 82 | |||
| 83 | int main(int argc, char **argv, char **envp) | ||
| 84 | { | ||
| 85 | char **new_argv; | ||
| 86 | sigset_t mask; | ||
| 87 | int ret, i, err; | ||
| 88 | |||
| 89 | /* Enable all signals except SIGIO - in some environments, we can | ||
| 90 | * enter with some signals blocked | ||
| 91 | */ | ||
| 92 | |||
| 93 | sigemptyset(&mask); | ||
| 94 | sigaddset(&mask, SIGIO); | ||
| 95 | if(sigprocmask(SIG_SETMASK, &mask, NULL) < 0){ | ||
| 96 | perror("sigprocmask"); | ||
| 97 | exit(1); | ||
| 98 | } | ||
| 99 | |||
| 100 | #ifdef UML_CONFIG_CMDLINE_ON_HOST | ||
| 101 | /* Allocate memory for thread command lines */ | ||
| 102 | if(argc < 2 || strlen(argv[1]) < THREAD_NAME_LEN - 1){ | ||
| 103 | |||
| 104 | char padding[THREAD_NAME_LEN] = { | ||
| 105 | [ 0 ... THREAD_NAME_LEN - 2] = ' ', '\0' | ||
| 106 | }; | ||
| 107 | |||
| 108 | new_argv = malloc((argc + 2) * sizeof(char*)); | ||
| 109 | if(!new_argv) { | ||
| 110 | perror("Allocating extended argv"); | ||
| 111 | exit(1); | ||
| 112 | } | ||
| 113 | |||
| 114 | new_argv[0] = argv[0]; | ||
| 115 | new_argv[1] = padding; | ||
| 116 | |||
| 117 | for(i = 2; i <= argc; i++) | ||
| 118 | new_argv[i] = argv[i - 1]; | ||
| 119 | new_argv[argc + 1] = NULL; | ||
| 120 | |||
| 121 | execvp(new_argv[0], new_argv); | ||
| 122 | perror("execing with extended args"); | ||
| 123 | exit(1); | ||
| 124 | } | ||
| 125 | #endif | ||
| 126 | |||
| 127 | linux_prog = argv[0]; | ||
| 128 | |||
| 129 | set_stklim(); | ||
| 130 | |||
| 131 | new_argv = malloc((argc + 1) * sizeof(char *)); | ||
| 132 | if(new_argv == NULL){ | ||
| 133 | perror("Mallocing argv"); | ||
| 134 | exit(1); | ||
| 135 | } | ||
| 136 | for(i=0;i<argc;i++){ | ||
| 137 | new_argv[i] = strdup(argv[i]); | ||
| 138 | if(new_argv[i] == NULL){ | ||
| 139 | perror("Mallocing an arg"); | ||
| 140 | exit(1); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | new_argv[argc] = NULL; | ||
| 144 | |||
| 145 | set_handler(SIGINT, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1); | ||
| 146 | set_handler(SIGTERM, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1); | ||
| 147 | set_handler(SIGHUP, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1); | ||
| 148 | |||
| 149 | scan_elf_aux( envp); | ||
| 150 | |||
| 151 | do_uml_initcalls(); | ||
| 152 | ret = linux_main(argc, argv); | ||
| 153 | |||
| 154 | /* Disable SIGPROF - I have no idea why libc doesn't do this or turn | ||
| 155 | * off the profiling time, but UML dies with a SIGPROF just before | ||
| 156 | * exiting when profiling is active. | ||
| 157 | */ | ||
| 158 | change_sig(SIGPROF, 0); | ||
| 159 | |||
| 160 | /* This signal stuff used to be in the reboot case. However, | ||
| 161 | * sometimes a SIGVTALRM can come in when we're halting (reproducably | ||
| 162 | * when writing out gcov information, presumably because that takes | ||
| 163 | * some time) and cause a segfault. | ||
| 164 | */ | ||
| 165 | |||
| 166 | /* stop timers and set SIG*ALRM to be ignored */ | ||
| 167 | disable_timer(); | ||
| 168 | |||
| 169 | /* disable SIGIO for the fds and set SIGIO to be ignored */ | ||
| 170 | err = deactivate_all_fds(); | ||
| 171 | if(err) | ||
| 172 | printf("deactivate_all_fds failed, errno = %d\n", -err); | ||
| 173 | |||
| 174 | /* Let any pending signals fire now. This ensures | ||
| 175 | * that they won't be delivered after the exec, when | ||
| 176 | * they are definitely not expected. | ||
| 177 | */ | ||
| 178 | unblock_signals(); | ||
| 179 | |||
| 180 | /* Reboot */ | ||
| 181 | if(ret){ | ||
| 182 | printf("\n"); | ||
| 183 | execvp(new_argv[0], new_argv); | ||
| 184 | perror("Failed to exec kernel"); | ||
| 185 | ret = 1; | ||
| 186 | } | ||
| 187 | printf("\n"); | ||
| 188 | return(uml_exitcode); | ||
| 189 | } | ||
| 190 | |||
| 191 | #define CAN_KMALLOC() \ | ||
| 192 | (kmalloc_ok && CHOOSE_MODE((os_getpid() != tracing_pid), 1)) | ||
| 193 | |||
| 194 | extern void *__real_malloc(int); | ||
| 195 | |||
| 196 | void *__wrap_malloc(int size) | ||
| 197 | { | ||
| 198 | void *ret; | ||
| 199 | |||
| 200 | if(!CAN_KMALLOC()) | ||
| 201 | return(__real_malloc(size)); | ||
| 202 | else if(size <= PAGE_SIZE) /* finding contiguos pages can be hard*/ | ||
| 203 | ret = um_kmalloc(size); | ||
| 204 | else ret = um_vmalloc(size); | ||
| 205 | |||
| 206 | /* glibc people insist that if malloc fails, errno should be | ||
| 207 | * set by malloc as well. So we do. | ||
| 208 | */ | ||
| 209 | if(ret == NULL) | ||
| 210 | errno = ENOMEM; | ||
| 211 | |||
| 212 | return(ret); | ||
| 213 | } | ||
| 214 | |||
| 215 | void *__wrap_calloc(int n, int size) | ||
| 216 | { | ||
| 217 | void *ptr = __wrap_malloc(n * size); | ||
| 218 | |||
| 219 | if(ptr == NULL) return(NULL); | ||
| 220 | memset(ptr, 0, n * size); | ||
| 221 | return(ptr); | ||
| 222 | } | ||
| 223 | |||
| 224 | extern void __real_free(void *); | ||
| 225 | |||
| 226 | extern unsigned long high_physmem; | ||
| 227 | |||
| 228 | void __wrap_free(void *ptr) | ||
| 229 | { | ||
| 230 | unsigned long addr = (unsigned long) ptr; | ||
| 231 | |||
| 232 | /* We need to know how the allocation happened, so it can be correctly | ||
| 233 | * freed. This is done by seeing what region of memory the pointer is | ||
| 234 | * in - | ||
| 235 | * physical memory - kmalloc/kfree | ||
| 236 | * kernel virtual memory - vmalloc/vfree | ||
| 237 | * anywhere else - malloc/free | ||
| 238 | * If kmalloc is not yet possible, then either high_physmem and/or | ||
| 239 | * end_vm are still 0 (as at startup), in which case we call free, or | ||
| 240 | * we have set them, but anyway addr has not been allocated from those | ||
| 241 | * areas. So, in both cases __real_free is called. | ||
| 242 | * | ||
| 243 | * CAN_KMALLOC is checked because it would be bad to free a buffer | ||
| 244 | * with kmalloc/vmalloc after they have been turned off during | ||
| 245 | * shutdown. | ||
| 246 | * XXX: However, we sometimes shutdown CAN_KMALLOC temporarily, so | ||
| 247 | * there is a possibility for memory leaks. | ||
| 248 | */ | ||
| 249 | |||
| 250 | if((addr >= uml_physmem) && (addr < high_physmem)){ | ||
| 251 | if(CAN_KMALLOC()) | ||
| 252 | kfree(ptr); | ||
| 253 | } | ||
| 254 | else if((addr >= start_vm) && (addr < end_vm)){ | ||
| 255 | if(CAN_KMALLOC()) | ||
| 256 | vfree(ptr); | ||
| 257 | } | ||
| 258 | else __real_free(ptr); | ||
| 259 | } | ||
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index 8e71edaaf80b..9d7d69a523bb 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c | |||
| @@ -88,7 +88,7 @@ int make_tempfile(const char *template, char **out_tempname, int do_unlink) | |||
| 88 | * This proc is used in start_up.c | 88 | * This proc is used in start_up.c |
| 89 | * So it isn't 'static'. | 89 | * So it isn't 'static'. |
| 90 | */ | 90 | */ |
| 91 | int create_tmp_file(unsigned long len) | 91 | int create_tmp_file(unsigned long long len) |
| 92 | { | 92 | { |
| 93 | int fd, err; | 93 | int fd, err; |
| 94 | char zero; | 94 | char zero; |
| @@ -121,7 +121,7 @@ int create_tmp_file(unsigned long len) | |||
| 121 | return(fd); | 121 | return(fd); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | static int create_anon_file(unsigned long len) | 124 | static int create_anon_file(unsigned long long len) |
| 125 | { | 125 | { |
| 126 | void *addr; | 126 | void *addr; |
| 127 | int fd; | 127 | int fd; |
| @@ -144,7 +144,7 @@ static int create_anon_file(unsigned long len) | |||
| 144 | 144 | ||
| 145 | extern int have_devanon; | 145 | extern int have_devanon; |
| 146 | 146 | ||
| 147 | int create_mem_file(unsigned long len) | 147 | int create_mem_file(unsigned long long len) |
| 148 | { | 148 | { |
| 149 | int err, fd; | 149 | int err, fd; |
| 150 | 150 | ||
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c index b99ab414542f..37517d49c4ae 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c | |||
| @@ -135,7 +135,9 @@ static int stop_ptraced_child(int pid, void *stack, int exitcode, | |||
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | int ptrace_faultinfo = 1; | 137 | int ptrace_faultinfo = 1; |
| 138 | int ptrace_ldt = 1; | ||
| 138 | int proc_mm = 1; | 139 | int proc_mm = 1; |
| 140 | int skas_needs_stub = 0; | ||
| 139 | 141 | ||
| 140 | static int __init skas0_cmd_param(char *str, int* add) | 142 | static int __init skas0_cmd_param(char *str, int* add) |
| 141 | { | 143 | { |
| @@ -294,7 +296,7 @@ static void __init check_ptrace(void) | |||
| 294 | check_sysemu(); | 296 | check_sysemu(); |
| 295 | } | 297 | } |
| 296 | 298 | ||
| 297 | extern int create_tmp_file(unsigned long len); | 299 | extern int create_tmp_file(unsigned long long len); |
| 298 | 300 | ||
| 299 | static void check_tmpexec(void) | 301 | static void check_tmpexec(void) |
| 300 | { | 302 | { |
| @@ -352,14 +354,26 @@ __uml_setup("noptracefaultinfo", noptracefaultinfo_cmd_param, | |||
| 352 | " it. To support PTRACE_FAULTINFO, the host needs to be patched\n" | 354 | " it. To support PTRACE_FAULTINFO, the host needs to be patched\n" |
| 353 | " using the current skas3 patch.\n\n"); | 355 | " using the current skas3 patch.\n\n"); |
| 354 | 356 | ||
| 357 | static int __init noptraceldt_cmd_param(char *str, int* add) | ||
| 358 | { | ||
| 359 | ptrace_ldt = 0; | ||
| 360 | return 0; | ||
| 361 | } | ||
| 362 | |||
| 363 | __uml_setup("noptraceldt", noptraceldt_cmd_param, | ||
| 364 | "noptraceldt\n" | ||
| 365 | " Turns off usage of PTRACE_LDT, even if host supports it.\n" | ||
| 366 | " To support PTRACE_LDT, the host needs to be patched using\n" | ||
| 367 | " the current skas3 patch.\n\n"); | ||
| 368 | |||
| 355 | #ifdef UML_CONFIG_MODE_SKAS | 369 | #ifdef UML_CONFIG_MODE_SKAS |
| 356 | static inline void check_skas3_ptrace_support(void) | 370 | static inline void check_skas3_ptrace_faultinfo(void) |
| 357 | { | 371 | { |
| 358 | struct ptrace_faultinfo fi; | 372 | struct ptrace_faultinfo fi; |
| 359 | void *stack; | 373 | void *stack; |
| 360 | int pid, n; | 374 | int pid, n; |
| 361 | 375 | ||
| 362 | printf("Checking for the skas3 patch in the host..."); | 376 | printf(" - PTRACE_FAULTINFO..."); |
| 363 | pid = start_ptraced_child(&stack); | 377 | pid = start_ptraced_child(&stack); |
| 364 | 378 | ||
| 365 | n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi); | 379 | n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi); |
| @@ -381,9 +395,49 @@ static inline void check_skas3_ptrace_support(void) | |||
| 381 | stop_ptraced_child(pid, stack, 1, 1); | 395 | stop_ptraced_child(pid, stack, 1, 1); |
| 382 | } | 396 | } |
| 383 | 397 | ||
| 384 | int can_do_skas(void) | 398 | static inline void check_skas3_ptrace_ldt(void) |
| 399 | { | ||
| 400 | #ifdef PTRACE_LDT | ||
| 401 | void *stack; | ||
| 402 | int pid, n; | ||
| 403 | unsigned char ldtbuf[40]; | ||
| 404 | struct ptrace_ldt ldt_op = (struct ptrace_ldt) { | ||
| 405 | .func = 2, /* read default ldt */ | ||
| 406 | .ptr = ldtbuf, | ||
| 407 | .bytecount = sizeof(ldtbuf)}; | ||
| 408 | |||
| 409 | printf(" - PTRACE_LDT..."); | ||
| 410 | pid = start_ptraced_child(&stack); | ||
| 411 | |||
| 412 | n = ptrace(PTRACE_LDT, pid, 0, (unsigned long) &ldt_op); | ||
| 413 | if (n < 0) { | ||
| 414 | if(errno == EIO) | ||
| 415 | printf("not found\n"); | ||
| 416 | else { | ||
| 417 | perror("not found"); | ||
| 418 | } | ||
| 419 | ptrace_ldt = 0; | ||
| 420 | } | ||
| 421 | else { | ||
| 422 | if(ptrace_ldt) | ||
| 423 | printf("found\n"); | ||
| 424 | else | ||
| 425 | printf("found, but use is disabled\n"); | ||
| 426 | } | ||
| 427 | |||
| 428 | stop_ptraced_child(pid, stack, 1, 1); | ||
| 429 | #else | ||
| 430 | /* PTRACE_LDT might be disabled via cmdline option. | ||
| 431 | * We want to override this, else we might use the stub | ||
| 432 | * without real need | ||
| 433 | */ | ||
| 434 | ptrace_ldt = 1; | ||
| 435 | #endif | ||
| 436 | } | ||
| 437 | |||
| 438 | static inline void check_skas3_proc_mm(void) | ||
| 385 | { | 439 | { |
| 386 | printf("Checking for /proc/mm..."); | 440 | printf(" - /proc/mm..."); |
| 387 | if (os_access("/proc/mm", OS_ACC_W_OK) < 0) { | 441 | if (os_access("/proc/mm", OS_ACC_W_OK) < 0) { |
| 388 | proc_mm = 0; | 442 | proc_mm = 0; |
| 389 | printf("not found\n"); | 443 | printf("not found\n"); |
| @@ -394,8 +448,19 @@ int can_do_skas(void) | |||
| 394 | else | 448 | else |
| 395 | printf("found\n"); | 449 | printf("found\n"); |
| 396 | } | 450 | } |
| 451 | } | ||
| 452 | |||
| 453 | int can_do_skas(void) | ||
| 454 | { | ||
| 455 | printf("Checking for the skas3 patch in the host:\n"); | ||
| 456 | |||
| 457 | check_skas3_proc_mm(); | ||
| 458 | check_skas3_ptrace_faultinfo(); | ||
| 459 | check_skas3_ptrace_ldt(); | ||
| 460 | |||
| 461 | if(!proc_mm || !ptrace_faultinfo || !ptrace_ldt) | ||
| 462 | skas_needs_stub = 1; | ||
| 397 | 463 | ||
| 398 | check_skas3_ptrace_support(); | ||
| 399 | return 1; | 464 | return 1; |
| 400 | } | 465 | } |
| 401 | #else | 466 | #else |
diff --git a/arch/um/os-Linux/uaccess.c b/arch/um/os-Linux/uaccess.c new file mode 100644 index 000000000000..38d710158c3d --- /dev/null +++ b/arch/um/os-Linux/uaccess.c | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk) | ||
| 3 | * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) | ||
| 4 | * Licensed under the GPL | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <setjmp.h> | ||
| 8 | #include <string.h> | ||
| 9 | |||
| 10 | unsigned long __do_user_copy(void *to, const void *from, int n, | ||
| 11 | void **fault_addr, void **fault_catcher, | ||
| 12 | void (*op)(void *to, const void *from, | ||
| 13 | int n), int *faulted_out) | ||
| 14 | { | ||
| 15 | unsigned long *faddrp = (unsigned long *) fault_addr, ret; | ||
| 16 | |||
| 17 | sigjmp_buf jbuf; | ||
| 18 | *fault_catcher = &jbuf; | ||
| 19 | if(sigsetjmp(jbuf, 1) == 0){ | ||
| 20 | (*op)(to, from, n); | ||
| 21 | ret = 0; | ||
| 22 | *faulted_out = 0; | ||
| 23 | } | ||
| 24 | else { | ||
| 25 | ret = *faddrp; | ||
| 26 | *faulted_out = 1; | ||
| 27 | } | ||
| 28 | *fault_addr = NULL; | ||
| 29 | *fault_catcher = NULL; | ||
| 30 | return ret; | ||
| 31 | } | ||
| 32 | |||
