clone.c 1.2 KB
Newer Older
J
Jeff Dike 已提交
1 2 3 4 5
/*
 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
 * Licensed under the GPL
 */

6
#include <signal.h>
J
Jeff Dike 已提交
7
#include <sched.h>
8
#include <asm/unistd.h>
J
Jeff Dike 已提交
9
#include <sys/time.h>
10 11 12 13
#include <as-layout.h>
#include <ptrace_user.h>
#include <stub-data.h>
#include <sysdep/stub.h>
14

J
Jeff Dike 已提交
15 16
/*
 * This is in a separate file because it needs to be compiled with any
17
 * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
18 19 20
 *
 * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
 * on some systems.
21
 */
22

23 24 25
void __attribute__ ((__section__ (".__syscall_stub")))
stub_clone_handler(void)
{
J
Jeff Dike 已提交
26
	struct stub_data *data = (struct stub_data *) STUB_DATA;
27 28 29
	long err;

	err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
J
Jeff Dike 已提交
30
			    STUB_DATA + UM_KERN_PAGE_SIZE / 2 - sizeof(void *));
J
Jeff Dike 已提交
31
	if (err != 0)
32 33 34
		goto out;

	err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
J
Jeff Dike 已提交
35
	if (err)
36 37
		goto out;

J
Jeff Dike 已提交
38
	err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL,
J
Jeff Dike 已提交
39
			    (long) &data->timer, 0);
J
Jeff Dike 已提交
40
	if (err)
41 42
		goto out;

J
Jeff Dike 已提交
43 44 45
	remap_stack(data->fd, data->offset);
	goto done;

46
 out:
J
Jeff Dike 已提交
47 48 49 50
	/*
	 * save current result.
	 * Parent: pid;
	 * child: retcode of mmap already saved and it jumps around this
J
Jeff Dike 已提交
51 52 53 54
	 * assignment
	 */
	data->err = err;
 done:
55 56
	trap_myself();
}