Skip to content

Commit e74d01d

Browse files
committed
Update for WASI API changes.
file_open's fds argument has been split into scalars, and the RIGHT_FILE_FSTAT_* rights have been reinstated.
1 parent 9228d7a commit e74d01d

3 files changed

Lines changed: 28 additions & 13 deletions

File tree

expected/wasm32-wasi/predefined-macros.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,6 +3538,9 @@
35383538
#define __WASI_RIGHT_FILE_ALLOCATE (UINT64_C(0x0000000000000100))
35393539
#define __WASI_RIGHT_FILE_CREATE_DIRECTORY (UINT64_C(0x0000000000000200))
35403540
#define __WASI_RIGHT_FILE_CREATE_FILE (UINT64_C(0x0000000000000400))
3541+
#define __WASI_RIGHT_FILE_FSTAT_GET (UINT64_C(0x0000000000200000))
3542+
#define __WASI_RIGHT_FILE_FSTAT_SET_SIZE (UINT64_C(0x0000000000400000))
3543+
#define __WASI_RIGHT_FILE_FSTAT_SET_TIMES (UINT64_C(0x0000000000800000))
35413544
#define __WASI_RIGHT_FILE_LINK_SOURCE (UINT64_C(0x0000000000000800))
35423545
#define __WASI_RIGHT_FILE_LINK_TARGET (UINT64_C(0x0000000000001000))
35433546
#define __WASI_RIGHT_FILE_OPEN (UINT64_C(0x0000000000002000))
@@ -3548,10 +3551,10 @@
35483551
#define __WASI_RIGHT_FILE_STAT_GET (UINT64_C(0x0000000000040000))
35493552
#define __WASI_RIGHT_FILE_STAT_SET_SIZE (UINT64_C(0x0000000000080000))
35503553
#define __WASI_RIGHT_FILE_STAT_SET_TIMES (UINT64_C(0x0000000000100000))
3551-
#define __WASI_RIGHT_FILE_SYMLINK (UINT64_C(0x0000000000200000))
3552-
#define __WASI_RIGHT_FILE_UNLINK (UINT64_C(0x0000000000400000))
3553-
#define __WASI_RIGHT_POLL_FD_READWRITE (UINT64_C(0x0000000000800000))
3554-
#define __WASI_RIGHT_SOCK_SHUTDOWN (UINT64_C(0x0000000001000000))
3554+
#define __WASI_RIGHT_FILE_SYMLINK (UINT64_C(0x0000000001000000))
3555+
#define __WASI_RIGHT_FILE_UNLINK (UINT64_C(0x0000000002000000))
3556+
#define __WASI_RIGHT_POLL_FD_READWRITE (UINT64_C(0x0000000004000000))
3557+
#define __WASI_RIGHT_SOCK_SHUTDOWN (UINT64_C(0x0000000008000000))
35553558
#define __WASI_SHUT_RD (UINT8_C(0x01))
35563559
#define __WASI_SHUT_WR (UINT8_C(0x02))
35573560
#define __WASI_SIGABRT (UINT8_C(6))

libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int openat(int fd, const char *path, int oflag, ...) {
3232
#ifdef __wasilibc_unmodified_upstream // fstat
3333
__WASI_RIGHT_FILE_READDIR | __WASI_RIGHT_FILE_STAT_FPUT_SIZE |
3434
#else
35-
__WASI_RIGHT_FILE_READDIR | __WASI_RIGHT_FILE_STAT_SET_SIZE |
35+
__WASI_RIGHT_FILE_READDIR | __WASI_RIGHT_FILE_FSTAT_SET_SIZE |
3636
#endif
3737
#ifdef __wasilibc_unmodified_upstream // RIGHT_MEM_MAP_EXEC
3838
__WASI_RIGHT_MEM_MAP_EXEC);
@@ -62,7 +62,7 @@ int openat(int fd, const char *path, int oflag, ...) {
6262
#ifdef __wasilibc_unmodified_upstream // fstat
6363
__WASI_RIGHT_FILE_STAT_FPUT_SIZE;
6464
#else
65-
__WASI_RIGHT_FILE_STAT_SET_SIZE;
65+
__WASI_RIGHT_FILE_FSTAT_SET_SIZE;
6666
#endif
6767
}
6868
break;
@@ -110,18 +110,25 @@ int openat(int fd, const char *path, int oflag, ...) {
110110
#endif
111111

112112
// Open file with appropriate rights.
113+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t and __wasi_fdstat_t
113114
__wasi_fdstat_t fsb_new = {
114115
.fs_flags = oflag & 0xfff,
115116
.fs_rights_base = max & fsb_cur.fs_rights_inheriting,
116117
.fs_rights_inheriting = fsb_cur.fs_rights_inheriting,
117118
};
118119
__wasi_fd_t newfd;
119-
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
120120
error = __wasi_file_open(lookup, path, strlen(path),
121+
(oflag >> 12) & 0xfff, &fsb_new, &newfd);
121122
#else
123+
__wasi_fdflags_t fs_flags = oflag & 0xfff;
124+
__wasi_rights_t fs_rights_base = max & fsb_cur.fs_rights_inheriting;
125+
__wasi_rights_t fs_rights_inheriting = fsb_cur.fs_rights_inheriting;
126+
__wasi_fd_t newfd;
122127
error = __wasi_file_open(fd, lookup_flags, path, strlen(path),
128+
(oflag >> 12) & 0xfff,
129+
fs_rights_base, fs_rights_inheriting, fs_flags,
130+
&newfd);
123131
#endif
124-
(oflag >> 12) & 0xfff, &fsb_new, &newfd);
125132
if (error != 0) {
126133
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
127134
errno = errno_fixup_directory(lookup.fd, error);

libc-bottom-half/headers/public/wasi.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,13 @@ typedef uint64_t __wasi_rights_t;
207207
#define __WASI_RIGHT_FILE_STAT_GET (UINT64_C(0x0000000000040000))
208208
#define __WASI_RIGHT_FILE_STAT_SET_SIZE (UINT64_C(0x0000000000080000))
209209
#define __WASI_RIGHT_FILE_STAT_SET_TIMES (UINT64_C(0x0000000000100000))
210-
#define __WASI_RIGHT_FILE_SYMLINK (UINT64_C(0x0000000000200000))
211-
#define __WASI_RIGHT_FILE_UNLINK (UINT64_C(0x0000000000400000))
212-
#define __WASI_RIGHT_POLL_FD_READWRITE (UINT64_C(0x0000000000800000))
213-
#define __WASI_RIGHT_SOCK_SHUTDOWN (UINT64_C(0x0000000001000000))
210+
#define __WASI_RIGHT_FILE_FSTAT_GET (UINT64_C(0x0000000000200000))
211+
#define __WASI_RIGHT_FILE_FSTAT_SET_SIZE (UINT64_C(0x0000000000400000))
212+
#define __WASI_RIGHT_FILE_FSTAT_SET_TIMES (UINT64_C(0x0000000000800000))
213+
#define __WASI_RIGHT_FILE_SYMLINK (UINT64_C(0x0000000001000000))
214+
#define __WASI_RIGHT_FILE_UNLINK (UINT64_C(0x0000000002000000))
215+
#define __WASI_RIGHT_POLL_FD_READWRITE (UINT64_C(0x0000000004000000))
216+
#define __WASI_RIGHT_SOCK_SHUTDOWN (UINT64_C(0x0000000008000000))
214217

215218
typedef uint16_t __wasi_roflags_t;
216219
#define __WASI_SOCK_RECV_DATA_TRUNCATED (UINT16_C(0x0001))
@@ -546,7 +549,9 @@ __wasi_errno_t __wasi_file_open(
546549
const char *path,
547550
size_t path_len,
548551
__wasi_oflags_t oflags,
549-
const __wasi_fdstat_t *fds,
552+
__wasi_rights_t fs_rights_base,
553+
__wasi_rights_t fs_rights_inheriting,
554+
__wasi_fdflags_t fs_flags,
550555
__wasi_fd_t *fd
551556
) __WASI_SYSCALL_NAME(file_open) __attribute__((__warn_unused_result__));
552557

0 commit comments

Comments
 (0)