@@ -2226,13 +2226,7 @@ RUN set -euxo pipefail; \
22262226 source /root/emsdk/emsdk_env.sh; \
22272227 if [ "$WITH_JSPI" = "yes" ]; then \
22282228 # Both imports and exports are required for inter-module communication with wrapped methods, e.g., wasm_recv.
2229- export JSPI_ADD_IMPORTS="" ; \
2230- export JSPI_ADD_EXPORTS="" ; \
2231- if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
2232- export JSPI_ADD_IMPORTS=",fd_close" ; \
2233- export JSPI_ADD_EXPORTS=",fd_close" ; \
2234- fi; \
2235- export ASYNCIFY_FLAGS=" -s ASYNCIFY=2 -sSUPPORT_LONGJMP=wasm -fwasm-exceptions -sJSPI_IMPORTS=js_open_process,js_fd_read,js_waitpid,js_process_status,js_create_input_device,wasm_setsockopt,wasm_shutdown,wasm_close,wasm_recv,__syscall_fcntl64,js_flock,js_release_file_locks,js_waitpid$JSPI_ADD_IMPORTS -sJSPI_EXPORTS=php_wasm_init,wasm_sleep,wasm_read,emscripten_sleep,wasm_sapi_handle_request,wasm_sapi_request_shutdown,wasm_poll_socket,wrap_select,__wrap_select,select,php_pollfd_for,fflush,wasm_popen,wasm_read,wasm_php_exec,run_cli,wasm_recv,__wasm_call_ctors$JSPI_ADD_EXPORTS -s EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports " ; \
2229+ export ASYNCIFY_FLAGS=" -s ASYNCIFY=2 -sSUPPORT_LONGJMP=wasm -fwasm-exceptions -sJSPI_IMPORTS=js_open_process,js_fd_read,js_waitpid,js_process_status,js_create_input_device,wasm_setsockopt,wasm_shutdown,wasm_close,wasm_recv,__syscall_fcntl64,js_flock,js_release_file_locks,js_waitpid -sJSPI_EXPORTS=php_wasm_init,wasm_sleep,wasm_read,emscripten_sleep,wasm_sapi_handle_request,wasm_sapi_request_shutdown,wasm_poll_socket,wrap_select,__wrap_select,select,php_pollfd_for,fflush,wasm_popen,wasm_read,wasm_php_exec,run_cli,wasm_recv,__wasm_call_ctors,__errno_location -s EXPORTED_RUNTIME_METHODS=HEAPU32,HEAPU8,ccall,PROXYFS,wasmExports " ; \
22362230 echo '#define PLAYGROUND_JSPI 1' > /root/php_wasm_asyncify.h; \
22372231 else \
22382232 export ASYNCIFY_FLAGS=" -s ASYNCIFY=1 -s ASYNCIFY_IGNORE_INDIRECT=1 -s EXPORTED_RUNTIME_METHODS=ccall,PROXYFS,wasmExports $(cat /root/.emcc-php-asyncify-flags) " ; \
@@ -2243,6 +2237,7 @@ RUN set -euxo pipefail; \
22432237"stringToUTF8", \n \
22442238"lengthBytesUTF8", \n \
22452239"FS", \n \
2240+ "___errno_location", \n \
22462241"___wrap_select", \n \
22472242"_wasm_set_sapi_name", \n \
22482243"_php_wasm_init", \n \
@@ -2403,6 +2398,11 @@ RUN set -euxo pipefail; \
24032398 # wrapper function.
24042399 /root/replace.sh $'s/ENVIRONMENT_IS_([A-Z]+)\s *=\s *(true|false)/ENVIRONMENT_IS_$1=RuntimeName==="$1"/g' /root/output/php.js; \
24052400 /root/replace.sh 's/var ENV\s *=\s *\{ /var ENV = PHPLoader.ENV || {/g' /root/output/php.js; \
2401+ # Expose required functions to the module.
2402+ # Emscripten 4.0.10 removed the runtime exposure of `_malloc` and `_free`,
2403+ # so we rebind them from `wasmExports` and attach them to PHPLoader.
2404+ /root/replace.sh "s/_free\s *=\s *wasmExports\[ 'free'\] ;/_free = PHPLoader['free'] = wasmExports['free'];/g" /root/output/php.js; \
2405+ /root/replace.sh "s/_malloc\s *=\s *wasmExports\[ 'malloc'\] ;/_malloc = PHPLoader['malloc'] = wasmExports['malloc'];/g" /root/output/php.js; \
24062406 # Patch Emscripten exit status to include a stack trace
24072407 # Override Emscripten's default ExitStatus class which gets
24082408 # thrown on failure. Unfortunately, the default object is not
0 commit comments