]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 1996-2019 Free Software Foundation, Inc. |
8d2485ed | 2 | This file is part of the GNU C Library. |
e3ec78f5 | 3 | Contributed by Pat Beirne <patb@corelcomputer.com> |
8d2485ed UD |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or | |
3214b89b AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
8d2485ed UD |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3214b89b | 13 | Lesser General Public License for more details. |
8d2485ed | 14 | |
3214b89b | 15 | You should have received a copy of the GNU Lesser General Public |
ab84e3ff | 16 | License along with the GNU C Library. If not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
8d2485ed UD |
18 | |
19 | /* clone() is even more special than fork() as it mucks with stacks | |
20 | and invokes a function in the right context after its all over. */ | |
21 | ||
22 | #include <sysdep.h> | |
bba6da4e | 23 | #include <tcb-offsets.h> |
8d2485ed | 24 | #define _ERRNO_H 1 |
405916ef | 25 | #include <bits/errno.h> |
8d2485ed | 26 | |
02a9f771 DJ |
27 | /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg, |
28 | pid_t *ptid, struct user_desc *tls, pid_t *ctid); */ | |
8d2485ed UD |
29 | |
30 | .text | |
31 | ENTRY(__clone) | |
e3ec78f5 UD |
32 | @ sanity check args |
33 | cmp r0, #0 | |
6ccd0107 | 34 | ite ne |
e3ec78f5 UD |
35 | cmpne r1, #0 |
36 | moveq r0, #-EINVAL | |
37 | beq PLTJMP(syscall_error) | |
38 | ||
39 | @ insert the args onto the new stack | |
5b52ee17 UD |
40 | str r3, [r1, #-4]! |
41 | str r0, [r1, #-4]! | |
e3ec78f5 UD |
42 | |
43 | @ do the system call | |
f6e4428c | 44 | @ get flags |
e3ec78f5 | 45 | mov r0, r2 |
02a9f771 | 46 | mov ip, r2 |
e3ec78f5 | 47 | @ new sp is already in r1 |
55668624 | 48 | push {r4, r7} |
01b32e73 TS |
49 | cfi_adjust_cfa_offset (8) |
50 | cfi_rel_offset (r4, 0) | |
51 | cfi_rel_offset (r7, 4) | |
02a9f771 DJ |
52 | ldr r2, [sp, #8] |
53 | ldr r3, [sp, #12] | |
54 | ldr r4, [sp, #16] | |
02a9f771 DJ |
55 | ldr r7, =SYS_ify(clone) |
56 | swi 0x0 | |
01b32e73 | 57 | cfi_endproc |
02a9f771 DJ |
58 | cmp r0, #0 |
59 | beq 1f | |
55668624 | 60 | pop {r4, r7} |
f6e4428c | 61 | blt PLTJMP(C_SYMBOL_NAME(__syscall_error)) |
02a9f771 | 62 | RETINSTR(, lr) |
e3ec78f5 | 63 | |
01b32e73 | 64 | cfi_startproc |
3c6ac5cb AH |
65 | PSEUDO_END (__clone) |
66 | ||
02a9f771 | 67 | 1: |
3c6ac5cb AH |
68 | .fnstart |
69 | .cantunwind | |
e3ec78f5 UD |
70 | @ pick the function arg and call address off the stack and execute |
71 | ldr r0, [sp, #4] | |
b2b2415f | 72 | ldr ip, [sp], #8 |
47590bce | 73 | BLX (ip) |
e3ec78f5 UD |
74 | |
75 | @ and we are done, passing the return value through r0 | |
3f823e87 AZ |
76 | ldr r7, =SYS_ify(exit) |
77 | swi 0x0 | |
e3ec78f5 | 78 | |
3c6ac5cb | 79 | .fnend |
8d2485ed | 80 | |
9ff72da4 | 81 | libc_hidden_def (__clone) |
8d2485ed | 82 | weak_alias (__clone, clone) |