blob: 8d07a7acb909c707bd5ec4d0bcf3ce6d53045db1 [file] [log] [blame]
Bodo Stroesser9786a8f2005-07-07 17:56:50 -07001#include <sched.h>
2#include <signal.h>
3#include <sys/mman.h>
4#include <sys/time.h>
5#include <asm/unistd.h>
Jeff Dike54ae36f2007-10-16 01:27:33 -07006#include "as-layout.h"
Bodo Stroesser9786a8f2005-07-07 17:56:50 -07007#include "ptrace_user.h"
8#include "skas.h"
9#include "stub-data.h"
10#include "uml-config.h"
11#include "sysdep/stub.h"
Jeff Dikeaa1a64e2005-11-21 21:32:10 -080012#include "kern_constants.h"
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070013
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 Dikeaa1a64e2005-11-21 21:32:10 -080016 *
17 * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
18 * on some systems.
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070019 */
Jeff Dike39d730a2005-11-21 21:32:04 -080020
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070021void __attribute__ ((__section__ (".__syscall_stub")))
22stub_clone_handler(void)
23{
Jeff Dike54ae36f2007-10-16 01:27:33 -070024 struct stub_data *data = (struct stub_data *) STUB_DATA;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070025 long err;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070026
27 err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
Jeff Dike54ae36f2007-10-16 01:27:33 -070028 STUB_DATA + UM_KERN_PAGE_SIZE / 2 - sizeof(void *));
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070029 if(err != 0)
30 goto out;
31
32 err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
33 if(err)
34 goto out;
35
Jeff Dike5b7b15a2005-12-18 17:50:39 +010036 err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL,
37 (long) &data->timer, 0);
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070038 if(err)
39 goto out;
40
Jeff Dike5b7b15a2005-12-18 17:50:39 +010041 remap_stack(data->fd, data->offset);
42 goto done;
43
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070044 out:
Jeff Dike5b7b15a2005-12-18 17:50:39 +010045 /* save current result.
46 * Parent: pid;
47 * child: retcode of mmap already saved and it jumps around this
48 * assignment
49 */
50 data->err = err;
51 done:
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070052 trap_myself();
53}