stage1: implement fd_fdstat_get

I thought this might be needed, so may as well keep the implementation.
This commit is contained in:
Jacob Young 2024-02-04 03:47:17 +01:00
parent 26cb72086a
commit 8fa7635419

View File

@ -203,7 +203,9 @@ struct DirEntry {
static uint32_t fd_len;
static struct FileDescriptor {
uint32_t de;
enum wasi_fdflags fdflags;
FILE *stream;
uint64_t fs_rights_inheriting;
} *fds;
static void *dupe(const void *data, size_t len) {
@ -707,13 +709,17 @@ uint32_t wasi_snapshot_preview1_path_filestat_get(uint32_t fd, uint32_t flags, u
}
uint32_t wasi_snapshot_preview1_fd_fdstat_get(uint32_t fd, uint32_t res_fdstat) {
(void)fd;
(void)res_fdstat;
uint8_t *const m = *wasm_memory;
struct wasi_fdstat *res_fdstat_ptr = (struct wasi_fdstat *)&m[res_fdstat];
#if LOG_TRACE
fprintf(stderr, "wasi_snapshot_preview1_fd_fdstat_get(%u)\n", fd);
#endif
panic("unimplemented");
if (fd >= fd_len || fds[fd].de >= de_len) return wasi_errno_badf;
res_fdstat_ptr->fs_filetype = des[fds[fd].de].filetype;
res_fdstat_ptr->fs_flags = fds[fd].fdflags;
res_fdstat_ptr->padding = 0;
res_fdstat_ptr->fs_rights_inheriting = fds[fd].fs_rights_inheriting;
return wasi_errno_success;
}
@ -770,7 +776,6 @@ uint32_t wasi_snapshot_preview1_fd_write(uint32_t fd, uint32_t iovs, uint32_t io
uint32_t wasi_snapshot_preview1_path_open(uint32_t fd, uint32_t dirflags, uint32_t path, uint32_t path_len, uint32_t oflags, uint64_t fs_rights_base, uint64_t fs_rights_inheriting, uint32_t fdflags, uint32_t res_fd) {
uint8_t *const m = *wasm_memory;
const char *path_ptr = (const char *)&m[path];
(void)fs_rights_inheriting;
uint32_t *res_fd_ptr = (uint32_t *)&m[res_fd];
#if LOG_TRACE
fprintf(stderr, "wasi_snapshot_preview1_path_open(%u, 0x%X, \"%.*s\", 0x%X, 0x%llX, 0x%llX, 0x%X)\n", fd, dirflags, (int)path_len, path_ptr, oflags, (unsigned long long)fs_rights_base, (unsigned long long)fs_rights_inheriting, fdflags);
@ -792,10 +797,12 @@ uint32_t wasi_snapshot_preview1_path_open(uint32_t fd, uint32_t dirflags, uint32
fds = new_fds;
fds[fd_len].de = de;
fds[fd_len].fdflags = fdflags;
switch (des[de].filetype) {
case wasi_filetype_directory: fds[fd_len].stream = NULL; break;
default: panic("unimplemented");
}
fds[fd_len].fs_rights_inheriting = fs_rights_inheriting;
#if LOG_TRACE
fprintf(stderr, "fd = %u\n", fd_len);
@ -855,7 +862,9 @@ uint32_t wasi_snapshot_preview1_path_open(uint32_t fd, uint32_t dirflags, uint32
fprintf(stderr, "fd = %u\n", fd_len);
#endif
fds[fd_len].de = de;
fds[fd_len].fdflags = fdflags;
fds[fd_len].stream = stream;
fds[fd_len].fs_rights_inheriting = fs_rights_inheriting;
*res_fd_ptr = fd_len;
fd_len += 1;
return wasi_errno_success;