11.6Smatt/* $NetBSD: __clone.S,v 1.6 2014/08/23 02:24:22 matt Exp $ */ 21.1Stsubai 31.1Stsubai/*- 41.1Stsubai * Copyright (c) 2001 Tsubai Masanari. All rights reserved. 51.1Stsubai * 61.1Stsubai * Redistribution and use in source and binary forms, with or without 71.1Stsubai * modification, are permitted provided that the following conditions 81.1Stsubai * are met: 91.1Stsubai * 1. Redistributions of source code must retain the above copyright 101.1Stsubai * notice, this list of conditions and the following disclaimer. 111.1Stsubai * 2. Redistributions in binary form must reproduce the above copyright 121.1Stsubai * notice, this list of conditions and the following disclaimer in the 131.1Stsubai * documentation and/or other materials provided with the distribution. 141.1Stsubai * 3. The name of the author may not be used to endorse or promote products 151.1Stsubai * derived from this software without specific prior written permission. 161.1Stsubai * 171.1Stsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 181.1Stsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 191.1Stsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 201.1Stsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 211.1Stsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 221.1Stsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231.1Stsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241.1Stsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251.1Stsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261.1Stsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271.1Stsubai */ 281.1Stsubai 291.1Stsubai#include <sys/errno.h> 301.1Stsubai#include "SYS.h" 311.1Stsubai 321.3Smatt#if defined(LIBC_SCCS) && !defined(lint) 331.6Smatt__RCSID("$NetBSD: __clone.S,v 1.6 2014/08/23 02:24:22 matt Exp $") 341.3Smatt#endif /* LIBC_SCCS && !lint */ 351.3Smatt 361.1Stsubai#ifdef WEAK_ALIAS 371.1StsubaiWEAK_ALIAS(clone, __clone) 381.1Stsubai#endif 391.1Stsubai 401.1Stsubai/* 411.1Stsubai * int __clone(int (*fn)(void *), void *stack, int flags, void *arg); 421.1Stsubai */ 431.1StsubaiENTRY(__clone) 441.1Stsubai /* 451.1Stsubai * Sanity checks: func and stack may not be NULL. 461.1Stsubai */ 471.6Smatt cmpptri %r3,0 481.1Stsubai beq 1f 491.6Smatt cmpptri %r4,0 501.1Stsubai beq 1f 511.1Stsubai 521.2Smatt mr %r7,%r3 /* Save fn in r7. */ 531.2Smatt mr %r3,%r5 541.3Smatt _DOSYSCALL(__clone) /* (flags, stack) */ 551.1Stsubai bso 2f /* error... */ 561.1Stsubai 571.6Smatt cmpptri %r3,0 581.1Stsubai bnelr /* We're the parent, just return. */ 591.1Stsubai 601.2Smatt mtlr %r7 /* fn */ 611.2Smatt mr %r3,%r6 /* arg */ 621.1Stsubai blrl /* Call the clone's entry point. */ 631.1Stsubai 641.5Sjoerg#ifdef __PIC__ 651.4Smatt PIC_TOCSETUP(__clone, %r30) /* exit won't return so blow away r30 */ 661.4Smatt#endif 671.1Stsubai bl PIC_PLT(_C_LABEL(_exit)) 681.1Stsubai 691.1Stsubai1: 701.2Smatt li %r3,EINVAL 711.1Stsubai2: 721.6Smatt BRANCH_TO_CERROR() 731.3SmattEND(__clone) 74