From: Brendan Hansen Date: Fri, 15 Jan 2021 21:11:53 +0000 (-0600) Subject: bug fixes with making pointers 8 bytes in size on WASI X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=ff514c2178a7f2a0e47b2697d26ebe4cfca7db8a;p=onyx.git bug fixes with making pointers 8 bytes in size on WASI --- diff --git a/core/file.onyx b/core/file.onyx index 1499fa5f..ea5be3c8 100644 --- a/core/file.onyx +++ b/core/file.onyx @@ -106,9 +106,9 @@ close :: proc (file: File) -> bool { } write :: proc (file: File, data: str) { - vec := IOVec.{ buf = data.data, len = data.count }; + vec := IOVec.{ buf = cast(u32) data.data, len = data.count }; tmp : Size; - fd_write(file.fd, IOVecArray.{ ^vec, 1 }, ^tmp); + fd_write(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^tmp); fd_datasync(file.fd); } @@ -131,8 +131,8 @@ get_contents_from_file :: proc (file: File) -> str { fd_seek(file.fd, 0, Whence.Set, ^dummy); dummy2: u32; - buf := IOVec.{ data, size }; - fd_pread(file.fd, IOVecArray.{ ^buf, 1 }, 0, ^dummy2); + buf := IOVec.{ cast(u32) data, size }; + fd_pread(file.fd, IOVecArray.{ cast(u32) ^buf, 1 }, 0, ^dummy2); fd_seek(file.fd, prev_loc, Whence.Set, ^dummy); diff --git a/core/sys/wasi.onyx b/core/sys/wasi.onyx index 4c9ad645..80ad80ce 100644 --- a/core/sys/wasi.onyx +++ b/core/sys/wasi.onyx @@ -9,9 +9,9 @@ use package main as main STDOUT_FILENO :: 1 output_str :: proc (s: str) -> u32 { - vec := IOVec.{ buf = s.data, len = s.count }; + vec := IOVec.{ buf = cast(u32) s.data, len = s.count }; tmp : Size; - fd_write(STDOUT_FILENO, IOVecArray.{ ^vec, 1 }, ^tmp); + fd_write(STDOUT_FILENO, IOVecArray.{ cast(u32) ^vec, 1 }, ^tmp); fd_datasync(STDOUT_FILENO); return tmp; } @@ -39,14 +39,28 @@ proc () #export "_start" { argc : Size; argv_buf_size : Size; - args_sizes_get(^argc, ^argv_buf_size); argv := cast(^cstr) calloc(sizeof cstr * argc); argv_buf := cast(cstr) calloc(argv_buf_size); - args_get(argv, argv_buf); + + // This post processing of the argv array needs to happen if the target is using + // 32-bit pointers, instead of 64-bits. Right now, Onyx pointers take up 64-bits, + // but in most circumstances, only the lower 32-bits are used. When webassembly + // standardizes the 64-bit address space, it will be an easy conversion over. + // But for right now, WASI will give the argv array 32-bit pointers, instead of + // 64-bit pointers. This loops expands the 32-bit pointers into 64-bit pointers + // while not clobbering any of them. + while i := cast(i32) (argc - 1); i >= 0 { + defer i -= 1; + + argv[i] = cast(cstr) (cast(^u32) argv)[i]; + } + + + stdio_init(); main.main(argv[0 .. argc]); diff --git a/core/wasi.onyx b/core/wasi.onyx index f5600f9b..a52e980d 100644 --- a/core/wasi.onyx +++ b/core/wasi.onyx @@ -127,7 +127,7 @@ Rights :: enum #flags (u64) { FileDescriptor :: #type i32; IOVec :: struct { - buf : ^u8; + buf : u32; // actually a ^u8, but WASM is 32-bit at the moment; len : u32; } @@ -358,7 +358,7 @@ PrestatTagged :: struct { } IOVecArray :: struct { - iovs : ^IOVec; + iovs : u32; // actually ^IOVec; see comment above iovs_len : Size; } diff --git a/onyx.exe b/onyx.exe index 932a0a46..018363e4 100644 Binary files a/onyx.exe and b/onyx.exe differ