1 #ifndef CHILDPROC_MD_H 2 #define CHILDPROC_MD_H 3 4 #include <sys/types.h> 5 6 #ifdef __APPLE__ 7 #include <crt_externs.h> 8 #define environ (*_NSGetEnviron()) 9 #endif 10 11 /* This is one of the rare times it's more portable to declare an 12 * external symbol explicitly, rather than via a system header. 13 * The declaration is standardized as part of UNIX98, but there is 14 * no standard (not even de-facto) header file where the 15 * declaration is to be found. See: 16 * http://www.opengroup.org/onlinepubs/009695399/functions/environ.html 17 * http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_02.html 18 * 19 * "All identifiers in this volume of IEEE Std 1003.1-2001, except 20 * environ, are defined in at least one of the headers" (!) 21 */ 22 extern char **environ; 23 24 /* These numbers must be the same as the Enum in UNIXProcess.java 25 * Must be a better way of doing this. 26 */ 27 #define MODE_CLONE 1 28 #define MODE_FORK 2 29 #define MODE_VFORK 3 30 #define MODE_SPAWN 4 31 32 typedef struct _ChildStuff 33 { 34 int in[2]; 35 int out[2]; 36 int err[2]; 37 int fail[2]; 38 int childenv[2]; 39 int fds[3]; 40 int mode; 41 const char **argv; 42 int argc; 43 const char **envv; 44 const char *pdir; 45 int redirectErrorStream; 46 void *clone_stack; 47 } ChildStuff; 48 49 /* following used in addition when mode is SPAWN */ 50 typedef struct _SpawnInfo { 51 int nargv; /* number of argv array elements */ 52 int argvBytes; /* total number of bytes in argv array */ 53 int nenvv; /* number of envv array elements */ 54 int envvBytes; /* total number of bytes in envv array */ 55 int dirlen; /* length of home directory string */ 56 int parentPathLen; /* length of parentPath string */ 57 int nparentPathv; /* number of elements in parentPathv array */ 58 int parentPathvBytes; /* total number of bytes in parentPathv array */ 59 } SpawnInfo; 60 61 extern const char *parentPath; 62 extern const char * const *parentPathv; 63 64 ssize_t restartableWrite(int fd, const void *buf, size_t count); 65 int restartableDup2(int fd_from, int fd_to); 66 int restartableClose(int fd); 67 int closeSafely(int fd); 68 int isAsciiDigit(char c); 69 int closeDescriptors(void); 70 int moveDescriptor(int fd_from, int fd_to); 71 72 int magicNumber(); 73 ssize_t readFully(int fd, void *buf, size_t nbyte); 74 void initVectorFromBlock(const char**vector, const char* block, int count); 75 void execve_as_traditional_shell_script(const char *file, 76 const char *argv[], 77 const char *const envp[]); 78 void execve_with_shell_fallback(int mode, const char *file, 79 const char *argv[], 80 const char *const envp[]); 81 void JDK_execvpe(int mode, const char *file, 82 const char *argv[], 83 const char *const envp[]); 84 int childProcess(void *arg); 85 86 #endif