You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for building to the wasm32-wasi target
This change performs initial adaptations allowing the PHP interpreter
to be compiled for the wasm32-wasi target.
Challenges found:
- `setjmp`/`longjmp` not available in this platform: can be worked
around by using Asyncify; this is work in progress to be presented at
a later stage.
- Processes: WebAssembly has no concept of processes, so many
process-related operations had to be emulated, or are no-ops. `getpid`
and clocks are emulated. Signal handling has minimal emulation. `uid`,
`gid`, and related concepts that do not map well to a WebAssembly
sandbox are also removed.
- `mmap` implementation is a minimal emulation that allows to
allocate memory or map file contents to it.
- Filesystem: many filesystem operations cannot be mapped to WASI, and
so these operations are no-ops.
- `S_IFSOCK` matches `S_IFIFO` in current `wasi-libc`; removed the
`S_IFIFO` case, because `clang` will fail building due to a
duplicated constant in `switch` statements.
- File locks are also stubbed and always return success.
- Networking: given the WebAssembly sandbox and capability-based
security, it is not possible to open a socket as of today. Although
the host is able to open a socket and forward a file descriptor,
leaving the `accept()` syscall to the WebAssembly module, we have
removed networking syscalls at this time.
The only binary that builds with this change is `php-cgi` at this
time. It's possible to adapt the change so that `php` builds and is
able to run scripts and programs in the filesystem in a CLI
fashion. However, starting a PHP server to listen on a socket using
the CLI is a more contrived situation, given it's not possible to open
a listening socket from within the sandbox; however it would be
possible to create the socket on the host side, and forward the file
descriptor to the module.
Co-Authored-By: Asen Alexandrov <alexandrov@vmware.com>
0 commit comments