1 /* Copyright (C) 1996, 1997, 2000, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ralf Baechle <ralf@linux-mips.org>, 1996.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 /* clone() is even more special than fork() as it mucks with stacks
21 and invokes a function in the right context after its all over. */
26 #include <bits/errno.h>
28 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg) */
32 FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
33 GPOFF= FRAMESZ-(1*SZREG)
34 NESTED(__clone,4*SZREG,sp)
39 SETUP_GP64 (GPOFF, __clone)
51 /* Sanity check arguments. */
53 beqz a0,L(error) /* No NULL function pointers. */
54 beqz a1,L(error) /* No NULL stack pointers. */
56 PTR_SUBU a1,32 /* Reserve argument save space. */
57 PTR_S a0,0(a1) /* Save function pointer. */
58 PTR_S a3,PTRSIZE(a1) /* Save argument pointer. */
61 /* Do the system call */
67 beqz v0,L(thread_start)
69 /* Successful return from the parent */
74 /* Something bad happened -- no child created */
77 PTR_LA t9,__syscall_error
88 /* Load up the arguments to the function. Put this block of code in
89 its own function so that we can terminate the stack trace with our
94 /* cp is already loaded. */
96 /* The stackframe has been created on entry of clone(). */
97 /* Restore the arg for user's function. */
98 PTR_L t9,0(sp) /* Function pointer. */
99 PTR_L a0,PTRSIZE(sp) /* Argument pointer. */
101 /* Call the user's function. */
104 /* Call _exit rather than doing it inline for breakpoint purposes. */
114 weak_alias(__clone, clone)