| 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 |  | 
| Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 21 | void __attribute__ ((__section__ (".__syscall_stub"))) | 
|  | 22 | stub_clone_handler(void) | 
|  | 23 | { | 
| Jeff Dike | 5b7b15a | 2005-12-18 17:50:39 +0100 | [diff] [blame] | 24 | struct stub_data *data = (struct stub_data *) UML_CONFIG_STUB_DATA; | 
| Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 25 | long err; | 
| Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD, | 
| Jeff Dike | aa1a64e | 2005-11-21 21:32:10 -0800 | [diff] [blame] | 28 | UML_CONFIG_STUB_DATA + UM_KERN_PAGE_SIZE / 2 - | 
| Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 29 | sizeof(void *)); | 
|  | 30 | if(err != 0) | 
|  | 31 | goto out; | 
|  | 32 |  | 
|  | 33 | err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0); | 
|  | 34 | if(err) | 
|  | 35 | goto out; | 
|  | 36 |  | 
| Jeff Dike | 5b7b15a | 2005-12-18 17:50:39 +0100 | [diff] [blame] | 37 | err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL, | 
|  | 38 | (long) &data->timer, 0); | 
| Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 39 | if(err) | 
|  | 40 | goto out; | 
|  | 41 |  | 
| Jeff Dike | 5b7b15a | 2005-12-18 17:50:39 +0100 | [diff] [blame] | 42 | remap_stack(data->fd, data->offset); | 
|  | 43 | goto done; | 
|  | 44 |  | 
| Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 45 | out: | 
| Jeff Dike | 5b7b15a | 2005-12-18 17:50:39 +0100 | [diff] [blame] | 46 | /* save current result. | 
|  | 47 | * Parent: pid; | 
|  | 48 | * child: retcode of mmap already saved and it jumps around this | 
|  | 49 | * assignment | 
|  | 50 | */ | 
|  | 51 | data->err = err; | 
|  | 52 | done: | 
| Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 53 | trap_myself(); | 
|  | 54 | } |