Wasm Language Runtimes provides popular language runtimes (Ruby, Python, …) precompiled to WebAssembly that are tested for compatibility and kept up to date when new versions of upstream languages are released
Apache License 2.0
327
stars
27
forks
source link
fix: Emulated implementations for `is_readable()` and `is_writable()` by trial and error #89
This PR provides a patch to emulate PHP's is_readable() and is_writable() functions by trial and error.
In wasi-libc stat(), since there is no user/group concept in Wasm, st_mode is initialized to 000, as well as st_uid and st_gid.
So, by default, is_readable() and is_writable() will return FALSE.
Two approaches have been discussed:
Patch those methods to always return TRUE. This works for many scenarios since most PHP apps will check fopen() return value even if the is_xxxable() functions were previously called.
Trial and error. To avoid the above assumption and returning fake values that might be totally wrong, a different approach is to actually try to open/write those resources and return the result.
The latter approach seems more appropriate. The only drawback is a small penalty in performance since the execution of the new checkers takes longer than simply querying the values from stat. But once PHP's cache starts hitting, performance shouldn't be affected.
This PR provides a patch to emulate PHP's
is_readable()
andis_writable()
functions by trial and error.In wasi-libc
stat()
, since there is no user/group concept in Wasm,st_mode
is initialized to000
, as well asst_uid
andst_gid
.So, by default,
is_readable()
andis_writable()
will returnFALSE
.Two approaches have been discussed:
TRUE
. This works for many scenarios since most PHP apps will checkfopen()
return value even if the is_xxxable() functions were previously called.The latter approach seems more appropriate. The only drawback is a small penalty in performance since the execution of the new checkers takes longer than simply querying the values from
stat
. But once PHP's cache starts hitting, performance shouldn't be affected.