2004-12-23 04:10:10 +08:00
|
|
|
/* Copyright (C) 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
|
2001-07-06 12:58:11 +08:00
|
|
|
This file is part of the GNU C Library.
|
2000-07-16 01:32:51 +08:00
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 12:58:11 +08:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2000-07-16 01:32:51 +08:00
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 12:58:11 +08:00
|
|
|
Lesser General Public License for more details.
|
2000-07-16 01:32:51 +08:00
|
|
|
|
2001-07-06 12:58:11 +08:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
02111-1307 USA. */
|
2000-07-16 01:32:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include <sysdep.h>
|
|
|
|
#include <asm/errno.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* int __clone2(int (*fn) (void *arg), void *child_stack_base, */
|
2003-03-04 03:53:27 +08:00
|
|
|
/* size_t child_stack_size, int flags, void *arg, */
|
2003-03-11 17:30:37 +08:00
|
|
|
/* pid_t *parent_tid, void *tls, pid_t *child_tid) */
|
2000-07-16 01:32:51 +08:00
|
|
|
|
2003-12-11 07:02:33 +08:00
|
|
|
#define CHILD p8
|
|
|
|
#define PARENT p9
|
|
|
|
|
2000-07-16 01:32:51 +08:00
|
|
|
ENTRY(__clone2)
|
2003-12-11 07:02:33 +08:00
|
|
|
.prologue
|
2004-12-08 04:34:18 +08:00
|
|
|
alloc r2=ar.pfs,8,1,6,0
|
2001-02-20 02:55:39 +08:00
|
|
|
cmp.eq p6,p0=0,in0
|
2000-07-16 01:32:51 +08:00
|
|
|
mov r8=EINVAL
|
2001-02-20 02:55:39 +08:00
|
|
|
mov out0=in3 /* Flags are first syscall argument. */
|
|
|
|
mov out1=in1 /* Stack address. */
|
2004-12-23 04:10:10 +08:00
|
|
|
(p6) br.cond.spnt.many __syscall_error
|
2003-12-11 07:02:33 +08:00
|
|
|
;;
|
2001-02-20 02:55:39 +08:00
|
|
|
mov out2=in2 /* Stack size. */
|
Update.
2003-03-13 Jakub Jelinek <jakub@redhat.com>
* sysdeps/unix/sysv/linux/ia64/sysdep.h (BREAK_INSN_1, BREAK_INSN,
ASM_OUTARGS_0, ASM_OUTARGS_1, ASM_OUTARGS_2, ASM_OUTARGS_3,
ASM_OUTARGS_4, ASM_OUTARGS_5, ASM_OUTARGS_6): Define.
(INTERNAL_SYSCALL, INLINE_SYSCALL): Use it. Make syscall arguments
clobbered by the syscall.
(ASM_ARGS_1, ASM_ARGS_2, ASM_ARGS_3, ASM_ARGS_4, ASM_ARGS_5,
ASM_ARGS_6): Change constraints from r to index of corresponding
output register.
* sysdeps/unix/sysv/linux/ia64/clone2.S (__clone2): Swap
ptid and ctid to match kernel.
* sysdeps/unix/sysv/linux/ia64/system.c (FORK): Likewise.
* sysdeps/powerpc/powerpc64/elf/configure.in: Remove
* sysdeps/powerpc/powerpc64/elf/configure: Regenerated.
2003-03-13 12:41:39 +08:00
|
|
|
mov out3=in5 /* Parent TID Pointer */
|
|
|
|
mov out4=in7 /* Child TID Pointer */
|
2003-03-11 17:30:37 +08:00
|
|
|
mov out5=in6 /* TLS pointer */
|
2003-12-11 07:02:33 +08:00
|
|
|
/*
|
|
|
|
* clone2() is special: the child cannot execute br.ret right
|
|
|
|
* after the system call returns, because it starts out
|
|
|
|
* executing on an empty stack. Because of this, we can't use
|
|
|
|
* the new (lightweight) syscall convention here. Instead, we
|
|
|
|
* just fall back on always using "break".
|
|
|
|
*
|
|
|
|
* Furthermore, since the child starts with an empty stack, we
|
|
|
|
* need to avoid unwinding past invalid memory. To that end,
|
|
|
|
* we'll pretend now that __clone2() is the end of the
|
|
|
|
* call-chain. This is wrong for the parent, but only until
|
|
|
|
* it returns from clone2() but it's better than the
|
|
|
|
* alternative.
|
|
|
|
*/
|
|
|
|
mov r15=SYS_ify (clone2)
|
|
|
|
.save rp, r0
|
|
|
|
break __BREAK_SYSCALL
|
|
|
|
.body
|
2000-07-16 01:32:51 +08:00
|
|
|
cmp.eq p6,p0=-1,r10
|
2003-12-11 07:02:33 +08:00
|
|
|
cmp.eq CHILD,PARENT=0,r8 /* Are we the child? */
|
|
|
|
(p6) br.cond.spnt.many __syscall_error
|
2000-07-16 01:32:51 +08:00
|
|
|
;;
|
2004-12-08 04:34:18 +08:00
|
|
|
(CHILD) mov loc0=gp
|
2000-07-16 01:32:51 +08:00
|
|
|
(PARENT) ret
|
|
|
|
;;
|
2004-12-08 04:34:18 +08:00
|
|
|
#ifdef RESET_PID
|
|
|
|
tbit.nz p6,p0=in3,16 /* CLONE_THREAD */
|
|
|
|
tbit.z p7,p10=in3,8 /* CLONE_VM */
|
|
|
|
(p6) br.cond.dptk 1f
|
|
|
|
;;
|
|
|
|
mov r15=SYS_ify (getpid)
|
|
|
|
(p10) addl r8=-1,r0
|
|
|
|
(p7) break __BREAK_SYSCALL
|
|
|
|
;;
|
|
|
|
add r9=PID,r13
|
|
|
|
add r10=TID,r13
|
|
|
|
;;
|
|
|
|
st4 [r9]=r8
|
|
|
|
st4 [r10]=r8
|
|
|
|
;;
|
|
|
|
#endif
|
|
|
|
1: ld8 out1=[in0],8 /* Retrieve code pointer. */
|
|
|
|
mov out0=in4 /* Pass proper argument to fn */
|
|
|
|
;;
|
2003-12-11 07:02:33 +08:00
|
|
|
ld8 gp=[in0] /* Load function gp. */
|
2001-02-20 02:55:39 +08:00
|
|
|
mov b6=out1
|
2003-12-11 07:02:33 +08:00
|
|
|
br.call.dptk.many rp=b6 /* Call fn(arg) in the child */
|
2000-07-16 01:32:51 +08:00
|
|
|
;;
|
2001-02-20 02:55:39 +08:00
|
|
|
mov out0=r8 /* Argument to _exit */
|
2004-12-08 04:34:18 +08:00
|
|
|
mov gp=loc0
|
2004-04-22 07:12:39 +08:00
|
|
|
.globl HIDDEN_JUMPTARGET(_exit)
|
|
|
|
br.call.dpnt.many rp=HIDDEN_JUMPTARGET(_exit)
|
|
|
|
/* call _exit with result from fn. */
|
2000-07-16 01:32:51 +08:00
|
|
|
ret /* Not reached. */
|
|
|
|
PSEUDO_END(__clone2)
|
|
|
|
|
|
|
|
/* For now we leave __clone undefined. This is unlikely to be a */
|
|
|
|
/* problem, since at least the i386 __clone in glibc always failed */
|
|
|
|
/* with a 0 sp (eventhough the kernel explicitly handled it). */
|
|
|
|
/* Thus all such calls needed to pass an explicit sp, and as a result, */
|
|
|
|
/* would be unlikely to work on ia64. */
|