__clone.S revision 1.1
11.1Sscw/* $NetBSD: __clone.S,v 1.1 2001/07/19 21:50:46 scw 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 * 3. All advertising materials mentioning features or use of this software 191.1Sscw * must display the following acknowledgement: 201.1Sscw * This product includes software developed by the NetBSD 211.1Sscw * Foundation, Inc. and its contributors. 221.1Sscw * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Sscw * contributors may be used to endorse or promote products derived 241.1Sscw * from this software without specific prior written permission. 251.1Sscw * 261.1Sscw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Sscw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Sscw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Sscw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Sscw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Sscw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Sscw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Sscw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Sscw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Sscw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Sscw * POSSIBILITY OF SUCH DAMAGE. 371.1Sscw */ 381.1Sscw 391.1Sscw#include <sys/errno.h> 401.1Sscw#include "SYS.h" 411.1Sscw 421.1Sscw#ifdef WEAK_ALIAS 431.1SscwWEAK_ALIAS(clone, __clone) 441.1Sscw#endif 451.1Sscw 461.1Sscw/* 471.1Sscw * int clone(int (*fn)(void *), void *stack, int flags, void *arg); 481.1Sscw */ 491.1SscwENTRY(__clone) 501.1Sscw movl %sp@(4),%d0 /* NULL function pointer? */ 511.1Sscw jeq 2f /* Yup, bomb out */ 521.1Sscw movl %d0,%a1 531.1Sscw movl %sp@(8),%d0 /* NULL stack? */ 541.1Sscw jeq 2f /* Yup, bomb out */ 551.1Sscw movl %d0,%a0 561.1Sscw movl %sp@(16),%a0@- /* Push clone's `arg' on its new stack */ 571.1Sscw movl %a0,%sp@- /* Syscall arg: stack */ 581.1Sscw movl %sp@(16),%sp@- /* Syscall arg: flags */ 591.1Sscw clrl %sp@- /* Fake return address */ 601.1Sscw SYSTRAP(__clone) /* Note: `fn' in a1@ is preserved */ 611.1Sscw lea %sp@(12),%sp /* Zap syscall args */ 621.1Sscw jcs 3f /* Punt if syscall failed */ 631.1Sscw tstl %d0 641.1Sscw jne 1f /* We're the parent, just return. */ 651.1Sscw jsr %a1@ /* We're the clone, call the function */ 661.1Sscw movl %d0,%sp@- /* If clone returns, invoke _exit(3) */ 671.1Sscw jbsr PIC_PLT(_C_LABEL(_exit)) 681.1Sscw /* NOTREACHED */ 691.1Sscw1: rts 701.1Sscw2: movl #EINVAL,%d0 711.1Sscw3: jra PIC_PLT(CERROR) 72