1*787e823fSmatt/* $NetBSD: __clone.S,v 1.4 2011/01/25 02:38:15 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 * 1963237a33Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2063237a33Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2163237a33Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2263237a33Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2363237a33Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2463237a33Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2563237a33Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2663237a33Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2763237a33Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2863237a33Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2963237a33Smatt * POSSIBILITY OF SUCH DAMAGE. 3063237a33Smatt */ 3163237a33Smatt 3263237a33Smatt#include <sys/errno.h> 3363237a33Smatt 3463237a33Smatt#include "SYS.h" 3563237a33Smatt 36*787e823fSmatt#ifdef SYSLIBC_SCCS 37*787e823fSmattRCSID("$NetBSD: __clone.S,v 1.4 2011/01/25 02:38:15 matt Exp $") 38*787e823fSmatt#endif 39*787e823fSmatt 4063237a33Smatt#ifdef WEAK_ALIAS 4163237a33SmattWEAK_ALIAS(clone, __clone) 4263237a33Smatt#endif 4363237a33Smatt 4463237a33Smatt/* 4563237a33Smatt * int __clone(int (*fn)(void *), void *stack, int flags, void *arg); 4663237a33Smatt */ 4763237a33SmattENTRY(__clone, 0) 4863237a33Smatt 4963237a33Smatt /* 5063237a33Smatt * Sanity checks: func and stack may not be NULL. 5163237a33Smatt */ 520ce5ca14Smatt movl 4(%ap),%r2 /* check and save function */ 5363237a33Smatt beql 9f 540ce5ca14Smatt tstl 8(%ap) /* check stack */ 5563237a33Smatt beql 9f 5663237a33Smatt 5763237a33Smatt /* 5863237a33Smatt * The system call expects (flags, stack). 5963237a33Smatt */ 600ce5ca14Smatt movl 12(%ap),4(%ap) /* XXX this doesn't work for 6163237a33Smatt callg with a RO arglist */ 620ce5ca14Smatt movl $2,(%ap) 630ce5ca14Smatt SYSTRAP(__clone) /* only %r0/%r1 munged */ 6463237a33Smatt 650ce5ca14Smatt blbc %r1,8f /* %r1<0>: 0=parent 1=child */ 6663237a33Smatt 6763237a33Smatt /* Call the clone's entry point. */ 680ce5ca14Smatt pushl 16(%ap) 690ce5ca14Smatt calls $1,(%r2) 7063237a33Smatt 7163237a33Smatt /* Pass return value to _exit(). */ 720ce5ca14Smatt pushl %r0 7363237a33Smatt calls $1,_C_LABEL(_exit) 7463237a33Smatt 7563237a33Smatt /* NOTREACHED */ 7663237a33Smatt 7763237a33Smatt8: ret 7863237a33Smatt 790ce5ca14Smatt9: movl $EINVAL,%r0 8063237a33Smatt jmp CERROR+2 81*787e823fSmattEND(__clone) 82