11.8Schristos/* $NetBSD: __clone.S,v 1.8 2025/11/06 15:25:18 christos Exp $ */ 21.1Sfvdl 31.1Sfvdl/* 41.1Sfvdl * Copyright (c) 2001 Wasabi Systems, Inc. 51.1Sfvdl * All rights reserved. 61.1Sfvdl * 71.1Sfvdl * Written by Frank van der Linden for Wasabi Systems, Inc. 81.1Sfvdl * 91.1Sfvdl * Redistribution and use in source and binary forms, with or without 101.1Sfvdl * modification, are permitted provided that the following conditions 111.1Sfvdl * are met: 121.1Sfvdl * 1. Redistributions of source code must retain the above copyright 131.1Sfvdl * notice, this list of conditions and the following disclaimer. 141.1Sfvdl * 2. Redistributions in binary form must reproduce the above copyright 151.1Sfvdl * notice, this list of conditions and the following disclaimer in the 161.1Sfvdl * documentation and/or other materials provided with the distribution. 171.1Sfvdl * 3. All advertising materials mentioning features or use of this software 181.1Sfvdl * must display the following acknowledgement: 191.1Sfvdl * This product includes software developed for the NetBSD Project by 201.1Sfvdl * Wasabi Systems, Inc. 211.1Sfvdl * 4. The name of Wasabi Systems, Inc. may not be used to endorse 221.1Sfvdl * or promote products derived from this software without specific prior 231.1Sfvdl * written permission. 241.1Sfvdl * 251.1Sfvdl * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 261.1Sfvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 271.1Sfvdl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 281.1Sfvdl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 291.1Sfvdl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301.1Sfvdl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311.1Sfvdl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 321.1Sfvdl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 331.1Sfvdl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 341.1Sfvdl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 351.1Sfvdl * POSSIBILITY OF SUCH DAMAGE. 361.1Sfvdl */ 371.1Sfvdl 381.1Sfvdl#include <machine/asm.h> 391.1Sfvdl#include <sys/errno.h> 401.1Sfvdl#include "SYS.h" 411.1Sfvdl 421.1Sfvdl#ifdef WEAK_ALIAS 431.1SfvdlWEAK_ALIAS(clone, __clone) 441.1Sfvdl#endif 451.1Sfvdl .text 461.1Sfvdl 471.2Sthorpej/* 481.2Sthorpej * int clone(int (*fn)(void *), void *stack, int flags, void *arg); 491.2Sthorpej */ 501.1SfvdlENTRY(__clone) 511.1Sfvdl pushl %ebp 521.1Sfvdl 531.1Sfvdl /* 541.1Sfvdl * Sanity checks: func and stack may not be NULL. 551.1Sfvdl */ 561.1Sfvdl movl 8(%esp), %ebp 571.1Sfvdl cmpl $0,%ebp /* function */ 581.1Sfvdl je 3f 591.1Sfvdl movl 12(%esp),%eax /* stack */ 601.1Sfvdl cmpl $0,%eax 611.1Sfvdl je 3f 621.1Sfvdl 631.1Sfvdl /* 641.1Sfvdl * Set up the stack for the clone. 651.1Sfvdl */ 661.1Sfvdl movl 20(%esp),%ecx 671.1Sfvdl movl %ecx,-4(%eax) /* argument */ 681.2Sthorpej leal -4(%eax),%eax /* sp points to arg */ 691.1Sfvdl 701.1Sfvdl pushl %eax /* stack */ 711.1Sfvdl pushl 20(%esp) /* flags */ 721.1Sfvdl pushl $0 /* dummy return address */ 731.1Sfvdl 741.1Sfvdl SYSTRAP(__clone) 751.1Sfvdl jc 4f 761.1Sfvdl cmpl $0,%eax 771.1Sfvdl jne 2f /* we're the parent */ 781.2Sthorpej call *%ebp /* this is the clone, call the function */ 791.2Sthorpej 801.1Sfvdl PIC_PROLOGUE 811.3Sfvdl pushl %eax /* clone does _exit(func(arg)); */ 821.1Sfvdl call PIC_PLT(_C_LABEL(_exit)) 831.3Sfvdl addl $4,%esp 841.1Sfvdl PIC_EPILOGUE 851.1Sfvdl 861.1Sfvdl2: 871.1Sfvdl addl $12,%esp 881.1Sfvdl popl %ebp 891.1Sfvdl ret 901.1Sfvdl3: 911.1Sfvdl movl $EINVAL,%eax 921.1Sfvdl jmp 5f 931.1Sfvdl4: 941.1Sfvdl addl $12,%esp 951.1Sfvdl5: 961.1Sfvdl popl %ebp 971.8Schristos _SYSCALL_ERR 981.6SuebayasiEND(__clone) 99