1 /* Copyright (C) 1996-2000,02,03,04,2005 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.
22 Hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
26 #include <bits/errno.h>
27 #include <sys/syscall.h>
29 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
30 pid_t *ptid, struct user_desc *tls, pid_t *ctid); */
34 #define PARMS LINKAGE /* no space for saved regs */
37 #define FLAGS STACK+PTR_SIZE
39 #define PTID ARG+PTR_SIZE
40 #define TLS PTID+PTR_SIZE
41 #define CTID TLS+PTR_SIZE
47 /* Sanity check arguments. */
50 /* no NULL function pointers */
59 /* no NULL stack pointers */
68 /* Insert the argument onto the new stack. Make sure the new
69 thread is started with an alignment of (mod 16). */
70 andl $0xfffffff0, %ecx
72 movl ARG(%esp),%eax /* no negative argument counts */
75 /* Save the function pointer as the zeroth argument.
76 It will be popped off in the child in the ebx frobbing below. */
79 /* Don't leak any information. */
86 /* Do the system call */
90 movl TLS+12(%esp),%esi
91 movl PTID+12(%esp),%edx
92 movl FLAGS+12(%esp),%ebx
93 movl CTID+12(%esp),%edi
96 /* Remember the flag value. */
110 /* Note: %esi is zero. */
111 movl %esi,%ebp /* terminate the stack frame */
117 addl $_GLOBAL_OFFSET_TABLE_+[.-.Lhere], %ebx
120 movl $__NR_exit, %eax
123 /* Need to indirect jump to syscall error
124 * or we end up with TEXTREL's
130 weak_alias(clone, __clone)