11.4Smatt/* $NetBSD: __clone.S,v 1.4 2011/01/25 02:38:15 matt Exp $ */ 21.1Smatt 31.1Smatt/*- 41.1Smatt * Copyright (c) 2001 The NetBSD Foundation, Inc. 51.1Smatt * All rights reserved. 61.1Smatt * 71.1Smatt * This code is derived from software contributed to The NetBSD Foundation 81.1Smatt * by Matt Thomas <matt@3am-software.com> 91.1Smatt * 101.1Smatt * Redistribution and use in source and binary forms, with or without 111.1Smatt * modification, are permitted provided that the following conditions 121.1Smatt * are met: 131.1Smatt * 1. Redistributions of source code must retain the above copyright 141.1Smatt * notice, this list of conditions and the following disclaimer. 151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright 161.1Smatt * notice, this list of conditions and the following disclaimer in the 171.1Smatt * documentation and/or other materials provided with the distribution. 181.1Smatt * 191.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Smatt * POSSIBILITY OF SUCH DAMAGE. 301.1Smatt */ 311.1Smatt 321.1Smatt#include <sys/errno.h> 331.1Smatt 341.1Smatt#include "SYS.h" 351.1Smatt 361.4Smatt#ifdef SYSLIBC_SCCS 371.4SmattRCSID("$NetBSD: __clone.S,v 1.4 2011/01/25 02:38:15 matt Exp $") 381.4Smatt#endif 391.4Smatt 401.1Smatt#ifdef WEAK_ALIAS 411.1SmattWEAK_ALIAS(clone, __clone) 421.1Smatt#endif 431.1Smatt 441.1Smatt/* 451.1Smatt * int __clone(int (*fn)(void *), void *stack, int flags, void *arg); 461.1Smatt */ 471.1SmattENTRY(__clone, 0) 481.1Smatt 491.1Smatt /* 501.1Smatt * Sanity checks: func and stack may not be NULL. 511.1Smatt */ 521.2Smatt movl 4(%ap),%r2 /* check and save function */ 531.1Smatt beql 9f 541.2Smatt tstl 8(%ap) /* check stack */ 551.1Smatt beql 9f 561.1Smatt 571.1Smatt /* 581.1Smatt * The system call expects (flags, stack). 591.1Smatt */ 601.2Smatt movl 12(%ap),4(%ap) /* XXX this doesn't work for 611.1Smatt callg with a RO arglist */ 621.2Smatt movl $2,(%ap) 631.2Smatt SYSTRAP(__clone) /* only %r0/%r1 munged */ 641.1Smatt 651.2Smatt blbc %r1,8f /* %r1<0>: 0=parent 1=child */ 661.1Smatt 671.1Smatt /* Call the clone's entry point. */ 681.2Smatt pushl 16(%ap) 691.2Smatt calls $1,(%r2) 701.1Smatt 711.1Smatt /* Pass return value to _exit(). */ 721.2Smatt pushl %r0 731.1Smatt calls $1,_C_LABEL(_exit) 741.1Smatt 751.1Smatt /* NOTREACHED */ 761.1Smatt 771.1Smatt8: ret 781.1Smatt 791.2Smatt9: movl $EINVAL,%r0 801.1Smatt jmp CERROR+2 811.4SmattEND(__clone) 82