Blame sysdeps/unix/sysv/linux/ia64/clone2.S

Packit 6c4009
/* Copyright (C) 2000-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
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
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
#include <asm/errno.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* int  __clone2(int (*fn) (void *arg), void *child_stack_base, 	*/
Packit 6c4009
/* 	         size_t child_stack_size, int flags, void *arg,		*/
Packit 6c4009
/*	         pid_t *parent_tid, void *tls, pid_t *child_tid)	*/
Packit 6c4009
Packit 6c4009
#define CHILD	p8
Packit 6c4009
#define PARENT	p9
Packit 6c4009
Packit 6c4009
ENTRY(__clone2)
Packit 6c4009
	.prologue
Packit 6c4009
	alloc r2=ar.pfs,8,1,6,0
Packit 6c4009
	cmp.eq p6,p0=0,in0
Packit 6c4009
	cmp.eq p7,p0=0,in1
Packit 6c4009
	mov r8=EINVAL
Packit 6c4009
	mov out0=in3		/* Flags are first syscall argument.	*/
Packit 6c4009
	mov out1=in1		/* Stack address.			*/
Packit 6c4009
(p6)	br.cond.spnt.many __syscall_error	/* no NULL function pointers */
Packit 6c4009
(p7)	br.cond.spnt.many __syscall_error	/* no NULL stack pointers */
Packit 6c4009
	;;
Packit 6c4009
	mov out2=in2		/* Stack size.				*/
Packit 6c4009
	mov out3=in5		/* Parent TID Pointer			*/
Packit 6c4009
	mov out4=in7		/* Child TID Pointer			*/
Packit 6c4009
	mov out5=in6		/* TLS pointer				*/
Packit 6c4009
	/*
Packit 6c4009
	 * clone2() is special: the child cannot execute br.ret right
Packit 6c4009
	 * after the system call returns, because it starts out
Packit 6c4009
	 * executing on an empty stack.  Because of this, we can't use
Packit 6c4009
	 * the new (lightweight) syscall convention here.  Instead, we
Packit 6c4009
	 * just fall back on always using "break".
Packit 6c4009
	 *
Packit 6c4009
	 * Furthermore, since the child starts with an empty stack, we
Packit 6c4009
	 * need to avoid unwinding past invalid memory.  To that end,
Packit 6c4009
	 * we'll pretend now that __clone2() is the end of the
Packit 6c4009
	 * call-chain.  This is wrong for the parent, but only until
Packit 6c4009
	 * it returns from clone2() but it's better than the
Packit 6c4009
	 * alternative.
Packit 6c4009
	 */
Packit 6c4009
	mov r15=SYS_ify (clone2)
Packit 6c4009
	.save rp, r0
Packit 6c4009
	break __BREAK_SYSCALL
Packit 6c4009
	.body
Packit 6c4009
	cmp.eq p6,p0=-1,r10
Packit 6c4009
	cmp.eq CHILD,PARENT=0,r8 /* Are we the child?   */
Packit 6c4009
(p6)	br.cond.spnt.many __syscall_error
Packit 6c4009
	;;
Packit 6c4009
(CHILD)	mov loc0=gp
Packit 6c4009
(PARENT) ret
Packit 6c4009
	;;
Packit 6c4009
	ld8 out1=[in0],8	/* Retrieve code pointer.	*/
Packit 6c4009
	mov out0=in4		/* Pass proper argument	to fn */
Packit 6c4009
	;;
Packit 6c4009
	ld8 gp=[in0]		/* Load function gp.		*/
Packit 6c4009
	mov b6=out1
Packit 6c4009
	br.call.dptk.many rp=b6	/* Call fn(arg) in the child 	*/
Packit 6c4009
	;;
Packit 6c4009
	mov out0=r8		/* Argument to exit		*/
Packit 6c4009
	mov gp=loc0
Packit 6c4009
	mov r15=SYS_ify (exit)
Packit 6c4009
	.save rp, r0
Packit 6c4009
	break __BREAK_SYSCALL
Packit 6c4009
	ret			/* Not reached.		*/
Packit 6c4009
PSEUDO_END(__clone2)
Packit 6c4009
Packit 6c4009
libc_hidden_def (__clone2)
Packit 6c4009
Packit 6c4009
/* For now we leave __clone undefined.  This is unlikely to be a	*/
Packit 6c4009
/* problem, since at least the i386 __clone in glibc always failed	*/
Packit 6c4009
/* with a 0 sp (eventhough the kernel explicitly handled it).		*/
Packit 6c4009
/* Thus all such calls needed to pass an explicit sp, and as a result,	*/
Packit 6c4009
/* would be unlikely to work on ia64.					*/