authorgravatar for mattnite@protonmail.comMatt Knight <mattnite@protonmail.com> 2022-11-18 17:56:15-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-06 12:15:04-07:00
loge9d9be2902e63a389531f2ce2197766398c281d6
tree50869ed642476bdcfc99a3d97c16588b3ac0b0e5
parenteef780ebf2299181ec182470aa057d77a065ff13

Some fixes for the wasi interpreter for macOS (#13587)

* Remove usage of O_PATH, ifdef for macos stat struct, and integer formatting

2 files changed, 14 insertions(+), 6 deletions(-)

CMakeLists.txt+2-2
......@@ -713,8 +713,8 @@ if(MSVC)
713713 set(ZIG2_COMPILE_FLAGS "/std:c99")
714714 set(ZIG2_LINK_FLAGS "/STACK:16777216")
715715else()
716 set(ZIG1_COMPILE_FLAGS "-std=c99 -O1 -march=native")
717 set(ZIG2_COMPILE_FLAGS "-std=c99 -O1 -march=native")
716 set(ZIG1_COMPILE_FLAGS "-std=c99 -O1")
717 set(ZIG2_COMPILE_FLAGS "-std=c99 -O1")
718718 set(ZIG2_LINK_FLAGS "-Wl,-z,stack-size=0x10000000")
719719endif()
720720
stage1/zig1.c+12-4
......@@ -9,6 +9,7 @@
99#include <stdio.h>
1010#include <stdlib.h>
1111#include <string.h>
12#include <inttypes.h>
1213
1314#include <fcntl.h>
1415#include <sys/mman.h>
......@@ -859,9 +860,16 @@ static enum wasi_errno_t finish_wasi_stat(struct VirtualMachine *vm,
859860 write_u64_le(vm->memory + buf + 0x10, to_wasi_filetype(st.st_mode));
860861 write_u64_le(vm->memory + buf + 0x18, 1); // nlink
861862 write_u64_le(vm->memory + buf + 0x20, st.st_size);
863#if defined(__APPLE__)
864 write_u64_le(vm->memory + buf + 0x28, to_wasi_timestamp(st.st_atimespec));
865 write_u64_le(vm->memory + buf + 0x30, to_wasi_timestamp(st.st_mtimespec));
866 write_u64_le(vm->memory + buf + 0x38, to_wasi_timestamp(st.st_ctimespec));
867#else
862868 write_u64_le(vm->memory + buf + 0x28, to_wasi_timestamp(st.st_atim));
863869 write_u64_le(vm->memory + buf + 0x30, to_wasi_timestamp(st.st_mtim));
864870 write_u64_le(vm->memory + buf + 0x38, to_wasi_timestamp(st.st_ctim));
871#endif
872
865873 return WASI_ESUCCESS;
866874}
867875
......@@ -1173,7 +1181,7 @@ static enum wasi_errno_t wasi_clock_time_get(struct VirtualMachine *vm,
11731181
11741182///pub extern "wasi_snapshot_preview1" fn debug(string: [*:0]const u8, x: u64) void;
11751183void wasi_debug(struct VirtualMachine *vm, uint32_t text, uint64_t n) {
1176 fprintf(stderr, "wasi_debug: '%s' number=%lu %lx\n", vm->memory + text, n, n);
1184 fprintf(stderr, "wasi_debug: '%s' number=%" PRIu64" %" PRIx64 "\n", vm->memory + text, n, n);
11771185}
11781186
11791187/// pub extern "wasi_snapshot_preview1" fn debug_slice(ptr: [*]const u8, len: usize) void;
......@@ -4082,7 +4090,7 @@ int main(int argc, char **argv) {
40824090
40834091 mkdir(cache_dir_buf, 0777);
40844092 cache_dir = err_wrap("opening cache dir",
4085 open(cache_dir_buf, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_PATH));
4093 open(cache_dir_buf, O_DIRECTORY|O_RDONLY|O_CLOEXEC));
40864094 }
40874095
40884096 // Construct a new argv for the WASI code which has absolute paths
......@@ -4171,8 +4179,8 @@ int main(int argc, char **argv) {
41714179 size_t mod_len = ZSTD_decompress(mod_ptr, max_uncompressed_size,
41724180 compressed_bytes.ptr, compressed_bytes.len);
41734181
4174 int cwd = err_wrap("opening cwd", open(".", O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_PATH));
4175 int zig_lib_dir = err_wrap("opening zig lib dir", open(zig_lib_dir_path, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_PATH));
4182 int cwd = err_wrap("opening cwd", open(".", O_DIRECTORY|O_RDONLY|O_CLOEXEC));
4183 int zig_lib_dir = err_wrap("opening zig lib dir", open(zig_lib_dir_path, O_DIRECTORY|O_RDONLY|O_CLOEXEC));
41764184
41774185 add_preopen(0, "stdin", STDIN_FILENO);
41784186 add_preopen(1, "stdout", STDOUT_FILENO);