^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sys/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <as-layout.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <ptrace_user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <stub-data.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <sysdep/stub.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * This is in a separate file because it needs to be compiled with any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * on some systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) void __attribute__ ((__section__ (".__syscall_stub")))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) stub_clone_handler(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct stub_data *data = (struct stub_data *) STUB_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) long err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) STUB_DATA + UM_KERN_PAGE_SIZE / 2 - sizeof(void *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) remap_stack(data->fd, data->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * save current result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Parent: pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * child: retcode of mmap already saved and it jumps around this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * assignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) data->err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) trap_myself();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }