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