(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / sysdeps / unix / sysv / linux / i386 / vfork.S
blobc7a120d2397dc0aa72b83fd2a6a8cb2a15527c66
1 /* Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Andreas Schwab <schwab@gnu.org>.
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
18    02111-1307 USA.  */
20 #include <sysdep-cancel.h>
21 #define _ERRNO_H        1
22 #include <bits/errno.h>
23 #include <kernel-features.h>
25 /* Clone the calling process, but without copying the whole address space.
26    The calling process is suspended until the new process exits or is
27    replaced by a call to `execve'.  Return -1 for errors, 0 to the new process,
28    and the process ID of the new process to the old process.  */
30 ENTRY (__vfork)
32 #ifdef __NR_vfork
34 # ifdef SHARED
35 #  if !defined HAVE_HIDDEN || !USE___THREAD
36         SETUP_PIC_REG (cx)
37 #  else
38         call    __i686.get_pc_thunk.cx
39 #  endif
40         addl    $_GLOBAL_OFFSET_TABLE_, %ecx
41         cmpl    $0, __libc_pthread_functions@GOTOFF(%ecx)
42 # else
43         .weak   pthread_create
44         movl    $pthread_create, %eax
45         testl   %eax, %eax
46 # endif
47         jne     HIDDEN_JUMPTARGET (__fork)
49         /* Pop the return PC value into ECX.  */
50         popl    %ecx
52         /* Stuff the syscall number in EAX and enter into the kernel.  */
53         movl    $SYS_ify (vfork), %eax
54         int     $0x80
56         /* Jump to the return PC.  Don't jump directly since this
57            disturbs the branch target cache.  Instead push the return
58            address back on the stack.  */
59         pushl   %ecx
61         cmpl    $-4095, %eax
62         /* Branch forward if it failed.  */
63 # ifdef __ASSUME_VFORK_SYSCALL
64         jae     SYSCALL_ERROR_LABEL
65 .Lpseudo_end:
66 # else
67         jae     .Lerror
68 # endif
70         ret
72 # ifndef __ASSUME_VFORK_SYSCALL
73 .Lerror:
74         /* Check if vfork syscall is known at all.  */
75         cmpl    $-ENOSYS, %eax
76         jne     SYSCALL_ERROR_LABEL
77 # endif
78 #endif
80 #ifndef __ASSUME_VFORK_SYSCALL
81         /* If we don't have vfork, fork is close enough.  */
83         movl    $SYS_ify (fork), %eax
84         int     $0x80
85         cmpl    $-4095, %eax
86         jae     SYSCALL_ERROR_LABEL
87 .Lpseudo_end:
88         ret
89 #elif !defined __NR_vfork
90 # error "__NR_vfork not available and __ASSUME_VFORK_SYSCALL defined"
91 #endif
92 PSEUDO_END (__vfork)
93 libc_hidden_def (__vfork)
95 weak_alias (__vfork, vfork)