|
Packit |
6c4009 |
/* Copyright (C) 1997-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 <asm/errno.h>
|
|
Packit |
6c4009 |
#include <asm/unistd.h>
|
|
Packit |
6c4009 |
#include <tcb-offsets.h>
|
|
Packit |
6c4009 |
#include <sysdep.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
|
|
Packit |
6c4009 |
pid_t *ptid, void *tls, pid_t *ctid); */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.register %g2,#scratch
|
|
Packit |
6c4009 |
.register %g3,#scratch
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.text
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ENTRY (__clone)
|
|
Packit |
6c4009 |
save %sp, -192, %sp
|
|
Packit |
6c4009 |
cfi_def_cfa_register(%fp)
|
|
Packit |
6c4009 |
cfi_window_save
|
|
Packit |
6c4009 |
cfi_register(%o7, %i7)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* sanity check arguments */
|
|
Packit |
6c4009 |
brz,pn %i0, 99f /* fn non-NULL? */
|
|
Packit |
6c4009 |
mov %i0, %g2
|
|
Packit |
6c4009 |
brz,pn %i1, 99f /* child_stack non-NULL? */
|
|
Packit |
6c4009 |
mov %i2, %o0 /* clone flags */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The child_stack is the top of the stack, allocate one
|
|
Packit |
6c4009 |
whole stack frame from that as this is what the kernel
|
|
Packit |
6c4009 |
expects. Also, subtract STACK_BIAS. */
|
|
Packit |
6c4009 |
sub %i1, 192 + 0x7ff, %o1
|
|
Packit |
6c4009 |
mov %i3, %g3
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
mov %i4,%o2 /* PTID */
|
|
Packit |
6c4009 |
mov %i5,%o3 /* TLS */
|
|
Packit |
6c4009 |
ldx [%fp+0x7ff+176],%o4 /* CTID */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Do the system call */
|
|
Packit |
6c4009 |
set __NR_clone, %g1
|
|
Packit |
6c4009 |
ta 0x6d
|
|
Packit |
6c4009 |
bcs,pn %xcc, 98f
|
|
Packit |
6c4009 |
nop
|
|
Packit |
6c4009 |
brnz,pn %o1, __thread_start
|
|
Packit |
6c4009 |
nop
|
|
Packit |
6c4009 |
jmpl %i7 + 8, %g0
|
|
Packit |
6c4009 |
restore %o0, %g0, %o0
|
|
Packit |
6c4009 |
99: mov EINVAL, %o0
|
|
Packit |
6c4009 |
98: call HIDDEN_JUMPTARGET(__errno_location)
|
|
Packit |
6c4009 |
mov %o0, %i0
|
|
Packit |
6c4009 |
st %i0, [%o0]
|
|
Packit |
6c4009 |
jmpl %i7 + 8, %g0
|
|
Packit |
6c4009 |
restore %g0,-1,%o0
|
|
Packit |
6c4009 |
END(__clone)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.type __thread_start,@function
|
|
Packit |
6c4009 |
__thread_start:
|
|
Packit |
6c4009 |
mov %g0, %fp /* terminate backtrace */
|
|
Packit |
6c4009 |
call %g2
|
|
Packit |
6c4009 |
mov %g3,%o0
|
|
Packit |
6c4009 |
set __NR_exit, %g1
|
|
Packit |
6c4009 |
ta 0x6d
|
|
Packit |
6c4009 |
nop
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.size __thread_start, .-__thread_start
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
libc_hidden_def (__clone)
|
|
Packit |
6c4009 |
weak_alias (__clone, clone)
|