blob: d119f4f7d8971ee7576e6c7db57c59bd3d4704a5 [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>
6#include <asm/page.h>
Jeff Dike54ae36f2007-10-16 01:27:33 -07007#include "as-layout.h"
Bodo Stroesser9786a8f2005-07-07 17:56:50 -07008#include "ptrace_user.h"
9#include "skas.h"
10#include "stub-data.h"
11#include "uml-config.h"
12#include "sysdep/stub.h"
Jeff Dikeaa1a64e2005-11-21 21:32:10 -080013#include "kern_constants.h"
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070014
15/* This is in a separate file because it needs to be compiled with any
16 * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
Jeff Dikeaa1a64e2005-11-21 21:32:10 -080017 *
18 * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
19 * on some systems.
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070020 */
Jeff Dike39d730a2005-11-21 21:32:04 -080021
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070022void __attribute__ ((__section__ (".__syscall_stub")))
23stub_clone_handler(void)
24{
Jeff Dike54ae36f2007-10-16 01:27:33 -070025 struct stub_data *data = (struct stub_data *) STUB_DATA;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070026 long err;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070027
28 err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
Jeff Dike54ae36f2007-10-16 01:27:33 -070029 STUB_DATA + UM_KERN_PAGE_SIZE / 2 - sizeof(void *));
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070030 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 Dike5b7b15a2005-12-18 17:50:39 +010037 err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL,
38 (long) &data->timer, 0);
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070039 if(err)
40 goto out;
41
Jeff Dike5b7b15a2005-12-18 17:50:39 +010042 remap_stack(data->fd, data->offset);
43 goto done;
44
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070045 out:
Jeff Dike5b7b15a2005-12-18 17:50:39 +010046 /* 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 Stroesser9786a8f2005-07-07 17:56:50 -070053 trap_myself();
54}