blob: 7f067dff8f6ed6ff8199307e159e2cfed4e16f1d [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Copyright (C) 2000, 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
18
19#include "sysdep.h"
20
21#include "sysdep.h"
22#include <asm/errno.h>
23
24
25/* int __clone2(int (*fn) (void *arg), void *child_stack_base, */
26/* size_t child_stack_size, int flags, void *arg, */
27/* pid_t *parent_tid, void *tls, pid_t *child_tid) */
28
29#define CHILD p8
30#define PARENT p9
31
32ENTRY(__clone2)
33 .prologue
34 alloc r2=ar.pfs,8,1,6,0
35 cmp.eq p6,p0=0,in0
36 cmp.eq p7,p0=0,in1
37 mov r8=EINVAL
38 mov out0=in3 /* Flags are first syscall argument. */
39 mov out1=in1 /* Stack address. */
40(p6) br.cond.spnt.many __syscall_error /* no NULL function pointers */
41(p7) br.cond.spnt.many __syscall_error /* no NULL stack pointers */
42 ;;
43 mov out2=in2 /* Stack size. */
44 mov out3=in5 /* Parent TID Pointer */
45 mov out4=in7 /* Child TID Pointer */
46 mov out5=in6 /* TLS pointer */
47 /*
48 * clone2() is special: the child cannot execute br.ret right
49 * after the system call returns, because it starts out
50 * executing on an empty stack. Because of this, we can't use
51 * the new (lightweight) syscall convention here. Instead, we
52 * just fall back on always using "break".
53 *
54 * Furthermore, since the child starts with an empty stack, we
55 * need to avoid unwinding past invalid memory. To that end,
56 * we'll pretend now that __clone2() is the end of the
57 * call-chain. This is wrong for the parent, but only until
58 * it returns from clone2() but it's better than the
59 * alternative.
60 */
61 mov r15=SYS_ify (clone2)
62 .save rp, r0
63 break __BREAK_SYSCALL
64 .body
65 cmp.eq p6,p0=-1,r10
66 cmp.eq CHILD,PARENT=0,r8 /* Are we the child? */
67(p6) br.cond.spnt.many __syscall_error
68 ;;
69(CHILD) mov loc0=gp
70(PARENT) ret
71 ;;
72#ifdef RESET_PID
73 tbit.nz p6,p0=in3,16 /* CLONE_THREAD */
74 tbit.z p7,p10=in3,8 /* CLONE_VM */
75(p6) br.cond.dptk 1f
76 ;;
77 mov r15=SYS_ify (getpid)
78(p10) addl r8=-1,r0
79(p7) break __BREAK_SYSCALL
80 ;;
81 add r9=PID,r13
82 add r10=TID,r13
83 ;;
84 st4 [r9]=r8
85 st4 [r10]=r8
86 ;;
87#endif
881: ld8 out1=[in0],8 /* Retrieve code pointer. */
89 mov out0=in4 /* Pass proper argument to fn */
90 ;;
91 ld8 gp=[in0] /* Load function gp. */
92 mov b6=out1
93 br.call.dptk.many rp=b6 /* Call fn(arg) in the child */
94 ;;
95 mov out0=r8 /* Argument to _exit */
96 mov gp=loc0
97 .globl HIDDEN_JUMPTARGET(_exit)
98 br.call.dpnt.many rp=HIDDEN_JUMPTARGET(_exit)
99 /* call _exit with result from fn. */
100 ret /* Not reached. */
101PSEUDO_END(__clone2)
102
103/* For now we leave __clone undefined. This is unlikely to be a */
104/* problem, since at least the i386 __clone in glibc always failed */
105/* with a 0 sp (eventhough the kernel explicitly handled it). */
106/* Thus all such calls needed to pass an explicit sp, and as a result, */
107/* would be unlikely to work on ia64. */