Skip to content

Commit f93f222

Browse files
committed
feat: implement os_invalid_raw_handle function for consistent invalid handle representation
1 parent cf8b932 commit f93f222

File tree

12 files changed

+71
-16
lines changed

12 files changed

+71
-16
lines changed

core/iwasm/aot/aot_loader.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -4121,13 +4121,9 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
41214121
#endif
41224122

41234123
#if WASM_ENABLE_LIBC_WASI != 0
4124-
/*
4125-
* learned from all implementations of `os_get_invalid_handle()`
4126-
* that invalid handles across all platforms are represented by -1.
4127-
*/
4128-
module->wasi_args.stdio[0] = -1;
4129-
module->wasi_args.stdio[1] = -1;
4130-
module->wasi_args.stdio[2] = -1;
4124+
module->wasi_args.stdio[0] = os_invalid_raw_handle();
4125+
module->wasi_args.stdio[1] = os_invalid_raw_handle();
4126+
module->wasi_args.stdio[2] = os_invalid_raw_handle();
41314127
#endif
41324128

41334129
return module;

core/iwasm/interpreter/wasm_loader.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -6369,13 +6369,9 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
63696369
#endif
63706370

63716371
#if WASM_ENABLE_LIBC_WASI != 0
6372-
/*
6373-
* learned from all implementations of `os_get_invalid_handle()`
6374-
* that invalid handles across all platforms are represented by -1.
6375-
*/
6376-
module->wasi_args.stdio[0] = -1;
6377-
module->wasi_args.stdio[1] = -1;
6378-
module->wasi_args.stdio[2] = -1;
6372+
module->wasi_args.stdio[0] = os_invalid_raw_handle();
6373+
module->wasi_args.stdio[1] = os_invalid_raw_handle();
6374+
module->wasi_args.stdio[2] = os_invalid_raw_handle();
63796375
#endif
63806376

63816377
(void)ret;

core/iwasm/interpreter/wasm_mini_loader.c

+6
Original file line numberDiff line numberDiff line change
@@ -3122,6 +3122,12 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
31223122
}
31233123
#endif
31243124

3125+
#if WASM_ENABLE_LIBC_WASI != 0
3126+
module->wasi_args.stdio[0] = os_invalid_raw_handle();
3127+
module->wasi_args.stdio[1] = os_invalid_raw_handle();
3128+
module->wasi_args.stdio[2] = os_invalid_raw_handle();
3129+
#endif
3130+
31253131
(void)ret;
31263132
return module;
31273133
}

core/shared/platform/alios/alios_platform.c

+6
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,9 @@ os_dcache_flush()
7979
void
8080
os_icache_flush(void *start, size_t len)
8181
{}
82+
83+
os_raw_file_handle
84+
os_invalid_raw_handle(void)
85+
{
86+
return -1;
87+
}

core/shared/platform/common/posix/posix_file.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1032,4 +1032,10 @@ char *
10321032
os_realpath(const char *path, char *resolved_path)
10331033
{
10341034
return realpath(path, resolved_path);
1035-
}
1035+
}
1036+
1037+
os_raw_file_handle
1038+
os_invalid_raw_handle(void)
1039+
{
1040+
return -1;
1041+
}

core/shared/platform/esp-idf/espidf_file.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1032,4 +1032,10 @@ char *
10321032
os_realpath(const char *path, char *resolved_path)
10331033
{
10341034
return realpath(path, resolved_path);
1035-
}
1035+
}
1036+
1037+
os_raw_file_handle
1038+
os_invalid_raw_handle(void)
1039+
{
1040+
return -1;
1041+
}

core/shared/platform/include/platform_api_extension.h

+9
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,15 @@ os_is_dir_stream_valid(os_dir_stream *dir_stream);
16071607
os_file_handle
16081608
os_get_invalid_handle(void);
16091609

1610+
/**
1611+
* Returns an invalid raw file handle that is guaranteed to cause failure when
1612+
* called with any filesystem operation.
1613+
*
1614+
* @return the invalid raw file handle
1615+
*/
1616+
os_raw_file_handle
1617+
os_invalid_raw_handle(void);
1618+
16101619
/**
16111620
* Checks whether the given file handle is valid. An invalid handle is
16121621
* guaranteed to cause failure when called with any filesystem operation.

core/shared/platform/linux-sgx/sgx_file.c

+6
Original file line numberDiff line numberDiff line change
@@ -1114,4 +1114,10 @@ get_errno(void)
11141114
return ret;
11151115
}
11161116

1117+
os_raw_file_handle
1118+
os_invalid_raw_handle(void)
1119+
{
1120+
return -1;
1121+
}
1122+
11171123
#endif

core/shared/platform/riot/riot_platform.c

+6
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,9 @@ os_dcache_flush(void)
9595
void
9696
os_icache_flush(void *start, size_t len)
9797
{}
98+
99+
os_raw_file_handle
100+
os_invalid_raw_handle(void)
101+
{
102+
return -1;
103+
}

core/shared/platform/rt-thread/rtt_file.c

+6
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,9 @@ posix_fallocate(int __fd, off_t __offset, off_t __length)
192192
errno = ENOSYS;
193193
return -1;
194194
}
195+
196+
os_raw_file_handle
197+
os_invalid_raw_handle(void)
198+
{
199+
return -1;
200+
}

core/shared/platform/windows/win_file.c

+6
Original file line numberDiff line numberDiff line change
@@ -1810,3 +1810,9 @@ os_realpath(const char *path, char *resolved_path)
18101810

18111811
return resolved_path;
18121812
}
1813+
1814+
os_raw_file_handle
1815+
os_invalid_raw_handle(void)
1816+
{
1817+
return INVALID_HANDLE_VALUE;
1818+
}

core/shared/platform/zephyr/zephyr_platform.c

+6
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,9 @@ set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func,
255255
exec_mem_alloc_func = alloc_func;
256256
exec_mem_free_func = free_func;
257257
}
258+
259+
os_raw_file_handle
260+
os_invalid_raw_handle(void)
261+
{
262+
return -1;
263+
}

0 commit comments

Comments
 (0)