]>
Commit | Line | Data |
---|---|---|
4cca6b86 | 1 | /* Wrapper around clone system call. |
f7a9f785 | 2 | Copyright (C) 1997-2016 Free Software Foundation, Inc. |
4cca6b86 UD |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 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. | |
4cca6b86 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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
4cca6b86 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
4cca6b86 UD |
18 | |
19 | #include <sysdep.h> | |
20 | #define _ERRNO_H 1 | |
5107cf1d | 21 | #include <bits/errno.h> |
4cca6b86 | 22 | |
917fbe70 UD |
23 | #define CLONE_VM 0x00000100 |
24 | #define CLONE_THREAD 0x00010000 | |
25 | ||
26 | ||
4cca6b86 UD |
27 | /* This is the only really unusual system call in PPC linux, but not |
28 | because of any weirdness in the system call itself; because of | |
29 | all the freaky stuff we have to do to make the call useful. */ | |
30 | ||
df0f2bf8 | 31 | /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4], |
350635a5 | 32 | int flags [r5], void *arg [r6], void *parent_tid [r7], |
ce5e9b12 | 33 | void *tls [r8], void *child_tid [r9]); */ |
df0f2bf8 | 34 | |
b5510883 | 35 | ENTRY (__clone) |
4cca6b86 | 36 | |
5929563f | 37 | /* Check for child_stack == NULL || fn == NULL. */ |
acf47bbe UD |
38 | cmpwi cr0,r4,0 |
39 | cmpwi cr1,r3,0 | |
ed1ac6a2 | 40 | cror cr0*4+eq,cr1*4+eq,cr0*4+eq |
acf47bbe | 41 | beq- cr0,L(badargs) |
4cca6b86 | 42 | |
ed1ac6a2 | 43 | /* Set up stack frame for parent. */ |
dcac063c | 44 | stwu r1,-32(r1) |
a7e91561 | 45 | cfi_adjust_cfa_offset (32) |
917fbe70 | 46 | stmw r28,16(r1) |
b38de2c8 | 47 | |
5929563f | 48 | /* Set up stack frame for child. */ |
acf47bbe UD |
49 | clrrwi r4,r4,4 |
50 | li r0,0 | |
51 | stwu r0,-16(r4) | |
4cca6b86 | 52 | |
ed1ac6a2 | 53 | /* Save fn, args, stack across syscall. */ |
b1b060c3 | 54 | mr r30,r3 /* Function in r30. */ |
917fbe70 | 55 | mr r28,r5 |
acf47bbe | 56 | mr r31,r6 /* Argument in r31. */ |
5929563f UD |
57 | |
58 | /* 'flags' argument is first parameter to clone syscall. (The other | |
59 | argument is the stack pointer, already in r4.) */ | |
acf47bbe | 60 | mr r3,r5 |
4cca6b86 | 61 | |
ce5e9b12 RM |
62 | /* Move the parent_tid, child_tid and tls arguments. */ |
63 | mr r5,r7 | |
64 | mr r6,r8 | |
65 | mr r7,r9 | |
66 | ||
97d901a6 RM |
67 | /* End FDE now, because in the child the unwind info will be |
68 | wrong. */ | |
69 | cfi_endproc | |
70 | ||
4cca6b86 UD |
71 | /* Do the call. */ |
72 | DO_CALL(SYS_ify(clone)) | |
4cca6b86 | 73 | |
ed1ac6a2 | 74 | /* Check for child process. */ |
acf47bbe | 75 | cmpwi cr1,r3,0 |
ed1ac6a2 | 76 | crandc cr1*4+eq,cr1*4+eq,cr0*4+so |
acf47bbe | 77 | bne- cr1,L(parent) /* The '-' is to minimise the race. */ |
4cca6b86 | 78 | |
dcac063c | 79 | andis. r0,r28,CLONE_THREAD>>16 |
917fbe70 UD |
80 | bne+ r0,L(oldpid) |
81 | andi. r0,r28,CLONE_VM | |
82 | li r3,-1 | |
83 | bne- r0,L(nomoregetpid) | |
84 | DO_CALL(SYS_ify(getpid)) | |
85 | L(nomoregetpid): | |
86 | stw r3,TID(r2) | |
87 | stw r3,PID(r2) | |
88 | L(oldpid): | |
917fbe70 | 89 | |
4cca6b86 | 90 | /* Call procedure. */ |
b1b060c3 | 91 | mtctr r30 |
acf47bbe | 92 | mr r3,r31 |
ed1ac6a2 | 93 | bctrl |
4cca6b86 | 94 | /* Call _exit with result from procedure. */ |
b38de2c8 | 95 | b HIDDEN_JUMPTARGET(_exit) |
ed1ac6a2 UD |
96 | |
97 | L(parent): | |
98 | /* Parent. Restore registers & return. */ | |
917fbe70 | 99 | lmw r28,16(r1) |
dcac063c | 100 | addi r1,r1,32 |
ed1ac6a2 | 101 | bnslr+ |
b0e196a4 | 102 | b __syscall_error@local |
ed1ac6a2 UD |
103 | |
104 | L(badargs): | |
acf47bbe | 105 | li r3,EINVAL |
b0e196a4 | 106 | b __syscall_error@local |
97d901a6 RM |
107 | |
108 | cfi_startproc | |
b5510883 | 109 | END (__clone) |
5929563f | 110 | |
b5510883 | 111 | weak_alias (__clone, clone) |