From ce71ed8deb4563b037a457f1017d8e5552e15a00 Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Sun, 3 Apr 2011 07:40:04 +0900 Subject: [PATCH] Fix the implementations of posix_spawn_file_actions_* --- libmac/mac.c | 55 ++++++++++++++++++++++++++++++++++++++-------------- rename.tab | 9 ++++++--- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/libmac/mac.c b/libmac/mac.c index 4dc072168..8c920c99e 100644 --- a/libmac/mac.c +++ b/libmac/mac.c @@ -722,16 +722,20 @@ int __darwin_execle(const char* file, const char* arg, ...) { return 0; } +// It seems the size of posix_spawn_file_actions_t of Mac is smaller +// than Linux so modifying posix_spawn_file_actions_t allocated in +// Mac's stack would cause stack overflow. Let's wrap it. + int __darwin_posix_spawn(pid_t* pid, const char* path, - const posix_spawn_file_actions_t* file_actions, + const posix_spawn_file_actions_t** file_actions, const posix_spawnattr_t* attrp, char* argv[], char* const envp[]) { char** new_argv = add_loader_to_argv(argv); int r = posix_spawn(pid, __loader_path, - file_actions, + *file_actions, attrp, new_argv, envp); @@ -749,6 +753,40 @@ int __darwin_posix_spawnp(pid_t *pid, return 0; } +int __darwin_posix_spawn_file_actions_init(posix_spawn_file_actions_t** p) { + *p = (posix_spawn_file_actions_t*)malloc(sizeof(posix_spawn_file_actions_t)); + return posix_spawn_file_actions_init(*p); +} + +int __darwin_posix_spawn_file_actions_destroy(posix_spawn_file_actions_t** p) { + int r = posix_spawn_file_actions_destroy(*p); + free(*p); + return r; +} + +int __darwin_posix_spawn_file_actions_addopen( + posix_spawn_file_actions_t** file_actions, + int fd, + const char* path, + int oflag, + int mode) { + return posix_spawn_file_actions_addopen( + *file_actions, fd, path, oflag, mode); +} + +int __darwin_posix_spawn_file_actions_addclose( + posix_spawn_file_actions_t** file_actions, + int fd) { + return posix_spawn_file_actions_addclose(*file_actions, fd); +} + +int __darwin_posix_spawn_file_actions_adddup2( + posix_spawn_file_actions_t** file_actions, + int fd, + int newfd) { + return posix_spawn_file_actions_adddup2(*file_actions, fd, newfd); +} + typedef struct { const char *name; unsigned int cputype; @@ -927,19 +965,6 @@ char*** _NSGetEnviron() { return &environ; } -// It seems the size of posix_spawn_file_actions_t of Mac is smaller -// than Linux so modifying posix_spawn_file_actions_t allocated in -// Mac's stack would cause stack overflow. Let's wrap it. -int __darwin_posix_spawn_file_actions_init(posix_spawn_file_actions_t** p) { - *p = (posix_spawn_file_actions_t*)malloc(sizeof(posix_spawn_file_actions_t)); - return posix_spawn_file_actions_init(*p); -} -int __darwin_posix_spawn_file_actions_destroy(posix_spawn_file_actions_t** p) { - int r = posix_spawn_file_actions_destroy(*p); - free(*p); - return r; -} - #define __DARWIN_PTHREAD_MUTEX_NORMAL 0 #define __DARWIN_PTHREAD_MUTEX_ERRORCHECK 1 #define __DARWIN_PTHREAD_MUTEX_RECURSIVE 2 diff --git a/rename.tab b/rename.tab index 1c8e86edf..478379771 100644 --- a/rename.tab +++ b/rename.tab @@ -94,6 +94,12 @@ WRAP(execle) WRAP(posix_spawn) WRAP(posix_spawnp) +WRAP(posix_spawn_file_actions_init) +WRAP(posix_spawn_file_actions_destroy) +WRAP(posix_spawn_file_actions_addopen) +WRAP(posix_spawn_file_actions_addclose) +WRAP(posix_spawn_file_actions_adddup2) + RENAME(CC_MD5_Init, MD5_Init) RENAME(CC_MD5_Update, MD5_Update) RENAME(CC_MD5_Final, MD5_Final) @@ -106,9 +112,6 @@ WRAP(signal) WRAP(sigaction) WRAP(sigaltstack) -WRAP(posix_spawn_file_actions_init) -WRAP(posix_spawn_file_actions_destroy) - RENAME(__ashldi3, __ashlti3) RENAME(__ashrdi3, __ashrti3) RENAME(__cmpdi2, __cmpti2)