arch-fork.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. 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.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef __ARCH_FORK_H
  16. #define __ARCH_FORK_H
  17. #include <unistd.h>
  18. /* Call the clone syscall with fork semantic. The CTID address is used
  19. to store the child thread ID at its locationm, to erase it in child memory
  20. when the child exits, and do a wakeup on the futex at that address.
  21. The architecture with non-default kernel abi semantic should correctlly
  22. override it with one of the supported calling convention (check generic
  23. kernel-features.h for the clone abi variants). */
  24. static inline pid_t
  25. arch_fork (void *ctid)
  26. {
  27. const int flags = CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD;
  28. long int ret;
  29. #ifdef __ASSUME_CLONE_BACKWARDS
  30. # ifdef INLINE_CLONE_SYSCALL
  31. ret = INLINE_CLONE_SYSCALL (flags, 0, NULL, 0, ctid);
  32. # else
  33. ret = INLINE_SYSCALL_CALL (clone, flags, 0, NULL, 0, ctid);
  34. # endif
  35. #elif defined(__ASSUME_CLONE_BACKWARDS2)
  36. ret = INLINE_SYSCALL_CALL (clone, 0, flags, NULL, ctid, 0);
  37. #elif defined(__ASSUME_CLONE_BACKWARDS3)
  38. ret = INLINE_SYSCALL_CALL (clone, flags, 0, 0, NULL, ctid, 0);
  39. #elif defined(__ASSUME_CLONE2)
  40. ret = INLINE_SYSCALL_CALL (clone2, flags, 0, 0, NULL, ctid, 0);
  41. #elif defined(__ASSUME_CLONE_DEFAULT)
  42. ret = INLINE_SYSCALL_CALL (clone, flags, 0, NULL, ctid, 0);
  43. #else
  44. # error "Undefined clone variant"
  45. #endif
  46. return ret;
  47. }
  48. #endif /* __ARCH_FORK_H */