1*92d1d441Suebayasi/* $NetBSD: __clone.S,v 1.5 2014/05/22 15:01:57 uebayasi Exp $ */ 210940acfSfvdl 310940acfSfvdl/* 410940acfSfvdl * Copyright (c) 2002 Wasabi Systems, Inc. 510940acfSfvdl * All rights reserved. 610940acfSfvdl * 710940acfSfvdl * Written by Frank van der Linden for Wasabi Systems, Inc. 810940acfSfvdl * 910940acfSfvdl * Redistribution and use in source and binary forms, with or without 1010940acfSfvdl * modification, are permitted provided that the following conditions 1110940acfSfvdl * are met: 1210940acfSfvdl * 1. Redistributions of source code must retain the above copyright 1310940acfSfvdl * notice, this list of conditions and the following disclaimer. 1410940acfSfvdl * 2. Redistributions in binary form must reproduce the above copyright 1510940acfSfvdl * notice, this list of conditions and the following disclaimer in the 1610940acfSfvdl * documentation and/or other materials provided with the distribution. 1710940acfSfvdl * 3. All advertising materials mentioning features or use of this software 1810940acfSfvdl * must display the following acknowledgement: 1910940acfSfvdl * This product includes software developed for the NetBSD Project by 2010940acfSfvdl * Wasabi Systems, Inc. 2110940acfSfvdl * 4. The name of Wasabi Systems, Inc. may not be used to endorse 2210940acfSfvdl * or promote products derived from this software without specific prior 2310940acfSfvdl * written permission. 2410940acfSfvdl * 2510940acfSfvdl * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 2610940acfSfvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2710940acfSfvdl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2810940acfSfvdl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 2910940acfSfvdl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3010940acfSfvdl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3110940acfSfvdl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3210940acfSfvdl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3310940acfSfvdl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3410940acfSfvdl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3510940acfSfvdl * POSSIBILITY OF SUCH DAMAGE. 3610940acfSfvdl */ 3710940acfSfvdl 3810940acfSfvdl#include <machine/asm.h> 3910940acfSfvdl#include <sys/errno.h> 4010940acfSfvdl#include "SYS.h" 4110940acfSfvdl 4210940acfSfvdl#ifdef WEAK_ALIAS 4310940acfSfvdlWEAK_ALIAS(clone, __clone) 4410940acfSfvdl#endif 4510940acfSfvdl .text 4610940acfSfvdl 4710940acfSfvdl/* 4810940acfSfvdl * int clone(int (*fn)(void *), void *stack, int flags, void *arg); 4910940acfSfvdl */ 5010940acfSfvdlENTRY(__clone) 5110940acfSfvdl pushq %r12 5210940acfSfvdl pushq %r13 5310940acfSfvdl /* 5410940acfSfvdl * Sanity checks: func and stack may not be NULL. 5510940acfSfvdl */ 5610940acfSfvdl testq %rdi,%rdi 5710940acfSfvdl je 3f 5810940acfSfvdl testq %rsi,%rsi 5910940acfSfvdl je 3f 6010940acfSfvdl 6110940acfSfvdl 6210940acfSfvdl movq %rdi,%r12 6310940acfSfvdl movq %rcx,%r13 6410940acfSfvdl 6510940acfSfvdl movq %rdx,%rdi 6610940acfSfvdl 6710940acfSfvdl pushq $0 /* dummy return address */ 6810940acfSfvdl 6910940acfSfvdl SYSTRAP(__clone) 7010940acfSfvdl jc 4f 7110940acfSfvdl cmpl $0,%eax 7210940acfSfvdl jne 2f /* we're the parent */ 7310940acfSfvdl movq %r13,%rdi /* restore argument */ 7410940acfSfvdl call *%r12 /* this is the clone, call the function */ 7510940acfSfvdl 7610940acfSfvdl movq %rax,%rdi 774d12bfcdSjoerg#ifdef __PIC__ 7810940acfSfvdl call PIC_PLT(_C_LABEL(_exit)) 7910940acfSfvdl#else 8010940acfSfvdl call _C_LABEL(_exit) 8110940acfSfvdl#endif 8210940acfSfvdl 8310940acfSfvdl2: 8410940acfSfvdl addq $8,%rsp 8510940acfSfvdl popq %r13 8610940acfSfvdl popq %r12 8710940acfSfvdl ret 8810940acfSfvdl3: 8910940acfSfvdl movl $EINVAL,%eax 9010940acfSfvdl jmp 5f 9110940acfSfvdl4: 9210940acfSfvdl addq $8,%rsp 93e6f161c8Sfvdl5: 9410940acfSfvdl popq %r13 9510940acfSfvdl popq %r12 9610940acfSfvdl jmp CERROR 97*92d1d441SuebayasiEND(__clone) 98