aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um')
-rw-r--r--arch/um/include/mem_user.h15
-rw-r--r--arch/um/include/os.h5
-rw-r--r--arch/um/kernel/Makefile6
-rw-r--r--arch/um/kernel/init_task.c5
-rw-r--r--arch/um/kernel/mem_user.c205
-rw-r--r--arch/um/kernel/tempfile.c82
-rw-r--r--arch/um/kernel/tlb.c2
-rw-r--r--arch/um/kernel/tt/mem_user.c1
-rw-r--r--arch/um/kernel/um_arch.c5
-rw-r--r--arch/um/os-Linux/Makefile8
-rw-r--r--arch/um/os-Linux/mem.c161
-rw-r--r--arch/um/os-Linux/start_up.c109
-rw-r--r--arch/um/os-Linux/tt.c14
13 files changed, 300 insertions, 318 deletions
diff --git a/arch/um/include/mem_user.h b/arch/um/include/mem_user.h
index d6404bb64662..9fef4123a65a 100644
--- a/arch/um/include/mem_user.h
+++ b/arch/um/include/mem_user.h
@@ -51,7 +51,6 @@ extern unsigned long task_size;
51 51
52extern void check_devanon(void); 52extern void check_devanon(void);
53extern int init_mem_user(void); 53extern int init_mem_user(void);
54extern int create_mem_file(unsigned long len);
55extern void setup_memory(void *entry); 54extern void setup_memory(void *entry);
56extern unsigned long find_iomem(char *driver, unsigned long *len_out); 55extern unsigned long find_iomem(char *driver, unsigned long *len_out);
57extern int init_maps(unsigned long physmem, unsigned long iomem, 56extern int init_maps(unsigned long physmem, unsigned long iomem,
@@ -64,20 +63,6 @@ extern unsigned long phys_offset(unsigned long phys);
64extern void unmap_physmem(void); 63extern void unmap_physmem(void);
65extern void map_memory(unsigned long virt, unsigned long phys, 64extern void map_memory(unsigned long virt, unsigned long phys,
66 unsigned long len, int r, int w, int x); 65 unsigned long len, int r, int w, int x);
67extern int protect_memory(unsigned long addr, unsigned long len,
68 int r, int w, int x, int must_succeed);
69extern unsigned long get_kmem_end(void); 66extern unsigned long get_kmem_end(void);
70extern void check_tmpexec(void);
71 67
72#endif 68#endif
73
74/*
75 * Overrides for Emacs so that we follow Linus's tabbing style.
76 * Emacs will notice this stuff at the end of the file and automatically
77 * adjust the settings for this buffer only. This must remain at the end
78 * of the file.
79 * ---------------------------------------------------------------------------
80 * Local variables:
81 * c-file-style: "linux"
82 * End:
83 */
diff --git a/arch/um/include/os.h b/arch/um/include/os.h
index 4c362458052c..583329d0a539 100644
--- a/arch/um/include/os.h
+++ b/arch/um/include/os.h
@@ -157,6 +157,9 @@ extern int os_lock_file(int fd, int excl);
157extern void os_early_checks(void); 157extern void os_early_checks(void);
158extern int can_do_skas(void); 158extern int can_do_skas(void);
159 159
160/* mem.c */
161extern int create_mem_file(unsigned long len);
162
160/* process.c */ 163/* process.c */
161extern unsigned long os_process_pc(int pid); 164extern unsigned long os_process_pc(int pid);
162extern int os_process_parent(int pid); 165extern int os_process_parent(int pid);
@@ -181,6 +184,8 @@ extern unsigned long long os_usecs(void);
181/* tt.c 184/* tt.c
182 * for tt mode only (will be deleted in future...) 185 * for tt mode only (will be deleted in future...)
183 */ 186 */
187extern int protect_memory(unsigned long addr, unsigned long len,
188 int r, int w, int x, int must_succeed);
184extern void forward_pending_sigio(int target); 189extern void forward_pending_sigio(int target);
185extern int start_fork_tramp(void *arg, unsigned long temp_stack, 190extern int start_fork_tramp(void *arg, unsigned long temp_stack,
186 int clone_flags, int (*tramp)(void *)); 191 int clone_flags, int (*tramp)(void *));
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
16obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o 16obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o
@@ -24,8 +24,8 @@ obj-$(CONFIG_MODE_SKAS) += skas/
24 24
25user-objs-$(CONFIG_TTY_LOG) += tty_log.o 25user-objs-$(CONFIG_TTY_LOG) += tty_log.o
26 26
27USER_OBJS := $(user-objs-y) config.o helper.o main.o tempfile.o time.o \ 27USER_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
30include arch/um/scripts/Makefile.rules 30include 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
17static struct fs_struct init_fs = INIT_FS; 18static struct fs_struct init_fs = INIT_FS;
18struct mm_struct init_mm = INIT_MM(init_mm); 19struct mm_struct init_mm = INIT_MM(init_mm);
@@ -45,8 +46,8 @@ __attribute__((__section__(".data.init_task"))) =
45 46
46void unprotect_stack(unsigned long stack) 47void 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
53static 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
84void 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
106static int have_devanon = 0;
107
108void 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
123static 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
144int 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
158struct iomem_region *iomem_regions = NULL; 51struct iomem_region *iomem_regions = NULL;
159int iomem_size = 0; 52int iomem_size = 0;
160 53
161static int __init parse_iomem(char *str, int *add) 54extern 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
217int 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
237int logging = 1;
238int logging_fd = -1;
239
240int logging_line = 0;
241char logging_buf[512];
242
243void 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 */
15static char *tempdir = NULL;
16
17static 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
42int 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
16void remap_data(void *segment_start, void *segment_end, int w) 17void 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
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
6obj-y = aio.o elf_aux.o file.o process.o signal.o start_up.o time.o tt.o \ 6obj-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
9USER_OBJS := aio.o elf_aux.o file.o process.o signal.o start_up.o time.o tt.o \ 9USER_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
12elf_aux.o: $(ARCH_DIR)/kernel-offsets.h 12elf_aux.o: $(ARCH_DIR)/kernel-offsets.h
13CFLAGS_elf_aux.o += -I$(objtree)/arch/um 13CFLAGS_elf_aux.o += -I$(objtree)/arch/um
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
22static char *tempdir = NULL;
23
24static 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 */
54int 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 */
91int 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
124static 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
145extern int have_devanon;
146
147int 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/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
286extern int create_tmp_file(unsigned long len);
287
288static 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
279void os_early_checks(void) 310void 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
284static int __init noprocmm_cmd_param(char *str, int* add) 320static 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
397int have_devanon = 0;
398
399void 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
414int __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
39int 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...)