bug fixes with making pointers 8 bytes in size on WASI
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 Jan 2021 21:11:53 +0000 (15:11 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 Jan 2021 21:11:53 +0000 (15:11 -0600)
core/file.onyx
core/sys/wasi.onyx
core/wasi.onyx
onyx.exe

index 1499fa5f62788406a4ffb5586525473573efc3eb..ea5be3c827f7b032ea95b68ef86232070e1d71ef 100644 (file)
@@ -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);
 
index 4c9ad645200b889538c672032fcf96e3a786c1f6..80ad80ce657b56c335afdaa4ff45c8e861414625 100644 (file)
@@ -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]);
index f5600f9b320ba96b9e44cc8ab67273ee286ddfb0..a52e980df6a5f940d6de92d3b84cfcc6fc2b9739 100644 (file)
@@ -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;
 }
 
index 932a0a46d6640f5a9aacf1435ffa2c5e633583db..018363e400c939ca96ad12d8a0e3164173a0e48f 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ