11.7Schristos/* $NetBSD: __clone.S,v 1.7 2025/11/06 15:25:18 christos Exp $ */ 21.1Sfvdl 31.1Sfvdl/* 41.1Sfvdl * Copyright (c) 2002 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.1Sfvdl/* 481.1Sfvdl * int clone(int (*fn)(void *), void *stack, int flags, void *arg); 491.1Sfvdl */ 501.1SfvdlENTRY(__clone) 511.1Sfvdl pushq %r12 521.1Sfvdl pushq %r13 531.1Sfvdl /* 541.1Sfvdl * Sanity checks: func and stack may not be NULL. 551.1Sfvdl */ 561.1Sfvdl testq %rdi,%rdi 571.1Sfvdl je 3f 581.1Sfvdl testq %rsi,%rsi 591.1Sfvdl je 3f 601.1Sfvdl 611.1Sfvdl 621.1Sfvdl movq %rdi,%r12 631.1Sfvdl movq %rcx,%r13 641.1Sfvdl 651.1Sfvdl movq %rdx,%rdi 661.1Sfvdl 671.1Sfvdl pushq $0 /* dummy return address */ 681.1Sfvdl 691.1Sfvdl SYSTRAP(__clone) 701.1Sfvdl jc 4f 711.1Sfvdl cmpl $0,%eax 721.1Sfvdl jne 2f /* we're the parent */ 731.1Sfvdl movq %r13,%rdi /* restore argument */ 741.1Sfvdl call *%r12 /* this is the clone, call the function */ 751.1Sfvdl 761.1Sfvdl movq %rax,%rdi 771.1Sfvdl call PIC_PLT(_C_LABEL(_exit)) 781.1Sfvdl 791.1Sfvdl2: 801.1Sfvdl addq $8,%rsp 811.1Sfvdl popq %r13 821.1Sfvdl popq %r12 831.1Sfvdl ret 841.1Sfvdl3: 851.1Sfvdl movl $EINVAL,%eax 861.1Sfvdl jmp 5f 871.1Sfvdl4: 881.1Sfvdl addq $8,%rsp 891.2Sfvdl5: 901.1Sfvdl popq %r13 911.1Sfvdl popq %r12 921.7Schristos _SYSCALL_ERR 931.5SuebayasiEND(__clone) 94