]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/clone.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / clone.S
1 /* Copyright (C) 1996-2017 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 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.
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 Lesser General Public License for more details.
14
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/>. */
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 #define _ERRNO_H 1
24 #include <bits/errno.h>
25 #include <asm-syntax.h>
26
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); */
29
30 #define PARMS 4 /* no space for saved regs */
31 #define FUNC PARMS
32 #define STACK FUNC+4
33 #define FLAGS STACK+4
34 #define ARG FLAGS+4
35 #define PTID ARG+4
36 #define TLS PTID+4
37 #define CTID TLS+4
38
39 #define __NR_clone 120
40 #define SYS_clone 120
41
42 #define CLONE_VM 0x00000100
43
44 .text
45 ENTRY (__clone)
46 /* Sanity check arguments. */
47 movl $-EINVAL,%eax
48 movl FUNC(%esp),%ecx /* no NULL function pointers */
49 testl %ecx,%ecx
50 jz SYSCALL_ERROR_LABEL
51 movl STACK(%esp),%ecx /* no NULL stack pointers */
52 testl %ecx,%ecx
53 jz SYSCALL_ERROR_LABEL
54
55 /* Insert the argument onto the new stack. Make sure the new
56 thread is started with an alignment of (mod 16). */
57 andl $0xfffffff0, %ecx
58 subl $28,%ecx
59 movl ARG(%esp),%eax /* no negative argument counts */
60 movl %eax,12(%ecx)
61
62 /* Save the function pointer as the zeroth argument.
63 It will be popped off in the child in the ebx frobbing below. */
64 movl FUNC(%esp),%eax
65 movl %eax,8(%ecx)
66 /* Don't leak any information. */
67 movl $0,4(%ecx)
68
69 /* Do the system call */
70 pushl %ebx
71 cfi_adjust_cfa_offset (4)
72 pushl %esi
73 cfi_adjust_cfa_offset (4)
74 pushl %edi
75 cfi_adjust_cfa_offset (4)
76
77 movl TLS+12(%esp),%esi
78 cfi_rel_offset (esi, 4)
79 movl PTID+12(%esp),%edx
80 movl FLAGS+12(%esp),%ebx
81 cfi_rel_offset (ebx, 8)
82 movl CTID+12(%esp),%edi
83 cfi_rel_offset (edi, 0)
84 movl $SYS_ify(clone),%eax
85
86 /* Remember the flag value. */
87 movl %ebx, (%ecx)
88
89 /* End FDE now, because in the child the unwind info will be
90 wrong. */
91 cfi_endproc
92
93 int $0x80
94 popl %edi
95 popl %esi
96 popl %ebx
97
98 test %eax,%eax
99 jl SYSCALL_ERROR_LABEL
100 jz L(thread_start)
101
102 ret
103
104 L(thread_start):
105 cfi_startproc;
106 /* Clearing frame pointer is insufficient, use CFI. */
107 cfi_undefined (eip);
108 /* Note: %esi is zero. */
109 movl %esi,%ebp /* terminate the stack frame */
110 call *%ebx
111 #ifdef PIC
112 call L(here)
113 L(here):
114 popl %ebx
115 addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebx
116 #endif
117 movl %eax, %ebx
118 movl $SYS_ify(exit), %eax
119 ENTER_KERNEL
120
121 PSEUDO_END (__clone)
122
123 libc_hidden_def (__clone)
124 weak_alias (__clone, clone)