11.5Smatt/* $NetBSD: __clone.S,v 1.5 2013/07/16 23:00:15 matt Exp $ */ 21.1Sscw 31.1Sscw/*- 41.1Sscw * Copyright (c) 2001 The NetBSD Foundation, Inc. 51.1Sscw * All rights reserved. 61.1Sscw * 71.1Sscw * This code is derived from software contributed to The NetBSD Foundation 81.1Sscw * by Steve C. Woodford. 91.1Sscw * 101.1Sscw * Redistribution and use in source and binary forms, with or without 111.1Sscw * modification, are permitted provided that the following conditions 121.1Sscw * are met: 131.1Sscw * 1. Redistributions of source code must retain the above copyright 141.1Sscw * notice, this list of conditions and the following disclaimer. 151.1Sscw * 2. Redistributions in binary form must reproduce the above copyright 161.1Sscw * notice, this list of conditions and the following disclaimer in the 171.1Sscw * documentation and/or other materials provided with the distribution. 181.1Sscw * 191.1Sscw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sscw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sscw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sscw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sscw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sscw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sscw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sscw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sscw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sscw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sscw * POSSIBILITY OF SUCH DAMAGE. 301.1Sscw */ 311.1Sscw 321.1Sscw#include <sys/errno.h> 331.1Sscw#include "SYS.h" 341.1Sscw 351.1Sscw#ifdef WEAK_ALIAS 361.1SscwWEAK_ALIAS(clone, __clone) 371.1Sscw#endif 381.1Sscw 391.1Sscw/* 401.1Sscw * int clone(int (*fn)(void *), void *stack, int flags, void *arg); 411.1Sscw */ 421.1SscwENTRY(__clone) 431.4Smatt movl 4(%sp),%d0 /* NULL function pointer? */ 441.1Sscw jeq 2f /* Yup, bomb out */ 451.1Sscw movl %d0,%a1 461.4Smatt movl 8(%sp),%d0 /* NULL stack? */ 471.1Sscw jeq 2f /* Yup, bomb out */ 481.1Sscw movl %d0,%a0 491.4Smatt movl 16(%sp),-(%a0) /* Push clone's `arg' on its new stack */ 501.4Smatt lea -12(%a0),%a0 /* Fake syscall args for the clone */ 511.4Smatt movl %a0,-(%sp) /* Syscall arg: stack */ 521.4Smatt movl 16(%sp),-(%sp) /* Syscall arg: flags */ 531.4Smatt clrl -(%sp) /* Fake return address */ 541.4Smatt SYSTRAP(__clone) /* Note: `fn' in (a1) is preserved */ 551.4Smatt lea 12(%sp),%sp /* Zap syscall args */ 561.1Sscw jcs 3f /* Punt if syscall failed */ 571.1Sscw tstl %d0 581.1Sscw jne 1f /* We're the parent, just return. */ 591.4Smatt jsr (%a1) /* We're the clone, call the function */ 601.4Smatt movl %d0,-(%sp) /* If clone returns, invoke _exit(3) */ 611.1Sscw jbsr PIC_PLT(_C_LABEL(_exit)) 621.1Sscw /* NOTREACHED */ 631.1Sscw1: rts 641.1Sscw2: movl #EINVAL,%d0 651.5Smatt3: jbra CERROR 661.5SmattEND(__clone) 67