1*0ce5ca14Smatt/* $NetBSD: __clone.S,v 1.2 2002/02/24 01:06:20 matt Exp $ */ 263237a33Smatt 363237a33Smatt/*- 463237a33Smatt * Copyright (c) 2001 The NetBSD Foundation, Inc. 563237a33Smatt * All rights reserved. 663237a33Smatt * 763237a33Smatt * This code is derived from software contributed to The NetBSD Foundation 863237a33Smatt * by Matt Thomas <matt@3am-software.com> 963237a33Smatt * 1063237a33Smatt * Redistribution and use in source and binary forms, with or without 1163237a33Smatt * modification, are permitted provided that the following conditions 1263237a33Smatt * are met: 1363237a33Smatt * 1. Redistributions of source code must retain the above copyright 1463237a33Smatt * notice, this list of conditions and the following disclaimer. 1563237a33Smatt * 2. Redistributions in binary form must reproduce the above copyright 1663237a33Smatt * notice, this list of conditions and the following disclaimer in the 1763237a33Smatt * documentation and/or other materials provided with the distribution. 1863237a33Smatt * 3. All advertising materials mentioning features or use of this software 1963237a33Smatt * must display the following acknowledgement: 2063237a33Smatt * This product includes software developed by the NetBSD 2163237a33Smatt * Foundation, Inc. and its contributors. 2263237a33Smatt * 4. Neither the name of The NetBSD Foundation nor the names of its 2363237a33Smatt * contributors may be used to endorse or promote products derived 2463237a33Smatt * from this software without specific prior written permission. 2563237a33Smatt * 2663237a33Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2763237a33Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2863237a33Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2963237a33Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3063237a33Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3163237a33Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3263237a33Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3363237a33Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3463237a33Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3563237a33Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3663237a33Smatt * POSSIBILITY OF SUCH DAMAGE. 3763237a33Smatt */ 3863237a33Smatt 3963237a33Smatt#include <sys/errno.h> 4063237a33Smatt 4163237a33Smatt#include "SYS.h" 4263237a33Smatt 4363237a33Smatt#ifdef WEAK_ALIAS 4463237a33SmattWEAK_ALIAS(clone, __clone) 4563237a33Smatt#endif 4663237a33Smatt 4763237a33Smatt/* 4863237a33Smatt * int __clone(int (*fn)(void *), void *stack, int flags, void *arg); 4963237a33Smatt */ 5063237a33SmattENTRY(__clone, 0) 5163237a33Smatt 5263237a33Smatt /* 5363237a33Smatt * Sanity checks: func and stack may not be NULL. 5463237a33Smatt */ 55*0ce5ca14Smatt movl 4(%ap),%r2 /* check and save function */ 5663237a33Smatt beql 9f 57*0ce5ca14Smatt tstl 8(%ap) /* check stack */ 5863237a33Smatt beql 9f 5963237a33Smatt 6063237a33Smatt /* 6163237a33Smatt * The system call expects (flags, stack). 6263237a33Smatt */ 63*0ce5ca14Smatt movl 12(%ap),4(%ap) /* XXX this doesn't work for 6463237a33Smatt callg with a RO arglist */ 65*0ce5ca14Smatt movl $2,(%ap) 66*0ce5ca14Smatt SYSTRAP(__clone) /* only %r0/%r1 munged */ 6763237a33Smatt 68*0ce5ca14Smatt blbc %r1,8f /* %r1<0>: 0=parent 1=child */ 6963237a33Smatt 7063237a33Smatt /* Call the clone's entry point. */ 71*0ce5ca14Smatt pushl 16(%ap) 72*0ce5ca14Smatt calls $1,(%r2) 7363237a33Smatt 7463237a33Smatt /* Pass return value to _exit(). */ 75*0ce5ca14Smatt pushl %r0 7663237a33Smatt calls $1,_C_LABEL(_exit) 7763237a33Smatt 7863237a33Smatt /* NOTREACHED */ 7963237a33Smatt 8063237a33Smatt8: ret 8163237a33Smatt 82*0ce5ca14Smatt9: movl $EINVAL,%r0 8363237a33Smatt jmp CERROR+2 84