1 /* Copyright (C) 1996-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Richard Henderson (rth@tamu.edu)
5 The GNU C Library is free software; you can redistribute it and/or
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.
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
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
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. */
24 #include <bits/errno.h>
25 #include <asm-syntax.h>
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); */
30 #define PARMS 4 /* no space for saved regs */
39 #define __NR_clone 120
42 #define CLONE_VM 0x00000100
43 #define CLONE_THREAD 0x00010000
47 /* Sanity check arguments. */
49 movl FUNC(%esp),%ecx /* no NULL function pointers */
51 jz SYSCALL_ERROR_LABEL
52 movl STACK(%esp),%ecx /* no NULL stack pointers */
54 jz SYSCALL_ERROR_LABEL
56 /* Insert the argument onto the new stack. Make sure the new
57 thread is started with an alignment of (mod 16). */
58 andl $0xfffffff0, %ecx
60 movl ARG(%esp),%eax /* no negative argument counts */
63 /* Save the function pointer as the zeroth argument.
64 It will be popped off in the child in the ebx frobbing below. */
67 /* Don't leak any information. */
70 /* Do the system call */
72 cfi_adjust_cfa_offset (4)
74 cfi_adjust_cfa_offset (4)
76 cfi_adjust_cfa_offset (4)
78 movl TLS+12(%esp),%esi
79 cfi_rel_offset (esi, 4)
80 movl PTID+12(%esp),%edx
81 movl FLAGS+12(%esp),%ebx
82 cfi_rel_offset (ebx, 8)
83 movl CTID+12(%esp),%edi
84 cfi_rel_offset (edi, 0)
85 movl $SYS_ify(clone),%eax
87 /* Remember the flag value. */
90 /* End FDE now, because in the child the unwind info will be
100 jl SYSCALL_ERROR_LABEL
107 /* Clearing frame pointer is insufficient, use CFI. */
109 /* Note: %esi is zero. */
110 movl %esi,%ebp /* terminate the stack frame */
111 testl $CLONE_THREAD, %edi
119 addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebx
122 movl $SYS_ify(exit), %eax
127 testl $CLONE_VM, %edi
130 movl $SYS_ify(getpid), %eax
142 weak_alias (__clone, clone)