]>
Commit | Line | Data |
---|---|---|
9a756540 | 1 | /* _Fork implementation. Linux version. |
581c785b | 2 | Copyright (C) 2021-2022 Free Software Foundation, Inc. |
9a756540 AZ |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
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 | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
17 | <https://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #include <arch-fork.h> | |
20 | #include <pthreadP.h> | |
21 | ||
9a756540 AZ |
22 | pid_t |
23 | _Fork (void) | |
24 | { | |
25 | pid_t pid = arch_fork (&THREAD_SELF->tid); | |
26 | if (pid == 0) | |
27 | { | |
28 | struct pthread *self = THREAD_SELF; | |
29 | ||
30 | /* Initialize the robust mutex list setting in the kernel which has | |
31 | been reset during the fork. We do not check for errors because if | |
32 | it fails here, it must have failed at process startup as well and | |
33 | nobody could have used robust mutexes. | |
34 | Before we do that, we have to clear the list of robust mutexes | |
35 | because we do not inherit ownership of mutexes from the parent. | |
36 | We do not have to set self->robust_head.futex_offset since we do | |
37 | inherit the correct value from the parent. We do not need to clear | |
38 | the pending operation because it must have been zero when fork was | |
39 | called. */ | |
40 | #if __PTHREAD_MUTEX_HAVE_PREV | |
41 | self->robust_prev = &self->robust_head; | |
42 | #endif | |
43 | self->robust_head.list = &self->robust_head; | |
44 | INTERNAL_SYSCALL_CALL (set_robust_list, &self->robust_head, | |
45 | sizeof (struct robust_list_head)); | |
46 | } | |
47 | return pid; | |
48 | } | |
49 | libc_hidden_def (_Fork) |