diff options
Diffstat (limited to 'arch/um/os-Linux')
-rw-r--r-- | arch/um/os-Linux/Makefile | 7 | ||||
-rw-r--r-- | arch/um/os-Linux/drivers/ethertap_kern.c | 13 | ||||
-rw-r--r-- | arch/um/os-Linux/drivers/tuntap_kern.c | 13 | ||||
-rw-r--r-- | arch/um/os-Linux/mem.c | 27 | ||||
-rw-r--r-- | arch/um/os-Linux/process.c | 44 | ||||
-rw-r--r-- | arch/um/os-Linux/start_up.c | 20 | ||||
-rw-r--r-- | arch/um/os-Linux/sys-i386/Makefile | 2 | ||||
-rw-r--r-- | arch/um/os-Linux/sys-i386/tls.c | 33 | ||||
-rw-r--r-- | arch/um/os-Linux/tls.c | 76 |
9 files changed, 159 insertions, 76 deletions
diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index 1659386b42bb..f4bfc4c7ccac 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile | |||
@@ -4,7 +4,7 @@ | |||
4 | # | 4 | # |
5 | 5 | ||
6 | obj-y = aio.o elf_aux.o file.o helper.o irq.o main.o mem.o process.o sigio.o \ | 6 | obj-y = aio.o elf_aux.o file.o helper.o irq.o main.o mem.o process.o sigio.o \ |
7 | signal.o start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o \ | 7 | signal.o start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o tls.o \ |
8 | user_syms.o util.o drivers/ sys-$(SUBARCH)/ | 8 | user_syms.o util.o drivers/ sys-$(SUBARCH)/ |
9 | 9 | ||
10 | obj-$(CONFIG_MODE_SKAS) += skas/ | 10 | obj-$(CONFIG_MODE_SKAS) += skas/ |
@@ -12,12 +12,9 @@ obj-$(CONFIG_TTY_LOG) += tty_log.o | |||
12 | user-objs-$(CONFIG_TTY_LOG) += tty_log.o | 12 | user-objs-$(CONFIG_TTY_LOG) += tty_log.o |
13 | 13 | ||
14 | USER_OBJS := $(user-objs-y) aio.o elf_aux.o file.o helper.o irq.o main.o mem.o \ | 14 | USER_OBJS := $(user-objs-y) aio.o elf_aux.o file.o helper.o irq.o main.o mem.o \ |
15 | process.o sigio.o signal.o start_up.o time.o trap.o tt.o tty.o \ | 15 | process.o sigio.o signal.o start_up.o time.o trap.o tt.o tty.o tls.o \ |
16 | uaccess.o umid.o util.o | 16 | uaccess.o umid.o util.o |
17 | 17 | ||
18 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h | ||
19 | CFLAGS_elf_aux.o += -I$(objtree)/arch/um | ||
20 | |||
21 | CFLAGS_user_syms.o += -DSUBARCH_$(SUBARCH) | 18 | CFLAGS_user_syms.o += -DSUBARCH_$(SUBARCH) |
22 | 19 | ||
23 | HAVE_AIO_ABI := $(shell [ -r /usr/include/linux/aio_abi.h ] && \ | 20 | HAVE_AIO_ABI := $(shell [ -r /usr/include/linux/aio_abi.h ] && \ |
diff --git a/arch/um/os-Linux/drivers/ethertap_kern.c b/arch/um/os-Linux/drivers/ethertap_kern.c index 6ae4b19d9f50..768606bec233 100644 --- a/arch/um/os-Linux/drivers/ethertap_kern.c +++ b/arch/um/os-Linux/drivers/ethertap_kern.c | |||
@@ -102,18 +102,7 @@ static struct transport ethertap_transport = { | |||
102 | static int register_ethertap(void) | 102 | static int register_ethertap(void) |
103 | { | 103 | { |
104 | register_transport(ðertap_transport); | 104 | register_transport(ðertap_transport); |
105 | return(1); | 105 | return 0; |
106 | } | 106 | } |
107 | 107 | ||
108 | __initcall(register_ethertap); | 108 | __initcall(register_ethertap); |
109 | |||
110 | /* | ||
111 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
112 | * Emacs will notice this stuff at the end of the file and automatically | ||
113 | * adjust the settings for this buffer only. This must remain at the end | ||
114 | * of the file. | ||
115 | * --------------------------------------------------------------------------- | ||
116 | * Local variables: | ||
117 | * c-file-style: "linux" | ||
118 | * End: | ||
119 | */ | ||
diff --git a/arch/um/os-Linux/drivers/tuntap_kern.c b/arch/um/os-Linux/drivers/tuntap_kern.c index 4202b9ebad4c..190009a6f89c 100644 --- a/arch/um/os-Linux/drivers/tuntap_kern.c +++ b/arch/um/os-Linux/drivers/tuntap_kern.c | |||
@@ -87,18 +87,7 @@ static struct transport tuntap_transport = { | |||
87 | static int register_tuntap(void) | 87 | static int register_tuntap(void) |
88 | { | 88 | { |
89 | register_transport(&tuntap_transport); | 89 | register_transport(&tuntap_transport); |
90 | return(1); | 90 | return 0; |
91 | } | 91 | } |
92 | 92 | ||
93 | __initcall(register_tuntap); | 93 | __initcall(register_tuntap); |
94 | |||
95 | /* | ||
96 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
97 | * Emacs will notice this stuff at the end of the file and automatically | ||
98 | * adjust the settings for this buffer only. This must remain at the end | ||
99 | * of the file. | ||
100 | * --------------------------------------------------------------------------- | ||
101 | * Local variables: | ||
102 | * c-file-style: "linux" | ||
103 | * End: | ||
104 | */ | ||
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index 9d7d69a523bb..6ab372da9657 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c | |||
@@ -121,36 +121,11 @@ int create_tmp_file(unsigned long long len) | |||
121 | return(fd); | 121 | return(fd); |
122 | } | 122 | } |
123 | 123 | ||
124 | static int create_anon_file(unsigned long 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 long len) | 124 | int create_mem_file(unsigned long long len) |
148 | { | 125 | { |
149 | int err, fd; | 126 | int err, fd; |
150 | 127 | ||
151 | if(have_devanon) | 128 | fd = create_tmp_file(len); |
152 | fd = create_anon_file(len); | ||
153 | else fd = create_tmp_file(len); | ||
154 | 129 | ||
155 | err = os_set_exec_close(fd, 1); | 130 | err = os_set_exec_close(fd, 1); |
156 | if(err < 0){ | 131 | if(err < 0){ |
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index d261888f39c4..8176b0b52047 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/unistd.h> | 11 | #include <linux/unistd.h> |
12 | #include <sys/mman.h> | 12 | #include <sys/mman.h> |
13 | #include <sys/wait.h> | 13 | #include <sys/wait.h> |
14 | #include <sys/mman.h> | ||
14 | #include "ptrace_user.h" | 15 | #include "ptrace_user.h" |
15 | #include "os.h" | 16 | #include "os.h" |
16 | #include "user.h" | 17 | #include "user.h" |
@@ -20,6 +21,7 @@ | |||
20 | #include "kern_util.h" | 21 | #include "kern_util.h" |
21 | #include "longjmp.h" | 22 | #include "longjmp.h" |
22 | #include "skas_ptrace.h" | 23 | #include "skas_ptrace.h" |
24 | #include "kern_constants.h" | ||
23 | 25 | ||
24 | #define ARBITRARY_ADDR -1 | 26 | #define ARBITRARY_ADDR -1 |
25 | #define FAILURE_PID -1 | 27 | #define FAILURE_PID -1 |
@@ -187,6 +189,48 @@ int os_unmap_memory(void *addr, int len) | |||
187 | return(0); | 189 | return(0); |
188 | } | 190 | } |
189 | 191 | ||
192 | #ifndef MADV_REMOVE | ||
193 | #define MADV_REMOVE 0x5 /* remove these pages & resources */ | ||
194 | #endif | ||
195 | |||
196 | int os_drop_memory(void *addr, int length) | ||
197 | { | ||
198 | int err; | ||
199 | |||
200 | err = madvise(addr, length, MADV_REMOVE); | ||
201 | if(err < 0) | ||
202 | err = -errno; | ||
203 | return err; | ||
204 | } | ||
205 | |||
206 | int can_drop_memory(void) | ||
207 | { | ||
208 | void *addr; | ||
209 | int fd; | ||
210 | |||
211 | printk("Checking host MADV_REMOVE support..."); | ||
212 | fd = create_mem_file(UM_KERN_PAGE_SIZE); | ||
213 | if(fd < 0){ | ||
214 | printk("Creating test memory file failed, err = %d\n", -fd); | ||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | addr = mmap64(NULL, UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE, | ||
219 | MAP_PRIVATE, fd, 0); | ||
220 | if(addr == MAP_FAILED){ | ||
221 | printk("Mapping test memory file failed, err = %d\n", -errno); | ||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | if(madvise(addr, UM_KERN_PAGE_SIZE, MADV_REMOVE) != 0){ | ||
226 | printk("MADV_REMOVE failed, err = %d\n", -errno); | ||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | printk("OK\n"); | ||
231 | return 1; | ||
232 | } | ||
233 | |||
190 | void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)) | 234 | void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)) |
191 | { | 235 | { |
192 | int flags = 0, pages; | 236 | int flags = 0, pages; |
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c index 32753131f8d8..387e26af301a 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c | |||
@@ -470,25 +470,6 @@ int can_do_skas(void) | |||
470 | } | 470 | } |
471 | #endif | 471 | #endif |
472 | 472 | ||
473 | int have_devanon = 0; | ||
474 | |||
475 | /* Runs on boot kernel stack - already safe to use printk. */ | ||
476 | |||
477 | void check_devanon(void) | ||
478 | { | ||
479 | int fd; | ||
480 | |||
481 | printk("Checking for /dev/anon on the host..."); | ||
482 | fd = open("/dev/anon", O_RDWR); | ||
483 | if(fd < 0){ | ||
484 | printk("Not available (open failed with errno %d)\n", errno); | ||
485 | return; | ||
486 | } | ||
487 | |||
488 | printk("OK\n"); | ||
489 | have_devanon = 1; | ||
490 | } | ||
491 | |||
492 | int __init parse_iomem(char *str, int *add) | 473 | int __init parse_iomem(char *str, int *add) |
493 | { | 474 | { |
494 | struct iomem_region *new; | 475 | struct iomem_region *new; |
@@ -664,6 +645,5 @@ void os_check_bugs(void) | |||
664 | { | 645 | { |
665 | check_ptrace(); | 646 | check_ptrace(); |
666 | check_sigio(); | 647 | check_sigio(); |
667 | check_devanon(); | ||
668 | } | 648 | } |
669 | 649 | ||
diff --git a/arch/um/os-Linux/sys-i386/Makefile b/arch/um/os-Linux/sys-i386/Makefile index 340ef26f5944..b3213613c41c 100644 --- a/arch/um/os-Linux/sys-i386/Makefile +++ b/arch/um/os-Linux/sys-i386/Makefile | |||
@@ -3,7 +3,7 @@ | |||
3 | # Licensed under the GPL | 3 | # Licensed under the GPL |
4 | # | 4 | # |
5 | 5 | ||
6 | obj-$(CONFIG_MODE_SKAS) = registers.o | 6 | obj-$(CONFIG_MODE_SKAS) = registers.o tls.o |
7 | 7 | ||
8 | USER_OBJS := $(obj-y) | 8 | USER_OBJS := $(obj-y) |
9 | 9 | ||
diff --git a/arch/um/os-Linux/sys-i386/tls.c b/arch/um/os-Linux/sys-i386/tls.c new file mode 100644 index 000000000000..ba21f0e04a2f --- /dev/null +++ b/arch/um/os-Linux/sys-i386/tls.c | |||
@@ -0,0 +1,33 @@ | |||
1 | #include <linux/unistd.h> | ||
2 | #include "sysdep/tls.h" | ||
3 | #include "user_util.h" | ||
4 | |||
5 | static _syscall1(int, get_thread_area, user_desc_t *, u_info); | ||
6 | |||
7 | /* Checks whether host supports TLS, and sets *tls_min according to the value | ||
8 | * valid on the host. | ||
9 | * i386 host have it == 6; x86_64 host have it == 12, for i386 emulation. */ | ||
10 | void check_host_supports_tls(int *supports_tls, int *tls_min) { | ||
11 | /* Values for x86 and x86_64.*/ | ||
12 | int val[] = {GDT_ENTRY_TLS_MIN_I386, GDT_ENTRY_TLS_MIN_X86_64}; | ||
13 | int i; | ||
14 | |||
15 | for (i = 0; i < ARRAY_SIZE(val); i++) { | ||
16 | user_desc_t info; | ||
17 | info.entry_number = val[i]; | ||
18 | |||
19 | if (get_thread_area(&info) == 0) { | ||
20 | *tls_min = val[i]; | ||
21 | *supports_tls = 1; | ||
22 | return; | ||
23 | } else { | ||
24 | if (errno == EINVAL) | ||
25 | continue; | ||
26 | else if (errno == ENOSYS) | ||
27 | *supports_tls = 0; | ||
28 | return; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | *supports_tls = 0; | ||
33 | } | ||
diff --git a/arch/um/os-Linux/tls.c b/arch/um/os-Linux/tls.c new file mode 100644 index 000000000000..9cb09a45546b --- /dev/null +++ b/arch/um/os-Linux/tls.c | |||
@@ -0,0 +1,76 @@ | |||
1 | #include <errno.h> | ||
2 | #include <sys/ptrace.h> | ||
3 | #include <asm/ldt.h> | ||
4 | #include "sysdep/tls.h" | ||
5 | #include "uml-config.h" | ||
6 | |||
7 | /* TLS support - we basically rely on the host's one.*/ | ||
8 | |||
9 | /* In TT mode, this should be called only by the tracing thread, and makes sense | ||
10 | * only for PTRACE_SET_THREAD_AREA. In SKAS mode, it's used normally. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #ifndef PTRACE_GET_THREAD_AREA | ||
15 | #define PTRACE_GET_THREAD_AREA 25 | ||
16 | #endif | ||
17 | |||
18 | #ifndef PTRACE_SET_THREAD_AREA | ||
19 | #define PTRACE_SET_THREAD_AREA 26 | ||
20 | #endif | ||
21 | |||
22 | int os_set_thread_area(user_desc_t *info, int pid) | ||
23 | { | ||
24 | int ret; | ||
25 | |||
26 | ret = ptrace(PTRACE_SET_THREAD_AREA, pid, info->entry_number, | ||
27 | (unsigned long) info); | ||
28 | if (ret < 0) | ||
29 | ret = -errno; | ||
30 | return ret; | ||
31 | } | ||
32 | |||
33 | #ifdef UML_CONFIG_MODE_SKAS | ||
34 | |||
35 | int os_get_thread_area(user_desc_t *info, int pid) | ||
36 | { | ||
37 | int ret; | ||
38 | |||
39 | ret = ptrace(PTRACE_GET_THREAD_AREA, pid, info->entry_number, | ||
40 | (unsigned long) info); | ||
41 | if (ret < 0) | ||
42 | ret = -errno; | ||
43 | return ret; | ||
44 | } | ||
45 | |||
46 | #endif | ||
47 | |||
48 | #ifdef UML_CONFIG_MODE_TT | ||
49 | #include "linux/unistd.h" | ||
50 | |||
51 | static _syscall1(int, get_thread_area, user_desc_t *, u_info); | ||
52 | static _syscall1(int, set_thread_area, user_desc_t *, u_info); | ||
53 | |||
54 | int do_set_thread_area_tt(user_desc_t *info) | ||
55 | { | ||
56 | int ret; | ||
57 | |||
58 | ret = set_thread_area(info); | ||
59 | if (ret < 0) { | ||
60 | ret = -errno; | ||
61 | } | ||
62 | return ret; | ||
63 | } | ||
64 | |||
65 | int do_get_thread_area_tt(user_desc_t *info) | ||
66 | { | ||
67 | int ret; | ||
68 | |||
69 | ret = get_thread_area(info); | ||
70 | if (ret < 0) { | ||
71 | ret = -errno; | ||
72 | } | ||
73 | return ret; | ||
74 | } | ||
75 | |||
76 | #endif /* UML_CONFIG_MODE_TT */ | ||