1 /* Copyright (C) 1996,1997,98,99,2000,02,03,04 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 /* clone() is even more special than fork() as it mucks with stacks
21 and invokes a function in the right context after its all over. */
25 #include <bits/errno.h>
26 #include <asm-syntax.h>
30 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
31 pid_t *ptid, struct user_desc *tls, pid_t *ctid); */
33 #define PARMS LINKAGE /* no space for saved regs */
36 #define FLAGS STACK+PTR_SIZE
38 #define PTID ARG+PTR_SIZE
39 #define TLS PTID+PTR_SIZE
40 #define CTID TLS+PTR_SIZE
42 #define __NR_clone 120
45 #define CLONE_VM 0x00000100
46 #define CLONE_THREAD 0x00010000
49 ENTRY (BP_SYM (__clone))
50 /* Sanity check arguments. */
52 movl FUNC(%esp),%ecx /* no NULL function pointers */
54 jecxz SYSCALL_ERROR_LABEL
57 jz SYSCALL_ERROR_LABEL
59 movl STACK(%esp),%ecx /* no NULL stack pointers */
61 jecxz SYSCALL_ERROR_LABEL
64 jz SYSCALL_ERROR_LABEL
67 /* Insert the argument onto the new stack. Make sure the new
68 thread is started with an alignment of (mod 16). */
69 andl $0xfffffff0, %ecx
71 movl ARG(%esp),%eax /* no negative argument counts */
74 /* Save the function pointer as the zeroth argument.
75 It will be popped off in the child in the ebx frobbing below. */
78 /* Don't leak any information. */
84 /* Do the system call */
88 movl TLS+12(%esp),%esi
89 movl PTID+12(%esp),%edx
90 movl FLAGS+12(%esp),%ebx
91 movl CTID+12(%esp),%edi
92 movl $SYS_ify(clone),%eax
95 /* Remember the flag value. */
105 jl SYSCALL_ERROR_LABEL
112 /* Note: %esi is zero. */
113 movl %esi,%ebp /* terminate the stack frame */
115 testl $CLONE_THREAD, %edi
124 addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebx
127 movl $SYS_ify(exit), %eax
133 testl $CLONE_VM, %edi
136 movl $SYS_ify(getpid), %eax
145 PSEUDO_END (BP_SYM (__clone))
147 weak_alias (BP_SYM (__clone), BP_SYM (clone))