1*2fe8fb19SBen Gras/* $NetBSD: __clone.S,v 1.4 2011/01/16 02:43:10 matt Exp $ */ 2*2fe8fb19SBen Gras 3*2fe8fb19SBen Gras/*- 4*2fe8fb19SBen Gras * Copyright (c) 2001 Tsubai Masanari. All rights reserved. 5*2fe8fb19SBen Gras * 6*2fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 7*2fe8fb19SBen Gras * modification, are permitted provided that the following conditions 8*2fe8fb19SBen Gras * are met: 9*2fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 10*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 11*2fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 12*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 13*2fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 14*2fe8fb19SBen Gras * 3. The name of the author may not be used to endorse or promote products 15*2fe8fb19SBen Gras * derived from this software without specific prior written permission. 16*2fe8fb19SBen Gras * 17*2fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18*2fe8fb19SBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19*2fe8fb19SBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20*2fe8fb19SBen Gras * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21*2fe8fb19SBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22*2fe8fb19SBen Gras * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23*2fe8fb19SBen Gras * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24*2fe8fb19SBen Gras * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25*2fe8fb19SBen Gras * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26*2fe8fb19SBen Gras * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27*2fe8fb19SBen Gras */ 28*2fe8fb19SBen Gras 29*2fe8fb19SBen Gras#include <sys/errno.h> 30*2fe8fb19SBen Gras#include "SYS.h" 31*2fe8fb19SBen Gras 32*2fe8fb19SBen Gras#if defined(LIBC_SCCS) && !defined(lint) 33*2fe8fb19SBen Gras__RCSID("$NetBSD: __clone.S,v 1.4 2011/01/16 02:43:10 matt Exp $") 34*2fe8fb19SBen Gras#endif /* LIBC_SCCS && !lint */ 35*2fe8fb19SBen Gras 36*2fe8fb19SBen Gras#ifdef WEAK_ALIAS 37*2fe8fb19SBen GrasWEAK_ALIAS(clone, __clone) 38*2fe8fb19SBen Gras#endif 39*2fe8fb19SBen Gras 40*2fe8fb19SBen Gras/* 41*2fe8fb19SBen Gras * int __clone(int (*fn)(void *), void *stack, int flags, void *arg); 42*2fe8fb19SBen Gras */ 43*2fe8fb19SBen GrasENTRY(__clone) 44*2fe8fb19SBen Gras /* 45*2fe8fb19SBen Gras * Sanity checks: func and stack may not be NULL. 46*2fe8fb19SBen Gras */ 47*2fe8fb19SBen Gras cmpwi %r3,0 48*2fe8fb19SBen Gras beq 1f 49*2fe8fb19SBen Gras cmpwi %r4,0 50*2fe8fb19SBen Gras beq 1f 51*2fe8fb19SBen Gras 52*2fe8fb19SBen Gras mr %r7,%r3 /* Save fn in r7. */ 53*2fe8fb19SBen Gras mr %r3,%r5 54*2fe8fb19SBen Gras _DOSYSCALL(__clone) /* (flags, stack) */ 55*2fe8fb19SBen Gras bso 2f /* error... */ 56*2fe8fb19SBen Gras 57*2fe8fb19SBen Gras cmpwi %r3,0 58*2fe8fb19SBen Gras bnelr /* We're the parent, just return. */ 59*2fe8fb19SBen Gras 60*2fe8fb19SBen Gras mtlr %r7 /* fn */ 61*2fe8fb19SBen Gras mr %r3,%r6 /* arg */ 62*2fe8fb19SBen Gras blrl /* Call the clone's entry point. */ 63*2fe8fb19SBen Gras 64*2fe8fb19SBen Gras#ifdef PIC 65*2fe8fb19SBen Gras PIC_TOCSETUP(__clone, %r30) /* exit won't return so blow away r30 */ 66*2fe8fb19SBen Gras#endif 67*2fe8fb19SBen Gras bl PIC_PLT(_C_LABEL(_exit)) 68*2fe8fb19SBen Gras 69*2fe8fb19SBen Gras1: 70*2fe8fb19SBen Gras li %r3,EINVAL 71*2fe8fb19SBen Gras2: 72*2fe8fb19SBen Gras b _C_LABEL(__cerror) 73*2fe8fb19SBen GrasEND(__clone) 74