]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/i386/clone.S
update from main archive 961005
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / clone.S
CommitLineData
267ca16a
UD
1/* Copyright (C) 1996 Free Software Foundation, Inc.
2 Contributed by Richard Henderson (rth@tamu.edu)
3
4The GNU C Library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Library General Public License as
6published by the Free Software Foundation; either version 2 of the
7License, or (at your option) any later version.
8
9The GNU C Library is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12Library General Public License for more details.
13
14You should have received a copy of the GNU Library General Public
15License along with the GNU C Library; see the file COPYING.LIB. If
16not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17Cambridge, MA 02139, USA. */
18
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. */
21
22#include <sysdep.h>
23#include <errnos.h>
24
25/* int clone(int (*fn)(), void *child_stack, int flags, int nargs, ...) */
26
27 .text
28ENTRY(__clone)
29 /* Sanity check arguments. */
30 movl $-EINVAL,%eax
31 movl 4(%esp),%ecx /* no NULL function pointers */
32 testl %ecx,%ecx
33 jz syscall_error
34 movl 8(%esp),%ecx /* no NULL stack pointers */
35 testl %ecx,%ecx
36 jz syscall_error
37 movl 16(%esp),%edx /* no negative argument counts */
38 testl %edx,%edx
39 js syscall_error
40
41 /* Allocate space on the new stack and copy args over */
42 movl %edx,%eax
43 negl %eax
44 lea -4(%ecx,%eax,4),%ecx
45 jz 2f
461: movl 16(%esp,%edx,4),%eax
47 movl %eax,0(%ecx,%edx,4)
48 dec %edx
49 jnz 1b
502:
51 /* Save the function pointer as the zeroth argument.
52 It will be popped off in the child in the ebx frobbing below. */
53 movl 4(%esp),%eax
54 movl %eax,0(%ecx)
55
56 /* Do the system call */
57 pushl %ebx
58 movl 16(%esp),%ebx
59 movl $SYS_ify(clone),%eax
60 int $0x80
61 popl %ebx
62
63 test %eax,%eax
64 jl syscall_error
65 jz thread_start
66
67 ret
cccda09f 68 .size __clone,.-__clone
267ca16a
UD
69
70 SYSCALL_ERROR_HANDLER
71
72thread_start:
73 subl %ebp,%ebp /* terminate the stack frame */
74 call *%ebx
706074a5 75 pushl %eax
267ca16a
UD
76#ifdef PIC
77 call _exit@PLT
78#else
79 call _exit
80#endif
81
82weak_alias(__clone, clone)