xref: /openbmc/linux/arch/um/kernel/skas/clone.c (revision fbb6b31a)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
4  * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
5  */
6 
7 #include <signal.h>
8 #include <sched.h>
9 #include <asm/unistd.h>
10 #include <sys/time.h>
11 #include <as-layout.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
18  * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
19  *
20  * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
21  * on some systems.
22  */
23 
24 void __attribute__ ((__section__ (".__syscall_stub")))
25 stub_clone_handler(void)
26 {
27 	struct stub_data *data = get_stub_page();
28 	long err;
29 
30 	err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
31 			    (unsigned long)data + UM_KERN_PAGE_SIZE / 2);
32 	if (err) {
33 		data->parent_err = err;
34 		goto done;
35 	}
36 
37 	err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
38 	if (err) {
39 		data->child_err = err;
40 		goto done;
41 	}
42 
43 	remap_stack_and_trap();
44 
45  done:
46 	trap_myself();
47 }
48