Path: blob/main/python/cpython/src/patches/07-subprocess.patch
1067 views
--- native/Lib/subprocess.py 2022-08-05 07:45:18.000000000 -07001+++ wasm/Lib/subprocess.py 2022-09-13 22:02:10.921551009 -07002@@ -75,7 +75,7 @@3_mswindows = True45# wasm32-emscripten and wasm32-wasi do not support processes6-_can_fork_exec = sys.platform not in {"emscripten", "wasi"}7+_can_fork_exec = sys.platform not in {"emscripten"}89if _mswindows:10import _winapi1112--- native/Modules/_posixsubprocess.c 2022-08-05 07:45:18.000000000 -070013+++ wasm/Modules/_posixsubprocess.c 2022-09-14 10:40:07.000000000 -070014@@ -702,6 +702,22 @@15}16}1718+extern int python_wasm_fork_exec(char *const exec_array[],19+ char *const argv[],20+ char *const envp[],21+ const char *cwd,22+ int p2cread, int p2cwrite,23+ int c2pread, int c2pwrite,24+ int errread, int errwrite,25+ int errpipe_read, int errpipe_write,26+ int close_fds, int restore_signals,27+ int call_setsid, pid_t pgid_to_set,28+ int call_setgid, gid_t gid,29+ int call_setgroups, size_t groups_size, const gid_t *groups,30+ int call_setuid, uid_t uid, int child_umask,31+ const void *child_sigmask,32+ int *py_fds_to_keep // null or a null terminated int[]33+ );3435/* The main purpose of this wrapper function is to isolate vfork() from both36* subprocess_fork_exec() and child_exec(). A child process created via37@@ -731,6 +747,30 @@38PyObject *preexec_fn_args_tuple)39{4041+ // For python-wasm we MUST take care of the entire42+ // fork --> do stuff --> exec43+ // ourselves at the node.js / zig layer, since once44+ // fork happens you can't robustly run any javascript45+ // code, but all the setup requires arbitrarily much46+ // such code to be run. Also, doing this externally47+ // provides a clear API to implement and provide a48+ // browser version as well. Unless we switch from node49+ // to some custom webassembly runtime of our own like wasmtime,50+ // doing this sort of thing generally via system calls can't51+ // be supported.52+ return python_wasm_fork_exec(exec_array,53+ argv,envp,cwd,p2cread, p2cwrite,54+ c2pread, c2pwrite,55+ errread, errwrite,56+ errpipe_read, errpipe_write,57+ close_fds, restore_signals,58+ call_setsid, pgid_to_set,59+ call_setgid, gid,60+ call_setgroups, groups_size, groups,61+ call_setuid, uid, child_umask,62+ child_sigmask,63+ NULL);64+65pid_t pid;6667#ifdef VFORK_USABLE686970