| author | |
| committer | |
| log | 72bcd5a4a50787b0407c21e61d660e59fa74e449 |
| tree | 3f19328aa871e1c042bdaccaca0d24561b70ffc5 |
| parent | 63f2e96eeaaa032ffa9ff11a4a632d8032883233 |
5 files changed, 136 insertions(+), 3 deletions(-)
std/os.zig+4-1| ... | @@ -23,6 +23,7 @@ test "std.os" { | ... | @@ -23,6 +23,7 @@ test "std.os" { |
| 23 | _ = @import("os/time.zig"); | 23 | _ = @import("os/time.zig"); |
| 24 | _ = @import("os/windows.zig"); | 24 | _ = @import("os/windows.zig"); |
| 25 | _ = @import("os/uefi.zig"); | 25 | _ = @import("os/uefi.zig"); |
| 26 | _ = @import("os/wasi.zig"); | ||
| 26 | _ = @import("os/get_app_data_dir.zig"); | 27 | _ = @import("os/get_app_data_dir.zig"); |
| 27 | } | 28 | } |
| 28 | 29 | ||
| ... | @@ -33,6 +34,7 @@ pub const freebsd = @import("os/freebsd.zig"); | ... | @@ -33,6 +34,7 @@ pub const freebsd = @import("os/freebsd.zig"); |
| 33 | pub const netbsd = @import("os/netbsd.zig"); | 34 | pub const netbsd = @import("os/netbsd.zig"); |
| 34 | pub const zen = @import("os/zen.zig"); | 35 | pub const zen = @import("os/zen.zig"); |
| 35 | pub const uefi = @import("os/uefi.zig"); | 36 | pub const uefi = @import("os/uefi.zig"); |
| 37 | pub const wasi = @import("os/wasi.zig"); | ||
| 36 | 38 | ||
| 37 | pub const posix = switch (builtin.os) { | 39 | pub const posix = switch (builtin.os) { |
| 38 | Os.linux => linux, | 40 | Os.linux => linux, |
| ... | @@ -40,6 +42,7 @@ pub const posix = switch (builtin.os) { | ... | @@ -40,6 +42,7 @@ pub const posix = switch (builtin.os) { |
| 40 | Os.freebsd => freebsd, | 42 | Os.freebsd => freebsd, |
| 41 | Os.netbsd => netbsd, | 43 | Os.netbsd => netbsd, |
| 42 | Os.zen => zen, | 44 | Os.zen => zen, |
| 45 | Os.wasi => wasi, | ||
| 43 | else => @compileError("Unsupported OS"), | 46 | else => @compileError("Unsupported OS"), |
| 44 | }; | 47 | }; |
| 45 | 48 | ||
| ... | @@ -187,7 +190,7 @@ pub fn abort() noreturn { | ... | @@ -187,7 +190,7 @@ pub fn abort() noreturn { |
| 187 | c.abort(); | 190 | c.abort(); |
| 188 | } | 191 | } |
| 189 | switch (builtin.os) { | 192 | switch (builtin.os) { |
| 190 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { | 193 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd, Os.wasi => { |
| 191 | _ = posix.raise(posix.SIGABRT); | 194 | _ = posix.raise(posix.SIGABRT); |
| 192 | _ = posix.raise(posix.SIGKILL); | 195 | _ = posix.raise(posix.SIGKILL); |
| 193 | while (true) {} | 196 | while (true) {} |
std/os/wasi.zig created+105| ... | @@ -0,0 +1,105 @@ | ||
| 1 | use @import("wasi/core.zig"); | ||
| 2 | |||
| 3 | pub const STDIN_FILENO = 0; | ||
| 4 | pub const STDOUT_FILENO = 1; | ||
| 5 | pub const STDERR_FILENO = 2; | ||
| 6 | |||
| 7 | pub const ESUCCESS = 0; | ||
| 8 | pub const E2BIG = 1; | ||
| 9 | pub const EACCES = 2; | ||
| 10 | pub const EADDRINUSE = 3; | ||
| 11 | pub const EADDRNOTAVAIL = 4; | ||
| 12 | pub const EAFNOSUPPORT = 5; | ||
| 13 | pub const EAGAIN = 6; | ||
| 14 | pub const EALREADY = 7; | ||
| 15 | pub const EBADF = 8; | ||
| 16 | pub const EBADMSG = 9; | ||
| 17 | pub const EBUSY = 10; | ||
| 18 | pub const ECANCELED = 11; | ||
| 19 | pub const ECHILD = 12; | ||
| 20 | pub const ECONNABORTED = 13; | ||
| 21 | pub const ECONNREFUSED = 14; | ||
| 22 | pub const ECONNRESET = 15; | ||
| 23 | pub const EDEADLK = 16; | ||
| 24 | pub const EDESTADDRREQ = 17; | ||
| 25 | pub const EDOM = 18; | ||
| 26 | pub const EDQUOT = 19; | ||
| 27 | pub const EEXIST = 20; | ||
| 28 | pub const EFAULT = 21; | ||
| 29 | pub const EFBIG = 22; | ||
| 30 | pub const EHOSTUNREACH = 23; | ||
| 31 | pub const EIDRM = 24; | ||
| 32 | pub const EILSEQ = 25; | ||
| 33 | pub const EINPROGRESS = 26; | ||
| 34 | pub const EINTR = 27; | ||
| 35 | pub const EINVAL = 28; | ||
| 36 | pub const EIO = 29; | ||
| 37 | pub const EISCONN = 30; | ||
| 38 | pub const EISDIR = 31; | ||
| 39 | pub const ELOOP = 32; | ||
| 40 | pub const EMFILE = 33; | ||
| 41 | pub const EMLINK = 34; | ||
| 42 | pub const EMSGSIZE = 35; | ||
| 43 | pub const EMULTIHOP = 36; | ||
| 44 | pub const ENAMETOOLONG = 37; | ||
| 45 | pub const ENETDOWN = 38; | ||
| 46 | pub const ENETRESET = 39; | ||
| 47 | pub const ENETUNREACH = 40; | ||
| 48 | pub const ENFILE = 41; | ||
| 49 | pub const ENOBUFS = 42; | ||
| 50 | pub const ENODEV = 43; | ||
| 51 | pub const ENOENT = 44; | ||
| 52 | pub const ENOEXEC = 45; | ||
| 53 | pub const ENOLCK = 46; | ||
| 54 | pub const ENOLINK = 47; | ||
| 55 | pub const ENOMEM = 48; | ||
| 56 | pub const ENOMSG = 49; | ||
| 57 | pub const ENOPROTOOPT = 50; | ||
| 58 | pub const ENOSPC = 51; | ||
| 59 | pub const ENOSYS = 52; | ||
| 60 | pub const ENOTCONN = 53; | ||
| 61 | pub const ENOTDIR = 54; | ||
| 62 | pub const ENOTEMPTY = 55; | ||
| 63 | pub const ENOTRECOVERABLE = 56; | ||
| 64 | pub const ENOTSOCK = 57; | ||
| 65 | pub const ENOTSUP = 58; | ||
| 66 | pub const ENOTTY = 59; | ||
| 67 | pub const ENXIO = 60; | ||
| 68 | pub const EOVERFLOW = 61; | ||
| 69 | pub const EOWNERDEAD = 62; | ||
| 70 | pub const EPERM = 63; | ||
| 71 | pub const EPIPE = 64; | ||
| 72 | pub const EPROTO = 65; | ||
| 73 | pub const EPROTONOSUPPORT = 66; | ||
| 74 | pub const EPROTOTYPE = 67; | ||
| 75 | pub const ERANGE = 68; | ||
| 76 | pub const EROFS = 69; | ||
| 77 | pub const ESPIPE = 70; | ||
| 78 | pub const ESRCH = 71; | ||
| 79 | pub const ESTALE = 72; | ||
| 80 | pub const ETIMEDOUT = 73; | ||
| 81 | pub const ETXTBSY = 74; | ||
| 82 | pub const EXDEV = 75; | ||
| 83 | pub const ENOTCAPABLE = 76; | ||
| 84 | |||
| 85 | // TODO: figure out what's going on here | ||
| 86 | pub fn getErrno(r: usize) usize { | ||
| 87 | const signed_r = @bitCast(isize, r); | ||
| 88 | return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; | ||
| 89 | } | ||
| 90 | |||
| 91 | pub fn exit(status: i32) noreturn { | ||
| 92 | __wasi_proc_exit(@bitCast(__wasi_exitcode_t, isize(status))); | ||
| 93 | } | ||
| 94 | |||
| 95 | pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { | ||
| 96 | var nwritten: usize = undefined; | ||
| 97 | |||
| 98 | const iovs = []__wasi_ciovec_t{__wasi_ciovec_t{ | ||
| 99 | .buf = buf, | ||
| 100 | .buf_len = count, | ||
| 101 | }}; | ||
| 102 | |||
| 103 | _ = __wasi_fd_write(@bitCast(__wasi_fd_t, isize(fd)), &iovs[0], iovs.len, &nwritten); | ||
| 104 | return nwritten; | ||
| 105 | } | ||
std/os/wasi/core.zig created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | pub const __wasi_errno_t = u16; | ||
| 2 | pub const __wasi_exitcode_t = u32; | ||
| 3 | pub const __wasi_fd_t = u32; | ||
| 4 | |||
| 5 | pub const __wasi_ciovec_t = extern struct { | ||
| 6 | buf: [*]const u8, | ||
| 7 | buf_len: usize, | ||
| 8 | }; | ||
| 9 | |||
| 10 | pub extern fn __wasi_proc_exit(rval: __wasi_exitcode_t) noreturn; | ||
| 11 | |||
| 12 | pub extern fn __wasi_fd_write(fd: __wasi_fd_t, iovs: *const __wasi_ciovec_t, iovs_len: usize, nwritten: *usize) __wasi_errno_t; | ||
std/special/bootstrap.zig+12| ... | @@ -14,6 +14,8 @@ comptime { | ... | @@ -14,6 +14,8 @@ comptime { |
| 14 | @export("main", main, strong_linkage); | 14 | @export("main", main, strong_linkage); |
| 15 | } else if (builtin.os == builtin.Os.windows) { | 15 | } else if (builtin.os == builtin.Os.windows) { |
| 16 | @export("WinMainCRTStartup", WinMainCRTStartup, strong_linkage); | 16 | @export("WinMainCRTStartup", WinMainCRTStartup, strong_linkage); |
| 17 | } else if (builtin.os == builtin.Os.wasi) { | ||
| 18 | @export("_start", wasiStart, strong_linkage); | ||
| 17 | } else { | 19 | } else { |
| 18 | @export("_start", _start, strong_linkage); | 20 | @export("_start", _start, strong_linkage); |
| 19 | } | 21 | } |
| ... | @@ -43,6 +45,16 @@ nakedcc fn _start() noreturn { | ... | @@ -43,6 +45,16 @@ nakedcc fn _start() noreturn { |
| 43 | @noInlineCall(posixCallMainAndExit); | 45 | @noInlineCall(posixCallMainAndExit); |
| 44 | } | 46 | } |
| 45 | 47 | ||
| 48 | nakedcc fn wasiStart() noreturn { | ||
| 49 | // TODO: Decide if alloc at init is acceptable for args and env | ||
| 50 | // @llvm.wasm.mem.grow.i32 | ||
| 51 | // __wasi_args_get() | ||
| 52 | // __wasi_args_sizes_get() | ||
| 53 | // __wasi_environ_get() | ||
| 54 | // __wasi_environ_sizes_get() | ||
| 55 | std.os.posix.exit(callMain()); | ||
| 56 | } | ||
| 57 | |||
| 46 | extern fn WinMainCRTStartup() noreturn { | 58 | extern fn WinMainCRTStartup() noreturn { |
| 47 | @setAlignStack(16); | 59 | @setAlignStack(16); |
| 48 | if (!builtin.single_threaded) { | 60 | if (!builtin.single_threaded) { |
std/special/panic.zig+3-2| ... | @@ -9,8 +9,9 @@ const std = @import("std"); | ... | @@ -9,8 +9,9 @@ const std = @import("std"); |
| 9 | pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { | 9 | pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { |
| 10 | @setCold(true); | 10 | @setCold(true); |
| 11 | switch (builtin.os) { | 11 | switch (builtin.os) { |
| 12 | // TODO: fix panic in zen. | 12 | // TODO: fix panic in zen |
| 13 | builtin.Os.freestanding, builtin.Os.zen => { | 13 | // TODO: fix panic in wasi |
| 14 | builtin.Os.freestanding, builtin.Os.zen, builtin.Os.wasi => { | ||
| 14 | while (true) {} | 15 | while (true) {} |
| 15 | }, | 16 | }, |
| 16 | builtin.Os.uefi => { | 17 | builtin.Os.uefi => { |