| 1 | /* arch_fork definition for Linux fork implementation. | 
| 2 |    Copyright (C) 2014-2019 Free Software Foundation, Inc. | 
| 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 |    <http://www.gnu.org/licenses/>.  */ | 
| 18 |  | 
| 19 | #ifndef __ARCH_FORK_H | 
| 20 | #define __ARCH_FORK_H | 
| 21 |  | 
| 22 | #include <unistd.h> | 
| 23 |  | 
| 24 | /* Call the clone syscall with fork semantic.  The CTID address is used | 
| 25 |    to store the child thread ID at its locationm, to erase it in child memory | 
| 26 |    when the child exits, and do a wakeup on the futex at that address. | 
| 27 |  | 
| 28 |    The architecture with non-default kernel abi semantic should correctlly | 
| 29 |    override it with one of the supported calling convention (check generic | 
| 30 |    kernel-features.h for the clone abi variants).  */ | 
| 31 | static inline pid_t | 
| 32 | arch_fork (void *ctid) | 
| 33 | { | 
| 34 |   const int flags = CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD; | 
| 35 |   long int ret; | 
| 36 | #ifdef __ASSUME_CLONE_BACKWARDS | 
| 37 | # ifdef INLINE_CLONE_SYSCALL | 
| 38 |   ret = INLINE_CLONE_SYSCALL (flags, 0, NULL, 0, ctid); | 
| 39 | # else | 
| 40 |   ret = INLINE_SYSCALL_CALL (clone, flags, 0, NULL, 0, ctid); | 
| 41 | # endif | 
| 42 | #elif defined(__ASSUME_CLONE_BACKWARDS2) | 
| 43 |   ret = INLINE_SYSCALL_CALL (clone, 0, flags, NULL, ctid, 0); | 
| 44 | #elif defined(__ASSUME_CLONE_BACKWARDS3) | 
| 45 |   ret = INLINE_SYSCALL_CALL (clone, flags, 0, 0, NULL, ctid, 0); | 
| 46 | #elif defined(__ASSUME_CLONE2) | 
| 47 |   ret = INLINE_SYSCALL_CALL (clone2, flags, 0, 0, NULL, ctid, 0); | 
| 48 | #elif defined(__ASSUME_CLONE_DEFAULT) | 
| 49 |   ret = INLINE_SYSCALL_CALL (clone, flags, 0, NULL, ctid, 0); | 
| 50 | #else | 
| 51 | # error "Undefined clone variant" | 
| 52 | #endif | 
| 53 |   return ret; | 
| 54 | } | 
| 55 |  | 
| 56 | #endif /* __ARCH_FORK_H  */ | 
| 57 |  |