From dd9b4e021e73c43ca9d4a0c6e2bc20ea61f7166e Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 14 Oct 2021 14:56:30 +0100 Subject: [PATCH] Fix WASI type/macro misalignments (#766) Some of the WASI definitions in libc-wasi are out of sync with those of [wasi-libc](https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/headers/public/wasi/api.h). This PR fixed the misalignments of type __wasi_dirnamlen_t, __wasi_linkcount_t and __wasi_dirent_t, and WASI RIGHT related macros. --- .../include/wasmtime_ssp.h | 79 ++++++++++--------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h index 7c241d88..ace66163 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h @@ -62,6 +62,8 @@ typedef uint64_t __wasi_device_t; typedef uint64_t __wasi_dircookie_t; #define __WASI_DIRCOOKIE_START (0) +typedef uint32_t __wasi_dirnamlen_t; + typedef uint16_t __wasi_errno_t; #define __WASI_ESUCCESS (0) #define __WASI_E2BIG (1) @@ -182,7 +184,7 @@ typedef uint16_t __wasi_fstflags_t; typedef uint64_t __wasi_inode_t; -typedef uint32_t __wasi_linkcount_t; +typedef uint64_t __wasi_linkcount_t __attribute__((aligned(8))); typedef uint32_t __wasi_lookupflags_t; #define __WASI_LOOKUP_SYMLINK_FOLLOW (0x00000001) @@ -198,35 +200,38 @@ typedef uint16_t __wasi_riflags_t; #define __WASI_SOCK_RECV_WAITALL (0x0002) typedef uint64_t __wasi_rights_t; -#define __WASI_RIGHT_FD_DATASYNC (0x0000000000000001) -#define __WASI_RIGHT_FD_READ (0x0000000000000002) -#define __WASI_RIGHT_FD_SEEK (0x0000000000000004) -#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS (0x0000000000000008) -#define __WASI_RIGHT_FD_SYNC (0x0000000000000010) -#define __WASI_RIGHT_FD_TELL (0x0000000000000020) -#define __WASI_RIGHT_FD_WRITE (0x0000000000000040) -#define __WASI_RIGHT_FD_ADVISE (0x0000000000000080) -#define __WASI_RIGHT_FD_ALLOCATE (0x0000000000000100) -#define __WASI_RIGHT_PATH_CREATE_DIRECTORY (0x0000000000000200) -#define __WASI_RIGHT_PATH_CREATE_FILE (0x0000000000000400) -#define __WASI_RIGHT_PATH_LINK_SOURCE (0x0000000000000800) -#define __WASI_RIGHT_PATH_LINK_TARGET (0x0000000000001000) -#define __WASI_RIGHT_PATH_OPEN (0x0000000000002000) -#define __WASI_RIGHT_FD_READDIR (0x0000000000004000) -#define __WASI_RIGHT_PATH_READLINK (0x0000000000008000) -#define __WASI_RIGHT_PATH_RENAME_SOURCE (0x0000000000010000) -#define __WASI_RIGHT_PATH_RENAME_TARGET (0x0000000000020000) -#define __WASI_RIGHT_PATH_FILESTAT_GET (0x0000000000040000) -#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE (0x0000000000080000) -#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES (0x0000000000100000) -#define __WASI_RIGHT_FD_FILESTAT_GET (0x0000000000200000) -#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE (0x0000000000400000) -#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES (0x0000000000800000) -#define __WASI_RIGHT_PATH_SYMLINK (0x0000000001000000) -#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY (0x0000000002000000) -#define __WASI_RIGHT_PATH_UNLINK_FILE (0x0000000004000000) -#define __WASI_RIGHT_POLL_FD_READWRITE (0x0000000008000000) -#define __WASI_RIGHT_SOCK_SHUTDOWN (0x0000000010000000) + +// Observe that WASI defines rights in the plural form +// TODO - re-factor to use RIGHTS instead of RIGHT +#define __WASI_RIGHT_FD_DATASYNC ((__wasi_rights_t)(1 << 0)) +#define __WASI_RIGHT_FD_READ ((__wasi_rights_t)(1 << 1)) +#define __WASI_RIGHT_FD_SEEK ((__wasi_rights_t)(1 << 2)) +#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(1 << 3)) +#define __WASI_RIGHT_FD_SYNC ((__wasi_rights_t)(1 << 4)) +#define __WASI_RIGHT_FD_TELL ((__wasi_rights_t)(1 << 5)) +#define __WASI_RIGHT_FD_WRITE ((__wasi_rights_t)(1 << 6)) +#define __WASI_RIGHT_FD_ADVISE ((__wasi_rights_t)(1 << 7)) +#define __WASI_RIGHT_FD_ALLOCATE ((__wasi_rights_t)(1 << 8)) +#define __WASI_RIGHT_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(1 << 9)) +#define __WASI_RIGHT_PATH_CREATE_FILE ((__wasi_rights_t)(1 << 10)) +#define __WASI_RIGHT_PATH_LINK_SOURCE ((__wasi_rights_t)(1 << 11)) +#define __WASI_RIGHT_PATH_LINK_TARGET ((__wasi_rights_t)(1 << 12)) +#define __WASI_RIGHT_PATH_OPEN ((__wasi_rights_t)(1 << 13)) +#define __WASI_RIGHT_FD_READDIR ((__wasi_rights_t)(1 << 14)) +#define __WASI_RIGHT_PATH_READLINK ((__wasi_rights_t)(1 << 15)) +#define __WASI_RIGHT_PATH_RENAME_SOURCE ((__wasi_rights_t)(1 << 16)) +#define __WASI_RIGHT_PATH_RENAME_TARGET ((__wasi_rights_t)(1 << 17)) +#define __WASI_RIGHT_PATH_FILESTAT_GET ((__wasi_rights_t)(1 << 18)) +#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 19)) +#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 20)) +#define __WASI_RIGHT_FD_FILESTAT_GET ((__wasi_rights_t)(1 << 21)) +#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 22)) +#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 23)) +#define __WASI_RIGHT_PATH_SYMLINK ((__wasi_rights_t)(1 << 24)) +#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(1 << 25)) +#define __WASI_RIGHT_PATH_UNLINK_FILE ((__wasi_rights_t)(1 << 26)) +#define __WASI_RIGHT_POLL_FD_READWRITE ((__wasi_rights_t)(1 << 27)) +#define __WASI_RIGHT_SOCK_SHUTDOWN ((__wasi_rights_t)(1 << 28)) typedef uint16_t __wasi_roflags_t; #define __WASI_SOCK_RECV_DATA_TRUNCATED (0x0001) @@ -292,7 +297,7 @@ struct argv_environ_values; typedef struct __wasi_dirent_t { __wasi_dircookie_t d_next; __wasi_inode_t d_ino; - uint32_t d_namlen; + __wasi_dirnamlen_t d_namlen; __wasi_filetype_t d_type; } __wasi_dirent_t __attribute__((aligned(8))); _Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "non-wasi data layout"); @@ -380,16 +385,16 @@ _Static_assert(offsetof(__wasi_filestat_t, st_ino) == 8, "non-wasi data layout") _Static_assert( offsetof(__wasi_filestat_t, st_filetype) == 16, "non-wasi data layout"); _Static_assert( - offsetof(__wasi_filestat_t, st_nlink) == 20, "non-wasi data layout"); + offsetof(__wasi_filestat_t, st_nlink) == 24, "non-wasi data layout"); _Static_assert( - offsetof(__wasi_filestat_t, st_size) == 24, "non-wasi data layout"); + offsetof(__wasi_filestat_t, st_size) == 32, "non-wasi data layout"); _Static_assert( - offsetof(__wasi_filestat_t, st_atim) == 32, "non-wasi data layout"); + offsetof(__wasi_filestat_t, st_atim) == 40, "non-wasi data layout"); _Static_assert( - offsetof(__wasi_filestat_t, st_mtim) == 40, "non-wasi data layout"); + offsetof(__wasi_filestat_t, st_mtim) == 48, "non-wasi data layout"); _Static_assert( - offsetof(__wasi_filestat_t, st_ctim) == 48, "non-wasi data layout"); -_Static_assert(sizeof(__wasi_filestat_t) == 56, "non-wasi data layout"); + offsetof(__wasi_filestat_t, st_ctim) == 56, "non-wasi data layout"); +_Static_assert(sizeof(__wasi_filestat_t) == 64, "non-wasi data layout"); _Static_assert(_Alignof(__wasi_filestat_t) == 8, "non-wasi data layout"); typedef struct __wasi_ciovec_t {