hurd: add TLS support
[glibc.git] / sysdeps / mach / hurd / fork.c
blobcc322ebee5525f57a63250d5f90ed14a6c8f2cc3
1 /* Copyright (C) 1994-2018 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, see
16 <http://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <unistd.h>
20 #include <hurd.h>
21 #include <hurd/signal.h>
22 #include <setjmp.h>
23 #include <thread_state.h>
24 #include <sysdep.h> /* For stack growth direction. */
25 #include "set-hooks.h"
26 #include <assert.h>
27 #include "hurdmalloc.h" /* XXX */
28 #include <tls.h>
29 #include <malloc/malloc-internal.h>
31 #undef __fork
34 /* Things that want to be locked while forking. */
35 symbol_set_declare (_hurd_fork_locks)
38 /* Application callbacks registered through pthread_atfork. */
39 DEFINE_HOOK (_hurd_atfork_prepare_hook, (void));
40 DEFINE_HOOK (_hurd_atfork_child_hook, (void));
41 DEFINE_HOOK (_hurd_atfork_parent_hook, (void));
43 /* Things that want to be called before we fork, to prepare the parent for
44 task_create, when the new child task will inherit our address space. */
45 DEFINE_HOOK (_hurd_fork_prepare_hook, (void));
47 /* Things that want to be called when we are forking, with the above all
48 locked. They are passed the task port of the child. The child process
49 is all set up except for doing proc_child, and has no threads yet. */
50 DEFINE_HOOK (_hurd_fork_setup_hook, (void));
52 /* Things to be run in the child fork. */
53 DEFINE_HOOK (_hurd_fork_child_hook, (void));
55 /* Things to be run in the parent fork. */
56 DEFINE_HOOK (_hurd_fork_parent_hook, (void));
59 /* Clone the calling process, creating an exact copy.
60 Return -1 for errors, 0 to the new process,
61 and the process ID of the new process to the old process. */
62 pid_t
63 __fork (void)
65 jmp_buf env;
66 pid_t pid;
67 size_t i;
68 error_t err;
69 struct hurd_sigstate *volatile ss;
71 RUN_HOOK (_hurd_atfork_prepare_hook, ());
73 ss = _hurd_self_sigstate ();
74 __spin_lock (&ss->critical_section_lock);
76 #undef LOSE
77 #define LOSE do { assert_perror (err); goto lose; } while (0) /* XXX */
79 if (! setjmp (env))
81 process_t newproc;
82 task_t newtask;
83 thread_t thread, sigthread;
84 mach_port_urefs_t thread_refs, sigthread_refs;
85 struct machine_thread_state state;
86 mach_msg_type_number_t statecount;
87 mach_port_t *portnames = NULL;
88 mach_msg_type_number_t nportnames = 0;
89 mach_port_type_t *porttypes = NULL;
90 mach_msg_type_number_t nporttypes = 0;
91 thread_t *threads = NULL;
92 mach_msg_type_number_t nthreads = 0;
93 int ports_locked = 0, stopped = 0;
95 void resume_threads (void)
97 if (! stopped)
98 return;
100 assert (threads);
102 for (i = 0; i < nthreads; ++i)
103 if (threads[i] != ss->thread)
104 __thread_resume (threads[i]);
105 stopped = 0;
108 /* Run things that prepare for forking before we create the task. */
109 RUN_HOOK (_hurd_fork_prepare_hook, ());
111 /* Lock things that want to be locked before we fork. */
113 void *const *p;
114 for (p = symbol_set_first_element (_hurd_fork_locks);
115 ! symbol_set_end_p (_hurd_fork_locks, p);
116 ++p)
117 __mutex_lock (*p);
119 __mutex_lock (&_hurd_siglock);
121 /* Acquire malloc locks. This needs to come last because fork
122 handlers may use malloc, and the libio list lock has an
123 indirect malloc dependency as well (via the getdelim
124 function). */
125 call_function_static_weak (__malloc_fork_lock_parent);
126 _hurd_malloc_fork_prepare ();
128 newtask = MACH_PORT_NULL;
129 thread = sigthread = MACH_PORT_NULL;
130 newproc = MACH_PORT_NULL;
132 /* Lock all the port cells for the standard ports while we copy the
133 address space. We want to insert all the send rights into the
134 child with the same names. */
135 for (i = 0; i < _hurd_nports; ++i)
136 __spin_lock (&_hurd_ports[i].lock);
137 ports_locked = 1;
140 /* Keep our SS locked while stopping other threads, so they don't get a
141 chance to have it locked in the copied space. */
142 __spin_lock (&ss->lock);
143 /* Stop all other threads while copying the address space,
144 so nothing changes. */
145 err = __proc_dostop (_hurd_ports[INIT_PORT_PROC].port, ss->thread);
146 __spin_unlock (&ss->lock);
147 if (!err)
149 stopped = 1;
151 #define XXX_KERNEL_PAGE_FAULT_BUG /* XXX work around page fault bug in mk */
153 #ifdef XXX_KERNEL_PAGE_FAULT_BUG
154 /* Gag me with a pitchfork.
155 The bug scenario is this:
157 - The page containing __mach_task_self_ is paged out.
158 - The signal thread was faulting on that page when we
159 suspended it via proc_dostop. It holds some lock, or set
160 some busy bit, or somesuch.
161 - Now this thread faults on that same page.
162 - GRATUIOUS DEADLOCK
164 We can break the deadlock by aborting the thread that faulted
165 first, which if the bug happened was the signal thread because
166 it is the only other thread and we just suspended it.
168 __thread_abort (_hurd_msgport_thread);
169 #endif
170 /* Create the child task. It will inherit a copy of our memory. */
171 err = __task_create (__mach_task_self (),
172 #ifdef KERN_INVALID_LEDGER
173 NULL, 0, /* OSF Mach */
174 #endif
175 1, &newtask);
178 /* Unlock the global signal state lock, so we do not
179 block the signal thread any longer than necessary. */
180 __mutex_unlock (&_hurd_siglock);
182 if (err)
183 LOSE;
185 /* Fetch the names of all ports used in this task. */
186 if (err = __mach_port_names (__mach_task_self (),
187 &portnames, &nportnames,
188 &porttypes, &nporttypes))
189 LOSE;
190 if (nportnames != nporttypes)
192 err = EGRATUITOUS;
193 LOSE;
196 /* Get send rights for all the threads in this task.
197 We want to avoid giving these rights to the child. */
198 if (err = __task_threads (__mach_task_self (), &threads, &nthreads))
199 LOSE;
201 /* Get the child process's proc server port. We will insert it into
202 the child with the same name as we use for our own proc server
203 port; and we will need it to set the child's message port. */
204 if (err = __proc_task2proc (_hurd_ports[INIT_PORT_PROC].port,
205 newtask, &newproc))
206 LOSE;
208 /* Insert all our port rights into the child task. */
209 thread_refs = sigthread_refs = 0;
210 for (i = 0; i < nportnames; ++i)
212 if (porttypes[i] & MACH_PORT_TYPE_RECEIVE)
214 /* This is a receive right. We want to give the child task
215 its own new receive right under the same name. */
216 if (err = __mach_port_allocate_name (newtask,
217 MACH_PORT_RIGHT_RECEIVE,
218 portnames[i]))
219 LOSE;
220 if (porttypes[i] & MACH_PORT_TYPE_SEND)
222 /* Give the child as many send rights for its receive
223 right as we have for ours. */
224 mach_port_urefs_t refs;
225 mach_port_t port;
226 mach_msg_type_name_t poly;
227 if (err = __mach_port_get_refs (__mach_task_self (),
228 portnames[i],
229 MACH_PORT_RIGHT_SEND,
230 &refs))
231 LOSE;
232 if (err = __mach_port_extract_right (newtask,
233 portnames[i],
234 MACH_MSG_TYPE_MAKE_SEND,
235 &port, &poly))
236 LOSE;
237 if (portnames[i] == _hurd_msgport)
239 /* We just created a receive right for the child's
240 message port and are about to insert send rights
241 for it. Now, while we happen to have a send right
242 for it, give it to the proc server. */
243 mach_port_t old;
244 if (err = __proc_setmsgport (newproc, port, &old))
245 LOSE;
246 if (old != MACH_PORT_NULL)
247 /* XXX what to do here? */
248 __mach_port_deallocate (__mach_task_self (), old);
249 /* The new task will receive its own exceptions
250 on its message port. */
251 if (err =
252 #ifdef TASK_EXCEPTION_PORT
253 __task_set_special_port (newtask,
254 TASK_EXCEPTION_PORT,
255 port)
256 #elif defined (EXC_MASK_ALL)
257 __task_set_exception_ports
258 (newtask, EXC_MASK_ALL & ~(EXC_MASK_SYSCALL
259 | EXC_MASK_MACH_SYSCALL
260 | EXC_MASK_RPC_ALERT),
261 port, EXCEPTION_DEFAULT, MACHINE_THREAD_STATE)
262 #else
263 # error task_set_exception_port?
264 #endif
266 LOSE;
268 if (err = __mach_port_insert_right (newtask,
269 portnames[i],
270 port,
271 MACH_MSG_TYPE_MOVE_SEND))
272 LOSE;
273 if (refs > 1 &&
274 (err = __mach_port_mod_refs (newtask,
275 portnames[i],
276 MACH_PORT_RIGHT_SEND,
277 refs - 1)))
278 LOSE;
280 if (porttypes[i] & MACH_PORT_TYPE_SEND_ONCE)
282 /* Give the child a send-once right for its receive right,
283 since we have one for ours. */
284 mach_port_t port;
285 mach_msg_type_name_t poly;
286 if (err = __mach_port_extract_right
287 (newtask,
288 portnames[i],
289 MACH_MSG_TYPE_MAKE_SEND_ONCE,
290 &port, &poly))
291 LOSE;
292 if (err = __mach_port_insert_right
293 (newtask,
294 portnames[i], port,
295 MACH_MSG_TYPE_MOVE_SEND_ONCE))
296 LOSE;
299 else if (porttypes[i] &
300 (MACH_PORT_TYPE_SEND|MACH_PORT_TYPE_DEAD_NAME))
302 /* This is a send right or a dead name.
303 Give the child as many references for it as we have. */
304 mach_port_urefs_t refs = 0, *record_refs = NULL;
305 mach_port_t insert;
306 mach_msg_type_name_t insert_type = MACH_MSG_TYPE_COPY_SEND;
307 if (portnames[i] == newtask || portnames[i] == newproc)
308 /* Skip the name we use for the child's task or proc ports. */
309 continue;
310 if (portnames[i] == __mach_task_self ())
311 /* For the name we use for our own task port,
312 insert the child's task port instead. */
313 insert = newtask;
314 else if (portnames[i] == _hurd_ports[INIT_PORT_PROC].port)
316 /* Use the proc server port for the new task. */
317 insert = newproc;
318 insert_type = MACH_MSG_TYPE_COPY_SEND;
320 else if (portnames[i] == ss->thread)
322 /* For the name we use for our own thread port, we will
323 insert the thread port for the child main user thread
324 after we create it. */
325 insert = MACH_PORT_NULL;
326 record_refs = &thread_refs;
327 /* Allocate a dead name right for this name as a
328 placeholder, so the kernel will not chose this name
329 for any other new port (it might use it for one of the
330 rights created when a thread is created). */
331 if (err = __mach_port_allocate_name
332 (newtask, MACH_PORT_RIGHT_DEAD_NAME, portnames[i]))
333 LOSE;
335 else if (portnames[i] == _hurd_msgport_thread)
336 /* For the name we use for our signal thread's thread port,
337 we will insert the thread port for the child's signal
338 thread after we create it. */
340 insert = MACH_PORT_NULL;
341 record_refs = &sigthread_refs;
342 /* Allocate a dead name right as a placeholder. */
343 if (err = __mach_port_allocate_name
344 (newtask, MACH_PORT_RIGHT_DEAD_NAME, portnames[i]))
345 LOSE;
347 else
349 /* Skip the name we use for any of our own thread ports. */
350 mach_msg_type_number_t j;
351 for (j = 0; j < nthreads; ++j)
352 if (portnames[i] == threads[j])
353 break;
354 if (j < nthreads)
355 continue;
357 /* Copy our own send right. */
358 insert = portnames[i];
360 /* Find out how many user references we have for
361 the send right with this name. */
362 if (err = __mach_port_get_refs (__mach_task_self (),
363 portnames[i],
364 MACH_PORT_RIGHT_SEND,
365 record_refs ?: &refs))
366 LOSE;
367 if (insert == MACH_PORT_NULL)
368 continue;
369 if (insert == portnames[i] &&
370 (porttypes[i] & MACH_PORT_TYPE_DEAD_NAME))
371 /* This is a dead name; allocate another dead name
372 with the same name in the child. */
373 allocate_dead_name:
374 err = __mach_port_allocate_name (newtask,
375 MACH_PORT_RIGHT_DEAD_NAME,
376 portnames[i]);
377 else
378 /* Insert the chosen send right into the child. */
379 err = __mach_port_insert_right (newtask,
380 portnames[i],
381 insert, insert_type);
382 switch (err)
384 case KERN_NAME_EXISTS:
386 /* It already has a send right under this name (?!).
387 Well, it starts out with a send right for its task
388 port, and inherits the bootstrap and exception ports
389 from us. */
390 mach_port_t childport;
391 mach_msg_type_name_t poly;
392 assert (__mach_port_extract_right (newtask, portnames[i],
393 MACH_MSG_TYPE_COPY_SEND,
394 &childport,
395 &poly) == 0 &&
396 childport == insert &&
397 __mach_port_deallocate (__mach_task_self (),
398 childport) == 0);
399 break;
402 case KERN_INVALID_CAPABILITY:
403 /* The port just died. It was a send right,
404 and now it's a dead name. */
405 goto allocate_dead_name;
407 default:
408 LOSE;
409 break;
411 case KERN_SUCCESS:
412 /* Give the child as many user references as we have. */
413 if (refs > 1 &&
414 (err = __mach_port_mod_refs (newtask,
415 portnames[i],
416 MACH_PORT_RIGHT_SEND,
417 refs - 1)))
418 LOSE;
423 /* Unlock the standard port cells. The child must unlock its own
424 copies too. */
425 for (i = 0; i < _hurd_nports; ++i)
426 __spin_unlock (&_hurd_ports[i].lock);
427 ports_locked = 0;
429 /* All state has now been copied from the parent. It is safe to
430 resume other parent threads. */
431 resume_threads ();
433 /* Create the child main user thread and signal thread. */
434 if ((err = __thread_create (newtask, &thread)) ||
435 (err = __thread_create (newtask, &sigthread)))
436 LOSE;
438 /* Insert send rights for those threads. We previously allocated
439 dead name rights with the names we want to give the thread ports
440 in the child as placeholders. Now deallocate them so we can use
441 the names. */
442 if ((err = __mach_port_deallocate (newtask, ss->thread)) ||
443 (err = __mach_port_insert_right (newtask, ss->thread,
444 thread, MACH_MSG_TYPE_COPY_SEND)))
445 LOSE;
446 if (thread_refs > 1 &&
447 (err = __mach_port_mod_refs (newtask, ss->thread,
448 MACH_PORT_RIGHT_SEND,
449 thread_refs - 1)))
450 LOSE;
451 if ((_hurd_msgport_thread != MACH_PORT_NULL) /* Let user have none. */
452 && ((err = __mach_port_deallocate (newtask, _hurd_msgport_thread)) ||
453 (err = __mach_port_insert_right (newtask, _hurd_msgport_thread,
454 sigthread,
455 MACH_MSG_TYPE_COPY_SEND))))
456 LOSE;
457 if (sigthread_refs > 1 &&
458 (err = __mach_port_mod_refs (newtask, _hurd_msgport_thread,
459 MACH_PORT_RIGHT_SEND,
460 sigthread_refs - 1)))
461 LOSE;
463 /* This seems like a convenient juncture to copy the proc server's
464 idea of what addresses our argv and envp are found at from the
465 parent into the child. Since we happen to know that the child
466 shares our memory image, it is we who should do this copying. */
468 vm_address_t argv, envp;
469 err = (__USEPORT (PROC, __proc_get_arg_locations (port, &argv, &envp))
470 ?: __proc_set_arg_locations (newproc, argv, envp));
471 if (err)
472 LOSE;
475 /* Set the child signal thread up to run the msgport server function
476 using the same signal thread stack copied from our address space.
477 We fetch the state before longjmp'ing it so that miscellaneous
478 registers not affected by longjmp (such as i386 segment registers)
479 are in their normal default state. */
480 statecount = MACHINE_THREAD_STATE_COUNT;
481 if (err = __thread_get_state (_hurd_msgport_thread,
482 MACHINE_THREAD_STATE_FLAVOR,
483 (natural_t *) &state, &statecount))
484 LOSE;
485 #ifdef STACK_GROWTH_UP
486 #define THREADVAR_SPACE (__hurd_threadvar_max \
487 * sizeof *__hurd_sightread_variables)
488 if (__hurd_sigthread_stack_base == 0)
490 state.SP &= __hurd_threadvar_stack_mask;
491 state.SP += __hurd_threadvar_stack_offset + THREADVAR_SPACE;
493 else
494 state.SP = __hurd_sigthread_stack_base;
495 #else
496 if (__hurd_sigthread_stack_end == 0)
498 /* The signal thread has a normal stack assigned by cthreads.
499 The threadvar_stack variables conveniently tell us how
500 to get to the highest address in the stack, just below
501 the per-thread variables. */
502 state.SP &= __hurd_threadvar_stack_mask;
503 state.SP += __hurd_threadvar_stack_offset;
505 else
506 state.SP = __hurd_sigthread_stack_end;
507 #endif
508 MACHINE_THREAD_STATE_SET_PC (&state,
509 (unsigned long int) _hurd_msgport_receive);
511 /* Do special signal thread setup for TLS if needed. */
512 if (err = _hurd_tls_fork (sigthread, _hurd_msgport_thread, &state))
513 LOSE;
515 if (err = __thread_set_state (sigthread, MACHINE_THREAD_STATE_FLAVOR,
516 (natural_t *) &state, statecount))
517 LOSE;
518 /* We do not thread_resume SIGTHREAD here because the child
519 fork needs to do more setup before it can take signals. */
521 /* Set the child user thread up to return 1 from the setjmp above. */
522 _hurd_longjmp_thread_state (&state, env, 1);
524 /* Do special thread setup for TLS if needed. */
525 if (err = _hurd_tls_fork (thread, ss->thread, &state))
526 LOSE;
528 if (err = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
529 (natural_t *) &state, statecount))
530 LOSE;
532 /* Get the PID of the child from the proc server. We must do this
533 before calling proc_child below, because at that point any
534 authorized POSIX.1 process may kill the child task with SIGKILL. */
535 if (err = __USEPORT (PROC, __proc_task2pid (port, newtask, &pid)))
536 LOSE;
538 /* Register the child with the proc server. It is important that
539 this be that last thing we do before starting the child thread
540 running. Once proc_child has been done for the task, it appears
541 as a POSIX.1 process. Any errors we get must be detected before
542 this point, and the child must have a message port so it responds
543 to POSIX.1 signals. */
544 if (err = __USEPORT (PROC, __proc_child (port, newtask)))
545 LOSE;
547 /* This must be the absolutely last thing we do; we can't assume that
548 the child will remain alive for even a moment once we do this. We
549 ignore errors because we have committed to the fork and are not
550 allowed to return them after the process becomes visible to
551 POSIX.1 (which happened right above when we called proc_child). */
552 (void) __thread_resume (thread);
554 lose:
555 if (ports_locked)
556 for (i = 0; i < _hurd_nports; ++i)
557 __spin_unlock (&_hurd_ports[i].lock);
559 resume_threads ();
561 if (newtask != MACH_PORT_NULL)
563 if (err)
564 __task_terminate (newtask);
565 __mach_port_deallocate (__mach_task_self (), newtask);
567 if (thread != MACH_PORT_NULL)
568 __mach_port_deallocate (__mach_task_self (), thread);
569 if (sigthread != MACH_PORT_NULL)
570 __mach_port_deallocate (__mach_task_self (), sigthread);
571 if (newproc != MACH_PORT_NULL)
572 __mach_port_deallocate (__mach_task_self (), newproc);
574 if (portnames)
575 __vm_deallocate (__mach_task_self (),
576 (vm_address_t) portnames,
577 nportnames * sizeof (*portnames));
578 if (porttypes)
579 __vm_deallocate (__mach_task_self (),
580 (vm_address_t) porttypes,
581 nporttypes * sizeof (*porttypes));
582 if (threads)
584 for (i = 0; i < nthreads; ++i)
585 __mach_port_deallocate (__mach_task_self (), threads[i]);
586 __vm_deallocate (__mach_task_self (),
587 (vm_address_t) threads,
588 nthreads * sizeof (*threads));
591 /* Release malloc locks. */
592 _hurd_malloc_fork_parent ();
593 call_function_static_weak (__malloc_fork_unlock_parent);
595 /* Run things that want to run in the parent to restore it to
596 normality. Usually prepare hooks and parent hooks are
597 symmetrical: the prepare hook arrests state in some way for the
598 fork, and the parent hook restores the state for the parent to
599 continue executing normally. */
600 RUN_HOOK (_hurd_fork_parent_hook, ());
602 else
604 struct hurd_sigstate *oldstates;
606 /* We are the child task. Unlock the standard port cells, which were
607 locked in the parent when we copied its memory. The parent has
608 inserted send rights with the names that were in the cells then. */
609 for (i = 0; i < _hurd_nports; ++i)
610 __spin_unlock (&_hurd_ports[i].lock);
612 /* We are one of the (exactly) two threads in this new task, we
613 will take the task-global signals. */
614 _hurd_sigthread = ss->thread;
616 /* Claim our sigstate structure and unchain the rest: the
617 threads existed in the parent task but don't exist in this
618 task (the child process). Delay freeing them until later
619 because some of the further setup and unlocking might be
620 required for free to work. Before we finish cleaning up,
621 we will reclaim the signal thread's sigstate structure (if
622 it had one). */
623 oldstates = _hurd_sigstates;
624 if (oldstates == ss)
625 oldstates = ss->next;
626 else
628 while (_hurd_sigstates->next != ss)
629 _hurd_sigstates = _hurd_sigstates->next;
630 _hurd_sigstates->next = ss->next;
632 ss->next = NULL;
633 _hurd_sigstates = ss;
634 __mutex_unlock (&_hurd_siglock);
636 /* Fetch our new process IDs from the proc server. No need to
637 refetch our pgrp; it is always inherited from the parent (so
638 _hurd_pgrp is already correct), and the proc server will send us a
639 proc_newids notification when it changes. */
640 err = __USEPORT (PROC, __proc_getpids (port, &_hurd_pid, &_hurd_ppid,
641 &_hurd_orphaned));
643 /* Forking clears the trace flag. */
644 __sigemptyset (&_hurdsig_traced);
646 /* Release malloc locks. */
647 _hurd_malloc_fork_child ();
648 call_function_static_weak (__malloc_fork_unlock_child);
650 /* Run things that want to run in the child task to set up. */
651 RUN_HOOK (_hurd_fork_child_hook, ());
653 /* Set up proc server-assisted fault recovery for the signal thread. */
654 _hurdsig_fault_init ();
656 /* Start the signal thread listening on the message port. */
657 if (!err)
658 err = __thread_resume (_hurd_msgport_thread);
660 /* Reclaim the signal thread's sigstate structure and free the
661 other old sigstate structures. */
662 while (oldstates != NULL)
664 struct hurd_sigstate *next = oldstates->next;
666 if (oldstates->thread == _hurd_msgport_thread)
668 /* If we have a second signal state structure then we
669 must have been through here before--not good. */
670 assert (_hurd_sigstates->next == 0);
671 _hurd_sigstates->next = oldstates;
672 oldstates->next = 0;
674 else
675 free (oldstates);
677 oldstates = next;
680 /* XXX what to do if we have any errors here? */
682 pid = 0;
685 /* Unlock things we locked before creating the child task.
686 They are locked in both the parent and child tasks. */
688 void *const *p;
689 for (p = symbol_set_first_element (_hurd_fork_locks);
690 ! symbol_set_end_p (_hurd_fork_locks, p);
691 ++p)
692 __mutex_unlock (*p);
695 _hurd_critical_section_unlock (ss);
697 if (!err)
699 if (pid != 0)
700 RUN_HOOK (_hurd_atfork_parent_hook, ());
701 else
702 RUN_HOOK (_hurd_atfork_child_hook, ());
705 return err ? __hurd_fail (err) : pid;
707 libc_hidden_def (__fork)
709 weak_alias (__fork, fork)