Blame sysdeps/unix/sysv/linux/arch-fork.h

Packit Service 82fcde
/* arch_fork definition for Linux fork implementation.
Packit Service 82fcde
   Copyright (C) 2014-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#ifndef __ARCH_FORK_H
Packit Service 82fcde
#define __ARCH_FORK_H
Packit Service 82fcde
Packit Service 82fcde
#include <unistd.h>
Packit Service 82fcde
Packit Service 82fcde
/* Call the clone syscall with fork semantic.  The CTID address is used
Packit Service 82fcde
   to store the child thread ID at its locationm, to erase it in child memory
Packit Service 82fcde
   when the child exits, and do a wakeup on the futex at that address.
Packit Service 82fcde
Packit Service 82fcde
   The architecture with non-default kernel abi semantic should correctlly
Packit Service 82fcde
   override it with one of the supported calling convention (check generic
Packit Service 82fcde
   kernel-features.h for the clone abi variants).  */
Packit Service 82fcde
static inline pid_t
Packit Service 82fcde
arch_fork (void *ctid)
Packit Service 82fcde
{
Packit Service 82fcde
  const int flags = CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD;
Packit Service 82fcde
  long int ret;
Packit Service 82fcde
#ifdef __ASSUME_CLONE_BACKWARDS
Packit Service 82fcde
# ifdef INLINE_CLONE_SYSCALL
Packit Service 82fcde
  ret = INLINE_CLONE_SYSCALL (flags, 0, NULL, 0, ctid);
Packit Service 82fcde
# else
Packit Service 82fcde
  ret = INLINE_SYSCALL_CALL (clone, flags, 0, NULL, 0, ctid);
Packit Service 82fcde
# endif
Packit Service 82fcde
#elif defined(__ASSUME_CLONE_BACKWARDS2)
Packit Service 82fcde
  ret = INLINE_SYSCALL_CALL (clone, 0, flags, NULL, ctid, 0);
Packit Service 82fcde
#elif defined(__ASSUME_CLONE_BACKWARDS3)
Packit Service 82fcde
  ret = INLINE_SYSCALL_CALL (clone, flags, 0, 0, NULL, ctid, 0);
Packit Service 82fcde
#elif defined(__ASSUME_CLONE2)
Packit Service 82fcde
  ret = INLINE_SYSCALL_CALL (clone2, flags, 0, 0, NULL, ctid, 0);
Packit Service 82fcde
#elif defined(__ASSUME_CLONE_DEFAULT)
Packit Service 82fcde
  ret = INLINE_SYSCALL_CALL (clone, flags, 0, NULL, ctid, 0);
Packit Service 82fcde
#else
Packit Service 82fcde
# error "Undefined clone variant"
Packit Service 82fcde
#endif
Packit Service 82fcde
  return ret;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#endif /* __ARCH_FORK_H  */