blob: 2c8583c1a344df2003ee0f2371ca6ead0a085982 [file] [log] [blame]
Jeff Dikeee563142008-02-04 22:30:43 -08001/*
2 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
Bodo Stroesser9786a8f2005-07-07 17:56:50 -07005
Jeff Dikeee563142008-02-04 22:30:43 -08006#include <signal.h>
7#include <sched.h>
8#include <asm/unistd.h>
9#include <sys/time.h>
10#include "as-layout.h"
11#include "kern_constants.h"
12#include "ptrace_user.h"
13#include "stub-data.h"
14#include "sysdep/stub.h"
15
16/*
17 * This is in a separate file because it needs to be compiled with any
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070018 * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
Jeff Dikeaa1a64e2005-11-21 21:32:10 -080019 *
20 * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
21 * on some systems.
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070022 */
Jeff Dike39d730a2005-11-21 21:32:04 -080023
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070024void __attribute__ ((__section__ (".__syscall_stub")))
25stub_clone_handler(void)
26{
Jeff Dike54ae36f2007-10-16 01:27:33 -070027 struct stub_data *data = (struct stub_data *) STUB_DATA;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070028 long err;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070029
30 err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
Jeff Dike54ae36f2007-10-16 01:27:33 -070031 STUB_DATA + UM_KERN_PAGE_SIZE / 2 - sizeof(void *));
Jeff Dikeee563142008-02-04 22:30:43 -080032 if (err != 0)
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070033 goto out;
34
35 err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
Jeff Dikeee563142008-02-04 22:30:43 -080036 if (err)
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070037 goto out;
38
Jeff Dikeee563142008-02-04 22:30:43 -080039 err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL,
Jeff Dike5b7b15a2005-12-18 17:50:39 +010040 (long) &data->timer, 0);
Jeff Dikeee563142008-02-04 22:30:43 -080041 if (err)
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070042 goto out;
43
Jeff Dike5b7b15a2005-12-18 17:50:39 +010044 remap_stack(data->fd, data->offset);
45 goto done;
46
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070047 out:
Jeff Dikeee563142008-02-04 22:30:43 -080048 /*
49 * save current result.
50 * Parent: pid;
51 * child: retcode of mmap already saved and it jumps around this
Jeff Dike5b7b15a2005-12-18 17:50:39 +010052 * assignment
53 */
54 data->err = err;
55 done:
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070056 trap_myself();
57}