blob: e1fd066a3525c20f4820c0227c42613984edabd4 [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"
Jeff Dikeee563142008-02-04 22:30:43 -080011#include "ptrace_user.h"
12#include "stub-data.h"
13#include "sysdep/stub.h"
14
15/*
16 * This is in a separate file because it needs to be compiled with any
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070017 * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
Jeff Dikeaa1a64e2005-11-21 21:32:10 -080018 *
19 * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
20 * on some systems.
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070021 */
Jeff Dike39d730a2005-11-21 21:32:04 -080022
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070023void __attribute__ ((__section__ (".__syscall_stub")))
24stub_clone_handler(void)
25{
Jeff Dike54ae36f2007-10-16 01:27:33 -070026 struct stub_data *data = (struct stub_data *) STUB_DATA;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070027 long err;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070028
29 err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
Jeff Dike54ae36f2007-10-16 01:27:33 -070030 STUB_DATA + UM_KERN_PAGE_SIZE / 2 - sizeof(void *));
Jeff Dikeee563142008-02-04 22:30:43 -080031 if (err != 0)
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070032 goto out;
33
34 err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
Jeff Dikeee563142008-02-04 22:30:43 -080035 if (err)
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070036 goto out;
37
Jeff Dikeee563142008-02-04 22:30:43 -080038 err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL,
Jeff Dike5b7b15a2005-12-18 17:50:39 +010039 (long) &data->timer, 0);
Jeff Dikeee563142008-02-04 22:30:43 -080040 if (err)
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070041 goto out;
42
Jeff Dike5b7b15a2005-12-18 17:50:39 +010043 remap_stack(data->fd, data->offset);
44 goto done;
45
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070046 out:
Jeff Dikeee563142008-02-04 22:30:43 -080047 /*
48 * save current result.
49 * Parent: pid;
50 * child: retcode of mmap already saved and it jumps around this
Jeff Dike5b7b15a2005-12-18 17:50:39 +010051 * assignment
52 */
53 data->err = err;
54 done:
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070055 trap_myself();
56}