Update.
[glibc.git] / linuxthreads / sysdeps / unix / sysv / linux / mips / vfork.S
blobbf541439b54624a6c970b68f9e7b40f1589fd860
1 /* Copyright (C) 2005 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
19 /* vfork() is just a special case of clone().  */
21 #include <sys/asm.h>
22 #include <sysdep.h>
23 #include <asm/unistd.h>
25 /* int vfork() */
27         .text
28 LOCALSZ= 1
29 FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
30 GPOFF= FRAMESZ-(1*SZREG)
31 NESTED(__vfork,FRAMESZ,sp)
32 #ifdef __PIC__
33         SETUP_GP
34 #endif
35         PTR_SUBU sp, FRAMESZ
36         SETUP_GP64 (a5, __vfork)
37 #ifdef __PIC__
38         SAVE_GP (GPOFF)
39 #endif
40 #ifdef PROF
41 # if (_MIPS_SIM != _ABIO32)
42         PTR_S           a5, GPOFF(sp)
43 # endif
44         .set            noat
45         move            $1, ra
46 # if (_MIPS_SIM == _ABIO32)
47         subu            sp,sp,8
48 # endif
49         jal             _mcount
50         .set            at
51 # if (_MIPS_SIM != _ABIO32)
52         PTR_L           a5, GPOFF(sp)
53 # endif
54 #endif
56         /* If libpthread is loaded, we need to call fork instead.  */
57 #ifdef SHARED
58         PTR_L           a0, __libc_pthread_functions
59 #else
60         .weak           pthread_create
61         PTR_LA          a0, pthread_create
62 #endif
64         PTR_ADDU        sp, FRAMESZ
66         bnez            a0, L(call_fork)
68         li              a0, 0x4112      /* CLONE_VM | CLONE_VFORK | SIGCHLD */
69         move            a1, sp
71         /* Do the system call */
72         li              v0,__NR_clone
73         syscall
75         bnez            a3,L(error)
77         /* Successful return from the parent or child.  */
78         RESTORE_GP64
79         ret
81         /* Something bad happened -- no child created.  */
82 L(error):
83 #ifdef __PIC__
84         PTR_LA          t9, __syscall_error
85         RESTORE_GP64
86         jr              t9
87 #else
88         RESTORE_GP64
89         j               __syscall_error
90 #endif
92 L(call_fork):
93 #ifdef __PIC__
94         PTR_LA          t9, fork
95         RESTORE_GP64
96         jr              t9
97 #else
98         RESTORE_GP64
99         j               fork
100 #endif
101         END(__vfork)
103 libc_hidden_def(__vfork)
104 weak_alias(__vfork, vfork)