aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux/start_up.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/os-Linux/start_up.c')
-rw-r--r--arch/um/os-Linux/start_up.c120
1 files changed, 118 insertions, 2 deletions
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c
index 040cc1472bc..b99ab414542 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"
@@ -136,11 +143,22 @@ static int __init skas0_cmd_param(char *str, int* add)
136 return 0; 143 return 0;
137} 144}
138 145
146/* The two __uml_setup would conflict, without this stupid alias. */
147
148static int __init mode_skas0_cmd_param(char *str, int* add)
149 __attribute__((alias("skas0_cmd_param")));
150
139__uml_setup("skas0", skas0_cmd_param, 151__uml_setup("skas0", skas0_cmd_param,
140 "skas0\n" 152 "skas0\n"
141 " Disables SKAS3 usage, so that SKAS0 is used, unless \n" 153 " Disables SKAS3 usage, so that SKAS0 is used, unless \n"
142 " you specify mode=tt.\n\n"); 154 " you specify mode=tt.\n\n");
143 155
156__uml_setup("mode=skas0", mode_skas0_cmd_param,
157 "mode=skas0\n"
158 " Disables SKAS3 usage, so that SKAS0 is used, unless you \n"
159 " specify mode=tt. Note that this was recently added - on \n"
160 " older kernels you must use simply \"skas0\".\n\n");
161
144static int force_sysemu_disabled = 0; 162static int force_sysemu_disabled = 0;
145 163
146static int __init nosysemu_cmd_param(char *str, int* add) 164static int __init nosysemu_cmd_param(char *str, int* add)
@@ -276,9 +294,38 @@ static void __init check_ptrace(void)
276 check_sysemu(); 294 check_sysemu();
277} 295}
278 296
297extern int create_tmp_file(unsigned long len);
298
299static void check_tmpexec(void)
300{
301 void *addr;
302 int err, fd = create_tmp_file(UM_KERN_PAGE_SIZE);
303
304 addr = mmap(NULL, UM_KERN_PAGE_SIZE,
305 PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0);
306 printf("Checking PROT_EXEC mmap in /tmp...");
307 fflush(stdout);
308 if(addr == MAP_FAILED){
309 err = errno;
310 perror("failed");
311 if(err == EPERM)
312 printf("/tmp must be not mounted noexec\n");
313 exit(1);
314 }
315 printf("OK\n");
316 munmap(addr, UM_KERN_PAGE_SIZE);
317
318 close(fd);
319}
320
279void os_early_checks(void) 321void os_early_checks(void)
280{ 322{
281 check_ptrace(); 323 check_ptrace();
324
325 /* Need to check this early because mmapping happens before the
326 * kernel is running.
327 */
328 check_tmpexec();
282} 329}
283 330
284static int __init noprocmm_cmd_param(char *str, int* add) 331static int __init noprocmm_cmd_param(char *str, int* add)
@@ -357,3 +404,72 @@ int can_do_skas(void)
357 return(0); 404 return(0);
358} 405}
359#endif 406#endif
407
408int have_devanon = 0;
409
410void check_devanon(void)
411{
412 int fd;
413
414 printk("Checking for /dev/anon on the host...");
415 fd = open("/dev/anon", O_RDWR);
416 if(fd < 0){
417 printk("Not available (open failed with errno %d)\n", errno);
418 return;
419 }
420
421 printk("OK\n");
422 have_devanon = 1;
423}
424
425int __init parse_iomem(char *str, int *add)
426{
427 struct iomem_region *new;
428 struct uml_stat buf;
429 char *file, *driver;
430 int fd, err, size;
431
432 driver = str;
433 file = strchr(str,',');
434 if(file == NULL){
435 printf("parse_iomem : failed to parse iomem\n");
436 goto out;
437 }
438 *file = '\0';
439 file++;
440 fd = os_open_file(file, of_rdwr(OPENFLAGS()), 0);
441 if(fd < 0){
442 os_print_error(fd, "parse_iomem - Couldn't open io file");
443 goto out;
444 }
445
446 err = os_stat_fd(fd, &buf);
447 if(err < 0){
448 os_print_error(err, "parse_iomem - cannot stat_fd file");
449 goto out_close;
450 }
451
452 new = malloc(sizeof(*new));
453 if(new == NULL){
454 perror("Couldn't allocate iomem_region struct");
455 goto out_close;
456 }
457
458 size = (buf.ust_size + UM_KERN_PAGE_SIZE) & ~(UM_KERN_PAGE_SIZE - 1);
459
460 *new = ((struct iomem_region) { .next = iomem_regions,
461 .driver = driver,
462 .fd = fd,
463 .size = size,
464 .phys = 0,
465 .virt = 0 });
466 iomem_regions = new;
467 iomem_size += new->size + UM_KERN_PAGE_SIZE;
468
469 return(0);
470 out_close:
471 os_close_file(fd);
472 out:
473 return(1);
474}
475