|
Packit |
6c4009 |
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Richard Henderson (rth@tamu.edu)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* clone() is even more special than fork() as it mucks with stacks
|
|
Packit |
6c4009 |
and invokes a function in the right context after its all over. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sysdep.h>
|
|
Packit |
6c4009 |
#define _ERRNO_H 1
|
|
Packit |
6c4009 |
#include <bits/errno.h>
|
|
Packit |
6c4009 |
#include <asm-syntax.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
|
|
Packit |
6c4009 |
pid_t *ptid, struct user_desc *tls, pid_t *ctid); */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define PARMS 4 /* no space for saved regs */
|
|
Packit |
6c4009 |
#define FUNC PARMS
|
|
Packit |
6c4009 |
#define STACK FUNC+4
|
|
Packit |
6c4009 |
#define FLAGS STACK+4
|
|
Packit |
6c4009 |
#define ARG FLAGS+4
|
|
Packit |
6c4009 |
#define PTID ARG+4
|
|
Packit |
6c4009 |
#define TLS PTID+4
|
|
Packit |
6c4009 |
#define CTID TLS+4
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define __NR_clone 120
|
|
Packit |
6c4009 |
#define SYS_clone 120
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.text
|
|
Packit |
6c4009 |
ENTRY (__clone)
|
|
Packit |
6c4009 |
/* Sanity check arguments. */
|
|
Packit |
6c4009 |
movl $-EINVAL,%eax
|
|
Packit |
6c4009 |
movl FUNC(%esp),%ecx /* no NULL function pointers */
|
|
Packit |
6c4009 |
testl %ecx,%ecx
|
|
Packit |
6c4009 |
jz SYSCALL_ERROR_LABEL
|
|
Packit |
6c4009 |
movl STACK(%esp),%ecx /* no NULL stack pointers */
|
|
Packit |
6c4009 |
testl %ecx,%ecx
|
|
Packit |
6c4009 |
jz SYSCALL_ERROR_LABEL
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Insert the argument onto the new stack. Make sure the new
|
|
Packit |
6c4009 |
thread is started with an alignment of (mod 16). */
|
|
Packit |
6c4009 |
andl $0xfffffff0, %ecx
|
|
Packit |
6c4009 |
subl $28,%ecx
|
|
Packit |
6c4009 |
movl ARG(%esp),%eax /* no negative argument counts */
|
|
Packit |
6c4009 |
movl %eax,12(%ecx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Save the function pointer as the zeroth argument.
|
|
Packit |
6c4009 |
It will be popped off in the child in the ebx frobbing below. */
|
|
Packit |
6c4009 |
movl FUNC(%esp),%eax
|
|
Packit |
6c4009 |
movl %eax,8(%ecx)
|
|
Packit |
6c4009 |
/* Don't leak any information. */
|
|
Packit |
6c4009 |
movl $0,4(%ecx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Do the system call */
|
|
Packit |
6c4009 |
pushl %ebx
|
|
Packit |
6c4009 |
cfi_adjust_cfa_offset (4)
|
|
Packit |
6c4009 |
pushl %esi
|
|
Packit |
6c4009 |
cfi_adjust_cfa_offset (4)
|
|
Packit |
6c4009 |
pushl %edi
|
|
Packit |
6c4009 |
cfi_adjust_cfa_offset (4)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
movl TLS+12(%esp),%esi
|
|
Packit |
6c4009 |
cfi_rel_offset (esi, 4)
|
|
Packit |
6c4009 |
movl PTID+12(%esp),%edx
|
|
Packit |
6c4009 |
movl FLAGS+12(%esp),%ebx
|
|
Packit |
6c4009 |
cfi_rel_offset (ebx, 8)
|
|
Packit |
6c4009 |
movl CTID+12(%esp),%edi
|
|
Packit |
6c4009 |
cfi_rel_offset (edi, 0)
|
|
Packit |
6c4009 |
movl $SYS_ify(clone),%eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Remember the flag value. */
|
|
Packit |
6c4009 |
movl %ebx, (%ecx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* End FDE now, because in the child the unwind info will be
|
|
Packit |
6c4009 |
wrong. */
|
|
Packit |
6c4009 |
cfi_endproc
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int $0x80
|
|
Packit |
6c4009 |
popl %edi
|
|
Packit |
6c4009 |
popl %esi
|
|
Packit |
6c4009 |
popl %ebx
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
test %eax,%eax
|
|
Packit |
6c4009 |
jl SYSCALL_ERROR_LABEL
|
|
Packit |
6c4009 |
jz L(thread_start)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
L(thread_start):
|
|
Packit |
6c4009 |
cfi_startproc;
|
|
Packit |
6c4009 |
/* Clearing frame pointer is insufficient, use CFI. */
|
|
Packit |
6c4009 |
cfi_undefined (eip);
|
|
Packit |
6c4009 |
/* Note: %esi is zero. */
|
|
Packit |
6c4009 |
movl %esi,%ebp /* terminate the stack frame */
|
|
Packit |
6c4009 |
call *%ebx
|
|
Packit |
6c4009 |
#ifdef PIC
|
|
Packit |
6c4009 |
call L(here)
|
|
Packit |
6c4009 |
L(here):
|
|
Packit |
6c4009 |
popl %ebx
|
|
Packit |
6c4009 |
addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebx
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
movl %eax, %ebx
|
|
Packit |
6c4009 |
movl $SYS_ify(exit), %eax
|
|
Packit |
6c4009 |
ENTER_KERNEL
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
PSEUDO_END (__clone)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
libc_hidden_def (__clone)
|
|
Packit |
6c4009 |
weak_alias (__clone, clone)
|