Skip to content

Commit

Permalink
initialize WASI stdio handles to invalid for better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lum1n0us committed Feb 18, 2025
1 parent ff10b86 commit 32e10b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4120,6 +4120,12 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
}
#endif

#if WASM_ENABLE_LIBC_WASI != 0
module->wasi_args.stdio[0] = os_get_raw_invalid_handle();
module->wasi_args.stdio[1] = os_get_raw_invalid_handle();
module->wasi_args.stdio[2] = os_get_raw_invalid_handle();
#endif

return module;
#if WASM_ENABLE_GC != 0
fail2:
Expand Down
6 changes: 6 additions & 0 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -6368,6 +6368,12 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
}
#endif

#if WASM_ENABLE_LIBC_WASI != 0
module->wasi_args.stdio[0] = os_get_raw_invalid_handle();
module->wasi_args.stdio[1] = os_get_raw_invalid_handle();
module->wasi_args.stdio[2] = os_get_raw_invalid_handle();
#endif

(void)ret;
return module;

Expand Down
6 changes: 6 additions & 0 deletions core/shared/platform/linux/platform_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ os_get_invalid_handle(void)
return -1;
}

static inline os_raw_file_handle
os_get_raw_invalid_handle(void)
{
return -1;
}

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 32e10b9

Please sign in to comment.