@@ -923,30 +923,19 @@ Word wasi_unstable_fd_advise(Word fd, uint64_t offset, uint64_t len, Word advice
923
923
// __wasi_errno_t __wasi_fd_allocate(__wasi_fd_t fd, __wasi_filesize_t offset, __wasi_filesize_t len);
924
924
Word wasi_unstable_fd_allocate (Word fd, uint64_t offset, uint64_t len) {
925
925
// fd_allocate is used to ensure that space is allocated for a file.
926
- // Since we don't have a real file system in proxy-wasm, we can just return success without doing anything.
927
- // This is similar to how other file-related functions are implemented in this codebase.
928
-
929
- // We only support stdout and stderr in proxy-wasm, which don't need allocation
930
- if (fd != 1 /* stdout */ && fd != 2 /* stderr */ ) {
931
- return 8 ; // __WASI_ERRNO_BADF - Bad file descriptor
932
- }
926
+ // This operation doesn't make sense for stdout/stderr streams, so we return ENOTSUP.
927
+ // Unlike regular files, stdout/stderr don't need space allocation.
933
928
934
- return 0 ; // __WASI_ESUCCESS
929
+ return 58 ; // __WASI_ENOTSUP - Not supported
935
930
}
936
931
937
932
// __wasi_errno_t __wasi_fd_datasync(__wasi_fd_t fd);
938
933
Word wasi_unstable_fd_datasync (Word fd) {
939
934
// fd_datasync is used to synchronize the data of a file to disk.
940
- // Since we don 't have a real file system in proxy-wasm, we can just return success for stdout/stderr
941
- // and an error for other file descriptors .
935
+ // This operation doesn 't really make sense for stdout/stderr streams.
936
+ // We return ENOTSUP since syncing streams is not a meaningful operation .
942
937
943
- // We only support stdout and stderr in proxy-wasm
944
- if (fd != 1 /* stdout */ && fd != 2 /* stderr */ ) {
945
- return 8 ; // __WASI_ERRNO_BADF - Bad file descriptor
946
- }
947
-
948
- // For stdout and stderr, there's no need to sync as they're handled by the host system
949
- return 0 ; // __WASI_ESUCCESS
938
+ return 58 ; // __WASI_ENOTSUP - Not supported
950
939
}
951
940
952
941
// __wasi_errno_t __wasi_fd_fdstat_set_rights(__wasi_fd_t fd, __wasi_rights_t fs_rights_base, __wasi_rights_t fs_rights_inheriting);
@@ -968,33 +957,19 @@ Word wasi_unstable_fd_fdstat_set_rights(Word fd, uint64_t fs_rights_base, uint64
968
957
// __wasi_errno_t __wasi_fd_filestat_set_size(__wasi_fd_t fd, __wasi_filesize_t size);
969
958
Word wasi_unstable_fd_filestat_set_size (Word fd, uint64_t size) {
970
959
// fd_filestat_set_size is used to adjust the size of a file, similar to ftruncate.
971
- // Since we don 't have a real file system in proxy-wasm, we can just return success for stdout/stderr
972
- // and an error for other file descriptors .
960
+ // This operation doesn 't make sense for stdout/stderr streams.
961
+ // Streams don't have a settable size .
973
962
974
- // We only support stdout and stderr in proxy-wasm
975
- if (fd != 1 /* stdout */ && fd != 2 /* stderr */ ) {
976
- return 8 ; // __WASI_ERRNO_BADF - Bad file descriptor
977
- }
978
-
979
- // For stdout and stderr, we don't actually change any size, but we can pretend it succeeded
980
- // This is similar to how other file-related functions are implemented in this codebase
981
- return 0 ; // __WASI_ESUCCESS
963
+ return 58 ; // __WASI_ENOTSUP - Not supported
982
964
}
983
965
984
966
// __wasi_errno_t __wasi_fd_filestat_set_times(__wasi_fd_t fd, __wasi_timestamp_t atim, __wasi_timestamp_t mtim, __wasi_fstflags_t fst_flags);
985
967
Word wasi_unstable_fd_filestat_set_times (Word fd, uint64_t atim, uint64_t mtim, Word fst_flags) {
986
968
// fd_filestat_set_times is used to set the access and modification times of a file.
987
- // Since we don 't have a real file system in proxy-wasm, we can just return success for stdout/stderr
988
- // and an error for other file descriptors .
969
+ // This operation doesn 't make sense for stdout/stderr streams.
970
+ // Streams don't have access/modification times .
989
971
990
- // We only support stdout and stderr in proxy-wasm
991
- if (fd != 1 /* stdout */ && fd != 2 /* stderr */ ) {
992
- return 8 ; // __WASI_ERRNO_BADF - Bad file descriptor
993
- }
994
-
995
- // For stdout and stderr, we don't actually change any times, but we can pretend it succeeded
996
- // This is similar to how other file-related functions are implemented in this codebase
997
- return 0 ; // __WASI_ESUCCESS
972
+ return 58 ; // __WASI_ENOTSUP - Not supported
998
973
}
999
974
1000
975
// __wasi_errno_t __wasi_fd_pread(__wasi_fd_t fd, const __wasi_iovec_t *iovs, size_t iovs_len, __wasi_filesize_t offset, __wasi_size_t *retptr0);
@@ -1037,17 +1012,9 @@ Word wasi_unstable_fd_pwrite(Word fd, Word iovs_ptr, Word iovs_len, uint64_t off
1037
1012
1038
1013
// __wasi_errno_t __wasi_fd_readdir(__wasi_fd_t fd, uint8_t *buf, __wasi_size_t buf_len, __wasi_dircookie_t cookie, __wasi_size_t *retptr0);
1039
1014
Word wasi_unstable_fd_readdir (Word fd, Word buf_ptr, Word buf_len, uint64_t cookie, Word nread_ptr) {
1040
- auto *context = contextOrEffectiveContext ();
1041
-
1042
1015
// fd_readdir is used to read directory entries from a directory.
1043
1016
// Since we don't have a real file system in proxy-wasm, we can just return an error.
1044
1017
1045
- // Set the number of bytes read to 0
1046
- if (!context->wasmVm ()->setWord (nread_ptr, Word (0 ))) {
1047
- return 21 ; // __WASI_EFAULT
1048
- }
1049
-
1050
- // Return ENOTDIR (Not a directory) error
1051
1018
return 20 ; // __WASI_ENOTDIR
1052
1019
}
1053
1020
@@ -1069,16 +1036,10 @@ Word wasi_unstable_fd_renumber(Word fd, Word to) {
1069
1036
// __wasi_errno_t __wasi_fd_sync(__wasi_fd_t fd);
1070
1037
Word wasi_unstable_fd_sync (Word fd) {
1071
1038
// fd_sync is used to synchronize a file's in-core state with the storage device.
1072
- // Since we don 't have a real file system in proxy-wasm, we can just return success for stdout/stderr
1073
- // and an error for other file descriptors .
1039
+ // This operation doesn 't really make sense for stdout/stderr streams.
1040
+ // We return ENOTSUP since syncing streams is not a meaningful operation .
1074
1041
1075
- // We only support stdout and stderr in proxy-wasm
1076
- if (fd != 1 /* stdout */ && fd != 2 /* stderr */ ) {
1077
- return 8 ; // __WASI_ERRNO_BADF - Bad file descriptor
1078
- }
1079
-
1080
- // For stdout and stderr, there's no need to sync as they're handled by the host system
1081
- return 0 ; // __WASI_ESUCCESS
1042
+ return 58 ; // __WASI_ENOTSUP - Not supported
1082
1043
}
1083
1044
1084
1045
// __wasi_errno_t __wasi_fd_tell(__wasi_fd_t fd, __wasi_filesize_t *retptr0);
@@ -1127,16 +1088,9 @@ Word wasi_unstable_path_link(Word old_fd, Word old_flags, Word old_path_ptr, Wor
1127
1088
1128
1089
// __wasi_errno_t __wasi_path_readlink(__wasi_fd_t fd, const char *path, uint8_t *buf, __wasi_size_t buf_len, __wasi_size_t *retptr0);
1129
1090
Word wasi_unstable_path_readlink (Word fd, Word path_ptr, Word path_len, Word buf_ptr, Word buf_len, Word retptr0) {
1130
- auto *context = contextOrEffectiveContext ();
1131
-
1132
1091
// path_readlink is used to read the contents of a symbolic link.
1133
1092
// Since we don't have a real file system in proxy-wasm, we can just return an error.
1134
1093
1135
- // Set the number of bytes read to 0
1136
- if (!context->wasmVm ()->setWord (retptr0, Word (0 ))) {
1137
- return 21 ; // __WASI_EFAULT
1138
- }
1139
-
1140
1094
return 58 ; // __WASI_ENOTSUP - Not supported
1141
1095
}
1142
1096
@@ -1174,51 +1128,25 @@ Word wasi_unstable_path_unlink_file(Word fd, Word path_ptr, Word path_len) {
1174
1128
1175
1129
// __wasi_errno_t __wasi_sock_accept(__wasi_fd_t fd, __wasi_fdflags_t flags, __wasi_fd_t *retptr0);
1176
1130
Word wasi_unstable_sock_accept (Word fd, Word flags, Word retptr0) {
1177
- auto *context = contextOrEffectiveContext ();
1178
-
1179
1131
// sock_accept is used to accept a new connection on a socket.
1180
1132
// Since we don't have socket support in proxy-wasm, we can just return an error.
1181
1133
1182
- // Set the returned file descriptor to an invalid value
1183
- if (!context->wasm ()->setDatatype (retptr0, uint32_t (0 ))) {
1184
- return 21 ; // __WASI_EFAULT
1185
- }
1186
-
1187
1134
return 58 ; // __WASI_ENOTSUP - Not supported
1188
1135
}
1189
1136
1190
1137
// __wasi_errno_t __wasi_sock_recv(__wasi_fd_t fd, const __wasi_iovec_t *ri_data, size_t ri_data_len, __wasi_riflags_t ri_flags, __wasi_size_t *retptr0, __wasi_roflags_t *retptr1);
1191
1138
Word wasi_unstable_sock_recv (Word fd, Word ri_data_ptr, Word ri_data_len, Word ri_flags, Word retptr0, Word retptr1) {
1192
- auto *context = contextOrEffectiveContext ();
1193
-
1194
1139
// sock_recv is used to receive data from a socket.
1195
1140
// Since we don't have socket support in proxy-wasm, we can just return an error.
1196
1141
1197
- // Set the number of bytes received to 0
1198
- if (!context->wasmVm ()->setWord (retptr0, Word (0 ))) {
1199
- return 21 ; // __WASI_EFAULT
1200
- }
1201
-
1202
- // Set the output flags to 0
1203
- if (!context->wasm ()->setDatatype (retptr1, uint16_t (0 ))) {
1204
- return 21 ; // __WASI_EFAULT
1205
- }
1206
-
1207
1142
return 58 ; // __WASI_ENOTSUP - Not supported
1208
1143
}
1209
1144
1210
1145
// __wasi_errno_t __wasi_sock_send(__wasi_fd_t fd, const __wasi_ciovec_t *si_data, size_t si_data_len, __wasi_siflags_t si_flags, __wasi_size_t *retptr0);
1211
1146
Word wasi_unstable_sock_send (Word fd, Word si_data_ptr, Word si_data_len, Word si_flags, Word retptr0) {
1212
- auto *context = contextOrEffectiveContext ();
1213
-
1214
1147
// sock_send is used to send data on a socket.
1215
1148
// Since we don't have socket support in proxy-wasm, we can just return an error.
1216
1149
1217
- // Set the number of bytes sent to 0
1218
- if (!context->wasmVm ()->setWord (retptr0, Word (0 ))) {
1219
- return 21 ; // __WASI_EFAULT
1220
- }
1221
-
1222
1150
return 58 ; // __WASI_ENOTSUP - Not supported
1223
1151
}
1224
1152
0 commit comments