diff options
| author | Jeff Dike <jdike@addtoit.com> | 2005-09-16 22:27:50 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-09-17 14:50:00 -0400 |
| commit | 0f80bc85c587e8fdeecece4f294a47eca4922ea2 (patch) | |
| tree | f18924fbc19779b2fffb5337c8c6826d2d181508 /arch/um/kernel | |
| parent | b4fd310e163477236a241580b3b8c29aee65f4cc (diff) | |
[PATCH] uml: move libc code out of mem_user.c and tempfile.c
The serial UML OS-abstraction layer patch (um/kernel dir).
This moves all system calls from mem_user.c and tempfile.c files 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/Makefile | 6 | ||||
| -rw-r--r-- | arch/um/kernel/init_task.c | 5 | ||||
| -rw-r--r-- | arch/um/kernel/mem_user.c | 205 | ||||
| -rw-r--r-- | arch/um/kernel/tempfile.c | 82 | ||||
| -rw-r--r-- | arch/um/kernel/tlb.c | 2 | ||||
| -rw-r--r-- | arch/um/kernel/tt/mem_user.c | 1 | ||||
| -rw-r--r-- | arch/um/kernel/um_arch.c | 5 |
7 files changed, 9 insertions, 297 deletions
diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index 614b8ebeb0ed..7eb52c5a7cab 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile | |||
| @@ -10,7 +10,7 @@ obj-y = config.o exec_kern.o exitcode.o \ | |||
| 10 | helper.o init_task.o irq.o irq_user.o ksyms.o main.o mem.o mem_user.o \ | 10 | helper.o init_task.o irq.o irq_user.o ksyms.o main.o mem.o mem_user.o \ |
| 11 | physmem.o process_kern.o ptrace.o reboot.o resource.o sigio_user.o \ | 11 | physmem.o process_kern.o ptrace.o reboot.o resource.o sigio_user.o \ |
| 12 | sigio_kern.o signal_kern.o signal_user.o smp.o syscall_kern.o sysrq.o \ | 12 | sigio_kern.o signal_kern.o signal_user.o smp.o syscall_kern.o sysrq.o \ |
| 13 | tempfile.o time.o time_kern.o tlb.o trap_kern.o trap_user.o \ | 13 | time.o time_kern.o tlb.o trap_kern.o trap_user.o \ |
| 14 | uaccess_user.o um_arch.o umid.o user_util.o | 14 | uaccess_user.o um_arch.o umid.o user_util.o |
| 15 | 15 | ||
| 16 | obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o | 16 | obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o |
| @@ -24,8 +24,8 @@ obj-$(CONFIG_MODE_SKAS) += skas/ | |||
| 24 | 24 | ||
| 25 | user-objs-$(CONFIG_TTY_LOG) += tty_log.o | 25 | user-objs-$(CONFIG_TTY_LOG) += tty_log.o |
| 26 | 26 | ||
| 27 | USER_OBJS := $(user-objs-y) config.o helper.o main.o tempfile.o time.o \ | 27 | USER_OBJS := $(user-objs-y) config.o helper.o main.o time.o tty_log.o umid.o \ |
| 28 | tty_log.o umid.o user_util.o | 28 | user_util.o |
| 29 | 29 | ||
| 30 | include arch/um/scripts/Makefile.rules | 30 | include arch/um/scripts/Makefile.rules |
| 31 | 31 | ||
diff --git a/arch/um/kernel/init_task.c b/arch/um/kernel/init_task.c index cd7c85be0a1b..49ed5ddf0704 100644 --- a/arch/um/kernel/init_task.c +++ b/arch/um/kernel/init_task.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include "asm/pgtable.h" | 13 | #include "asm/pgtable.h" |
| 14 | #include "user_util.h" | 14 | #include "user_util.h" |
| 15 | #include "mem_user.h" | 15 | #include "mem_user.h" |
| 16 | #include "os.h" | ||
| 16 | 17 | ||
| 17 | static struct fs_struct init_fs = INIT_FS; | 18 | static struct fs_struct init_fs = INIT_FS; |
| 18 | struct mm_struct init_mm = INIT_MM(init_mm); | 19 | struct mm_struct init_mm = INIT_MM(init_mm); |
| @@ -45,8 +46,8 @@ __attribute__((__section__(".data.init_task"))) = | |||
| 45 | 46 | ||
| 46 | void unprotect_stack(unsigned long stack) | 47 | void unprotect_stack(unsigned long stack) |
| 47 | { | 48 | { |
| 48 | protect_memory(stack, (1 << CONFIG_KERNEL_STACK_ORDER) * PAGE_SIZE, | 49 | os_protect_memory((void *) stack, (1 << CONFIG_KERNEL_STACK_ORDER) * PAGE_SIZE, |
| 49 | 1, 1, 0, 1); | 50 | 1, 1, 0); |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | /* | 53 | /* |
diff --git a/arch/um/kernel/mem_user.c b/arch/um/kernel/mem_user.c index 4a663fd434bb..d49640d9923f 100644 --- a/arch/um/kernel/mem_user.c +++ b/arch/um/kernel/mem_user.c | |||
| @@ -48,219 +48,16 @@ | |||
| 48 | #include "tempfile.h" | 48 | #include "tempfile.h" |
| 49 | #include "kern_constants.h" | 49 | #include "kern_constants.h" |
| 50 | 50 | ||
| 51 | #define TEMPNAME_TEMPLATE "vm_file-XXXXXX" | ||
| 52 | |||
| 53 | static int create_tmp_file(unsigned long len) | ||
| 54 | { | ||
| 55 | int fd, err; | ||
| 56 | char zero; | ||
| 57 | |||
| 58 | fd = make_tempfile(TEMPNAME_TEMPLATE, NULL, 1); | ||
| 59 | if(fd < 0) { | ||
| 60 | os_print_error(fd, "make_tempfile"); | ||
| 61 | exit(1); | ||
| 62 | } | ||
| 63 | |||
| 64 | err = os_mode_fd(fd, 0777); | ||
| 65 | if(err < 0){ | ||
| 66 | os_print_error(err, "os_mode_fd"); | ||
| 67 | exit(1); | ||
| 68 | } | ||
| 69 | err = os_seek_file(fd, len); | ||
| 70 | if(err < 0){ | ||
| 71 | os_print_error(err, "os_seek_file"); | ||
| 72 | exit(1); | ||
| 73 | } | ||
| 74 | zero = 0; | ||
| 75 | err = os_write_file(fd, &zero, 1); | ||
| 76 | if(err != 1){ | ||
| 77 | os_print_error(err, "os_write_file"); | ||
| 78 | exit(1); | ||
| 79 | } | ||
| 80 | |||
| 81 | return(fd); | ||
| 82 | } | ||
| 83 | |||
| 84 | void check_tmpexec(void) | ||
| 85 | { | ||
| 86 | void *addr; | ||
| 87 | int err, fd = create_tmp_file(UM_KERN_PAGE_SIZE); | ||
| 88 | |||
| 89 | addr = mmap(NULL, UM_KERN_PAGE_SIZE, | ||
| 90 | PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0); | ||
| 91 | printf("Checking PROT_EXEC mmap in /tmp..."); | ||
| 92 | fflush(stdout); | ||
| 93 | if(addr == MAP_FAILED){ | ||
| 94 | err = errno; | ||
| 95 | perror("failed"); | ||
| 96 | if(err == EPERM) | ||
| 97 | printf("/tmp must be not mounted noexec\n"); | ||
| 98 | exit(1); | ||
| 99 | } | ||
| 100 | printf("OK\n"); | ||
| 101 | munmap(addr, UM_KERN_PAGE_SIZE); | ||
| 102 | |||
| 103 | os_close_file(fd); | ||
| 104 | } | ||
| 105 | |||
| 106 | static int have_devanon = 0; | ||
| 107 | |||
| 108 | void check_devanon(void) | ||
| 109 | { | ||
| 110 | int fd; | ||
| 111 | |||
| 112 | printk("Checking for /dev/anon on the host..."); | ||
| 113 | fd = open("/dev/anon", O_RDWR); | ||
| 114 | if(fd < 0){ | ||
| 115 | printk("Not available (open failed with errno %d)\n", errno); | ||
| 116 | return; | ||
| 117 | } | ||
| 118 | |||
| 119 | printk("OK\n"); | ||
| 120 | have_devanon = 1; | ||
| 121 | } | ||
| 122 | |||
| 123 | static int create_anon_file(unsigned long len) | ||
| 124 | { | ||
| 125 | void *addr; | ||
| 126 | int fd; | ||
| 127 | |||
| 128 | fd = open("/dev/anon", O_RDWR); | ||
| 129 | if(fd < 0) { | ||
| 130 | os_print_error(fd, "opening /dev/anon"); | ||
| 131 | exit(1); | ||
| 132 | } | ||
| 133 | |||
| 134 | addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); | ||
| 135 | if(addr == MAP_FAILED){ | ||
| 136 | perror("mapping physmem file"); | ||
| 137 | exit(1); | ||
| 138 | } | ||
| 139 | munmap(addr, len); | ||
| 140 | |||
| 141 | return(fd); | ||
| 142 | } | ||
| 143 | |||
| 144 | int create_mem_file(unsigned long len) | ||
| 145 | { | ||
| 146 | int err, fd; | ||
| 147 | |||
| 148 | if(have_devanon) | ||
| 149 | fd = create_anon_file(len); | ||
| 150 | else fd = create_tmp_file(len); | ||
| 151 | |||
| 152 | err = os_set_exec_close(fd, 1); | ||
| 153 | if(err < 0) | ||
| 154 | os_print_error(err, "exec_close"); | ||
| 155 | return(fd); | ||
| 156 | } | ||
| 157 | |||
| 158 | struct iomem_region *iomem_regions = NULL; | 51 | struct iomem_region *iomem_regions = NULL; |
| 159 | int iomem_size = 0; | 52 | int iomem_size = 0; |
| 160 | 53 | ||
| 161 | static int __init parse_iomem(char *str, int *add) | 54 | extern int parse_iomem(char *str, int *add) __init; |
| 162 | { | ||
| 163 | struct iomem_region *new; | ||
| 164 | struct uml_stat buf; | ||
| 165 | char *file, *driver; | ||
| 166 | int fd, err, size; | ||
| 167 | |||
| 168 | driver = str; | ||
| 169 | file = strchr(str,','); | ||
| 170 | if(file == NULL){ | ||
| 171 | printf("parse_iomem : failed to parse iomem\n"); | ||
| 172 | goto out; | ||
| 173 | } | ||
| 174 | *file = '\0'; | ||
| 175 | file++; | ||
| 176 | fd = os_open_file(file, of_rdwr(OPENFLAGS()), 0); | ||
| 177 | if(fd < 0){ | ||
| 178 | os_print_error(fd, "parse_iomem - Couldn't open io file"); | ||
| 179 | goto out; | ||
| 180 | } | ||
| 181 | |||
| 182 | err = os_stat_fd(fd, &buf); | ||
| 183 | if(err < 0){ | ||
| 184 | os_print_error(err, "parse_iomem - cannot stat_fd file"); | ||
| 185 | goto out_close; | ||
| 186 | } | ||
| 187 | |||
| 188 | new = malloc(sizeof(*new)); | ||
| 189 | if(new == NULL){ | ||
| 190 | perror("Couldn't allocate iomem_region struct"); | ||
| 191 | goto out_close; | ||
| 192 | } | ||
| 193 | |||
| 194 | size = (buf.ust_size + UM_KERN_PAGE_SIZE) & ~(UM_KERN_PAGE_SIZE - 1); | ||
| 195 | |||
| 196 | *new = ((struct iomem_region) { .next = iomem_regions, | ||
| 197 | .driver = driver, | ||
| 198 | .fd = fd, | ||
| 199 | .size = size, | ||
| 200 | .phys = 0, | ||
| 201 | .virt = 0 }); | ||
| 202 | iomem_regions = new; | ||
| 203 | iomem_size += new->size + UM_KERN_PAGE_SIZE; | ||
| 204 | |||
| 205 | return(0); | ||
| 206 | out_close: | ||
| 207 | os_close_file(fd); | ||
| 208 | out: | ||
| 209 | return(1); | ||
| 210 | } | ||
| 211 | 55 | ||
| 212 | __uml_setup("iomem=", parse_iomem, | 56 | __uml_setup("iomem=", parse_iomem, |
| 213 | "iomem=<name>,<file>\n" | 57 | "iomem=<name>,<file>\n" |
| 214 | " Configure <file> as an IO memory region named <name>.\n\n" | 58 | " Configure <file> as an IO memory region named <name>.\n\n" |
| 215 | ); | 59 | ); |
| 216 | 60 | ||
| 217 | int protect_memory(unsigned long addr, unsigned long len, int r, int w, int x, | ||
| 218 | int must_succeed) | ||
| 219 | { | ||
| 220 | int err; | ||
| 221 | |||
| 222 | err = os_protect_memory((void *) addr, len, r, w, x); | ||
| 223 | if(err < 0){ | ||
| 224 | if(must_succeed) | ||
| 225 | panic("protect failed, err = %d", -err); | ||
| 226 | else return(err); | ||
| 227 | } | ||
| 228 | return(0); | ||
| 229 | } | ||
| 230 | |||
| 231 | #if 0 | ||
| 232 | /* Debugging facility for dumping stuff out to the host, avoiding the timing | ||
| 233 | * problems that come with printf and breakpoints. | ||
| 234 | * Enable in case of emergency. | ||
| 235 | */ | ||
| 236 | |||
| 237 | int logging = 1; | ||
| 238 | int logging_fd = -1; | ||
| 239 | |||
| 240 | int logging_line = 0; | ||
| 241 | char logging_buf[512]; | ||
| 242 | |||
| 243 | void log(char *fmt, ...) | ||
| 244 | { | ||
| 245 | va_list ap; | ||
| 246 | struct timeval tv; | ||
| 247 | struct openflags flags; | ||
| 248 | |||
| 249 | if(logging == 0) return; | ||
| 250 | if(logging_fd < 0){ | ||
| 251 | flags = of_create(of_trunc(of_rdwr(OPENFLAGS()))); | ||
| 252 | logging_fd = os_open_file("log", flags, 0644); | ||
| 253 | } | ||
| 254 | gettimeofday(&tv, NULL); | ||
| 255 | sprintf(logging_buf, "%d\t %u.%u ", logging_line++, tv.tv_sec, | ||
| 256 | tv.tv_usec); | ||
| 257 | va_start(ap, fmt); | ||
| 258 | vsprintf(&logging_buf[strlen(logging_buf)], fmt, ap); | ||
| 259 | va_end(ap); | ||
| 260 | write(logging_fd, logging_buf, strlen(logging_buf)); | ||
| 261 | } | ||
| 262 | #endif | ||
| 263 | |||
| 264 | /* | 61 | /* |
| 265 | * Overrides for Emacs so that we follow Linus's tabbing style. | 62 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 266 | * Emacs will notice this stuff at the end of the file and automatically | 63 | * Emacs will notice this stuff at the end of the file and automatically |
diff --git a/arch/um/kernel/tempfile.c b/arch/um/kernel/tempfile.c deleted file mode 100644 index b1674bc1395d..000000000000 --- a/arch/um/kernel/tempfile.c +++ /dev/null | |||
| @@ -1,82 +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 <string.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <sys/param.h> | ||
| 12 | #include "init.h" | ||
| 13 | |||
| 14 | /* Modified from create_mem_file and start_debugger */ | ||
| 15 | static char *tempdir = NULL; | ||
| 16 | |||
| 17 | static void __init find_tempdir(void) | ||
| 18 | { | ||
| 19 | char *dirs[] = { "TMP", "TEMP", "TMPDIR", NULL }; | ||
| 20 | int i; | ||
| 21 | char *dir = NULL; | ||
| 22 | |||
| 23 | if(tempdir != NULL) return; /* We've already been called */ | ||
| 24 | for(i = 0; dirs[i]; i++){ | ||
| 25 | dir = getenv(dirs[i]); | ||
| 26 | if((dir != NULL) && (*dir != '\0')) | ||
| 27 | break; | ||
| 28 | } | ||
| 29 | if((dir == NULL) || (*dir == '\0')) | ||
| 30 | dir = "/tmp"; | ||
| 31 | |||
| 32 | tempdir = malloc(strlen(dir) + 2); | ||
| 33 | if(tempdir == NULL){ | ||
| 34 | fprintf(stderr, "Failed to malloc tempdir, " | ||
| 35 | "errno = %d\n", errno); | ||
| 36 | return; | ||
| 37 | } | ||
| 38 | strcpy(tempdir, dir); | ||
| 39 | strcat(tempdir, "/"); | ||
| 40 | } | ||
| 41 | |||
| 42 | int make_tempfile(const char *template, char **out_tempname, int do_unlink) | ||
| 43 | { | ||
| 44 | char tempname[MAXPATHLEN]; | ||
| 45 | int fd; | ||
| 46 | |||
| 47 | find_tempdir(); | ||
| 48 | if (*template != '/') | ||
| 49 | strcpy(tempname, tempdir); | ||
| 50 | else | ||
| 51 | *tempname = 0; | ||
| 52 | strcat(tempname, template); | ||
| 53 | fd = mkstemp(tempname); | ||
| 54 | if(fd < 0){ | ||
| 55 | fprintf(stderr, "open - cannot create %s: %s\n", tempname, | ||
| 56 | strerror(errno)); | ||
| 57 | return -1; | ||
| 58 | } | ||
| 59 | if(do_unlink && (unlink(tempname) < 0)){ | ||
| 60 | perror("unlink"); | ||
| 61 | return -1; | ||
| 62 | } | ||
| 63 | if(out_tempname){ | ||
| 64 | *out_tempname = strdup(tempname); | ||
| 65 | if(*out_tempname == NULL){ | ||
| 66 | perror("strdup"); | ||
| 67 | return -1; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | return(fd); | ||
| 71 | } | ||
| 72 | |||
| 73 | /* | ||
| 74 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
| 75 | * Emacs will notice this stuff at the end of the file and automatically | ||
| 76 | * adjust the settings for this buffer only. This must remain at the end | ||
| 77 | * of the file. | ||
| 78 | * --------------------------------------------------------------------------- | ||
| 79 | * Local variables: | ||
| 80 | * c-file-style: "linux" | ||
| 81 | * End: | ||
| 82 | */ | ||
diff --git a/arch/um/kernel/tlb.c b/arch/um/kernel/tlb.c index 80ed6188e8a2..0a562c3c0fd8 100644 --- a/arch/um/kernel/tlb.c +++ b/arch/um/kernel/tlb.c | |||
| @@ -307,7 +307,7 @@ int flush_tlb_kernel_range_common(unsigned long start, unsigned long end) | |||
| 307 | } | 307 | } |
| 308 | else if(pte_newprot(*pte)){ | 308 | else if(pte_newprot(*pte)){ |
| 309 | updated = 1; | 309 | updated = 1; |
| 310 | protect_memory(addr, PAGE_SIZE, 1, 1, 1, 1); | 310 | os_protect_memory((void *) addr, PAGE_SIZE, 1, 1, 1); |
| 311 | } | 311 | } |
| 312 | addr += PAGE_SIZE; | 312 | addr += PAGE_SIZE; |
| 313 | } | 313 | } |
diff --git a/arch/um/kernel/tt/mem_user.c b/arch/um/kernel/tt/mem_user.c index 3085267459b1..03e589895388 100644 --- a/arch/um/kernel/tt/mem_user.c +++ b/arch/um/kernel/tt/mem_user.c | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include "tt.h" | 12 | #include "tt.h" |
| 13 | #include "mem_user.h" | 13 | #include "mem_user.h" |
| 14 | #include "user_util.h" | 14 | #include "user_util.h" |
| 15 | #include "os.h" | ||
| 15 | 16 | ||
| 16 | void remap_data(void *segment_start, void *segment_end, int w) | 17 | void remap_data(void *segment_start, void *segment_end, int w) |
| 17 | { | 18 | { |
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index 09f6f7ce4695..f0a275947d34 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c | |||
| @@ -361,11 +361,6 @@ int linux_main(int argc, char **argv) | |||
| 361 | uml_start = CHOOSE_MODE_PROC(set_task_sizes_tt, set_task_sizes_skas, 0, | 361 | uml_start = CHOOSE_MODE_PROC(set_task_sizes_tt, set_task_sizes_skas, 0, |
| 362 | &host_task_size, &task_size); | 362 | &host_task_size, &task_size); |
| 363 | 363 | ||
| 364 | /* Need to check this early because mmapping happens before the | ||
| 365 | * kernel is running. | ||
| 366 | */ | ||
| 367 | check_tmpexec(); | ||
| 368 | |||
| 369 | brk_start = (unsigned long) sbrk(0); | 364 | brk_start = (unsigned long) sbrk(0); |
| 370 | CHOOSE_MODE_PROC(before_mem_tt, before_mem_skas, brk_start); | 365 | CHOOSE_MODE_PROC(before_mem_tt, before_mem_skas, brk_start); |
| 371 | /* Increase physical memory size for exec-shield users | 366 | /* Increase physical memory size for exec-shield users |
