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