diff options
Diffstat (limited to 'arch/um/os-Linux')
-rw-r--r-- | arch/um/os-Linux/Makefile | 8 | ||||
-rw-r--r-- | arch/um/os-Linux/aio.c | 10 | ||||
-rw-r--r-- | arch/um/os-Linux/drivers/tuntap_user.c | 8 | ||||
-rw-r--r-- | arch/um/os-Linux/elf_aux.c | 6 | ||||
-rw-r--r-- | arch/um/os-Linux/file.c | 82 | ||||
-rw-r--r-- | arch/um/os-Linux/mem.c | 161 | ||||
-rw-r--r-- | arch/um/os-Linux/process.c | 1 | ||||
-rw-r--r-- | arch/um/os-Linux/start_up.c | 109 | ||||
-rw-r--r-- | arch/um/os-Linux/tt.c | 14 |
9 files changed, 334 insertions, 65 deletions
diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index 7a1662419c0c..d15ec2af6a22 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile | |||
@@ -3,11 +3,11 @@ | |||
3 | # Licensed under the GPL | 3 | # Licensed under the GPL |
4 | # | 4 | # |
5 | 5 | ||
6 | obj-y = aio.o elf_aux.o file.o process.o signal.o start_up.o time.o tt.o \ | 6 | obj-y = aio.o elf_aux.o file.o mem.o process.o signal.o start_up.o time.o \ |
7 | tty.o user_syms.o drivers/ sys-$(SUBARCH)/ | 7 | tt.o tty.o user_syms.o drivers/ sys-$(SUBARCH)/ |
8 | 8 | ||
9 | USER_OBJS := aio.o elf_aux.o file.o process.o signal.o start_up.o time.o tt.o \ | 9 | USER_OBJS := aio.o elf_aux.o file.o mem.o process.o signal.o start_up.o \ |
10 | tty.o | 10 | time.o tt.o tty.o |
11 | 11 | ||
12 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h | 12 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h |
13 | CFLAGS_elf_aux.o += -I$(objtree)/arch/um | 13 | 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 b04897cd995d..f6e64026f995 100644 --- a/arch/um/os-Linux/aio.c +++ b/arch/um/os-Linux/aio.c | |||
@@ -117,6 +117,8 @@ static int do_aio(aio_context_t ctx, struct aio_context *aio) | |||
117 | err = io_submit(ctx, 1, &iocbp); | 117 | err = io_submit(ctx, 1, &iocbp); |
118 | if(err > 0) | 118 | if(err > 0) |
119 | err = 0; | 119 | err = 0; |
120 | else | ||
121 | err = -errno; | ||
120 | 122 | ||
121 | out: | 123 | out: |
122 | return err; | 124 | return err; |
@@ -142,7 +144,8 @@ static int aio_thread(void *arg) | |||
142 | "errno = %d\n", errno); | 144 | "errno = %d\n", errno); |
143 | } | 145 | } |
144 | else { | 146 | else { |
145 | aio = (struct aio_context *) event.data; | 147 | /* This is safe as we've just a pointer here. */ |
148 | aio = (struct aio_context *) (long) event.data; | ||
146 | if(update_aio(aio, event.res)){ | 149 | if(update_aio(aio, event.res)){ |
147 | do_aio(ctx, aio); | 150 | do_aio(ctx, aio); |
148 | continue; | 151 | continue; |
@@ -313,15 +316,16 @@ static int init_aio_26(void) | |||
313 | int err; | 316 | int err; |
314 | 317 | ||
315 | if(io_setup(256, &ctx)){ | 318 | if(io_setup(256, &ctx)){ |
319 | err = -errno; | ||
316 | printk("aio_thread failed to initialize context, err = %d\n", | 320 | printk("aio_thread failed to initialize context, err = %d\n", |
317 | errno); | 321 | errno); |
318 | return -errno; | 322 | return err; |
319 | } | 323 | } |
320 | 324 | ||
321 | err = run_helper_thread(aio_thread, NULL, | 325 | err = run_helper_thread(aio_thread, NULL, |
322 | CLONE_FILES | CLONE_VM | SIGCHLD, &stack, 0); | 326 | CLONE_FILES | CLONE_VM | SIGCHLD, &stack, 0); |
323 | if(err < 0) | 327 | if(err < 0) |
324 | return -errno; | 328 | return err; |
325 | 329 | ||
326 | aio_pid = err; | 330 | aio_pid = err; |
327 | 331 | ||
diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/arch/um/os-Linux/drivers/tuntap_user.c index 4b83c6c3f48d..4ba9b17adf13 100644 --- a/arch/um/os-Linux/drivers/tuntap_user.c +++ b/arch/um/os-Linux/drivers/tuntap_user.c | |||
@@ -75,7 +75,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, | |||
75 | struct msghdr msg; | 75 | struct msghdr msg; |
76 | struct cmsghdr *cmsg; | 76 | struct cmsghdr *cmsg; |
77 | struct iovec iov; | 77 | struct iovec iov; |
78 | int pid, n; | 78 | int pid, n, err; |
79 | 79 | ||
80 | sprintf(version_buf, "%d", UML_NET_VERSION); | 80 | sprintf(version_buf, "%d", UML_NET_VERSION); |
81 | 81 | ||
@@ -105,9 +105,10 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, | |||
105 | n = recvmsg(me, &msg, 0); | 105 | n = recvmsg(me, &msg, 0); |
106 | *used_out = n; | 106 | *used_out = n; |
107 | if(n < 0){ | 107 | if(n < 0){ |
108 | err = -errno; | ||
108 | printk("tuntap_open_tramp : recvmsg failed - errno = %d\n", | 109 | printk("tuntap_open_tramp : recvmsg failed - errno = %d\n", |
109 | errno); | 110 | errno); |
110 | return(-errno); | 111 | return err; |
111 | } | 112 | } |
112 | CATCH_EINTR(waitpid(pid, NULL, 0)); | 113 | CATCH_EINTR(waitpid(pid, NULL, 0)); |
113 | 114 | ||
@@ -147,9 +148,10 @@ static int tuntap_open(void *data) | |||
147 | ifr.ifr_flags = IFF_TAP | IFF_NO_PI; | 148 | ifr.ifr_flags = IFF_TAP | IFF_NO_PI; |
148 | strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name)); | 149 | strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name)); |
149 | if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){ | 150 | if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){ |
151 | err = -errno; | ||
150 | printk("TUNSETIFF failed, errno = %d\n", errno); | 152 | printk("TUNSETIFF failed, errno = %d\n", errno); |
151 | os_close_file(pri->fd); | 153 | os_close_file(pri->fd); |
152 | return(-errno); | 154 | return err; |
153 | } | 155 | } |
154 | } | 156 | } |
155 | else { | 157 | else { |
diff --git a/arch/um/os-Linux/elf_aux.c b/arch/um/os-Linux/elf_aux.c index 1399520a8588..ab33cb3c74ec 100644 --- a/arch/um/os-Linux/elf_aux.c +++ b/arch/um/os-Linux/elf_aux.c | |||
@@ -14,7 +14,8 @@ | |||
14 | #include "mem_user.h" | 14 | #include "mem_user.h" |
15 | #include <kernel-offsets.h> | 15 | #include <kernel-offsets.h> |
16 | 16 | ||
17 | #if HOST_ELF_CLASS == ELFCLASS32 | 17 | /* Use the one from the kernel - the host may miss it, if having old headers. */ |
18 | #if UM_ELF_CLASS == UM_ELFCLASS32 | ||
18 | typedef Elf32_auxv_t elf_auxv_t; | 19 | typedef Elf32_auxv_t elf_auxv_t; |
19 | #else | 20 | #else |
20 | typedef Elf64_auxv_t elf_auxv_t; | 21 | typedef Elf64_auxv_t elf_auxv_t; |
@@ -54,7 +55,8 @@ __init void scan_elf_aux( char **envp) | |||
54 | * a_un, so we have to use a_val, which is | 55 | * a_un, so we have to use a_val, which is |
55 | * all that's left. | 56 | * all that's left. |
56 | */ | 57 | */ |
57 | elf_aux_platform = (char *) auxv->a_un.a_val; | 58 | elf_aux_platform = |
59 | (char *) (long) auxv->a_un.a_val; | ||
58 | break; | 60 | break; |
59 | case AT_PAGESZ: | 61 | case AT_PAGESZ: |
60 | page_size = auxv->a_un.a_val; | 62 | page_size = auxv->a_un.a_val; |
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c index fd45bb260907..f55773c819e6 100644 --- a/arch/um/os-Linux/file.c +++ b/arch/um/os-Linux/file.c | |||
@@ -119,15 +119,11 @@ int os_window_size(int fd, int *rows, int *cols) | |||
119 | 119 | ||
120 | int os_new_tty_pgrp(int fd, int pid) | 120 | int os_new_tty_pgrp(int fd, int pid) |
121 | { | 121 | { |
122 | if(ioctl(fd, TIOCSCTTY, 0) < 0){ | 122 | if(ioctl(fd, TIOCSCTTY, 0) < 0) |
123 | printk("TIOCSCTTY failed, errno = %d\n", errno); | 123 | return -errno; |
124 | return(-errno); | ||
125 | } | ||
126 | 124 | ||
127 | if(tcsetpgrp(fd, pid) < 0){ | 125 | if(tcsetpgrp(fd, pid) < 0) |
128 | printk("tcsetpgrp failed, errno = %d\n", errno); | 126 | return -errno; |
129 | return(-errno); | ||
130 | } | ||
131 | 127 | ||
132 | return(0); | 128 | return(0); |
133 | } | 129 | } |
@@ -146,18 +142,12 @@ int os_set_slip(int fd) | |||
146 | int disc, sencap; | 142 | int disc, sencap; |
147 | 143 | ||
148 | disc = N_SLIP; | 144 | disc = N_SLIP; |
149 | if(ioctl(fd, TIOCSETD, &disc) < 0){ | 145 | if(ioctl(fd, TIOCSETD, &disc) < 0) |
150 | printk("Failed to set slip line discipline - " | 146 | return -errno; |
151 | "errno = %d\n", errno); | ||
152 | return(-errno); | ||
153 | } | ||
154 | 147 | ||
155 | sencap = 0; | 148 | sencap = 0; |
156 | if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0){ | 149 | if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0) |
157 | printk("Failed to set slip encapsulation - " | 150 | return -errno; |
158 | "errno = %d\n", errno); | ||
159 | return(-errno); | ||
160 | } | ||
161 | 151 | ||
162 | return(0); | 152 | return(0); |
163 | } | 153 | } |
@@ -180,22 +170,15 @@ int os_sigio_async(int master, int slave) | |||
180 | int flags; | 170 | int flags; |
181 | 171 | ||
182 | flags = fcntl(master, F_GETFL); | 172 | flags = fcntl(master, F_GETFL); |
183 | if(flags < 0) { | 173 | if(flags < 0) |
184 | printk("fcntl F_GETFL failed, errno = %d\n", errno); | 174 | return errno; |
185 | return(-errno); | ||
186 | } | ||
187 | 175 | ||
188 | if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) || | 176 | if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) || |
189 | (fcntl(master, F_SETOWN, os_getpid()) < 0)){ | 177 | (fcntl(master, F_SETOWN, os_getpid()) < 0)) |
190 | printk("fcntl F_SETFL or F_SETOWN failed, errno = %d\n", | 178 | return -errno; |
191 | errno); | ||
192 | return(-errno); | ||
193 | } | ||
194 | 179 | ||
195 | if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0)){ | 180 | if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0)) |
196 | printk("fcntl F_SETFL failed, errno = %d\n", errno); | 181 | return -errno; |
197 | return(-errno); | ||
198 | } | ||
199 | 182 | ||
200 | return(0); | 183 | return(0); |
201 | } | 184 | } |
@@ -255,7 +238,7 @@ int os_file_mode(char *file, struct openflags *mode_out) | |||
255 | 238 | ||
256 | int os_open_file(char *file, struct openflags flags, int mode) | 239 | int os_open_file(char *file, struct openflags flags, int mode) |
257 | { | 240 | { |
258 | int fd, f = 0; | 241 | int fd, err, f = 0; |
259 | 242 | ||
260 | if(flags.r && flags.w) f = O_RDWR; | 243 | if(flags.r && flags.w) f = O_RDWR; |
261 | else if(flags.r) f = O_RDONLY; | 244 | else if(flags.r) f = O_RDONLY; |
@@ -272,8 +255,9 @@ int os_open_file(char *file, struct openflags flags, int mode) | |||
272 | return(-errno); | 255 | return(-errno); |
273 | 256 | ||
274 | if(flags.cl && fcntl(fd, F_SETFD, 1)){ | 257 | if(flags.cl && fcntl(fd, F_SETFD, 1)){ |
258 | err = -errno; | ||
275 | os_close_file(fd); | 259 | os_close_file(fd); |
276 | return(-errno); | 260 | return err; |
277 | } | 261 | } |
278 | 262 | ||
279 | return(fd); | 263 | return(fd); |
@@ -383,9 +367,9 @@ int os_file_size(char *file, unsigned long long *size_out) | |||
383 | return(fd); | 367 | return(fd); |
384 | } | 368 | } |
385 | if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ | 369 | if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ |
370 | err = -errno; | ||
386 | printk("Couldn't get the block size of \"%s\", " | 371 | printk("Couldn't get the block size of \"%s\", " |
387 | "errno = %d\n", file, errno); | 372 | "errno = %d\n", file, errno); |
388 | err = -errno; | ||
389 | os_close_file(fd); | 373 | os_close_file(fd); |
390 | return(err); | 374 | return(err); |
391 | } | 375 | } |
@@ -473,11 +457,14 @@ int os_pipe(int *fds, int stream, int close_on_exec) | |||
473 | 457 | ||
474 | int os_set_fd_async(int fd, int owner) | 458 | int os_set_fd_async(int fd, int owner) |
475 | { | 459 | { |
460 | int err; | ||
461 | |||
476 | /* XXX This should do F_GETFL first */ | 462 | /* XXX This should do F_GETFL first */ |
477 | if(fcntl(fd, F_SETFL, O_ASYNC | O_NONBLOCK) < 0){ | 463 | if(fcntl(fd, F_SETFL, O_ASYNC | O_NONBLOCK) < 0){ |
464 | err = -errno; | ||
478 | printk("os_set_fd_async : failed to set O_ASYNC and " | 465 | printk("os_set_fd_async : failed to set O_ASYNC and " |
479 | "O_NONBLOCK on fd # %d, errno = %d\n", fd, errno); | 466 | "O_NONBLOCK on fd # %d, errno = %d\n", fd, errno); |
480 | return(-errno); | 467 | return err; |
481 | } | 468 | } |
482 | #ifdef notdef | 469 | #ifdef notdef |
483 | if(fcntl(fd, F_SETFD, 1) < 0){ | 470 | if(fcntl(fd, F_SETFD, 1) < 0){ |
@@ -488,10 +475,11 @@ int os_set_fd_async(int fd, int owner) | |||
488 | 475 | ||
489 | if((fcntl(fd, F_SETSIG, SIGIO) < 0) || | 476 | if((fcntl(fd, F_SETSIG, SIGIO) < 0) || |
490 | (fcntl(fd, F_SETOWN, owner) < 0)){ | 477 | (fcntl(fd, F_SETOWN, owner) < 0)){ |
478 | err = -errno; | ||
491 | printk("os_set_fd_async : Failed to fcntl F_SETOWN " | 479 | printk("os_set_fd_async : Failed to fcntl F_SETOWN " |
492 | "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd, | 480 | "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd, |
493 | owner, errno); | 481 | owner, errno); |
494 | return(-errno); | 482 | return err; |
495 | } | 483 | } |
496 | 484 | ||
497 | return(0); | 485 | return(0); |
@@ -516,11 +504,9 @@ int os_set_fd_block(int fd, int blocking) | |||
516 | if(blocking) flags &= ~O_NONBLOCK; | 504 | if(blocking) flags &= ~O_NONBLOCK; |
517 | else flags |= O_NONBLOCK; | 505 | else flags |= O_NONBLOCK; |
518 | 506 | ||
519 | if(fcntl(fd, F_SETFL, flags) < 0){ | 507 | if(fcntl(fd, F_SETFL, flags) < 0) |
520 | printk("Failed to change blocking on fd # %d, errno = %d\n", | 508 | return -errno; |
521 | fd, errno); | 509 | |
522 | return(-errno); | ||
523 | } | ||
524 | return(0); | 510 | return(0); |
525 | } | 511 | } |
526 | 512 | ||
@@ -609,11 +595,8 @@ int os_create_unix_socket(char *file, int len, int close_on_exec) | |||
609 | int sock, err; | 595 | int sock, err; |
610 | 596 | ||
611 | sock = socket(PF_UNIX, SOCK_DGRAM, 0); | 597 | sock = socket(PF_UNIX, SOCK_DGRAM, 0); |
612 | if (sock < 0){ | 598 | if(sock < 0) |
613 | printk("create_unix_socket - socket failed, errno = %d\n", | 599 | return -errno; |
614 | errno); | ||
615 | return(-errno); | ||
616 | } | ||
617 | 600 | ||
618 | if(close_on_exec) { | 601 | if(close_on_exec) { |
619 | err = os_set_exec_close(sock, 1); | 602 | err = os_set_exec_close(sock, 1); |
@@ -628,11 +611,8 @@ int os_create_unix_socket(char *file, int len, int close_on_exec) | |||
628 | snprintf(addr.sun_path, len, "%s", file); | 611 | snprintf(addr.sun_path, len, "%s", file); |
629 | 612 | ||
630 | err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); | 613 | err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); |
631 | if (err < 0){ | 614 | if(err < 0) |
632 | printk("create_listening_socket at '%s' - bind failed, " | 615 | return -errno; |
633 | "errno = %d\n", file, errno); | ||
634 | return(-errno); | ||
635 | } | ||
636 | 616 | ||
637 | return(sock); | 617 | return(sock); |
638 | } | 618 | } |
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c new file mode 100644 index 000000000000..8e71edaaf80b --- /dev/null +++ b/arch/um/os-Linux/mem.c | |||
@@ -0,0 +1,161 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <stddef.h> | ||
4 | #include <stdarg.h> | ||
5 | #include <unistd.h> | ||
6 | #include <errno.h> | ||
7 | #include <string.h> | ||
8 | #include <fcntl.h> | ||
9 | #include <sys/types.h> | ||
10 | #include <sys/mman.h> | ||
11 | #include "kern_util.h" | ||
12 | #include "user.h" | ||
13 | #include "user_util.h" | ||
14 | #include "mem_user.h" | ||
15 | #include "init.h" | ||
16 | #include "os.h" | ||
17 | #include "tempfile.h" | ||
18 | #include "kern_constants.h" | ||
19 | |||
20 | #include <sys/param.h> | ||
21 | |||
22 | static char *tempdir = NULL; | ||
23 | |||
24 | static void __init find_tempdir(void) | ||
25 | { | ||
26 | char *dirs[] = { "TMP", "TEMP", "TMPDIR", NULL }; | ||
27 | int i; | ||
28 | char *dir = NULL; | ||
29 | |||
30 | if(tempdir != NULL) return; /* We've already been called */ | ||
31 | for(i = 0; dirs[i]; i++){ | ||
32 | dir = getenv(dirs[i]); | ||
33 | if((dir != NULL) && (*dir != '\0')) | ||
34 | break; | ||
35 | } | ||
36 | if((dir == NULL) || (*dir == '\0')) | ||
37 | dir = "/tmp"; | ||
38 | |||
39 | tempdir = malloc(strlen(dir) + 2); | ||
40 | if(tempdir == NULL){ | ||
41 | fprintf(stderr, "Failed to malloc tempdir, " | ||
42 | "errno = %d\n", errno); | ||
43 | return; | ||
44 | } | ||
45 | strcpy(tempdir, dir); | ||
46 | strcat(tempdir, "/"); | ||
47 | } | ||
48 | |||
49 | /* | ||
50 | * This proc still used in tt-mode | ||
51 | * (file: kernel/tt/ptproxy/proxy.c, proc: start_debugger). | ||
52 | * So it isn't 'static' yet. | ||
53 | */ | ||
54 | int make_tempfile(const char *template, char **out_tempname, int do_unlink) | ||
55 | { | ||
56 | char tempname[MAXPATHLEN]; | ||
57 | int fd; | ||
58 | |||
59 | find_tempdir(); | ||
60 | if (*template != '/') | ||
61 | strcpy(tempname, tempdir); | ||
62 | else | ||
63 | *tempname = 0; | ||
64 | strcat(tempname, template); | ||
65 | fd = mkstemp(tempname); | ||
66 | if(fd < 0){ | ||
67 | fprintf(stderr, "open - cannot create %s: %s\n", tempname, | ||
68 | strerror(errno)); | ||
69 | return -1; | ||
70 | } | ||
71 | if(do_unlink && (unlink(tempname) < 0)){ | ||
72 | perror("unlink"); | ||
73 | return -1; | ||
74 | } | ||
75 | if(out_tempname){ | ||
76 | *out_tempname = strdup(tempname); | ||
77 | if(*out_tempname == NULL){ | ||
78 | perror("strdup"); | ||
79 | return -1; | ||
80 | } | ||
81 | } | ||
82 | return(fd); | ||
83 | } | ||
84 | |||
85 | #define TEMPNAME_TEMPLATE "vm_file-XXXXXX" | ||
86 | |||
87 | /* | ||
88 | * This proc is used in start_up.c | ||
89 | * So it isn't 'static'. | ||
90 | */ | ||
91 | int create_tmp_file(unsigned long len) | ||
92 | { | ||
93 | int fd, err; | ||
94 | char zero; | ||
95 | |||
96 | fd = make_tempfile(TEMPNAME_TEMPLATE, NULL, 1); | ||
97 | if(fd < 0) { | ||
98 | exit(1); | ||
99 | } | ||
100 | |||
101 | err = fchmod(fd, 0777); | ||
102 | if(err < 0){ | ||
103 | perror("os_mode_fd"); | ||
104 | exit(1); | ||
105 | } | ||
106 | |||
107 | if (lseek64(fd, len, SEEK_SET) < 0) { | ||
108 | perror("os_seek_file"); | ||
109 | exit(1); | ||
110 | } | ||
111 | |||
112 | zero = 0; | ||
113 | |||
114 | err = os_write_file(fd, &zero, 1); | ||
115 | if(err != 1){ | ||
116 | errno = -err; | ||
117 | perror("os_write_file"); | ||
118 | exit(1); | ||
119 | } | ||
120 | |||
121 | return(fd); | ||
122 | } | ||
123 | |||
124 | static int create_anon_file(unsigned long len) | ||
125 | { | ||
126 | void *addr; | ||
127 | int fd; | ||
128 | |||
129 | fd = open("/dev/anon", O_RDWR); | ||
130 | if(fd < 0) { | ||
131 | perror("opening /dev/anon"); | ||
132 | exit(1); | ||
133 | } | ||
134 | |||
135 | addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); | ||
136 | if(addr == MAP_FAILED){ | ||
137 | perror("mapping physmem file"); | ||
138 | exit(1); | ||
139 | } | ||
140 | munmap(addr, len); | ||
141 | |||
142 | return(fd); | ||
143 | } | ||
144 | |||
145 | extern int have_devanon; | ||
146 | |||
147 | int create_mem_file(unsigned long len) | ||
148 | { | ||
149 | int err, fd; | ||
150 | |||
151 | if(have_devanon) | ||
152 | fd = create_anon_file(len); | ||
153 | else fd = create_tmp_file(len); | ||
154 | |||
155 | err = os_set_exec_close(fd, 1); | ||
156 | if(err < 0){ | ||
157 | errno = -err; | ||
158 | perror("exec_close"); | ||
159 | } | ||
160 | return(fd); | ||
161 | } | ||
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index d32413e4b4ce..d9c52387c4a1 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <unistd.h> | ||
6 | #include <stdio.h> | 7 | #include <stdio.h> |
7 | #include <errno.h> | 8 | #include <errno.h> |
8 | #include <signal.h> | 9 | #include <signal.h> |
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c index 040cc1472bc7..6af83171ca4e 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c | |||
@@ -4,18 +4,22 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | #include <stddef.h> | ||
8 | #include <stdarg.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <string.h> | ||
7 | #include <unistd.h> | 11 | #include <unistd.h> |
8 | #include <signal.h> | 12 | #include <signal.h> |
9 | #include <sched.h> | 13 | #include <sched.h> |
14 | #include <fcntl.h> | ||
10 | #include <errno.h> | 15 | #include <errno.h> |
11 | #include <stdarg.h> | ||
12 | #include <stdlib.h> | ||
13 | #include <setjmp.h> | 16 | #include <setjmp.h> |
14 | #include <sys/time.h> | 17 | #include <sys/time.h> |
15 | #include <sys/wait.h> | 18 | #include <sys/wait.h> |
16 | #include <sys/mman.h> | 19 | #include <sys/mman.h> |
17 | #include <asm/unistd.h> | 20 | #include <asm/unistd.h> |
18 | #include <asm/page.h> | 21 | #include <asm/page.h> |
22 | #include <sys/types.h> | ||
19 | #include "user_util.h" | 23 | #include "user_util.h" |
20 | #include "kern_util.h" | 24 | #include "kern_util.h" |
21 | #include "user.h" | 25 | #include "user.h" |
@@ -25,6 +29,7 @@ | |||
25 | #include "sysdep/sigcontext.h" | 29 | #include "sysdep/sigcontext.h" |
26 | #include "irq_user.h" | 30 | #include "irq_user.h" |
27 | #include "ptrace_user.h" | 31 | #include "ptrace_user.h" |
32 | #include "mem_user.h" | ||
28 | #include "time_user.h" | 33 | #include "time_user.h" |
29 | #include "init.h" | 34 | #include "init.h" |
30 | #include "os.h" | 35 | #include "os.h" |
@@ -32,6 +37,8 @@ | |||
32 | #include "choose-mode.h" | 37 | #include "choose-mode.h" |
33 | #include "mode.h" | 38 | #include "mode.h" |
34 | #include "tempfile.h" | 39 | #include "tempfile.h" |
40 | #include "kern_constants.h" | ||
41 | |||
35 | #ifdef UML_CONFIG_MODE_SKAS | 42 | #ifdef UML_CONFIG_MODE_SKAS |
36 | #include "skas.h" | 43 | #include "skas.h" |
37 | #include "skas_ptrace.h" | 44 | #include "skas_ptrace.h" |
@@ -276,9 +283,38 @@ static void __init check_ptrace(void) | |||
276 | check_sysemu(); | 283 | check_sysemu(); |
277 | } | 284 | } |
278 | 285 | ||
286 | extern int create_tmp_file(unsigned long len); | ||
287 | |||
288 | static void check_tmpexec(void) | ||
289 | { | ||
290 | void *addr; | ||
291 | int err, fd = create_tmp_file(UM_KERN_PAGE_SIZE); | ||
292 | |||
293 | addr = mmap(NULL, UM_KERN_PAGE_SIZE, | ||
294 | PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0); | ||
295 | printf("Checking PROT_EXEC mmap in /tmp..."); | ||
296 | fflush(stdout); | ||
297 | if(addr == MAP_FAILED){ | ||
298 | err = errno; | ||
299 | perror("failed"); | ||
300 | if(err == EPERM) | ||
301 | printf("/tmp must be not mounted noexec\n"); | ||
302 | exit(1); | ||
303 | } | ||
304 | printf("OK\n"); | ||
305 | munmap(addr, UM_KERN_PAGE_SIZE); | ||
306 | |||
307 | close(fd); | ||
308 | } | ||
309 | |||
279 | void os_early_checks(void) | 310 | void os_early_checks(void) |
280 | { | 311 | { |
281 | check_ptrace(); | 312 | check_ptrace(); |
313 | |||
314 | /* Need to check this early because mmapping happens before the | ||
315 | * kernel is running. | ||
316 | */ | ||
317 | check_tmpexec(); | ||
282 | } | 318 | } |
283 | 319 | ||
284 | static int __init noprocmm_cmd_param(char *str, int* add) | 320 | static int __init noprocmm_cmd_param(char *str, int* add) |
@@ -357,3 +393,72 @@ int can_do_skas(void) | |||
357 | return(0); | 393 | return(0); |
358 | } | 394 | } |
359 | #endif | 395 | #endif |
396 | |||
397 | int have_devanon = 0; | ||
398 | |||
399 | void check_devanon(void) | ||
400 | { | ||
401 | int fd; | ||
402 | |||
403 | printk("Checking for /dev/anon on the host..."); | ||
404 | fd = open("/dev/anon", O_RDWR); | ||
405 | if(fd < 0){ | ||
406 | printk("Not available (open failed with errno %d)\n", errno); | ||
407 | return; | ||
408 | } | ||
409 | |||
410 | printk("OK\n"); | ||
411 | have_devanon = 1; | ||
412 | } | ||
413 | |||
414 | int __init parse_iomem(char *str, int *add) | ||
415 | { | ||
416 | struct iomem_region *new; | ||
417 | struct uml_stat buf; | ||
418 | char *file, *driver; | ||
419 | int fd, err, size; | ||
420 | |||
421 | driver = str; | ||
422 | file = strchr(str,','); | ||
423 | if(file == NULL){ | ||
424 | printf("parse_iomem : failed to parse iomem\n"); | ||
425 | goto out; | ||
426 | } | ||
427 | *file = '\0'; | ||
428 | file++; | ||
429 | fd = os_open_file(file, of_rdwr(OPENFLAGS()), 0); | ||
430 | if(fd < 0){ | ||
431 | os_print_error(fd, "parse_iomem - Couldn't open io file"); | ||
432 | goto out; | ||
433 | } | ||
434 | |||
435 | err = os_stat_fd(fd, &buf); | ||
436 | if(err < 0){ | ||
437 | os_print_error(err, "parse_iomem - cannot stat_fd file"); | ||
438 | goto out_close; | ||
439 | } | ||
440 | |||
441 | new = malloc(sizeof(*new)); | ||
442 | if(new == NULL){ | ||
443 | perror("Couldn't allocate iomem_region struct"); | ||
444 | goto out_close; | ||
445 | } | ||
446 | |||
447 | size = (buf.ust_size + UM_KERN_PAGE_SIZE) & ~(UM_KERN_PAGE_SIZE - 1); | ||
448 | |||
449 | *new = ((struct iomem_region) { .next = iomem_regions, | ||
450 | .driver = driver, | ||
451 | .fd = fd, | ||
452 | .size = size, | ||
453 | .phys = 0, | ||
454 | .virt = 0 }); | ||
455 | iomem_regions = new; | ||
456 | iomem_size += new->size + UM_KERN_PAGE_SIZE; | ||
457 | |||
458 | return(0); | ||
459 | out_close: | ||
460 | os_close_file(fd); | ||
461 | out: | ||
462 | return(1); | ||
463 | } | ||
464 | |||
diff --git a/arch/um/os-Linux/tt.c b/arch/um/os-Linux/tt.c index 5b047ab8416a..a6db8877931a 100644 --- a/arch/um/os-Linux/tt.c +++ b/arch/um/os-Linux/tt.c | |||
@@ -36,6 +36,20 @@ | |||
36 | #include "mode.h" | 36 | #include "mode.h" |
37 | #include "tempfile.h" | 37 | #include "tempfile.h" |
38 | 38 | ||
39 | int protect_memory(unsigned long addr, unsigned long len, int r, int w, int x, | ||
40 | int must_succeed) | ||
41 | { | ||
42 | int err; | ||
43 | |||
44 | err = os_protect_memory((void *) addr, len, r, w, x); | ||
45 | if(err < 0){ | ||
46 | if(must_succeed) | ||
47 | panic("protect failed, err = %d", -err); | ||
48 | else return(err); | ||
49 | } | ||
50 | return(0); | ||
51 | } | ||
52 | |||
39 | /* | 53 | /* |
40 | *------------------------- | 54 | *------------------------- |
41 | * only for tt mode (will be deleted in future...) | 55 | * only for tt mode (will be deleted in future...) |