|
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>, 1996.
|
|
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 |
|
|
Packit |
6c4009 |
/* int clone(int (*fn)(void *arg), void *child_stack, int flags,
|
|
Packit |
6c4009 |
void *arg, pid_t *ptid, void *tls, pid_t *ctid);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Note that everything past ARG is technically optional, based
|
|
Packit |
6c4009 |
on FLAGS, and that CTID is arg 7, and thus is on the stack.
|
|
Packit |
6c4009 |
However, since a load from top-of-stack better be legal always,
|
|
Packit |
6c4009 |
we don't bother checking FLAGS. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.text
|
|
Packit |
6c4009 |
.align 4
|
|
Packit |
6c4009 |
.globl __clone
|
|
Packit |
6c4009 |
.ent __clone
|
|
Packit |
6c4009 |
.usepv __clone, USEPV_PROF
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
cfi_startproc
|
|
Packit |
6c4009 |
__clone:
|
|
Packit |
6c4009 |
#ifdef PROF
|
|
Packit |
6c4009 |
.set noat
|
|
Packit |
6c4009 |
ldgp gp,0(pv)
|
|
Packit |
6c4009 |
lda AT, _mcount
|
|
Packit |
6c4009 |
jsr AT, (AT), _mcount
|
|
Packit |
6c4009 |
.set at
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Sanity check arguments. */
|
|
Packit |
6c4009 |
ldiq v0, EINVAL
|
|
Packit |
6c4009 |
beq a0, SYSCALL_ERROR_LABEL /* no NULL function pointers */
|
|
Packit |
6c4009 |
beq a1, SYSCALL_ERROR_LABEL /* no NULL stack pointers */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Save the fn ptr and arg on the new stack. */
|
|
Packit |
6c4009 |
subq a1, 32, a1
|
|
Packit |
6c4009 |
stq a0, 0(a1)
|
|
Packit |
6c4009 |
stq a3, 8(a1)
|
|
Packit |
6c4009 |
stq a2, 16(a1)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The syscall is of the form clone(flags, usp, ptid, ctid, tls).
|
|
Packit |
6c4009 |
Shift the flags, ptid, ctid, tls arguments into place; the
|
|
Packit |
6c4009 |
child_stack argument is already correct. */
|
|
Packit |
6c4009 |
mov a2, a0
|
|
Packit |
6c4009 |
mov a4, a2
|
|
Packit |
6c4009 |
ldq a3, 0(sp)
|
|
Packit |
6c4009 |
mov a5, a4
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Do the system call. */
|
|
Packit |
6c4009 |
ldiq v0, __NR_clone
|
|
Packit |
6c4009 |
call_pal PAL_callsys
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
bne a3, SYSCALL_ERROR_LABEL
|
|
Packit |
6c4009 |
beq v0, thread_start
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Successful return from the parent. */
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
PSEUDO_END(__clone)
|
|
Packit |
6c4009 |
cfi_endproc
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Load up the arguments to the function. Put this block of code in
|
|
Packit |
6c4009 |
its own function so that we can terminate the stack trace with our
|
|
Packit |
6c4009 |
debug info. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.align 4
|
|
Packit |
6c4009 |
.ent thread_start
|
|
Packit |
6c4009 |
cfi_startproc
|
|
Packit |
6c4009 |
thread_start:
|
|
Packit |
6c4009 |
mov 0, fp
|
|
Packit |
6c4009 |
cfi_def_cfa_register(fp)
|
|
Packit |
6c4009 |
cfi_undefined(ra)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Load up the arguments. */
|
|
Packit |
6c4009 |
ldq pv, 0(sp)
|
|
Packit |
6c4009 |
ldq a0, 8(sp)
|
|
Packit |
6c4009 |
addq sp, 32, sp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Call the user's function. */
|
|
Packit |
6c4009 |
jsr ra, (pv)
|
|
Packit |
6c4009 |
ldgp gp, 0(ra)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
mov v0, a0
|
|
Packit |
6c4009 |
ldiq v0, __NR_exit
|
|
Packit |
6c4009 |
call_pal PAL_callsys
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Die horribly. */
|
|
Packit |
6c4009 |
.align 4
|
|
Packit |
6c4009 |
halt
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.align 4
|
|
Packit |
6c4009 |
cfi_endproc
|
|
Packit |
6c4009 |
.end thread_start
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
libc_hidden_def (__clone)
|
|
Packit |
6c4009 |
weak_alias (__clone, clone)
|