| author | |
| committer | |
| log | 29a418c9d5b3b9c78b707e5b6a119d48ecce9a6a |
| tree | b0716f34ca3170edd1784c46c18a4e4595e52e34 |
| parent | 105a09e1d654c76addc26fd5616c06fcbd8b6a12 |
15 files changed, 434 insertions(+), 373 deletions(-)
CMakeLists.txt-1| ... | ... | @@ -297,7 +297,6 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}") |
| 297 | 297 | install(FILES "${CMAKE_SOURCE_DIR}/std/net.zig" DESTINATION "${ZIG_STD_DEST}") |
| 298 | 298 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/child_process.zig" DESTINATION "${ZIG_STD_DEST}/os") |
| 299 | 299 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin.zig" DESTINATION "${ZIG_STD_DEST}/os") |
| 300 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin_x86_64.zig" DESTINATION "${ZIG_STD_DEST}/os") | |
| 301 | 300 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/errno.zig" DESTINATION "${ZIG_STD_DEST}/os") |
| 302 | 301 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/index.zig" DESTINATION "${ZIG_STD_DEST}/os") |
| 303 | 302 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux.zig" DESTINATION "${ZIG_STD_DEST}/os") |
src/analyze.cpp+4| ... | ... | @@ -2891,6 +2891,10 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { |
| 2891 | 2891 | } |
| 2892 | 2892 | |
| 2893 | 2893 | static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *dst_use_node) { |
| 2894 | if (src_use_node->data.use.resolution == TldResolutionUnresolved) { | |
| 2895 | preview_use_decl(g, src_use_node); | |
| 2896 | } | |
| 2897 | ||
| 2894 | 2898 | IrInstruction *use_target_value = src_use_node->data.use.value; |
| 2895 | 2899 | if (use_target_value->value.type->id == TypeTableEntryIdInvalid) { |
| 2896 | 2900 | dst_use_node->owner->any_imports_failed = true; |
src/os.cpp+2-5| ... | ... | @@ -709,10 +709,6 @@ int os_delete_file(Buf *path) { |
| 709 | 709 | } |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | void os_init(void) { | |
| 713 | srand((unsigned)time(NULL)); | |
| 714 | } | |
| 715 | ||
| 716 | 712 | int os_rename(Buf *src_path, Buf *dest_path) { |
| 717 | 713 | if (rename(buf_ptr(src_path), buf_ptr(dest_path)) == -1) { |
| 718 | 714 | return ErrorFileSystem; |
| ... | ... | @@ -805,7 +801,8 @@ int os_make_dir(Buf *path) { |
| 805 | 801 | #endif |
| 806 | 802 | } |
| 807 | 803 | |
| 808 | int zig_os_init(void) { | |
| 804 | int os_init(void) { | |
| 805 | srand((unsigned)time(NULL)); | |
| 809 | 806 | #if defined(ZIG_OS_WINDOWS) |
| 810 | 807 | unsigned __int64 frequency; |
| 811 | 808 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) { |
src/os.hpp+1-1| ... | ... | @@ -27,8 +27,8 @@ struct Termination { |
| 27 | 27 | int code; |
| 28 | 28 | }; |
| 29 | 29 | |
| 30 | int os_init(void); | |
| 30 | 31 | |
| 31 | void os_init(void); | |
| 32 | 32 | void os_spawn_process(const char *exe, ZigList<const char *> &args, Termination *term); |
| 33 | 33 | int os_exec_process(const char *exe, ZigList<const char *> &args, |
| 34 | 34 | Termination *term, Buf *out_stderr, Buf *out_stdout); |
std/c/darwin.zig+30-2| ... | ... | @@ -1,4 +1,32 @@ |
| 1 | pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize) -> c_int; | |
| 2 | fn extern "c" __error() -> &c_int; | |
| 1 | extern "c" fn __error() -> &c_int; | |
| 3 | 2 | |
| 4 | 3 | pub const _errno = __error; |
| 4 | ||
| 5 | /// Renamed to Stat to not conflict with the stat function. | |
| 6 | pub const Stat = extern struct { | |
| 7 | dev: u32, | |
| 8 | mode: u16, | |
| 9 | nlink: u16, | |
| 10 | ino: u64, | |
| 11 | uid: u32, | |
| 12 | gid: u32, | |
| 13 | rdev: u64, | |
| 14 | ||
| 15 | atim: timespec, | |
| 16 | mtim: timespec, | |
| 17 | ctim: timespec, | |
| 18 | ||
| 19 | size: u64, | |
| 20 | blocks: u64, | |
| 21 | blksize: u32, | |
| 22 | flags: u32, | |
| 23 | gen: u32, | |
| 24 | lspare: i32, | |
| 25 | qspare: [2]u64, | |
| 26 | ||
| 27 | }; | |
| 28 | ||
| 29 | pub const timespec = extern struct { | |
| 30 | tv_sec: isize, | |
| 31 | tv_nsec: isize, | |
| 32 | }; |
std/c/index.zig+27-2| ... | ... | @@ -8,7 +8,32 @@ pub use switch(builtin.os) { |
| 8 | 8 | Os.darwin, Os.macosx, Os.ios => @import("darwin.zig"), |
| 9 | 9 | else => empty_import, |
| 10 | 10 | }; |
| 11 | const empty_import = @import("../empty.zig"); | |
| 11 | 12 | |
| 12 | 13 | pub extern "c" fn abort() -> noreturn; |
| 13 | ||
| 14 | const empty_import = @import("../empty.zig"); | |
| 14 | pub extern "c" fn exit(code: c_int) -> noreturn; | |
| 15 | pub extern "c" fn isatty(fd: c_int) -> c_int; | |
| 16 | pub extern "c" fn close(fd: c_int) -> c_int; | |
| 17 | pub extern "c" fn fstat(fd: c_int, buf: &stat) -> c_int; | |
| 18 | pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) -> isize; | |
| 19 | pub extern "c" fn open(path: &const u8, oflag: c_int, ...) -> c_int; | |
| 20 | pub extern "c" fn raise(sig: c_int) -> c_int; | |
| 21 | pub extern "c" fn read(fd: c_int, buf: &c_void, nbyte: usize) -> isize; | |
| 22 | pub extern "c" fn stat(noalias path: &const u8, noalias buf: &Stat) -> c_int; | |
| 23 | pub extern "c" fn write(fd: c_int, buf: &const c_void, nbyte: usize) -> c_int; | |
| 24 | pub extern "c" fn mmap(addr: ?&c_void, len: usize, prot: c_int, flags: c_int, | |
| 25 | fd: c_int, offset: isize) -> ?&c_void; | |
| 26 | pub extern "c" fn munmap(addr: &c_void, len: usize) -> c_int; | |
| 27 | pub extern "c" fn unlink(path: &const u8) -> c_int; | |
| 28 | pub extern "c" fn getcwd(buf: &u8, size: usize) -> ?&u8; | |
| 29 | pub extern "c" fn waitpid(pid: c_int, stat_loc: &c_int, options: c_int) -> c_int; | |
| 30 | pub extern "c" fn fork() -> c_int; | |
| 31 | pub extern "c" fn pipe(fds: &c_int) -> c_int; | |
| 32 | pub extern "c" fn mkdir(path: &const u8, mode: c_uint) -> c_int; | |
| 33 | pub extern "c" fn symlink(existing: &const u8, new: &const u8) -> c_int; | |
| 34 | pub extern "c" fn rename(old: &const u8, new: &const u8) -> c_int; | |
| 35 | pub extern "c" fn chdir(path: &const u8) -> c_int; | |
| 36 | pub extern "c" fn execve(path: &const u8, argv: &const ?&const u8, | |
| 37 | envp: &const ?&const u8) -> c_int; | |
| 38 | pub extern "c" fn dup(fd: c_int) -> c_int; | |
| 39 | pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) -> c_int; |
std/io.zig+12-3| ... | ... | @@ -2,10 +2,11 @@ const builtin = @import("builtin"); |
| 2 | 2 | const Os = builtin.Os; |
| 3 | 3 | const system = switch(builtin.os) { |
| 4 | 4 | Os.linux => @import("os/linux.zig"), |
| 5 | Os.darwin => @import("os/darwin.zig"), | |
| 5 | Os.darwin, Os.macosx, Os.ios => @import("os/darwin.zig"), | |
| 6 | 6 | Os.windows => @import("os/windows/index.zig"), |
| 7 | 7 | else => @compileError("Unsupported OS"), |
| 8 | 8 | }; |
| 9 | const c = @import("c/index.zig"); | |
| 9 | 10 | |
| 10 | 11 | const errno = @import("os/errno.zig"); |
| 11 | 12 | const math = @import("math/index.zig"); |
| ... | ... | @@ -180,7 +181,11 @@ pub const OutStream = struct { |
| 180 | 181 | |
| 181 | 182 | pub fn isTty(self: &OutStream) -> %bool { |
| 182 | 183 | if (is_posix) { |
| 183 | return system.isatty(self.fd); | |
| 184 | if (builtin.link_libc) { | |
| 185 | return c.isatty(self.fd) == 0; | |
| 186 | } else { | |
| 187 | return system.isatty(self.fd); | |
| 188 | } | |
| 184 | 189 | } else if (is_windows) { |
| 185 | 190 | return os.windowsIsTty(%return self.getHandle()); |
| 186 | 191 | } else { |
| ... | ... | @@ -417,7 +422,11 @@ pub const InStream = struct { |
| 417 | 422 | |
| 418 | 423 | pub fn isTty(self: &InStream) -> %bool { |
| 419 | 424 | if (is_posix) { |
| 420 | return system.isatty(self.fd); | |
| 425 | if (builtin.link_libc) { | |
| 426 | return c.isatty(self.fd) == 0; | |
| 427 | } else { | |
| 428 | return system.isatty(self.fd); | |
| 429 | } | |
| 421 | 430 | } else if (is_windows) { |
| 422 | 431 | return os.windowsIsTty(%return self.getHandle()); |
| 423 | 432 | } else { |
std/os/child_process.zig+3-30| ... | ... | @@ -229,42 +229,15 @@ fn forkChildErrReport(fd: i32, err: error) -> noreturn { |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | const ErrInt = @IntType(false, @sizeOf(error) * 8); |
| 232 | ||
| 232 | 233 | fn writeIntFd(fd: i32, value: ErrInt) -> %void { |
| 233 | 234 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; |
| 234 | 235 | mem.writeInt(bytes[0..], value, true); |
| 235 | ||
| 236 | var index: usize = 0; | |
| 237 | while (index < bytes.len) { | |
| 238 | const amt_written = posix.write(fd, &bytes[index], bytes.len - index); | |
| 239 | const err = posix.getErrno(amt_written); | |
| 240 | if (err > 0) { | |
| 241 | switch (err) { | |
| 242 | errno.EINTR => continue, | |
| 243 | errno.EINVAL => unreachable, | |
| 244 | else => return error.SystemResources, | |
| 245 | } | |
| 246 | } | |
| 247 | index += amt_written; | |
| 248 | } | |
| 236 | os.posixWrite(fd, bytes[0..]) %% return error.SystemResources; | |
| 249 | 237 | } |
| 250 | 238 | |
| 251 | 239 | fn readIntFd(fd: i32) -> %ErrInt { |
| 252 | 240 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; |
| 253 | ||
| 254 | var index: usize = 0; | |
| 255 | while (index < bytes.len) { | |
| 256 | const amt_written = posix.read(fd, &bytes[index], bytes.len - index); | |
| 257 | const err = posix.getErrno(amt_written); | |
| 258 | if (err > 0) { | |
| 259 | switch (err) { | |
| 260 | errno.EINTR => continue, | |
| 261 | errno.EINVAL => unreachable, | |
| 262 | else => return error.SystemResources, | |
| 263 | } | |
| 264 | } | |
| 265 | index += amt_written; | |
| 266 | } | |
| 267 | ||
| 241 | os.posixRead(fd, bytes[0..]) %% return error.SystemResources; | |
| 268 | 242 | return mem.readInt(bytes[0..], ErrInt, true); |
| 269 | 243 | } |
| 270 |
std/os/darwin.zig+136-44| ... | ... | @@ -1,18 +1,41 @@ |
| 1 | ||
| 2 | const builtin = @import("builtin"); | |
| 3 | const arch = switch (builtin.arch) { | |
| 4 | builtin.Arch.x86_64 => @import("darwin_x86_64.zig"), | |
| 5 | else => @compileError("unsupported arch"), | |
| 6 | }; | |
| 7 | ||
| 8 | const errno = @import("errno.zig"); | |
| 1 | const c = @import("../c/index.zig"); | |
| 2 | const assert = @import("../debug.zig").assert; | |
| 9 | 3 | |
| 10 | 4 | pub const STDIN_FILENO = 0; |
| 11 | 5 | pub const STDOUT_FILENO = 1; |
| 12 | 6 | pub const STDERR_FILENO = 2; |
| 13 | 7 | |
| 8 | pub const PROT_NONE = 0x00; /// [MC2] no permissions | |
| 9 | pub const PROT_READ = 0x01; /// [MC2] pages can be read | |
| 10 | pub const PROT_WRITE = 0x02; /// [MC2] pages can be written | |
| 11 | pub const PROT_EXEC = 0x04; /// [MC2] pages can be executed | |
| 12 | ||
| 13 | pub const MAP_ANONYMOUS = 0x1000; /// allocated from memory, swap space | |
| 14 | pub const MAP_FILE = 0x0000; /// map from file (default) | |
| 15 | pub const MAP_FIXED = 0x0010; /// interpret addr exactly | |
| 16 | pub const MAP_HASSEMAPHORE = 0x0200; /// region may contain semaphores | |
| 17 | pub const MAP_PRIVATE = 0x0002; /// changes are private | |
| 18 | pub const MAP_SHARED = 0x0001; /// share changes | |
| 19 | pub const MAP_NOCACHE = 0x0400; /// don't cache pages for this mapping | |
| 20 | pub const MAP_NORESERVE = 0x0040; /// don't reserve needed swap area | |
| 21 | pub const MAP_FAILED = @maxValue(usize); | |
| 22 | ||
| 14 | 23 | pub const O_LARGEFILE = 0x0000; |
| 15 | pub const O_RDONLY = 0x0000; | |
| 24 | ||
| 25 | pub const O_RDONLY = 0x0000; /// open for reading only | |
| 26 | pub const O_WRONLY = 0x0001; /// open for writing only | |
| 27 | pub const O_RDWR = 0x0002; /// open for reading and writing | |
| 28 | pub const O_NONBLOCK = 0x0004; /// do not block on open or for data to become available | |
| 29 | pub const O_APPEND = 0x0008; /// append on each write | |
| 30 | pub const O_CREAT = 0x0200; /// create file if it does not exist | |
| 31 | pub const O_TRUNC = 0x0400; /// truncate size to 0 | |
| 32 | pub const O_EXCL = 0x0800; /// error if O_CREAT and the file exists | |
| 33 | pub const O_SHLOCK = 0x0010; /// atomically obtain a shared lock | |
| 34 | pub const O_EXLOCK = 0x0020; /// atomically obtain an exclusive lock | |
| 35 | pub const O_NOFOLLOW = 0x0100; /// do not follow symlinks | |
| 36 | pub const O_SYMLINK = 0x200000; /// allow open of symlinks | |
| 37 | pub const O_EVTONLY = 0x8000; /// descriptor requested for event notifications only | |
| 38 | pub const O_CLOEXEC = 0x1000000; /// mark as close-on-exec | |
| 16 | 39 | |
| 17 | 40 | pub const SEEK_SET = 0x0; |
| 18 | 41 | pub const SEEK_CUR = 0x1; |
| ... | ... | @@ -53,64 +76,133 @@ pub const SIGPWR = 30; |
| 53 | 76 | pub const SIGSYS = 31; |
| 54 | 77 | pub const SIGUNUSED = SIGSYS; |
| 55 | 78 | |
| 56 | pub fn exit(status: usize) -> noreturn { | |
| 57 | _ = arch.syscall1(arch.SYS_exit, status); | |
| 58 | unreachable | |
| 59 | } | |
| 79 | fn wstatus(x: i32) -> i32 { x & 0o177 } | |
| 80 | const wstopped = 0o177; | |
| 81 | pub fn WEXITSTATUS(x: i32) -> i32 { x >> 8 } | |
| 82 | pub fn WTERMSIG(x: i32) -> i32 { wstatus(x) } | |
| 83 | pub fn WSTOPSIG(x: i32) -> i32 { x >> 8 } | |
| 84 | pub fn WIFEXITED(x: i32) -> bool { wstatus(x) == 0 } | |
| 85 | pub fn WIFSTOPPED(x: i32) -> bool { wstatus(x) == wstopped and WSTOPSIG(x) != 0x13 } | |
| 86 | pub fn WIFSIGNALED(x: i32) -> bool { wstatus(x) != wstopped and wstatus(x) != 0 } | |
| 60 | 87 | |
| 61 | 88 | /// Get the errno from a syscall return value, or 0 for no error. |
| 62 | 89 | pub fn getErrno(r: usize) -> usize { |
| 63 | const signed_r = *@ptrCast(&const isize, &r); | |
| 90 | const signed_r = @bitCast(isize, r); | |
| 64 | 91 | if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0 |
| 65 | 92 | } |
| 66 | 93 | |
| 67 | pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { | |
| 68 | arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count) | |
| 94 | pub fn close(fd: i32) -> usize { | |
| 95 | errnoWrap(c.close(fd)) | |
| 69 | 96 | } |
| 70 | 97 | |
| 71 | pub fn close(fd: i32) -> usize { | |
| 72 | arch.syscall1(arch.SYS_close, usize(fd)) | |
| 98 | pub fn abort() -> noreturn { | |
| 99 | c.abort() | |
| 100 | } | |
| 101 | ||
| 102 | pub fn exit(code: i32) -> noreturn { | |
| 103 | c.exit(code) | |
| 104 | } | |
| 105 | ||
| 106 | pub fn isatty(fd: i32) -> bool { | |
| 107 | c.isatty(fd) == 0 | |
| 108 | } | |
| 109 | ||
| 110 | pub fn fstat(fd: i32, buf: &c.stat) -> usize { | |
| 111 | errnoWrap(c.fstat(fd, buf)) | |
| 112 | } | |
| 113 | ||
| 114 | pub fn lseek(fd: i32, offset: isize, whence: c_int) -> usize { | |
| 115 | errnoWrap(c.lseek(fd, buf, whence)) | |
| 116 | } | |
| 117 | ||
| 118 | pub fn open(path: &const u8, flags: u32, mode: usize) -> usize { | |
| 119 | errnoWrap(c.open(path, @bitCast(c_int, flags), mode)) | |
| 120 | } | |
| 121 | ||
| 122 | pub fn raise(sig: i32) -> usize { | |
| 123 | errnoWrap(c.raise(sig)) | |
| 124 | } | |
| 125 | ||
| 126 | pub fn read(fd: i32, buf: &u8, nbyte: usize) -> usize { | |
| 127 | errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte)) | |
| 128 | } | |
| 129 | ||
| 130 | pub fn stat(noalias path: &const u8, noalias buf: &stat) -> usize { | |
| 131 | errnoWrap(c.stat(path, buf)) | |
| 132 | } | |
| 133 | ||
| 134 | pub fn write(fd: i32, buf: &const u8, nbyte: usize) -> usize { | |
| 135 | errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte)) | |
| 136 | } | |
| 137 | ||
| 138 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, | |
| 139 | offset: isize) -> usize | |
| 140 | { | |
| 141 | const ptr_result = c.mmap(@ptrCast(&c_void, address), length, | |
| 142 | @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset); | |
| 143 | const isize_result = @bitCast(isize, @ptrToInt(ptr_result)); | |
| 144 | return errnoWrap(isize_result); | |
| 73 | 145 | } |
| 74 | 146 | |
| 75 | pub fn open(path: &const u8, flags: usize, perm: usize) -> usize { | |
| 76 | arch.syscall3(arch.SYS_open, usize(path), flags, perm) | |
| 147 | pub fn munmap(address: &u8, length: usize) -> usize { | |
| 148 | errnoWrap(c.munmap(@ptrCast(&c_void, address), length)) | |
| 77 | 149 | } |
| 78 | 150 | |
| 79 | pub fn read(fd: i32, buf: &u8, count: usize) -> usize { | |
| 80 | arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count) | |
| 151 | pub fn unlink(path: &const u8) -> usize { | |
| 152 | errnoWrap(c.unlink(path)) | |
| 81 | 153 | } |
| 82 | 154 | |
| 83 | pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize { | |
| 84 | arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos) | |
| 155 | pub fn getcwd(buf: &u8, size: usize) -> usize { | |
| 156 | if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0 | |
| 85 | 157 | } |
| 86 | 158 | |
| 87 | pub const stat = arch.stat; | |
| 88 | pub const timespec = arch.timespec; | |
| 159 | pub fn waitpid(pid: i32, status: &i32, options: u32) -> usize { | |
| 160 | comptime assert(i32.bit_count == c_int.bit_count); | |
| 161 | errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options))) | |
| 162 | } | |
| 89 | 163 | |
| 90 | pub fn fstat(fd: i32, stat_buf: &stat) -> usize { | |
| 91 | arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf)) | |
| 164 | pub fn fork() -> usize { | |
| 165 | errnoWrap(c.fork()) | |
| 92 | 166 | } |
| 93 | 167 | |
| 94 | error Unexpected; | |
| 168 | pub fn pipe(fds: &[2]i32) -> usize { | |
| 169 | comptime assert(i32.bit_count == c_int.bit_count); | |
| 170 | errnoWrap(c.pipe(@ptrCast(&c_int, &(*fds)[0]))) | |
| 171 | } | |
| 95 | 172 | |
| 96 | pub fn getrandom(buf: &u8, count: usize) -> usize { | |
| 97 | const rr = open_c(c"/dev/urandom", O_LARGEFILE | O_RDONLY, 0); | |
| 173 | pub fn mkdir(path: &const u8, mode: u32) -> usize { | |
| 174 | errnoWrap(c.mkdir(path, mode)) | |
| 175 | } | |
| 98 | 176 | |
| 99 | if(getErrno(rr) > 0) return rr; | |
| 177 | pub fn symlink(existing: &const u8, new: &const u8) -> usize { | |
| 178 | errnoWrap(c.symlink(existing, new)) | |
| 179 | } | |
| 100 | 180 | |
| 101 | var fd: i32 = i32(rr); | |
| 102 | const readRes = read(fd, buf, count); | |
| 103 | readRes | |
| 181 | pub fn rename(old: &const u8, new: &const u8) -> usize { | |
| 182 | errnoWrap(c.rename(old, new)) | |
| 104 | 183 | } |
| 105 | 184 | |
| 106 | pub fn raise(sig: i32) -> i32 { | |
| 107 | // TODO investigate whether we need to block signals before calling kill | |
| 108 | // like we do in the linux version of raise | |
| 185 | pub fn chdir(path: &const u8) -> usize { | |
| 186 | errnoWrap(c.chdir(path)) | |
| 187 | } | |
| 188 | ||
| 189 | pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) | |
| 190 | -> usize | |
| 191 | { | |
| 192 | errnoWrap(c.execve(path, argv, envp)) | |
| 193 | } | |
| 194 | ||
| 195 | pub fn dup2(old: i32, new: i32) -> usize { | |
| 196 | errnoWrap(c.dup2(old, new)) | |
| 197 | } | |
| 109 | 198 | |
| 110 | //var set: sigset_t = undefined; | |
| 111 | //blockAppSignals(&set); | |
| 112 | const pid = i32(arch.syscall0(arch.SYS_getpid)); | |
| 113 | const ret = i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig))); | |
| 114 | //restoreSignals(&set); | |
| 115 | return ret; | |
| 199 | /// Takes the return value from a syscall and formats it back in the way | |
| 200 | /// that the kernel represents it to libc. Errno was a mistake, let's make | |
| 201 | /// it go away forever. | |
| 202 | fn errnoWrap(value: isize) -> usize { | |
| 203 | @bitCast(usize, if (value == -1) { | |
| 204 | -isize(*c._errno()) | |
| 205 | } else { | |
| 206 | value | |
| 207 | }) | |
| 116 | 208 | } |
std/os/darwin_x86_64.zig deleted-87| ... | ... | @@ -1,87 +0,0 @@ |
| 1 | ||
| 2 | pub const SYSCALL_CLASS_SHIFT = 24; | |
| 3 | pub const SYSCALL_CLASS_MASK = 0xFF << SYSCALL_CLASS_SHIFT; | |
| 4 | // pub const SYSCALL_NUMBER_MASK = ~SYSCALL_CLASS_MASK; // ~ modifier not supported yet | |
| 5 | ||
| 6 | pub const SYSCALL_CLASS_NONE = 0; // Invalid | |
| 7 | pub const SYSCALL_CLASS_MACH = 1; // Mach | |
| 8 | pub const SYSCALL_CLASS_UNIX = 2; // Unix/BSD | |
| 9 | pub const SYSCALL_CLASS_MDEP = 3; // Machine-dependent | |
| 10 | pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics | |
| 11 | ||
| 12 | // TODO: use the above constants to create the below values | |
| 13 | ||
| 14 | pub const SYS_exit = 0x2000001; | |
| 15 | pub const SYS_read = 0x2000003; | |
| 16 | pub const SYS_write = 0x2000004; | |
| 17 | pub const SYS_open = 0x2000005; | |
| 18 | pub const SYS_close = 0x2000006; | |
| 19 | pub const SYS_kill = 0x2000025; | |
| 20 | pub const SYS_getpid = 0x2000030; | |
| 21 | pub const SYS_fstat = 0x20000BD; | |
| 22 | pub const SYS_lseek = 0x20000C7; | |
| 23 | ||
| 24 | pub inline fn syscall0(number: usize) -> usize { | |
| 25 | asm volatile ("syscall" | |
| 26 | : [ret] "={rax}" (-> usize) | |
| 27 | : [number] "{rax}" (number) | |
| 28 | : "rcx", "r11") | |
| 29 | } | |
| 30 | ||
| 31 | pub inline fn syscall1(number: usize, arg1: usize) -> usize { | |
| 32 | asm volatile ("syscall" | |
| 33 | : [ret] "={rax}" (-> usize) | |
| 34 | : [number] "{rax}" (number), | |
| 35 | [arg1] "{rdi}" (arg1) | |
| 36 | : "rcx", "r11") | |
| 37 | } | |
| 38 | ||
| 39 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { | |
| 40 | asm volatile ("syscall" | |
| 41 | : [ret] "={rax}" (-> usize) | |
| 42 | : [number] "{rax}" (number), | |
| 43 | [arg1] "{rdi}" (arg1), | |
| 44 | [arg2] "{rsi}" (arg2) | |
| 45 | : "rcx", "r11") | |
| 46 | } | |
| 47 | ||
| 48 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { | |
| 49 | asm volatile ("syscall" | |
| 50 | : [ret] "={rax}" (-> usize) | |
| 51 | : [number] "{rax}" (number), | |
| 52 | [arg1] "{rdi}" (arg1), | |
| 53 | [arg2] "{rsi}" (arg2), | |
| 54 | [arg3] "{rdx}" (arg3) | |
| 55 | : "rcx", "r11") | |
| 56 | } | |
| 57 | ||
| 58 | ||
| 59 | ||
| 60 | ||
| 61 | pub const stat = extern struct { | |
| 62 | dev: u32, | |
| 63 | mode: u16, | |
| 64 | nlink: u16, | |
| 65 | ino: u64, | |
| 66 | uid: u32, | |
| 67 | gid: u32, | |
| 68 | rdev: u64, | |
| 69 | ||
| 70 | atim: timespec, | |
| 71 | mtim: timespec, | |
| 72 | ctim: timespec, | |
| 73 | ||
| 74 | size: u64, | |
| 75 | blocks: u64, | |
| 76 | blksize: u32, | |
| 77 | flags: u32, | |
| 78 | gen: u32, | |
| 79 | lspare: i32, | |
| 80 | qspare: [2]u64, | |
| 81 | ||
| 82 | }; | |
| 83 | ||
| 84 | pub const timespec = extern struct { | |
| 85 | tv_sec: isize, | |
| 86 | tv_nsec: isize, | |
| 87 | }; |
std/os/errno.zig+142-142| ... | ... | @@ -1,146 +1,146 @@ |
| 1 | pub const EPERM = 1; // Operation not permitted | |
| 2 | pub const ENOENT = 2; // No such file or directory | |
| 3 | pub const ESRCH = 3; // No such process | |
| 4 | pub const EINTR = 4; // Interrupted system call | |
| 5 | pub const EIO = 5; // I/O error | |
| 6 | pub const ENXIO = 6; // No such device or address | |
| 7 | pub const E2BIG = 7; // Arg list too long | |
| 8 | pub const ENOEXEC = 8; // Exec format error | |
| 9 | pub const EBADF = 9; // Bad file number | |
| 10 | pub const ECHILD = 10; // No child processes | |
| 11 | pub const EAGAIN = 11; // Try again | |
| 12 | pub const ENOMEM = 12; // Out of memory | |
| 13 | pub const EACCES = 13; // Permission denied | |
| 14 | pub const EFAULT = 14; // Bad address | |
| 15 | pub const ENOTBLK = 15; // Block device required | |
| 16 | pub const EBUSY = 16; // Device or resource busy | |
| 17 | pub const EEXIST = 17; // File exists | |
| 18 | pub const EXDEV = 18; // Cross-device link | |
| 19 | pub const ENODEV = 19; // No such device | |
| 20 | pub const ENOTDIR = 20; // Not a directory | |
| 21 | pub const EISDIR = 21; // Is a directory | |
| 22 | pub const EINVAL = 22; // Invalid argument | |
| 23 | pub const ENFILE = 23; // File table overflow | |
| 24 | pub const EMFILE = 24; // Too many open files | |
| 25 | pub const ENOTTY = 25; // Not a typewriter | |
| 26 | pub const ETXTBSY = 26; // Text file busy | |
| 27 | pub const EFBIG = 27; // File too large | |
| 28 | pub const ENOSPC = 28; // No space left on device | |
| 29 | pub const ESPIPE = 29; // Illegal seek | |
| 30 | pub const EROFS = 30; // Read-only file system | |
| 31 | pub const EMLINK = 31; // Too many links | |
| 32 | pub const EPIPE = 32; // Broken pipe | |
| 33 | pub const EDOM = 33; // Math argument out of domain of func | |
| 34 | pub const ERANGE = 34; // Math result not representable | |
| 35 | pub const EDEADLK = 35; // Resource deadlock would occur | |
| 36 | pub const ENAMETOOLONG = 36; // File name too long | |
| 37 | pub const ENOLCK = 37; // No record locks available | |
| 38 | pub const ENOSYS = 38; // Function not implemented | |
| 39 | pub const ENOTEMPTY = 39; // Directory not empty | |
| 40 | pub const ELOOP = 40; // Too many symbolic links encountered | |
| 41 | pub const EWOULDBLOCK = EAGAIN; // Operation would block | |
| 42 | pub const ENOMSG = 42; // No message of desired type | |
| 43 | pub const EIDRM = 43; // Identifier removed | |
| 44 | pub const ECHRNG = 44; // Channel number out of range | |
| 45 | pub const EL2NSYNC = 45; // Level 2 not synchronized | |
| 46 | pub const EL3HLT = 46; // Level 3 halted | |
| 47 | pub const EL3RST = 47; // Level 3 reset | |
| 48 | pub const ELNRNG = 48; // Link number out of range | |
| 49 | pub const EUNATCH = 49; // Protocol driver not attached | |
| 50 | pub const ENOCSI = 50; // No CSI structure available | |
| 51 | pub const EL2HLT = 51; // Level 2 halted | |
| 52 | pub const EBADE = 52; // Invalid exchange | |
| 53 | pub const EBADR = 53; // Invalid request descriptor | |
| 54 | pub const EXFULL = 54; // Exchange full | |
| 55 | pub const ENOANO = 55; // No anode | |
| 56 | pub const EBADRQC = 56; // Invalid request code | |
| 57 | pub const EBADSLT = 57; // Invalid slot | |
| 1 | pub const EPERM = 1; /// Operation not permitted | |
| 2 | pub const ENOENT = 2; /// No such file or directory | |
| 3 | pub const ESRCH = 3; /// No such process | |
| 4 | pub const EINTR = 4; /// Interrupted system call | |
| 5 | pub const EIO = 5; /// I/O error | |
| 6 | pub const ENXIO = 6; /// No such device or address | |
| 7 | pub const E2BIG = 7; /// Arg list too long | |
| 8 | pub const ENOEXEC = 8; /// Exec format error | |
| 9 | pub const EBADF = 9; /// Bad file number | |
| 10 | pub const ECHILD = 10; /// No child processes | |
| 11 | pub const EAGAIN = 11; /// Try again | |
| 12 | pub const ENOMEM = 12; /// Out of memory | |
| 13 | pub const EACCES = 13; /// Permission denied | |
| 14 | pub const EFAULT = 14; /// Bad address | |
| 15 | pub const ENOTBLK = 15; /// Block device required | |
| 16 | pub const EBUSY = 16; /// Device or resource busy | |
| 17 | pub const EEXIST = 17; /// File exists | |
| 18 | pub const EXDEV = 18; /// Cross-device link | |
| 19 | pub const ENODEV = 19; /// No such device | |
| 20 | pub const ENOTDIR = 20; /// Not a directory | |
| 21 | pub const EISDIR = 21; /// Is a directory | |
| 22 | pub const EINVAL = 22; /// Invalid argument | |
| 23 | pub const ENFILE = 23; /// File table overflow | |
| 24 | pub const EMFILE = 24; /// Too many open files | |
| 25 | pub const ENOTTY = 25; /// Not a typewriter | |
| 26 | pub const ETXTBSY = 26; /// Text file busy | |
| 27 | pub const EFBIG = 27; /// File too large | |
| 28 | pub const ENOSPC = 28; /// No space left on device | |
| 29 | pub const ESPIPE = 29; /// Illegal seek | |
| 30 | pub const EROFS = 30; /// Read-only file system | |
| 31 | pub const EMLINK = 31; /// Too many links | |
| 32 | pub const EPIPE = 32; /// Broken pipe | |
| 33 | pub const EDOM = 33; /// Math argument out of domain of func | |
| 34 | pub const ERANGE = 34; /// Math result not representable | |
| 35 | pub const EDEADLK = 35; /// Resource deadlock would occur | |
| 36 | pub const ENAMETOOLONG = 36; /// File name too long | |
| 37 | pub const ENOLCK = 37; /// No record locks available | |
| 38 | pub const ENOSYS = 38; /// Function not implemented | |
| 39 | pub const ENOTEMPTY = 39; /// Directory not empty | |
| 40 | pub const ELOOP = 40; /// Too many symbolic links encountered | |
| 41 | pub const EWOULDBLOCK = EAGAIN; /// Operation would block | |
| 42 | pub const ENOMSG = 42; /// No message of desired type | |
| 43 | pub const EIDRM = 43; /// Identifier removed | |
| 44 | pub const ECHRNG = 44; /// Channel number out of range | |
| 45 | pub const EL2NSYNC = 45; /// Level 2 not synchronized | |
| 46 | pub const EL3HLT = 46; /// Level 3 halted | |
| 47 | pub const EL3RST = 47; /// Level 3 reset | |
| 48 | pub const ELNRNG = 48; /// Link number out of range | |
| 49 | pub const EUNATCH = 49; /// Protocol driver not attached | |
| 50 | pub const ENOCSI = 50; /// No CSI structure available | |
| 51 | pub const EL2HLT = 51; /// Level 2 halted | |
| 52 | pub const EBADE = 52; /// Invalid exchange | |
| 53 | pub const EBADR = 53; /// Invalid request descriptor | |
| 54 | pub const EXFULL = 54; /// Exchange full | |
| 55 | pub const ENOANO = 55; /// No anode | |
| 56 | pub const EBADRQC = 56; /// Invalid request code | |
| 57 | pub const EBADSLT = 57; /// Invalid slot | |
| 58 | 58 | |
| 59 | pub const EBFONT = 59; // Bad font file format | |
| 60 | pub const ENOSTR = 60; // Device not a stream | |
| 61 | pub const ENODATA = 61; // No data available | |
| 62 | pub const ETIME = 62; // Timer expired | |
| 63 | pub const ENOSR = 63; // Out of streams resources | |
| 64 | pub const ENONET = 64; // Machine is not on the network | |
| 65 | pub const ENOPKG = 65; // Package not installed | |
| 66 | pub const EREMOTE = 66; // Object is remote | |
| 67 | pub const ENOLINK = 67; // Link has been severed | |
| 68 | pub const EADV = 68; // Advertise error | |
| 69 | pub const ESRMNT = 69; // Srmount error | |
| 70 | pub const ECOMM = 70; // Communication error on send | |
| 71 | pub const EPROTO = 71; // Protocol error | |
| 72 | pub const EMULTIHOP = 72; // Multihop attempted | |
| 73 | pub const EDOTDOT = 73; // RFS specific error | |
| 74 | pub const EBADMSG = 74; // Not a data message | |
| 75 | pub const EOVERFLOW = 75; // Value too large for defined data type | |
| 76 | pub const ENOTUNIQ = 76; // Name not unique on network | |
| 77 | pub const EBADFD = 77; // File descriptor in bad state | |
| 78 | pub const EREMCHG = 78; // Remote address changed | |
| 79 | pub const ELIBACC = 79; // Can not access a needed shared library | |
| 80 | pub const ELIBBAD = 80; // Accessing a corrupted shared library | |
| 81 | pub const ELIBSCN = 81; // .lib section in a.out corrupted | |
| 82 | pub const ELIBMAX = 82; // Attempting to link in too many shared libraries | |
| 83 | pub const ELIBEXEC = 83; // Cannot exec a shared library directly | |
| 84 | pub const EILSEQ = 84; // Illegal byte sequence | |
| 85 | pub const ERESTART = 85; // Interrupted system call should be restarted | |
| 86 | pub const ESTRPIPE = 86; // Streams pipe error | |
| 87 | pub const EUSERS = 87; // Too many users | |
| 88 | pub const ENOTSOCK = 88; // Socket operation on non-socket | |
| 89 | pub const EDESTADDRREQ = 89; // Destination address required | |
| 90 | pub const EMSGSIZE = 90; // Message too long | |
| 91 | pub const EPROTOTYPE = 91; // Protocol wrong type for socket | |
| 92 | pub const ENOPROTOOPT = 92; // Protocol not available | |
| 93 | pub const EPROTONOSUPPORT = 93; // Protocol not supported | |
| 94 | pub const ESOCKTNOSUPPORT = 94; // Socket type not supported | |
| 95 | pub const EOPNOTSUPP = 95; // Operation not supported on transport endpoint | |
| 96 | pub const EPFNOSUPPORT = 96; // Protocol family not supported | |
| 97 | pub const EAFNOSUPPORT = 97; // Address family not supported by protocol | |
| 98 | pub const EADDRINUSE = 98; // Address already in use | |
| 99 | pub const EADDRNOTAVAIL = 99; // Cannot assign requested address | |
| 100 | pub const ENETDOWN = 100; // Network is down | |
| 101 | pub const ENETUNREACH = 101; // Network is unreachable | |
| 102 | pub const ENETRESET = 102; // Network dropped connection because of reset | |
| 103 | pub const ECONNABORTED = 103; // Software caused connection abort | |
| 104 | pub const ECONNRESET = 104; // Connection reset by peer | |
| 105 | pub const ENOBUFS = 105; // No buffer space available | |
| 106 | pub const EISCONN = 106; // Transport endpoint is already connected | |
| 107 | pub const ENOTCONN = 107; // Transport endpoint is not connected | |
| 108 | pub const ESHUTDOWN = 108; // Cannot send after transport endpoint shutdown | |
| 109 | pub const ETOOMANYREFS = 109; // Too many references: cannot splice | |
| 110 | pub const ETIMEDOUT = 110; // Connection timed out | |
| 111 | pub const ECONNREFUSED = 111; // Connection refused | |
| 112 | pub const EHOSTDOWN = 112; // Host is down | |
| 113 | pub const EHOSTUNREACH = 113; // No route to host | |
| 114 | pub const EALREADY = 114; // Operation already in progress | |
| 115 | pub const EINPROGRESS = 115; // Operation now in progress | |
| 116 | pub const ESTALE = 116; // Stale NFS file handle | |
| 117 | pub const EUCLEAN = 117; // Structure needs cleaning | |
| 118 | pub const ENOTNAM = 118; // Not a XENIX named type file | |
| 119 | pub const ENAVAIL = 119; // No XENIX semaphores available | |
| 120 | pub const EISNAM = 120; // Is a named type file | |
| 121 | pub const EREMOTEIO = 121; // Remote I/O error | |
| 122 | pub const EDQUOT = 122; // Quota exceeded | |
| 59 | pub const EBFONT = 59; /// Bad font file format | |
| 60 | pub const ENOSTR = 60; /// Device not a stream | |
| 61 | pub const ENODATA = 61; /// No data available | |
| 62 | pub const ETIME = 62; /// Timer expired | |
| 63 | pub const ENOSR = 63; /// Out of streams resources | |
| 64 | pub const ENONET = 64; /// Machine is not on the network | |
| 65 | pub const ENOPKG = 65; /// Package not installed | |
| 66 | pub const EREMOTE = 66; /// Object is remote | |
| 67 | pub const ENOLINK = 67; /// Link has been severed | |
| 68 | pub const EADV = 68; /// Advertise error | |
| 69 | pub const ESRMNT = 69; /// Srmount error | |
| 70 | pub const ECOMM = 70; /// Communication error on send | |
| 71 | pub const EPROTO = 71; /// Protocol error | |
| 72 | pub const EMULTIHOP = 72; /// Multihop attempted | |
| 73 | pub const EDOTDOT = 73; /// RFS specific error | |
| 74 | pub const EBADMSG = 74; /// Not a data message | |
| 75 | pub const EOVERFLOW = 75; /// Value too large for defined data type | |
| 76 | pub const ENOTUNIQ = 76; /// Name not unique on network | |
| 77 | pub const EBADFD = 77; /// File descriptor in bad state | |
| 78 | pub const EREMCHG = 78; /// Remote address changed | |
| 79 | pub const ELIBACC = 79; /// Can not access a needed shared library | |
| 80 | pub const ELIBBAD = 80; /// Accessing a corrupted shared library | |
| 81 | pub const ELIBSCN = 81; /// .lib section in a.out corrupted | |
| 82 | pub const ELIBMAX = 82; /// Attempting to link in too many shared libraries | |
| 83 | pub const ELIBEXEC = 83; /// Cannot exec a shared library directly | |
| 84 | pub const EILSEQ = 84; /// Illegal byte sequence | |
| 85 | pub const ERESTART = 85; /// Interrupted system call should be restarted | |
| 86 | pub const ESTRPIPE = 86; /// Streams pipe error | |
| 87 | pub const EUSERS = 87; /// Too many users | |
| 88 | pub const ENOTSOCK = 88; /// Socket operation on non-socket | |
| 89 | pub const EDESTADDRREQ = 89; /// Destination address required | |
| 90 | pub const EMSGSIZE = 90; /// Message too long | |
| 91 | pub const EPROTOTYPE = 91; /// Protocol wrong type for socket | |
| 92 | pub const ENOPROTOOPT = 92; /// Protocol not available | |
| 93 | pub const EPROTONOSUPPORT = 93; /// Protocol not supported | |
| 94 | pub const ESOCKTNOSUPPORT = 94; /// Socket type not supported | |
| 95 | pub const EOPNOTSUPP = 95; /// Operation not supported on transport endpoint | |
| 96 | pub const EPFNOSUPPORT = 96; /// Protocol family not supported | |
| 97 | pub const EAFNOSUPPORT = 97; /// Address family not supported by protocol | |
| 98 | pub const EADDRINUSE = 98; /// Address already in use | |
| 99 | pub const EADDRNOTAVAIL = 99; /// Cannot assign requested address | |
| 100 | pub const ENETDOWN = 100; /// Network is down | |
| 101 | pub const ENETUNREACH = 101; /// Network is unreachable | |
| 102 | pub const ENETRESET = 102; /// Network dropped connection because of reset | |
| 103 | pub const ECONNABORTED = 103; /// Software caused connection abort | |
| 104 | pub const ECONNRESET = 104; /// Connection reset by peer | |
| 105 | pub const ENOBUFS = 105; /// No buffer space available | |
| 106 | pub const EISCONN = 106; /// Transport endpoint is already connected | |
| 107 | pub const ENOTCONN = 107; /// Transport endpoint is not connected | |
| 108 | pub const ESHUTDOWN = 108; /// Cannot send after transport endpoint shutdown | |
| 109 | pub const ETOOMANYREFS = 109; /// Too many references: cannot splice | |
| 110 | pub const ETIMEDOUT = 110; /// Connection timed out | |
| 111 | pub const ECONNREFUSED = 111; /// Connection refused | |
| 112 | pub const EHOSTDOWN = 112; /// Host is down | |
| 113 | pub const EHOSTUNREACH = 113; /// No route to host | |
| 114 | pub const EALREADY = 114; /// Operation already in progress | |
| 115 | pub const EINPROGRESS = 115; /// Operation now in progress | |
| 116 | pub const ESTALE = 116; /// Stale NFS file handle | |
| 117 | pub const EUCLEAN = 117; /// Structure needs cleaning | |
| 118 | pub const ENOTNAM = 118; /// Not a XENIX named type file | |
| 119 | pub const ENAVAIL = 119; /// No XENIX semaphores available | |
| 120 | pub const EISNAM = 120; /// Is a named type file | |
| 121 | pub const EREMOTEIO = 121; /// Remote I/O error | |
| 122 | pub const EDQUOT = 122; /// Quota exceeded | |
| 123 | 123 | |
| 124 | pub const ENOMEDIUM = 123; // No medium found | |
| 125 | pub const EMEDIUMTYPE = 124; // Wrong medium type | |
| 124 | pub const ENOMEDIUM = 123; /// No medium found | |
| 125 | pub const EMEDIUMTYPE = 124; /// Wrong medium type | |
| 126 | 126 | |
| 127 | 127 | // nameserver query return codes |
| 128 | pub const ENSROK = 0; // DNS server returned answer with no data | |
| 129 | pub const ENSRNODATA = 160; // DNS server returned answer with no data | |
| 130 | pub const ENSRFORMERR = 161; // DNS server claims query was misformatted | |
| 131 | pub const ENSRSERVFAIL = 162; // DNS server returned general failure | |
| 132 | pub const ENSRNOTFOUND = 163; // Domain name not found | |
| 133 | pub const ENSRNOTIMP = 164; // DNS server does not implement requested operation | |
| 134 | pub const ENSRREFUSED = 165; // DNS server refused query | |
| 135 | pub const ENSRBADQUERY = 166; // Misformatted DNS query | |
| 136 | pub const ENSRBADNAME = 167; // Misformatted domain name | |
| 137 | pub const ENSRBADFAMILY = 168; // Unsupported address family | |
| 138 | pub const ENSRBADRESP = 169; // Misformatted DNS reply | |
| 139 | pub const ENSRCONNREFUSED = 170; // Could not contact DNS servers | |
| 140 | pub const ENSRTIMEOUT = 171; // Timeout while contacting DNS servers | |
| 141 | pub const ENSROF = 172; // End of file | |
| 142 | pub const ENSRFILE = 173; // Error reading file | |
| 143 | pub const ENSRNOMEM = 174; // Out of memory | |
| 144 | pub const ENSRDESTRUCTION = 175; // Application terminated lookup | |
| 145 | pub const ENSRQUERYDOMAINTOOLONG = 176; // Domain name is too long | |
| 146 | pub const ENSRCNAMELOOP = 177; // Domain name is too long | |
| 128 | pub const ENSROK = 0; /// DNS server returned answer with no data | |
| 129 | pub const ENSRNODATA = 160; /// DNS server returned answer with no data | |
| 130 | pub const ENSRFORMERR = 161; /// DNS server claims query was misformatted | |
| 131 | pub const ENSRSERVFAIL = 162; /// DNS server returned general failure | |
| 132 | pub const ENSRNOTFOUND = 163; /// Domain name not found | |
| 133 | pub const ENSRNOTIMP = 164; /// DNS server does not implement requested operation | |
| 134 | pub const ENSRREFUSED = 165; /// DNS server refused query | |
| 135 | pub const ENSRBADQUERY = 166; /// Misformatted DNS query | |
| 136 | pub const ENSRBADNAME = 167; /// Misformatted domain name | |
| 137 | pub const ENSRBADFAMILY = 168; /// Unsupported address family | |
| 138 | pub const ENSRBADRESP = 169; /// Misformatted DNS reply | |
| 139 | pub const ENSRCONNREFUSED = 170; /// Could not contact DNS servers | |
| 140 | pub const ENSRTIMEOUT = 171; /// Timeout while contacting DNS servers | |
| 141 | pub const ENSROF = 172; /// End of file | |
| 142 | pub const ENSRFILE = 173; /// Error reading file | |
| 143 | pub const ENSRNOMEM = 174; /// Out of memory | |
| 144 | pub const ENSRDESTRUCTION = 175; /// Application terminated lookup | |
| 145 | pub const ENSRQUERYDOMAINTOOLONG = 176; /// Domain name is too long | |
| 146 | pub const ENSRCNAMELOOP = 177; /// Domain name is too long |
std/os/index.zig+56-37| ... | ... | @@ -56,43 +56,40 @@ error WouldBlock; |
| 56 | 56 | /// appropriate OS-specific library call. Otherwise it uses the zig standard |
| 57 | 57 | /// library implementation. |
| 58 | 58 | pub fn getRandomBytes(buf: []u8) -> %void { |
| 59 | while (true) { | |
| 60 | const err = switch (builtin.os) { | |
| 61 | Os.linux => { | |
| 62 | // TODO check libc version and potentially call c.getrandom. | |
| 63 | // See #397 | |
| 64 | posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0)) | |
| 65 | }, | |
| 66 | Os.darwin, Os.macosx, Os.ios => { | |
| 67 | if (builtin.link_libc) { | |
| 68 | if (posix.getrandom(buf.ptr, buf.len) == -1) *c._errno() else 0 | |
| 69 | } else { | |
| 70 | posix.getErrno(posix.getrandom(buf.ptr, buf.len)) | |
| 71 | } | |
| 72 | }, | |
| 73 | Os.windows => { | |
| 74 | var hCryptProv: windows.HCRYPTPROV = undefined; | |
| 75 | if (!windows.CryptAcquireContext(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) { | |
| 76 | return error.Unexpected; | |
| 59 | switch (builtin.os) { | |
| 60 | Os.linux => while (true) { | |
| 61 | // TODO check libc version and potentially call c.getrandom. | |
| 62 | // See #397 | |
| 63 | const err = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0)); | |
| 64 | if (err > 0) { | |
| 65 | return switch (err) { | |
| 66 | errno.EINVAL => unreachable, | |
| 67 | errno.EFAULT => unreachable, | |
| 68 | errno.EINTR => continue, | |
| 69 | else => error.Unexpected, | |
| 77 | 70 | } |
| 78 | defer _ = windows.CryptReleaseContext(hCryptProv, 0); | |
| 71 | } | |
| 72 | return; | |
| 73 | }, | |
| 74 | Os.darwin, Os.macosx, Os.ios => { | |
| 75 | const fd = %return posixOpen("/dev/urandom", posix.O_RDONLY|posix.O_CLOEXEC, | |
| 76 | 0, null); | |
| 77 | defer posixClose(fd); | |
| 79 | 78 | |
| 80 | if (!windows.CryptGenRandom(hCryptProv, windows.DWORD(buf.len), buf.ptr)) { | |
| 81 | return error.Unexpected; | |
| 82 | } | |
| 83 | return; | |
| 84 | }, | |
| 85 | else => @compileError("Unsupported OS"), | |
| 86 | }; | |
| 87 | if (err > 0) { | |
| 88 | return switch (err) { | |
| 89 | errno.EINVAL => unreachable, | |
| 90 | errno.EFAULT => unreachable, | |
| 91 | errno.EINTR => continue, | |
| 92 | else => error.Unexpected, | |
| 79 | %return posixRead(fd, buf); | |
| 80 | }, | |
| 81 | Os.windows => { | |
| 82 | var hCryptProv: windows.HCRYPTPROV = undefined; | |
| 83 | if (!windows.CryptAcquireContext(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) { | |
| 84 | return error.Unexpected; | |
| 93 | 85 | } |
| 94 | } | |
| 95 | return; | |
| 86 | defer _ = windows.CryptReleaseContext(hCryptProv, 0); | |
| 87 | ||
| 88 | if (!windows.CryptGenRandom(hCryptProv, windows.DWORD(buf.len), buf.ptr)) { | |
| 89 | return error.Unexpected; | |
| 90 | } | |
| 91 | }, | |
| 92 | else => @compileError("Unsupported OS"), | |
| 96 | 93 | } |
| 97 | 94 | } |
| 98 | 95 | |
| ... | ... | @@ -128,12 +125,34 @@ pub fn posixClose(fd: i32) { |
| 128 | 125 | } |
| 129 | 126 | } |
| 130 | 127 | |
| 128 | /// Calls POSIX read, and keeps trying if it gets interrupted. | |
| 129 | pub fn posixRead(fd: i32, buf: []u8) -> %void { | |
| 130 | var index: usize = 0; | |
| 131 | while (index < buf.len) { | |
| 132 | const amt_written = posix.read(fd, &buf[index], buf.len - index); | |
| 133 | const err = posix.getErrno(amt_written); | |
| 134 | if (err > 0) { | |
| 135 | return switch (err) { | |
| 136 | errno.EINTR => continue, | |
| 137 | errno.EINVAL, errno.EFAULT => unreachable, | |
| 138 | errno.EAGAIN => error.WouldBlock, | |
| 139 | errno.EBADF => error.FileClosed, | |
| 140 | errno.EIO => error.InputOutput, | |
| 141 | errno.EISDIR => error.IsDir, | |
| 142 | errno.ENOBUFS, errno.ENOMEM => error.SystemResources, | |
| 143 | else => return error.Unexpected, | |
| 144 | } | |
| 145 | } | |
| 146 | index += amt_written; | |
| 147 | } | |
| 148 | } | |
| 149 | ||
| 131 | 150 | error WouldBlock; |
| 132 | 151 | error FileClosed; |
| 133 | 152 | error DestinationAddressRequired; |
| 134 | 153 | error DiskQuota; |
| 135 | 154 | error FileTooBig; |
| 136 | error FileSystem; | |
| 155 | error InputOutput; | |
| 137 | 156 | error NoSpaceLeft; |
| 138 | 157 | error BrokenPipe; |
| 139 | 158 | error Unexpected; |
| ... | ... | @@ -152,7 +171,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void { |
| 152 | 171 | errno.EDESTADDRREQ => error.DestinationAddressRequired, |
| 153 | 172 | errno.EDQUOT => error.DiskQuota, |
| 154 | 173 | errno.EFBIG => error.FileTooBig, |
| 155 | errno.EIO => error.FileSystem, | |
| 174 | errno.EIO => error.InputOutput, | |
| 156 | 175 | errno.ENOSPC => error.NoSpaceLeft, |
| 157 | 176 | errno.EPERM => error.AccessDenied, |
| 158 | 177 | errno.EPIPE => error.BrokenPipe, |
| ... | ... | @@ -213,7 +232,7 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) -> bool { |
| 213 | 232 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 214 | 233 | /// Calls POSIX open, keeps trying if it gets interrupted, and translates |
| 215 | 234 | /// the return value into zig errors. |
| 216 | pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?&Allocator) -> %i32 { | |
| 235 | pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Allocator) -> %i32 { | |
| 217 | 236 | var stack_buf: [max_noalloc_path_len]u8 = undefined; |
| 218 | 237 | var path0: []u8 = undefined; |
| 219 | 238 | var need_free = false; |
std/os/linux.zig+17-16| ... | ... | @@ -309,8 +309,8 @@ pub const TIOCGPKT = 0x80045438; |
| 309 | 309 | pub const TIOCGPTLCK = 0x80045439; |
| 310 | 310 | pub const TIOCGEXCL = 0x80045440; |
| 311 | 311 | |
| 312 | fn unsigned(s: i32) -> u32 { *@ptrCast(&u32, &s) } | |
| 313 | fn signed(s: u32) -> i32 { *@ptrCast(&i32, &s) } | |
| 312 | fn unsigned(s: i32) -> u32 { @bitCast(u32, s) } | |
| 313 | fn signed(s: u32) -> i32 { @bitCast(i32, s) } | |
| 314 | 314 | pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) } |
| 315 | 315 | pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) } |
| 316 | 316 | pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) } |
| ... | ... | @@ -328,7 +328,7 @@ pub const winsize = extern struct { |
| 328 | 328 | |
| 329 | 329 | /// Get the errno from a syscall return value, or 0 for no error. |
| 330 | 330 | pub fn getErrno(r: usize) -> usize { |
| 331 | const signed_r = *@ptrCast(&const isize, &r); | |
| 331 | const signed_r = @bitCast(isize, r); | |
| 332 | 332 | if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0 |
| 333 | 333 | } |
| 334 | 334 | |
| ... | ... | @@ -353,7 +353,7 @@ pub fn getcwd(buf: &u8, size: usize) -> usize { |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize { |
| 356 | arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), usize(count)) | |
| 356 | arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count) | |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | pub fn isatty(fd: i32) -> bool { |
| ... | ... | @@ -365,14 +365,15 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) - |
| 365 | 365 | arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len) |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | pub fn mkdir(path: &const u8, mode: usize) -> usize { | |
| 368 | pub fn mkdir(path: &const u8, mode: u32) -> usize { | |
| 369 | 369 | arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode) |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: usize) | |
| 372 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) | |
| 373 | 373 | -> usize |
| 374 | 374 | { |
| 375 | arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), offset) | |
| 375 | arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), | |
| 376 | @bitCast(usize, offset)) | |
| 376 | 377 | } |
| 377 | 378 | |
| 378 | 379 | pub fn munmap(address: &u8, length: usize) -> usize { |
| ... | ... | @@ -415,7 +416,7 @@ pub fn rename(old: &const u8, new: &const u8) -> usize { |
| 415 | 416 | arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)) |
| 416 | 417 | } |
| 417 | 418 | |
| 418 | pub fn open(path: &const u8, flags: usize, perm: usize) -> usize { | |
| 419 | pub fn open(path: &const u8, flags: u32, perm: usize) -> usize { | |
| 419 | 420 | arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm) |
| 420 | 421 | } |
| 421 | 422 | |
| ... | ... | @@ -431,12 +432,12 @@ pub fn close(fd: i32) -> usize { |
| 431 | 432 | arch.syscall1(arch.SYS_close, usize(fd)) |
| 432 | 433 | } |
| 433 | 434 | |
| 434 | pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize { | |
| 435 | arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos) | |
| 435 | pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize { | |
| 436 | arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos) | |
| 436 | 437 | } |
| 437 | 438 | |
| 438 | 439 | pub fn exit(status: i32) -> noreturn { |
| 439 | _ = arch.syscall1(arch.SYS_exit, usize(status)); | |
| 440 | _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); | |
| 440 | 441 | unreachable |
| 441 | 442 | } |
| 442 | 443 | |
| ... | ... | @@ -453,7 +454,7 @@ pub fn unlink(path: &const u8) -> usize { |
| 453 | 454 | } |
| 454 | 455 | |
| 455 | 456 | pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize { |
| 456 | arch.syscall4(arch.SYS_wait4, usize(pid), @ptrToInt(status), usize(options), 0) | |
| 457 | arch.syscall4(arch.SYS_wait4, usize(pid), @ptrToInt(status), @bitCast(usize, isize(options)), 0) | |
| 457 | 458 | } |
| 458 | 459 | |
| 459 | 460 | const NSIG = 65; |
| ... | ... | @@ -461,11 +462,11 @@ const sigset_t = [128]u8; |
| 461 | 462 | const all_mask = []u8 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; |
| 462 | 463 | const app_mask = []u8 { 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, }; |
| 463 | 464 | |
| 464 | pub fn raise(sig: i32) -> i32 { | |
| 465 | pub fn raise(sig: i32) -> usize { | |
| 465 | 466 | var set: sigset_t = undefined; |
| 466 | 467 | blockAppSignals(&set); |
| 467 | 468 | const tid = i32(arch.syscall0(arch.SYS_gettid)); |
| 468 | const ret = i32(arch.syscall2(arch.SYS_tkill, usize(tid), usize(sig))); | |
| 469 | const ret = arch.syscall2(arch.SYS_tkill, usize(tid), usize(sig)); | |
| 469 | 470 | restoreSignals(&set); |
| 470 | 471 | return ret; |
| 471 | 472 | } |
| ... | ... | @@ -630,9 +631,9 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: |
| 630 | 631 | // return ifr.ifr_ifindex; |
| 631 | 632 | // } |
| 632 | 633 | |
| 633 | pub const stat = arch.stat; | |
| 634 | pub const Stat = arch.Stat; | |
| 634 | 635 | pub const timespec = arch.timespec; |
| 635 | 636 | |
| 636 | pub fn fstat(fd: i32, stat_buf: &stat) -> usize { | |
| 637 | pub fn fstat(fd: i32, stat_buf: &Stat) -> usize { | |
| 637 | 638 | arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)) |
| 638 | 639 | } |
std/os/linux_x86_64.zig+2-1| ... | ... | @@ -454,7 +454,8 @@ pub const msghdr = extern struct { |
| 454 | 454 | msg_flags: i32, |
| 455 | 455 | }; |
| 456 | 456 | |
| 457 | pub const stat = extern struct { | |
| 457 | /// Renamed to Stat to not conflict with the stat function. | |
| 458 | pub const Stat = extern struct { | |
| 458 | 459 | dev: u64, |
| 459 | 460 | ino: u64, |
| 460 | 461 | nlink: usize, |
test/cases/asm.zig+2-2| ... | ... | @@ -2,7 +2,7 @@ const config = @import("builtin"); |
| 2 | 2 | const assert = @import("std").debug.assert; |
| 3 | 3 | |
| 4 | 4 | comptime { |
| 5 | if (config.arch == config.Arch.x86_64) { | |
| 5 | if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) { | |
| 6 | 6 | asm volatile ( |
| 7 | 7 | \\.globl aoeu; |
| 8 | 8 | \\.type aoeu, @function; |
| ... | ... | @@ -12,7 +12,7 @@ comptime { |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "module level assembly" { |
| 15 | if (config.arch == config.Arch.x86_64) { | |
| 15 | if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) { | |
| 16 | 16 | assert(aoeu() == 1234); |
| 17 | 17 | } |
| 18 | 18 | } |