(INTERNAL_SYSCALL): Add LOAD_REGS_##nr. (LOAD_ARGS_0, LOAD_ARGS_1, LOAD_ARGS_2, LOAD_...
[glibc.git] / linuxthreads / ptfork.c
blob9cdbb54361b555aebc055db85e7c64b45409012a
1 /* Linuxthreads - a simple clone()-based implementation of Posix */
2 /* threads for Linux. */
3 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
4 /* */
5 /* This program is free software; you can redistribute it and/or */
6 /* modify it under the terms of the GNU Library General Public License */
7 /* as published by the Free Software Foundation; either version 2 */
8 /* of the License, or (at your option) any later version. */
9 /* */
10 /* This program 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 */
13 /* GNU Library General Public License for more details. */
15 /* The "atfork" stuff */
17 #include <errno.h>
18 #include <stddef.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include "pthread.h"
22 #include "internals.h"
23 #include <bits/libc-lock.h>
24 #include "fork.h"
26 extern int __libc_fork (void);
28 pid_t __pthread_fork (struct fork_block *b)
30 pid_t pid;
31 list_t *runp;
33 __libc_lock_lock (b->lock);
35 /* Run all the registered preparation handlers. In reverse order. */
36 list_for_each_prev (runp, &b->prepare_list)
38 struct fork_handler *curp;
39 curp = list_entry (runp, struct fork_handler, list);
40 curp->handler ();
43 __pthread_once_fork_prepare();
44 __flockfilelist();
46 pid = ARCH_FORK ();
48 if (pid == 0) {
49 __pthread_reset_main_thread();
51 __fresetlockfiles();
52 __pthread_once_fork_child();
54 /* Run the handlers registered for the child. */
55 list_for_each (runp, &b->child_list)
57 struct fork_handler *curp;
58 curp = list_entry (runp, struct fork_handler, list);
59 curp->handler ();
62 __libc_lock_init (b->lock);
63 } else {
64 __funlockfilelist();
65 __pthread_once_fork_parent();
67 /* Run the handlers registered for the parent. */
68 list_for_each (runp, &b->parent_list)
70 struct fork_handler *curp;
71 curp = list_entry (runp, struct fork_handler, list);
72 curp->handler ();
75 __libc_lock_unlock (b->lock);
78 return pid;
81 #ifdef SHARED
82 pid_t __fork (void)
84 return __libc_fork ();
86 weak_alias (__fork, fork);
88 pid_t __vfork(void)
90 return __libc_fork ();
92 weak_alias (__vfork, vfork);
93 #endif