]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/i386/clone.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / clone.S
CommitLineData
688903eb 1/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
0c5ecdc4 2 This file is part of the GNU C Library.
267ca16a
UD
3 Contributed by Richard Henderson (rth@tamu.edu)
4
0c5ecdc4 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
267ca16a 9
0c5ecdc4
UD
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
41bdb6e2 13 Lesser General Public License for more details.
267ca16a 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
267ca16a
UD
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>
11336c16 23#define _ERRNO_H 1
5107cf1d 24#include <bits/errno.h>
cbdee279 25#include <asm-syntax.h>
267ca16a 26
b7cb624b 27/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
b33e6163 28 pid_t *ptid, struct user_desc *tls, pid_t *ctid); */
267ca16a 29
2366713d 30#define PARMS 4 /* no space for saved regs */
9e25f6e2
GM
31#define FUNC PARMS
32#define STACK FUNC+4
2366713d 33#define FLAGS STACK+4
9e25f6e2 34#define ARG FLAGS+4
2366713d
JM
35#define PTID ARG+4
36#define TLS PTID+4
37#define CTID TLS+4
b7cb624b
UD
38
39#define __NR_clone 120
40#define SYS_clone 120
9e25f6e2 41
267ca16a 42 .text
2366713d 43ENTRY (__clone)
267ca16a
UD
44 /* Sanity check arguments. */
45 movl $-EINVAL,%eax
9e25f6e2 46 movl FUNC(%esp),%ecx /* no NULL function pointers */
69963deb
UD
47 testl %ecx,%ecx
48 jz SYSCALL_ERROR_LABEL
9e25f6e2 49 movl STACK(%esp),%ecx /* no NULL stack pointers */
69963deb
UD
50 testl %ecx,%ecx
51 jz SYSCALL_ERROR_LABEL
267ca16a 52
6c052003
UD
53 /* Insert the argument onto the new stack. Make sure the new
54 thread is started with an alignment of (mod 16). */
55 andl $0xfffffff0, %ecx
7d585303 56 subl $28,%ecx
9e25f6e2 57 movl ARG(%esp),%eax /* no negative argument counts */
56c91066 58 movl %eax,12(%ecx)
0c5ecdc4 59
267ca16a
UD
60 /* Save the function pointer as the zeroth argument.
61 It will be popped off in the child in the ebx frobbing below. */
9e25f6e2 62 movl FUNC(%esp),%eax
56c91066 63 movl %eax,8(%ecx)
dde36a31 64 /* Don't leak any information. */
56c91066 65 movl $0,4(%ecx)
267ca16a
UD
66
67 /* Do the system call */
68 pushl %ebx
1ad9da69 69 cfi_adjust_cfa_offset (4)
b7cb624b 70 pushl %esi
1ad9da69 71 cfi_adjust_cfa_offset (4)
56c91066 72 pushl %edi
1ad9da69 73 cfi_adjust_cfa_offset (4)
fee732e5 74
56c91066 75 movl TLS+12(%esp),%esi
1ad9da69 76 cfi_rel_offset (esi, 4)
56c91066
UD
77 movl PTID+12(%esp),%edx
78 movl FLAGS+12(%esp),%ebx
1ad9da69 79 cfi_rel_offset (ebx, 8)
56c91066 80 movl CTID+12(%esp),%edi
1ad9da69 81 cfi_rel_offset (edi, 0)
267ca16a 82 movl $SYS_ify(clone),%eax
1ff241b8 83
1ff241b8
UD
84 /* Remember the flag value. */
85 movl %ebx, (%ecx)
1ff241b8 86
fee732e5
UD
87 /* End FDE now, because in the child the unwind info will be
88 wrong. */
89 cfi_endproc
90
267ca16a 91 int $0x80
56c91066 92 popl %edi
b7cb624b 93 popl %esi
267ca16a
UD
94 popl %ebx
95
96 test %eax,%eax
c0fb8a56 97 jl SYSCALL_ERROR_LABEL
b7cb624b 98 jz L(thread_start)
267ca16a
UD
99
100 ret
267ca16a 101
b7cb624b 102L(thread_start):
11bf311e
UD
103 cfi_startproc;
104 /* Clearing frame pointer is insufficient, use CFI. */
105 cfi_undefined (eip);
1ff241b8
UD
106 /* Note: %esi is zero. */
107 movl %esi,%ebp /* terminate the stack frame */
267ca16a 108 call *%ebx
cbdee279
UD
109#ifdef PIC
110 call L(here)
111L(here):
112 popl %ebx
113 addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebx
114#endif
b7cb624b
UD
115 movl %eax, %ebx
116 movl $SYS_ify(exit), %eax
1ad9da69 117 ENTER_KERNEL
267ca16a 118
2366713d 119PSEUDO_END (__clone)
6ed0492f 120
9ff72da4 121libc_hidden_def (__clone)
2366713d 122weak_alias (__clone, clone)