Call exit directly in clone (BZ #21512)
[glibc.git] / sysdeps / unix / sysv / linux / alpha / clone.S
blob550461fb3b76599239eead16bcc05f7038cba4e8
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>, 1996.
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.
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.
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/>.  */
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.  */
22 #include <sysdep.h>
23 #define _ERRNO_H        1
24 #include <bits/errno.h>
26 /* int clone(int (*fn)(void *arg), void *child_stack, int flags,
27              void *arg, pid_t *ptid, void *tls, pid_t *ctid);
29    Note that everything past ARG is technically optional, based
30    on FLAGS, and that CTID is arg 7, and thus is on the stack.
31    However, since a load from top-of-stack better be legal always,
32    we don't bother checking FLAGS.  */
34         .text
35         .align  4
36         .globl  __clone
37         .ent    __clone
38         .usepv  __clone, USEPV_PROF
40         cfi_startproc
41 __clone:
42 #ifdef PROF
43         ldgp    gp,0(pv)
44         lda     AT, _mcount
45         jsr     AT, (AT), _mcount
46 #endif
48         /* Sanity check arguments.  */
49         ldiq    v0, EINVAL
50         beq     a0, SYSCALL_ERROR_LABEL /* no NULL function pointers */
51         beq     a1, SYSCALL_ERROR_LABEL /* no NULL stack pointers */
53         /* Save the fn ptr and arg on the new stack.  */
54         subq    a1, 32, a1
55         stq     a0, 0(a1)
56         stq     a3, 8(a1)
57         stq     a2, 16(a1)
59         /* The syscall is of the form clone(flags, usp, ptid, ctid, tls).
60            Shift the flags, ptid, ctid, tls arguments into place; the
61            child_stack argument is already correct.  */
62         mov     a2, a0
63         mov     a4, a2
64         ldq     a3, 0(sp)
65         mov     a5, a4
67         /* Do the system call.  */
68         ldiq    v0, __NR_clone
69         call_pal PAL_callsys
71         bne     a3, SYSCALL_ERROR_LABEL
72         beq     v0, thread_start
74         /* Successful return from the parent.  */
75         ret
77 PSEUDO_END(__clone)
78         cfi_endproc
80 /* Load up the arguments to the function.  Put this block of code in
81    its own function so that we can terminate the stack trace with our
82    debug info.  */
84         .align  4
85         .ent thread_start
86         cfi_startproc
87 thread_start:
88         mov     0, fp
89         cfi_def_cfa_register(fp)
90         cfi_undefined(ra)
92         /* Load up the arguments.  */
93         ldq     pv, 0(sp)
94         ldq     a0, 8(sp)
95         addq    sp, 32, sp
97         /* Call the user's function.  */
98         jsr     ra, (pv)
99         ldgp    gp, 0(ra)
101         ldiq    v0, __NR_exit
102         call_pal PAL_callsys
104         /* Die horribly.  */
105         .align  4
106         halt
108         .align  4
109         cfi_endproc
110         .end thread_start
112 libc_hidden_def (__clone)
113 weak_alias (__clone, clone)