mirror of
https://github.com/darlinghq/darling-xnu.git
synced 2024-11-23 04:29:53 +00:00
Perform most of the same pre- and post-fork work in posix_spawn as in fork
This commit is contained in:
parent
99020685f1
commit
8327ec8edd
@ -27,6 +27,7 @@
|
||||
#include "../unistd/fchdir.h"
|
||||
#include "../fcntl/fcntl.h"
|
||||
#include "../dirent/getdirentries.h"
|
||||
#include "../../../libsyscall/wrappers/_libkernel_init.h"
|
||||
|
||||
// for debugging only; remove before committing
|
||||
#include "../signal/kill.h"
|
||||
@ -40,6 +41,8 @@
|
||||
|
||||
#define LINUX_ADDR_NO_RANDOMIZE 0x40000
|
||||
|
||||
extern _libkernel_functions_t _libkernel_functions;
|
||||
|
||||
long sys_posix_spawn(int* pid, const char* path, const struct _posix_spawn_args_desc* desc,
|
||||
char** argvp, char** envp)
|
||||
{
|
||||
@ -53,14 +56,20 @@ long sys_posix_spawn(int* pid, const char* path, const struct _posix_spawn_args_
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
// we don't want to call user atfork callbacks, but we *do* want to call most
|
||||
// libsystem atfork callbacks to set up the environment for some of the calls we need
|
||||
// to make for the setup
|
||||
|
||||
_libkernel_functions->posix_spawn_prepare();
|
||||
|
||||
if ((my_pid = sys_fork()) == 0)
|
||||
{
|
||||
mach_driver_init(NULL);
|
||||
|
||||
// child
|
||||
// close the reading side
|
||||
close_internal(pipe[0]);
|
||||
|
||||
_libkernel_functions->posix_spawn_child();
|
||||
|
||||
no_fork:
|
||||
if (desc && desc->attrp)
|
||||
{
|
||||
@ -343,6 +352,8 @@ fail:
|
||||
// close the writing side
|
||||
close_internal(pipe[1]);
|
||||
|
||||
_libkernel_functions->posix_spawn_parent();
|
||||
|
||||
if (my_pid < 0)
|
||||
{
|
||||
ret = my_pid;
|
||||
|
@ -71,6 +71,9 @@ typedef const struct _libkernel_functions {
|
||||
/* Subsequent versions must only add pointers! */
|
||||
#ifdef DARLING
|
||||
int (*dyld_func_lookup)(const char*,void**);
|
||||
void (*posix_spawn_prepare)(void);
|
||||
void (*posix_spawn_parent)(void);
|
||||
void (*posix_spawn_child)(void);
|
||||
#endif
|
||||
} *_libkernel_functions_t;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user