Portably handle fd_advise on directory fd (#2875)

This commit adds a check to `fd_advise`.  If the fd is a directory,
return `ebadf`.  This brings iwasm in line with Wasmtime's behavior.
WASI folks have stated that fd_advise should not work on directories
as this is a Linux-specific behavior:
https://github.com/bytecodealliance/wasmtime/issues/6505#issuecomment-1574122949
This commit is contained in:
Yage Hu 2023-12-06 17:52:53 -08:00 committed by GitHub
parent ac602bda32
commit 0b332d8987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1155,6 +1155,11 @@ wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds,
if (error != 0)
return error;
if (fo->type == __WASI_FILETYPE_DIRECTORY) {
fd_object_release(exec_env, fo);
return __WASI_EBADF;
}
error = os_fadvise(fo->file_handle, offset, len, advice);
fd_object_release(exec_env, fo);