]>
Commit | Line | Data |
---|---|---|
2b778ceb | 1 | /* Copyright (C) 1999-2021 Free Software Foundation, Inc. |
53ad957e UD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Andreas Schwab <schwab@gnu.org>. | |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
53ad957e UD |
9 | |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
53ad957e | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
53ad957e UD |
18 | |
19 | #include <sysdep.h> | |
20 | #define _ERRNO_H 1 | |
21 | #include <bits/errno.h> | |
e2787137 RM |
22 | #include <tcb-offsets.h> |
23 | ||
53ad957e UD |
24 | /* Clone the calling process, but without copying the whole address space. |
25 | The calling process is suspended until the new process exits or is | |
26 | replaced by a call to `execve'. Return -1 for errors, 0 to the new process, | |
27 | and the process ID of the new process to the old process. */ | |
28 | ||
29 | ENTRY (__vfork) | |
30 | ||
53ad957e UD |
31 | /* Pop the return PC value into ECX. */ |
32 | popl %ecx | |
fee732e5 | 33 | cfi_adjust_cfa_offset (-4) |
6c30d38f | 34 | cfi_register (%eip, %ecx) |
53ad957e UD |
35 | |
36 | /* Stuff the syscall number in EAX and enter into the kernel. */ | |
37 | movl $SYS_ify (vfork), %eax | |
38 | int $0x80 | |
70829603 UD |
39 | |
40 | /* Jump to the return PC. Don't jump directly since this | |
41 | disturbs the branch target cache. Instead push the return | |
42 | address back on the stack. */ | |
43 | pushl %ecx | |
fee732e5 | 44 | cfi_adjust_cfa_offset (4) |
70829603 | 45 | |
53ad957e | 46 | cmpl $-4095, %eax |
70829603 | 47 | /* Branch forward if it failed. */ |
70829603 | 48 | jae SYSCALL_ERROR_LABEL |
53ad957e | 49 | |
3650e1d9 | 50 | #if SHSTK_ENABLED |
3650e1d9 L |
51 | /* Check if shadow stack is in use. */ |
52 | xorl %edx, %edx | |
53 | rdsspd %edx | |
54 | testl %edx, %edx | |
55 | /* Normal return if shadow stack isn't in use. */ | |
56 | je L(no_shstk) | |
57 | ||
c02695d7 L |
58 | testl %eax, %eax |
59 | /* In parent, normal return. */ | |
60 | jnz L(no_shstk) | |
61 | ||
62 | /* NB: In child, jump back to caller via indirect branch without | |
63 | popping shadow stack which is shared with parent. Keep shadow | |
64 | stack mismatched so that child returns in the vfork-calling | |
65 | function will trigger SIGSEGV. */ | |
66 | popl %ecx | |
67 | cfi_adjust_cfa_offset (-4) | |
3650e1d9 L |
68 | jmp *%ecx |
69 | ||
70 | L(no_shstk): | |
3650e1d9 L |
71 | #endif |
72 | ||
70829603 | 73 | ret |
53ad957e | 74 | |
53ad957e | 75 | PSEUDO_END (__vfork) |
a4baf360 | 76 | libc_hidden_def (__vfork) |
53ad957e UD |
77 | |
78 | weak_alias (__vfork, vfork) | |
e2787137 | 79 | strong_alias (__vfork, __libc_vfork) |