]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/clone.S
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / clone.S
1 /* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Richard Henderson (rth@tamu.edu)
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
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
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
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. */
22
23 #include <sysdep.h>
24 #define _ERRNO_H 1
25 #include <bits/errno.h>
26 #include <asm-syntax.h>
27
28 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
29
30 .text
31 ENTRY(__clone)
32 /* Sanity check arguments. */
33 movl $-EINVAL,%eax
34 movl 4(%esp),%ecx /* no NULL function pointers */
35 testl %ecx,%ecx
36 jz syscall_error
37 movl 8(%esp),%ecx /* no NULL stack pointers */
38 testl %ecx,%ecx
39 jz syscall_error
40
41 /* Insert the argument onto the new stack. */
42 subl $8,%ecx
43 movl 16(%esp),%eax /* no negative argument counts */
44 movl %eax,4(%ecx)
45
46 /* Save the function pointer as the zeroth argument.
47 It will be popped off in the child in the ebx frobbing below. */
48 movl 4(%esp),%eax
49 movl %eax,0(%ecx)
50
51 /* Do the system call */
52 pushl %ebx
53 movl 16(%esp),%ebx
54 movl $SYS_ify(clone),%eax
55 int $0x80
56 popl %ebx
57
58 test %eax,%eax
59 jl syscall_error
60 jz thread_start
61
62 ret
63
64 thread_start:
65 subl %ebp,%ebp /* terminate the stack frame */
66 call *%ebx
67 #ifdef PIC
68 call L(here)
69 L(here):
70 popl %ebx
71 addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebx
72 #endif
73 pushl %eax
74 call JUMPTARGET (_exit)
75
76 PSEUDO_END (__clone)
77
78 weak_alias (__clone, clone)