Skip to content

Commit

Permalink
Portably handle fd_advise on directory fd (#2875)
Browse files Browse the repository at this point in the history
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:
bytecodealliance/wasmtime#6505 (comment)
  • Loading branch information
yagehu committed Dec 7, 2023
1 parent ac602bd commit 0b332d8
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0b332d8

Please sign in to comment.