Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 1 | #include <sched.h> |
| 2 | #include <signal.h> |
| 3 | #include <sys/mman.h> |
| 4 | #include <sys/time.h> |
| 5 | #include <asm/unistd.h> |
| 6 | #include <asm/page.h> |
| 7 | #include "ptrace_user.h" |
| 8 | #include "skas.h" |
| 9 | #include "stub-data.h" |
| 10 | #include "uml-config.h" |
| 11 | #include "sysdep/stub.h" |
Jeff Dike | aa1a64e | 2005-11-21 21:32:10 -0800 | [diff] [blame^] | 12 | #include "kern_constants.h" |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 13 | |
| 14 | /* This is in a separate file because it needs to be compiled with any |
| 15 | * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled |
Jeff Dike | aa1a64e | 2005-11-21 21:32:10 -0800 | [diff] [blame^] | 16 | * |
| 17 | * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize |
| 18 | * on some systems. |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 19 | */ |
Jeff Dike | 39d730a | 2005-11-21 21:32:04 -0800 | [diff] [blame] | 20 | |
| 21 | #define STUB_DATA(field) (((struct stub_data *) UML_CONFIG_STUB_DATA)->field) |
| 22 | |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 23 | void __attribute__ ((__section__ (".__syscall_stub"))) |
| 24 | stub_clone_handler(void) |
| 25 | { |
| 26 | long err; |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 27 | |
| 28 | err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD, |
Jeff Dike | aa1a64e | 2005-11-21 21:32:10 -0800 | [diff] [blame^] | 29 | UML_CONFIG_STUB_DATA + UM_KERN_PAGE_SIZE / 2 - |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 30 | sizeof(void *)); |
| 31 | if(err != 0) |
| 32 | goto out; |
| 33 | |
| 34 | err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0); |
| 35 | if(err) |
| 36 | goto out; |
| 37 | |
| 38 | err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL, |
Jeff Dike | 39d730a | 2005-11-21 21:32:04 -0800 | [diff] [blame] | 39 | (long) &STUB_DATA(timer), 0); |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 40 | if(err) |
| 41 | goto out; |
| 42 | |
Jeff Dike | aa1a64e | 2005-11-21 21:32:10 -0800 | [diff] [blame^] | 43 | err = stub_syscall6(STUB_MMAP_NR, UML_CONFIG_STUB_DATA, |
| 44 | UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE, |
| 45 | MAP_FIXED | MAP_SHARED, STUB_DATA(fd), |
| 46 | STUB_DATA(offset)); |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 47 | out: |
| 48 | /* save current result. Parent: pid; child: retcode of mmap */ |
Jeff Dike | 39d730a | 2005-11-21 21:32:04 -0800 | [diff] [blame] | 49 | STUB_DATA(err) = err; |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 50 | trap_myself(); |
| 51 | } |