__clone.S revision 1.1
1/* $NetBSD: __clone.S,v 1.1 2001/07/17 06:03:43 fvdl Exp $ */ 2 3/* 4 * Copyright (c) 2001 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Frank van der Linden for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38#include <machine/asm.h> 39#include <sys/errno.h> 40#include "SYS.h" 41 42#ifdef WEAK_ALIAS 43WEAK_ALIAS(clone, __clone) 44#endif 45 .text 46 47ENTRY(__clone) 48 pushl %ebp 49 50 /* 51 * Sanity checks: func and stack may not be NULL. 52 */ 53 movl 8(%esp), %ebp 54 cmpl $0,%ebp /* function */ 55 je 3f 56 movl 12(%esp),%eax /* stack */ 57 cmpl $0,%eax 58 je 3f 59 60 /* 61 * Set up the stack for the clone. 62 */ 63 movl 20(%esp),%ecx 64 movl %ecx,-4(%eax) /* argument */ 65 leal -8(%eax),%eax /* sp points to return address */ 66 movl $1f,(%eax) /* return address */ 67 68 pushl %eax /* stack */ 69 pushl 20(%esp) /* flags */ 70 pushl $0 /* dummy return address */ 71 72 SYSTRAP(__clone) 73 jc 4f 74 cmpl $0,%eax 75 jne 2f /* we're the parent */ 76 jmp *%ebp /* this is the clone, jump to the function */ 771: 78 pushl %eax /* clone does _exit(func(arg)); */ 79#ifdef PIC 80 PIC_PROLOGUE 81 call PIC_PLT(_C_LABEL(_exit)) 82 PIC_EPILOGUE 83#else 84 call PIC_PLT(_C_LABEL(_exit)) 85#endif 86 872: 88 addl $12,%esp 89 popl %ebp 90 ret 913: 92 movl $EINVAL,%eax 93 jmp 5f 944: 95 addl $12,%esp 965: 97 popl %ebp 98#ifdef PIC 99 PIC_PROLOGUE 100 movl PIC_GOT(CERROR),%edx 101 PIC_EPILOGUE 102 jmp *%edx 103#else 104 jmp CERROR 105#endif 106