Skip to content

Commit

Permalink
nolibc: implement fork() based on clone()
Browse files Browse the repository at this point in the history
Some archs such as arm64 do not have fork() and have to use clone() instead
so let's make fork() always use clone() when available. This requires to
include signal.h to get the definition of SIGCHLD.
  • Loading branch information
wtarreau committed Oct 28, 2019
1 parent 2379f25 commit d2dc42f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nolibc.h
Expand Up @@ -290,6 +290,8 @@ struct stat {
#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
#define WIFEXITED(status) (((status) & 0x7f) == 0)

/* for SIGCHLD */
#include <asm/signal.h>

/* Below comes the architecture-specific code. For each architecture, we have
* the syscall declarations and the _start code definition. This is the only
Expand Down Expand Up @@ -1548,7 +1550,15 @@ int sys_execve(const char *filename, char *const argv[], char *const envp[])
static __attribute__((unused))
pid_t sys_fork(void)
{
#ifdef __NR_clone
/* note: some archs only have clone() and not fork(). Different archs
* have a different API, but most archs have the flags on first arg and
* will not use the rest with no other flag.
*/
return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0);
#else
return my_syscall0(__NR_fork);
#endif
}

static __attribute__((unused))
Expand Down

0 comments on commit d2dc42f

Please sign in to comment.