Skip to content

Commit d962aaa

Browse files
committed
Eliminate __wasi_lookup_t.
Instead of passing __wasi_lookup_t as a by-value struct, pass the fields as plain scalar values. This avoids having it go through memory in the current wasm ABI, and avoids a potential ABI break when clang re-evaluates how big of structs it'll be willing to pass by value when multi-value happens.
1 parent 7930289 commit d962aaa

6 files changed

Lines changed: 70 additions & 15 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,17 @@ int openat(int fd, const char *path, int oflag, ...) {
8989
}
9090

9191
// Path lookup properties.
92+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
9293
__wasi_lookup_t lookup = {.fd = fd, .flags = 0};
94+
#else
95+
__wasi_lookupflags_t lookup_flags = 0;
96+
#endif
9397
if ((oflag & O_NOFOLLOW) == 0)
98+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
9499
lookup.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
100+
#else
101+
lookup_flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
102+
#endif
95103

96104
// Open file with appropriate rights.
97105
__wasi_fdstat_t fsb_new = {
@@ -100,10 +108,18 @@ int openat(int fd, const char *path, int oflag, ...) {
100108
.fs_rights_inheriting = fsb_cur.fs_rights_inheriting,
101109
};
102110
__wasi_fd_t newfd;
111+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
103112
error = __wasi_file_open(lookup, path, strlen(path),
113+
#else
114+
error = __wasi_file_open(fd, lookup_flags, path, strlen(path),
115+
#endif
104116
(oflag >> 12) & 0xfff, &fsb_new, &newfd);
105117
if (error != 0) {
118+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
106119
errno = errno_fixup_directory(lookup.fd, error);
120+
#else
121+
errno = errno_fixup_directory(fd, error);
122+
#endif
107123
return -1;
108124
}
109125
return newfd;

libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,26 @@
1616
int fstatat(int fd, const char *restrict path, struct stat *restrict buf,
1717
int flag) {
1818
// Create lookup properties.
19+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
1920
__wasi_lookup_t lookup = {.fd = fd, .flags = 0};
21+
#else
22+
__wasi_lookupflags_t lookup_flags = 0;
23+
#endif
2024
if ((flag & AT_SYMLINK_NOFOLLOW) == 0)
25+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
2126
lookup.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
27+
#else
28+
lookup_flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
29+
#endif
2230

2331
// Perform system call.
2432
__wasi_filestat_t internal_stat;
2533
__wasi_errno_t error =
34+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
2635
__wasi_file_stat_get(lookup, path, strlen(path), &internal_stat);
36+
#else
37+
__wasi_file_stat_get(fd, lookup_flags, path, strlen(path), &internal_stat);
38+
#endif
2739
if (error != 0) {
2840
errno = errno_fixup_directory(fd, error);
2941
return -1;

libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,25 @@ int utimensat(int fd, const char *path, const struct timespec times[2],
2424
}
2525

2626
// Create lookup properties.
27+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
2728
__wasi_lookup_t lookup = {.fd = fd, .flags = 0};
29+
#else
30+
__wasi_lookupflags_t lookup_flags = 0;
31+
#endif
2832
if ((flag & AT_SYMLINK_NOFOLLOW) == 0)
33+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
2934
lookup.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
35+
#else
36+
lookup_flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
37+
#endif
3038

3139
// Perform system call.
3240
__wasi_errno_t error =
41+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
3342
__wasi_file_stat_put(lookup, path, strlen(path), &fs, flags);
43+
#else
44+
__wasi_file_stat_put(fd, lookup_flags, path, strlen(path), &fs, flags);
45+
#endif
3446
if (error != 0) {
3547
errno = errno_fixup_directory(fd, error);
3648
return -1;

libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ int faccessat(int fd, const char *path, int amode, int flag) {
1919
}
2020

2121
// Check for target file existence and obtain the file type.
22+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
2223
__wasi_lookup_t lookup = {
2324
.fd = fd,
2425
.flags = __WASI_LOOKUP_SYMLINK_FOLLOW,
2526
};
27+
#else
28+
__wasi_lookupflags_t lookup_flags = __WASI_LOOKUP_SYMLINK_FOLLOW;
29+
#endif
2630
__wasi_filestat_t file;
2731
__wasi_errno_t error =
32+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
2833
__wasi_file_stat_get(lookup, path, strlen(path), &file);
34+
#else
35+
__wasi_file_stat_get(fd, lookup_flags, path, strlen(path), &file);
36+
#endif
2937
if (error != 0) {
3038
errno = errno_fixup_directory(fd, error);
3139
return -1;

libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,24 @@
1212

1313
int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag) {
1414
// Create lookup properties.
15+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
1516
__wasi_lookup_t lookup1 = {.fd = fd1, .flags = 0};
17+
#else
18+
__wasi_lookupflags_t lookup1_flags = 0;
19+
#endif
1620
if ((flag & AT_SYMLINK_FOLLOW) != 0)
21+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
1722
lookup1.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
23+
#else
24+
lookup1_flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
25+
#endif
1826

1927
// Perform system call.
28+
#ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
2029
__wasi_errno_t error = __wasi_file_link(lookup1, path1, strlen(path1),
30+
#else
31+
__wasi_errno_t error = __wasi_file_link(fd1, lookup1_flags, path1, strlen(path1),
32+
#endif
2133
fd2, path2, strlen(path2));
2234
if (error != 0) {
2335
errno = errno_fixup_directory(fd1, errno_fixup_directory(fd2, error));

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,6 @@ _Static_assert(
358358
_Static_assert(sizeof(__wasi_filestat_t) == 56, "non-wasi data layout");
359359
_Static_assert(_Alignof(__wasi_filestat_t) == 8, "non-wasi data layout");
360360

361-
typedef struct __wasi_lookup_t {
362-
__wasi_fd_t fd;
363-
__wasi_lookupflags_t flags;
364-
} __wasi_lookup_t;
365-
_Static_assert(offsetof(__wasi_lookup_t, fd) == 0, "non-wasi data layout");
366-
_Static_assert(offsetof(__wasi_lookup_t, flags) == 4, "non-wasi data layout");
367-
_Static_assert(sizeof(__wasi_lookup_t) == 8, "non-wasi data layout");
368-
_Static_assert(_Alignof(__wasi_lookup_t) == 4, "non-wasi data layout");
369-
370361
typedef struct __wasi_ciovec_t {
371362
const void *buf;
372363
size_t buf_len;
@@ -656,7 +647,8 @@ __wasi_errno_t __wasi_file_create(
656647
) __WASI_SYSCALL_NAME(file_create) __attribute__((__warn_unused_result__));
657648

658649
__wasi_errno_t __wasi_file_link(
659-
__wasi_lookup_t old_fd,
650+
__wasi_fd_t old_fd,
651+
__wasi_lookupflags_t old_flags,
660652
const char *old_path,
661653
size_t old_path_len,
662654
__wasi_fd_t new_fd,
@@ -665,7 +657,8 @@ __wasi_errno_t __wasi_file_link(
665657
) __WASI_SYSCALL_NAME(file_link) __attribute__((__warn_unused_result__));
666658

667659
__wasi_errno_t __wasi_file_open(
668-
__wasi_lookup_t dirfd,
660+
__wasi_fd_t dirfd,
661+
__wasi_lookupflags_t dirflags,
669662
const char *path,
670663
size_t path_len,
671664
__wasi_oflags_t oflags,
@@ -707,22 +700,24 @@ __wasi_errno_t __wasi_file_stat_fget(
707700
__wasi_errno_t __wasi_file_stat_fput(
708701
__wasi_fd_t fd,
709702
const __wasi_filestat_t *buf,
710-
__wasi_fsflags_t flags
703+
__wasi_fsflags_t fsflags
711704
) __WASI_SYSCALL_NAME(file_stat_fput) __attribute__((__warn_unused_result__));
712705

713706
__wasi_errno_t __wasi_file_stat_get(
714-
__wasi_lookup_t fd,
707+
__wasi_fd_t fd,
708+
__wasi_lookupflags_t flags,
715709
const char *path,
716710
size_t path_len,
717711
__wasi_filestat_t *buf
718712
) __WASI_SYSCALL_NAME(file_stat_get) __attribute__((__warn_unused_result__));
719713

720714
__wasi_errno_t __wasi_file_stat_put(
721-
__wasi_lookup_t fd,
715+
__wasi_fd_t fd,
716+
__wasi_lookupflags_t flags,
722717
const char *path,
723718
size_t path_len,
724719
const __wasi_filestat_t *buf,
725-
__wasi_fsflags_t flags
720+
__wasi_fsflags_t fsflags
726721
) __WASI_SYSCALL_NAME(file_stat_put) __attribute__((__warn_unused_result__));
727722

728723
__wasi_errno_t __wasi_file_symlink(

0 commit comments

Comments
 (0)