4 * Functions for setting up host processes implementing tasks
14 #include <asm/unistd.h>
16 #include <sys/ptrace.h>
17 #include <sys/types.h>
24 #include "boot_info.h"
28 #include "lock_guard.h"
29 #include "mem_layout.h"
31 #include "trampoline.h"
37 char **args = Boot_info::args();
40 // Zero all args, making ps output pretty
41 do arglen += strlen (*args) + 1; while (*++args);
42 memset (*Boot_info::args(), 0, arglen);
44 // Put task number into argv[0] for ps
45 snprintf (*Boot_info::args(), arglen, "[Task]");
53 check (!sigprocmask (SIG_UNBLOCK, &mask, NULL));
56 stack.ss_sp = (void *) Mem_layout::Trampoline_page;
57 stack.ss_size = Config::PAGE_SIZE;
59 check (!sigaltstack (&stack, NULL));
61 struct sigaction action;
62 sigfillset (&action.sa_mask);
63 action.sa_flags = SA_ONSTACK | SA_SIGINFO;
64 action.sa_restorer = (void (*)()) 0xDEADC0DE;
65 action.sa_sigaction = (void (*)(int,siginfo_t*,void*))
66 Mem_layout::Trampoline_page;
67 check (!sigaction (SIGSEGV, &action, NULL));
69 // Map trampoline page
70 check (mmap ((void *) Mem_layout::Trampoline_page,
72 PROT_READ | PROT_WRITE | PROT_EXEC,
73 MAP_SHARED | MAP_FIXED,
75 Mem_layout::Trampoline_frame) != MAP_FAILED);
77 ptrace (PTRACE_TRACEME, 0, NULL, NULL);
86 Lock_guard <Cpu_lock> guard (&cpu_lock);
92 * Careful with local variables here because we are changing the
93 * stack pointer for the fork system call. This ensures that the
94 * child gets its own COW stack rather than running on the parent
97 asm volatile ("movl %%esp, %0; movl %1, %%esp" :
98 "=m" (esp), "=m" (boot_stack));
100 // Make sure the child doesn't inherit any of our unflushed output
103 switch (pid = fork())
110 _exit(1); // unreached
113 asm volatile ("movl %0, %%esp" : : "m" (esp));
116 check (waitpid (pid, &status, 0) == pid);
117 assert (WIFSTOPPED (status) && WSTOPSIG (status) == SIGUSR1);
119 Trampoline::syscall (pid, __NR_munmap, 0, Mem_layout::Trampoline_page);