authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-27 00:11:09-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-27 00:11:09-04:00
log29a418c9d5b3b9c78b707e5b6a119d48ecce9a6a
treeb0716f34ca3170edd1784c46c18a4e4595e52e34
parent105a09e1d654c76addc26fd5616c06fcbd8b6a12

progress toward tests passing on MacOS


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}")
297297install(FILES "${CMAKE_SOURCE_DIR}/std/net.zig" DESTINATION "${ZIG_STD_DEST}")
298298install(FILES "${CMAKE_SOURCE_DIR}/std/os/child_process.zig" DESTINATION "${ZIG_STD_DEST}/os")
299299install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin.zig" DESTINATION "${ZIG_STD_DEST}/os")
300install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin_x86_64.zig" DESTINATION "${ZIG_STD_DEST}/os")
301300install(FILES "${CMAKE_SOURCE_DIR}/std/os/errno.zig" DESTINATION "${ZIG_STD_DEST}/os")
302301install(FILES "${CMAKE_SOURCE_DIR}/std/os/index.zig" DESTINATION "${ZIG_STD_DEST}/os")
303302install(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) {
28912891}
28922892
28932893static 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
28942898 IrInstruction *use_target_value = src_use_node->data.use.value;
28952899 if (use_target_value->value.type->id == TypeTableEntryIdInvalid) {
28962900 dst_use_node->owner->any_imports_failed = true;
src/os.cpp+2-5
......@@ -709,10 +709,6 @@ int os_delete_file(Buf *path) {
709709 }
710710}
711711
712void os_init(void) {
713 srand((unsigned)time(NULL));
714}
715
716712int os_rename(Buf *src_path, Buf *dest_path) {
717713 if (rename(buf_ptr(src_path), buf_ptr(dest_path)) == -1) {
718714 return ErrorFileSystem;
......@@ -805,7 +801,8 @@ int os_make_dir(Buf *path) {
805801#endif
806802}
807803
808int zig_os_init(void) {
804int os_init(void) {
805 srand((unsigned)time(NULL));
809806#if defined(ZIG_OS_WINDOWS)
810807 unsigned __int64 frequency;
811808 if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) {
src/os.hpp+1-1
......@@ -27,8 +27,8 @@ struct Termination {
2727 int code;
2828};
2929
30int os_init(void);
3031
31void os_init(void);
3232void os_spawn_process(const char *exe, ZigList<const char *> &args, Termination *term);
3333int os_exec_process(const char *exe, ZigList<const char *> &args,
3434 Termination *term, Buf *out_stderr, Buf *out_stdout);
std/c/darwin.zig+30-2
......@@ -1,4 +1,32 @@
1pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize) -> c_int;
2fn extern "c" __error() -> &c_int;
1extern "c" fn __error() -> &c_int;
32
43pub const _errno = __error;
4
5/// Renamed to Stat to not conflict with the stat function.
6pub 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
29pub 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) {
88 Os.darwin, Os.macosx, Os.ios => @import("darwin.zig"),
99 else => empty_import,
1010};
11const empty_import = @import("../empty.zig");
1112
1213pub extern "c" fn abort() -> noreturn;
13
14const empty_import = @import("../empty.zig");
14pub extern "c" fn exit(code: c_int) -> noreturn;
15pub extern "c" fn isatty(fd: c_int) -> c_int;
16pub extern "c" fn close(fd: c_int) -> c_int;
17pub extern "c" fn fstat(fd: c_int, buf: &stat) -> c_int;
18pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) -> isize;
19pub extern "c" fn open(path: &const u8, oflag: c_int, ...) -> c_int;
20pub extern "c" fn raise(sig: c_int) -> c_int;
21pub extern "c" fn read(fd: c_int, buf: &c_void, nbyte: usize) -> isize;
22pub extern "c" fn stat(noalias path: &const u8, noalias buf: &Stat) -> c_int;
23pub extern "c" fn write(fd: c_int, buf: &const c_void, nbyte: usize) -> c_int;
24pub extern "c" fn mmap(addr: ?&c_void, len: usize, prot: c_int, flags: c_int,
25 fd: c_int, offset: isize) -> ?&c_void;
26pub extern "c" fn munmap(addr: &c_void, len: usize) -> c_int;
27pub extern "c" fn unlink(path: &const u8) -> c_int;
28pub extern "c" fn getcwd(buf: &u8, size: usize) -> ?&u8;
29pub extern "c" fn waitpid(pid: c_int, stat_loc: &c_int, options: c_int) -> c_int;
30pub extern "c" fn fork() -> c_int;
31pub extern "c" fn pipe(fds: &c_int) -> c_int;
32pub extern "c" fn mkdir(path: &const u8, mode: c_uint) -> c_int;
33pub extern "c" fn symlink(existing: &const u8, new: &const u8) -> c_int;
34pub extern "c" fn rename(old: &const u8, new: &const u8) -> c_int;
35pub extern "c" fn chdir(path: &const u8) -> c_int;
36pub extern "c" fn execve(path: &const u8, argv: &const ?&const u8,
37 envp: &const ?&const u8) -> c_int;
38pub extern "c" fn dup(fd: c_int) -> c_int;
39pub 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");
22const Os = builtin.Os;
33const system = switch(builtin.os) {
44 Os.linux => @import("os/linux.zig"),
5 Os.darwin => @import("os/darwin.zig"),
5 Os.darwin, Os.macosx, Os.ios => @import("os/darwin.zig"),
66 Os.windows => @import("os/windows/index.zig"),
77 else => @compileError("Unsupported OS"),
88};
9const c = @import("c/index.zig");
910
1011const errno = @import("os/errno.zig");
1112const math = @import("math/index.zig");
......@@ -180,7 +181,11 @@ pub const OutStream = struct {
180181
181182 pub fn isTty(self: &OutStream) -> %bool {
182183 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 }
184189 } else if (is_windows) {
185190 return os.windowsIsTty(%return self.getHandle());
186191 } else {
......@@ -417,7 +422,11 @@ pub const InStream = struct {
417422
418423 pub fn isTty(self: &InStream) -> %bool {
419424 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 }
421430 } else if (is_windows) {
422431 return os.windowsIsTty(%return self.getHandle());
423432 } else {
std/os/child_process.zig+3-30
......@@ -229,42 +229,15 @@ fn forkChildErrReport(fd: i32, err: error) -> noreturn {
229229}
230230
231231const ErrInt = @IntType(false, @sizeOf(error) * 8);
232
232233fn writeIntFd(fd: i32, value: ErrInt) -> %void {
233234 var bytes: [@sizeOf(ErrInt)]u8 = undefined;
234235 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;
249237}
250238
251239fn readIntFd(fd: i32) -> %ErrInt {
252240 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;
268242 return mem.readInt(bytes[0..], ErrInt, true);
269243}
270
std/os/darwin.zig+136-44
......@@ -1,18 +1,41 @@
1
2const builtin = @import("builtin");
3const arch = switch (builtin.arch) {
4 builtin.Arch.x86_64 => @import("darwin_x86_64.zig"),
5 else => @compileError("unsupported arch"),
6};
7
8const errno = @import("errno.zig");
1const c = @import("../c/index.zig");
2const assert = @import("../debug.zig").assert;
93
104pub const STDIN_FILENO = 0;
115pub const STDOUT_FILENO = 1;
126pub const STDERR_FILENO = 2;
137
8pub const PROT_NONE = 0x00; /// [MC2] no permissions
9pub const PROT_READ = 0x01; /// [MC2] pages can be read
10pub const PROT_WRITE = 0x02; /// [MC2] pages can be written
11pub const PROT_EXEC = 0x04; /// [MC2] pages can be executed
12
13pub const MAP_ANONYMOUS = 0x1000; /// allocated from memory, swap space
14pub const MAP_FILE = 0x0000; /// map from file (default)
15pub const MAP_FIXED = 0x0010; /// interpret addr exactly
16pub const MAP_HASSEMAPHORE = 0x0200; /// region may contain semaphores
17pub const MAP_PRIVATE = 0x0002; /// changes are private
18pub const MAP_SHARED = 0x0001; /// share changes
19pub const MAP_NOCACHE = 0x0400; /// don't cache pages for this mapping
20pub const MAP_NORESERVE = 0x0040; /// don't reserve needed swap area
21pub const MAP_FAILED = @maxValue(usize);
22
1423pub const O_LARGEFILE = 0x0000;
15pub const O_RDONLY = 0x0000;
24
25pub const O_RDONLY = 0x0000; /// open for reading only
26pub const O_WRONLY = 0x0001; /// open for writing only
27pub const O_RDWR = 0x0002; /// open for reading and writing
28pub const O_NONBLOCK = 0x0004; /// do not block on open or for data to become available
29pub const O_APPEND = 0x0008; /// append on each write
30pub const O_CREAT = 0x0200; /// create file if it does not exist
31pub const O_TRUNC = 0x0400; /// truncate size to 0
32pub const O_EXCL = 0x0800; /// error if O_CREAT and the file exists
33pub const O_SHLOCK = 0x0010; /// atomically obtain a shared lock
34pub const O_EXLOCK = 0x0020; /// atomically obtain an exclusive lock
35pub const O_NOFOLLOW = 0x0100; /// do not follow symlinks
36pub const O_SYMLINK = 0x200000; /// allow open of symlinks
37pub const O_EVTONLY = 0x8000; /// descriptor requested for event notifications only
38pub const O_CLOEXEC = 0x1000000; /// mark as close-on-exec
1639
1740pub const SEEK_SET = 0x0;
1841pub const SEEK_CUR = 0x1;
......@@ -53,64 +76,133 @@ pub const SIGPWR = 30;
5376pub const SIGSYS = 31;
5477pub const SIGUNUSED = SIGSYS;
5578
56pub fn exit(status: usize) -> noreturn {
57 _ = arch.syscall1(arch.SYS_exit, status);
58 unreachable
59}
79fn wstatus(x: i32) -> i32 { x & 0o177 }
80const wstopped = 0o177;
81pub fn WEXITSTATUS(x: i32) -> i32 { x >> 8 }
82pub fn WTERMSIG(x: i32) -> i32 { wstatus(x) }
83pub fn WSTOPSIG(x: i32) -> i32 { x >> 8 }
84pub fn WIFEXITED(x: i32) -> bool { wstatus(x) == 0 }
85pub fn WIFSTOPPED(x: i32) -> bool { wstatus(x) == wstopped and WSTOPSIG(x) != 0x13 }
86pub fn WIFSIGNALED(x: i32) -> bool { wstatus(x) != wstopped and wstatus(x) != 0 }
6087
6188/// Get the errno from a syscall return value, or 0 for no error.
6289pub fn getErrno(r: usize) -> usize {
63 const signed_r = *@ptrCast(&const isize, &r);
90 const signed_r = @bitCast(isize, r);
6491 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
6592}
6693
67pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
68 arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count)
94pub fn close(fd: i32) -> usize {
95 errnoWrap(c.close(fd))
6996}
7097
71pub fn close(fd: i32) -> usize {
72 arch.syscall1(arch.SYS_close, usize(fd))
98pub fn abort() -> noreturn {
99 c.abort()
100}
101
102pub fn exit(code: i32) -> noreturn {
103 c.exit(code)
104}
105
106pub fn isatty(fd: i32) -> bool {
107 c.isatty(fd) == 0
108}
109
110pub fn fstat(fd: i32, buf: &c.stat) -> usize {
111 errnoWrap(c.fstat(fd, buf))
112}
113
114pub fn lseek(fd: i32, offset: isize, whence: c_int) -> usize {
115 errnoWrap(c.lseek(fd, buf, whence))
116}
117
118pub fn open(path: &const u8, flags: u32, mode: usize) -> usize {
119 errnoWrap(c.open(path, @bitCast(c_int, flags), mode))
120}
121
122pub fn raise(sig: i32) -> usize {
123 errnoWrap(c.raise(sig))
124}
125
126pub fn read(fd: i32, buf: &u8, nbyte: usize) -> usize {
127 errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte))
128}
129
130pub fn stat(noalias path: &const u8, noalias buf: &stat) -> usize {
131 errnoWrap(c.stat(path, buf))
132}
133
134pub fn write(fd: i32, buf: &const u8, nbyte: usize) -> usize {
135 errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte))
136}
137
138pub 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);
73145}
74146
75pub fn open(path: &const u8, flags: usize, perm: usize) -> usize {
76 arch.syscall3(arch.SYS_open, usize(path), flags, perm)
147pub fn munmap(address: &u8, length: usize) -> usize {
148 errnoWrap(c.munmap(@ptrCast(&c_void, address), length))
77149}
78150
79pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
80 arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count)
151pub fn unlink(path: &const u8) -> usize {
152 errnoWrap(c.unlink(path))
81153}
82154
83pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
84 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
155pub fn getcwd(buf: &u8, size: usize) -> usize {
156 if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0
85157}
86158
87pub const stat = arch.stat;
88pub const timespec = arch.timespec;
159pub 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}
89163
90pub fn fstat(fd: i32, stat_buf: &stat) -> usize {
91 arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf))
164pub fn fork() -> usize {
165 errnoWrap(c.fork())
92166}
93167
94error Unexpected;
168pub 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}
95172
96pub fn getrandom(buf: &u8, count: usize) -> usize {
97 const rr = open_c(c"/dev/urandom", O_LARGEFILE | O_RDONLY, 0);
173pub fn mkdir(path: &const u8, mode: u32) -> usize {
174 errnoWrap(c.mkdir(path, mode))
175}
98176
99 if(getErrno(rr) > 0) return rr;
177pub fn symlink(existing: &const u8, new: &const u8) -> usize {
178 errnoWrap(c.symlink(existing, new))
179}
100180
101 var fd: i32 = i32(rr);
102 const readRes = read(fd, buf, count);
103 readRes
181pub fn rename(old: &const u8, new: &const u8) -> usize {
182 errnoWrap(c.rename(old, new))
104183}
105184
106pub 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
185pub fn chdir(path: &const u8) -> usize {
186 errnoWrap(c.chdir(path))
187}
188
189pub 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
195pub fn dup2(old: i32, new: i32) -> usize {
196 errnoWrap(c.dup2(old, new))
197}
109198
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.
202fn errnoWrap(value: isize) -> usize {
203 @bitCast(usize, if (value == -1) {
204 -isize(*c._errno())
205 } else {
206 value
207 })
116208}
std/os/darwin_x86_64.zig deleted-87
......@@ -1,87 +0,0 @@
1
2pub const SYSCALL_CLASS_SHIFT = 24;
3pub const SYSCALL_CLASS_MASK = 0xFF << SYSCALL_CLASS_SHIFT;
4// pub const SYSCALL_NUMBER_MASK = ~SYSCALL_CLASS_MASK; // ~ modifier not supported yet
5
6pub const SYSCALL_CLASS_NONE = 0; // Invalid
7pub const SYSCALL_CLASS_MACH = 1; // Mach
8pub const SYSCALL_CLASS_UNIX = 2; // Unix/BSD
9pub const SYSCALL_CLASS_MDEP = 3; // Machine-dependent
10pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics
11
12// TODO: use the above constants to create the below values
13
14pub const SYS_exit = 0x2000001;
15pub const SYS_read = 0x2000003;
16pub const SYS_write = 0x2000004;
17pub const SYS_open = 0x2000005;
18pub const SYS_close = 0x2000006;
19pub const SYS_kill = 0x2000025;
20pub const SYS_getpid = 0x2000030;
21pub const SYS_fstat = 0x20000BD;
22pub const SYS_lseek = 0x20000C7;
23
24pub inline fn syscall0(number: usize) -> usize {
25 asm volatile ("syscall"
26 : [ret] "={rax}" (-> usize)
27 : [number] "{rax}" (number)
28 : "rcx", "r11")
29}
30
31pub 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
39pub 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
48pub 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
61pub 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
84pub const timespec = extern struct {
85 tv_sec: isize,
86 tv_nsec: isize,
87};
std/os/errno.zig+142-142
......@@ -1,146 +1,146 @@
1pub const EPERM = 1; // Operation not permitted
2pub const ENOENT = 2; // No such file or directory
3pub const ESRCH = 3; // No such process
4pub const EINTR = 4; // Interrupted system call
5pub const EIO = 5; // I/O error
6pub const ENXIO = 6; // No such device or address
7pub const E2BIG = 7; // Arg list too long
8pub const ENOEXEC = 8; // Exec format error
9pub const EBADF = 9; // Bad file number
10pub const ECHILD = 10; // No child processes
11pub const EAGAIN = 11; // Try again
12pub const ENOMEM = 12; // Out of memory
13pub const EACCES = 13; // Permission denied
14pub const EFAULT = 14; // Bad address
15pub const ENOTBLK = 15; // Block device required
16pub const EBUSY = 16; // Device or resource busy
17pub const EEXIST = 17; // File exists
18pub const EXDEV = 18; // Cross-device link
19pub const ENODEV = 19; // No such device
20pub const ENOTDIR = 20; // Not a directory
21pub const EISDIR = 21; // Is a directory
22pub const EINVAL = 22; // Invalid argument
23pub const ENFILE = 23; // File table overflow
24pub const EMFILE = 24; // Too many open files
25pub const ENOTTY = 25; // Not a typewriter
26pub const ETXTBSY = 26; // Text file busy
27pub const EFBIG = 27; // File too large
28pub const ENOSPC = 28; // No space left on device
29pub const ESPIPE = 29; // Illegal seek
30pub const EROFS = 30; // Read-only file system
31pub const EMLINK = 31; // Too many links
32pub const EPIPE = 32; // Broken pipe
33pub const EDOM = 33; // Math argument out of domain of func
34pub const ERANGE = 34; // Math result not representable
35pub const EDEADLK = 35; // Resource deadlock would occur
36pub const ENAMETOOLONG = 36; // File name too long
37pub const ENOLCK = 37; // No record locks available
38pub const ENOSYS = 38; // Function not implemented
39pub const ENOTEMPTY = 39; // Directory not empty
40pub const ELOOP = 40; // Too many symbolic links encountered
41pub const EWOULDBLOCK = EAGAIN; // Operation would block
42pub const ENOMSG = 42; // No message of desired type
43pub const EIDRM = 43; // Identifier removed
44pub const ECHRNG = 44; // Channel number out of range
45pub const EL2NSYNC = 45; // Level 2 not synchronized
46pub const EL3HLT = 46; // Level 3 halted
47pub const EL3RST = 47; // Level 3 reset
48pub const ELNRNG = 48; // Link number out of range
49pub const EUNATCH = 49; // Protocol driver not attached
50pub const ENOCSI = 50; // No CSI structure available
51pub const EL2HLT = 51; // Level 2 halted
52pub const EBADE = 52; // Invalid exchange
53pub const EBADR = 53; // Invalid request descriptor
54pub const EXFULL = 54; // Exchange full
55pub const ENOANO = 55; // No anode
56pub const EBADRQC = 56; // Invalid request code
57pub const EBADSLT = 57; // Invalid slot
1pub const EPERM = 1; /// Operation not permitted
2pub const ENOENT = 2; /// No such file or directory
3pub const ESRCH = 3; /// No such process
4pub const EINTR = 4; /// Interrupted system call
5pub const EIO = 5; /// I/O error
6pub const ENXIO = 6; /// No such device or address
7pub const E2BIG = 7; /// Arg list too long
8pub const ENOEXEC = 8; /// Exec format error
9pub const EBADF = 9; /// Bad file number
10pub const ECHILD = 10; /// No child processes
11pub const EAGAIN = 11; /// Try again
12pub const ENOMEM = 12; /// Out of memory
13pub const EACCES = 13; /// Permission denied
14pub const EFAULT = 14; /// Bad address
15pub const ENOTBLK = 15; /// Block device required
16pub const EBUSY = 16; /// Device or resource busy
17pub const EEXIST = 17; /// File exists
18pub const EXDEV = 18; /// Cross-device link
19pub const ENODEV = 19; /// No such device
20pub const ENOTDIR = 20; /// Not a directory
21pub const EISDIR = 21; /// Is a directory
22pub const EINVAL = 22; /// Invalid argument
23pub const ENFILE = 23; /// File table overflow
24pub const EMFILE = 24; /// Too many open files
25pub const ENOTTY = 25; /// Not a typewriter
26pub const ETXTBSY = 26; /// Text file busy
27pub const EFBIG = 27; /// File too large
28pub const ENOSPC = 28; /// No space left on device
29pub const ESPIPE = 29; /// Illegal seek
30pub const EROFS = 30; /// Read-only file system
31pub const EMLINK = 31; /// Too many links
32pub const EPIPE = 32; /// Broken pipe
33pub const EDOM = 33; /// Math argument out of domain of func
34pub const ERANGE = 34; /// Math result not representable
35pub const EDEADLK = 35; /// Resource deadlock would occur
36pub const ENAMETOOLONG = 36; /// File name too long
37pub const ENOLCK = 37; /// No record locks available
38pub const ENOSYS = 38; /// Function not implemented
39pub const ENOTEMPTY = 39; /// Directory not empty
40pub const ELOOP = 40; /// Too many symbolic links encountered
41pub const EWOULDBLOCK = EAGAIN; /// Operation would block
42pub const ENOMSG = 42; /// No message of desired type
43pub const EIDRM = 43; /// Identifier removed
44pub const ECHRNG = 44; /// Channel number out of range
45pub const EL2NSYNC = 45; /// Level 2 not synchronized
46pub const EL3HLT = 46; /// Level 3 halted
47pub const EL3RST = 47; /// Level 3 reset
48pub const ELNRNG = 48; /// Link number out of range
49pub const EUNATCH = 49; /// Protocol driver not attached
50pub const ENOCSI = 50; /// No CSI structure available
51pub const EL2HLT = 51; /// Level 2 halted
52pub const EBADE = 52; /// Invalid exchange
53pub const EBADR = 53; /// Invalid request descriptor
54pub const EXFULL = 54; /// Exchange full
55pub const ENOANO = 55; /// No anode
56pub const EBADRQC = 56; /// Invalid request code
57pub const EBADSLT = 57; /// Invalid slot
5858
59pub const EBFONT = 59; // Bad font file format
60pub const ENOSTR = 60; // Device not a stream
61pub const ENODATA = 61; // No data available
62pub const ETIME = 62; // Timer expired
63pub const ENOSR = 63; // Out of streams resources
64pub const ENONET = 64; // Machine is not on the network
65pub const ENOPKG = 65; // Package not installed
66pub const EREMOTE = 66; // Object is remote
67pub const ENOLINK = 67; // Link has been severed
68pub const EADV = 68; // Advertise error
69pub const ESRMNT = 69; // Srmount error
70pub const ECOMM = 70; // Communication error on send
71pub const EPROTO = 71; // Protocol error
72pub const EMULTIHOP = 72; // Multihop attempted
73pub const EDOTDOT = 73; // RFS specific error
74pub const EBADMSG = 74; // Not a data message
75pub const EOVERFLOW = 75; // Value too large for defined data type
76pub const ENOTUNIQ = 76; // Name not unique on network
77pub const EBADFD = 77; // File descriptor in bad state
78pub const EREMCHG = 78; // Remote address changed
79pub const ELIBACC = 79; // Can not access a needed shared library
80pub const ELIBBAD = 80; // Accessing a corrupted shared library
81pub const ELIBSCN = 81; // .lib section in a.out corrupted
82pub const ELIBMAX = 82; // Attempting to link in too many shared libraries
83pub const ELIBEXEC = 83; // Cannot exec a shared library directly
84pub const EILSEQ = 84; // Illegal byte sequence
85pub const ERESTART = 85; // Interrupted system call should be restarted
86pub const ESTRPIPE = 86; // Streams pipe error
87pub const EUSERS = 87; // Too many users
88pub const ENOTSOCK = 88; // Socket operation on non-socket
89pub const EDESTADDRREQ = 89; // Destination address required
90pub const EMSGSIZE = 90; // Message too long
91pub const EPROTOTYPE = 91; // Protocol wrong type for socket
92pub const ENOPROTOOPT = 92; // Protocol not available
93pub const EPROTONOSUPPORT = 93; // Protocol not supported
94pub const ESOCKTNOSUPPORT = 94; // Socket type not supported
95pub const EOPNOTSUPP = 95; // Operation not supported on transport endpoint
96pub const EPFNOSUPPORT = 96; // Protocol family not supported
97pub const EAFNOSUPPORT = 97; // Address family not supported by protocol
98pub const EADDRINUSE = 98; // Address already in use
99pub const EADDRNOTAVAIL = 99; // Cannot assign requested address
100pub const ENETDOWN = 100; // Network is down
101pub const ENETUNREACH = 101; // Network is unreachable
102pub const ENETRESET = 102; // Network dropped connection because of reset
103pub const ECONNABORTED = 103; // Software caused connection abort
104pub const ECONNRESET = 104; // Connection reset by peer
105pub const ENOBUFS = 105; // No buffer space available
106pub const EISCONN = 106; // Transport endpoint is already connected
107pub const ENOTCONN = 107; // Transport endpoint is not connected
108pub const ESHUTDOWN = 108; // Cannot send after transport endpoint shutdown
109pub const ETOOMANYREFS = 109; // Too many references: cannot splice
110pub const ETIMEDOUT = 110; // Connection timed out
111pub const ECONNREFUSED = 111; // Connection refused
112pub const EHOSTDOWN = 112; // Host is down
113pub const EHOSTUNREACH = 113; // No route to host
114pub const EALREADY = 114; // Operation already in progress
115pub const EINPROGRESS = 115; // Operation now in progress
116pub const ESTALE = 116; // Stale NFS file handle
117pub const EUCLEAN = 117; // Structure needs cleaning
118pub const ENOTNAM = 118; // Not a XENIX named type file
119pub const ENAVAIL = 119; // No XENIX semaphores available
120pub const EISNAM = 120; // Is a named type file
121pub const EREMOTEIO = 121; // Remote I/O error
122pub const EDQUOT = 122; // Quota exceeded
59pub const EBFONT = 59; /// Bad font file format
60pub const ENOSTR = 60; /// Device not a stream
61pub const ENODATA = 61; /// No data available
62pub const ETIME = 62; /// Timer expired
63pub const ENOSR = 63; /// Out of streams resources
64pub const ENONET = 64; /// Machine is not on the network
65pub const ENOPKG = 65; /// Package not installed
66pub const EREMOTE = 66; /// Object is remote
67pub const ENOLINK = 67; /// Link has been severed
68pub const EADV = 68; /// Advertise error
69pub const ESRMNT = 69; /// Srmount error
70pub const ECOMM = 70; /// Communication error on send
71pub const EPROTO = 71; /// Protocol error
72pub const EMULTIHOP = 72; /// Multihop attempted
73pub const EDOTDOT = 73; /// RFS specific error
74pub const EBADMSG = 74; /// Not a data message
75pub const EOVERFLOW = 75; /// Value too large for defined data type
76pub const ENOTUNIQ = 76; /// Name not unique on network
77pub const EBADFD = 77; /// File descriptor in bad state
78pub const EREMCHG = 78; /// Remote address changed
79pub const ELIBACC = 79; /// Can not access a needed shared library
80pub const ELIBBAD = 80; /// Accessing a corrupted shared library
81pub const ELIBSCN = 81; /// .lib section in a.out corrupted
82pub const ELIBMAX = 82; /// Attempting to link in too many shared libraries
83pub const ELIBEXEC = 83; /// Cannot exec a shared library directly
84pub const EILSEQ = 84; /// Illegal byte sequence
85pub const ERESTART = 85; /// Interrupted system call should be restarted
86pub const ESTRPIPE = 86; /// Streams pipe error
87pub const EUSERS = 87; /// Too many users
88pub const ENOTSOCK = 88; /// Socket operation on non-socket
89pub const EDESTADDRREQ = 89; /// Destination address required
90pub const EMSGSIZE = 90; /// Message too long
91pub const EPROTOTYPE = 91; /// Protocol wrong type for socket
92pub const ENOPROTOOPT = 92; /// Protocol not available
93pub const EPROTONOSUPPORT = 93; /// Protocol not supported
94pub const ESOCKTNOSUPPORT = 94; /// Socket type not supported
95pub const EOPNOTSUPP = 95; /// Operation not supported on transport endpoint
96pub const EPFNOSUPPORT = 96; /// Protocol family not supported
97pub const EAFNOSUPPORT = 97; /// Address family not supported by protocol
98pub const EADDRINUSE = 98; /// Address already in use
99pub const EADDRNOTAVAIL = 99; /// Cannot assign requested address
100pub const ENETDOWN = 100; /// Network is down
101pub const ENETUNREACH = 101; /// Network is unreachable
102pub const ENETRESET = 102; /// Network dropped connection because of reset
103pub const ECONNABORTED = 103; /// Software caused connection abort
104pub const ECONNRESET = 104; /// Connection reset by peer
105pub const ENOBUFS = 105; /// No buffer space available
106pub const EISCONN = 106; /// Transport endpoint is already connected
107pub const ENOTCONN = 107; /// Transport endpoint is not connected
108pub const ESHUTDOWN = 108; /// Cannot send after transport endpoint shutdown
109pub const ETOOMANYREFS = 109; /// Too many references: cannot splice
110pub const ETIMEDOUT = 110; /// Connection timed out
111pub const ECONNREFUSED = 111; /// Connection refused
112pub const EHOSTDOWN = 112; /// Host is down
113pub const EHOSTUNREACH = 113; /// No route to host
114pub const EALREADY = 114; /// Operation already in progress
115pub const EINPROGRESS = 115; /// Operation now in progress
116pub const ESTALE = 116; /// Stale NFS file handle
117pub const EUCLEAN = 117; /// Structure needs cleaning
118pub const ENOTNAM = 118; /// Not a XENIX named type file
119pub const ENAVAIL = 119; /// No XENIX semaphores available
120pub const EISNAM = 120; /// Is a named type file
121pub const EREMOTEIO = 121; /// Remote I/O error
122pub const EDQUOT = 122; /// Quota exceeded
123123
124pub const ENOMEDIUM = 123; // No medium found
125pub const EMEDIUMTYPE = 124; // Wrong medium type
124pub const ENOMEDIUM = 123; /// No medium found
125pub const EMEDIUMTYPE = 124; /// Wrong medium type
126126
127127// nameserver query return codes
128pub const ENSROK = 0; // DNS server returned answer with no data
129pub const ENSRNODATA = 160; // DNS server returned answer with no data
130pub const ENSRFORMERR = 161; // DNS server claims query was misformatted
131pub const ENSRSERVFAIL = 162; // DNS server returned general failure
132pub const ENSRNOTFOUND = 163; // Domain name not found
133pub const ENSRNOTIMP = 164; // DNS server does not implement requested operation
134pub const ENSRREFUSED = 165; // DNS server refused query
135pub const ENSRBADQUERY = 166; // Misformatted DNS query
136pub const ENSRBADNAME = 167; // Misformatted domain name
137pub const ENSRBADFAMILY = 168; // Unsupported address family
138pub const ENSRBADRESP = 169; // Misformatted DNS reply
139pub const ENSRCONNREFUSED = 170; // Could not contact DNS servers
140pub const ENSRTIMEOUT = 171; // Timeout while contacting DNS servers
141pub const ENSROF = 172; // End of file
142pub const ENSRFILE = 173; // Error reading file
143pub const ENSRNOMEM = 174; // Out of memory
144pub const ENSRDESTRUCTION = 175; // Application terminated lookup
145pub const ENSRQUERYDOMAINTOOLONG = 176; // Domain name is too long
146pub const ENSRCNAMELOOP = 177; // Domain name is too long
128pub const ENSROK = 0; /// DNS server returned answer with no data
129pub const ENSRNODATA = 160; /// DNS server returned answer with no data
130pub const ENSRFORMERR = 161; /// DNS server claims query was misformatted
131pub const ENSRSERVFAIL = 162; /// DNS server returned general failure
132pub const ENSRNOTFOUND = 163; /// Domain name not found
133pub const ENSRNOTIMP = 164; /// DNS server does not implement requested operation
134pub const ENSRREFUSED = 165; /// DNS server refused query
135pub const ENSRBADQUERY = 166; /// Misformatted DNS query
136pub const ENSRBADNAME = 167; /// Misformatted domain name
137pub const ENSRBADFAMILY = 168; /// Unsupported address family
138pub const ENSRBADRESP = 169; /// Misformatted DNS reply
139pub const ENSRCONNREFUSED = 170; /// Could not contact DNS servers
140pub const ENSRTIMEOUT = 171; /// Timeout while contacting DNS servers
141pub const ENSROF = 172; /// End of file
142pub const ENSRFILE = 173; /// Error reading file
143pub const ENSRNOMEM = 174; /// Out of memory
144pub const ENSRDESTRUCTION = 175; /// Application terminated lookup
145pub const ENSRQUERYDOMAINTOOLONG = 176; /// Domain name is too long
146pub const ENSRCNAMELOOP = 177; /// Domain name is too long
std/os/index.zig+56-37
......@@ -56,43 +56,40 @@ error WouldBlock;
5656/// appropriate OS-specific library call. Otherwise it uses the zig standard
5757/// library implementation.
5858pub 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,
7770 }
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);
7978
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;
9385 }
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"),
9693 }
9794}
9895
......@@ -128,12 +125,34 @@ pub fn posixClose(fd: i32) {
128125 }
129126}
130127
128/// Calls POSIX read, and keeps trying if it gets interrupted.
129pub 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
131150error WouldBlock;
132151error FileClosed;
133152error DestinationAddressRequired;
134153error DiskQuota;
135154error FileTooBig;
136error FileSystem;
155error InputOutput;
137156error NoSpaceLeft;
138157error BrokenPipe;
139158error Unexpected;
......@@ -152,7 +171,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void {
152171 errno.EDESTADDRREQ => error.DestinationAddressRequired,
153172 errno.EDQUOT => error.DiskQuota,
154173 errno.EFBIG => error.FileTooBig,
155 errno.EIO => error.FileSystem,
174 errno.EIO => error.InputOutput,
156175 errno.ENOSPC => error.NoSpaceLeft,
157176 errno.EPERM => error.AccessDenied,
158177 errno.EPIPE => error.BrokenPipe,
......@@ -213,7 +232,7 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) -> bool {
213232/// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
214233/// Calls POSIX open, keeps trying if it gets interrupted, and translates
215234/// the return value into zig errors.
216pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?&Allocator) -> %i32 {
235pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Allocator) -> %i32 {
217236 var stack_buf: [max_noalloc_path_len]u8 = undefined;
218237 var path0: []u8 = undefined;
219238 var need_free = false;
std/os/linux.zig+17-16
......@@ -309,8 +309,8 @@ pub const TIOCGPKT = 0x80045438;
309309pub const TIOCGPTLCK = 0x80045439;
310310pub const TIOCGEXCL = 0x80045440;
311311
312fn unsigned(s: i32) -> u32 { *@ptrCast(&u32, &s) }
313fn signed(s: u32) -> i32 { *@ptrCast(&i32, &s) }
312fn unsigned(s: i32) -> u32 { @bitCast(u32, s) }
313fn signed(s: u32) -> i32 { @bitCast(i32, s) }
314314pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) }
315315pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) }
316316pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) }
......@@ -328,7 +328,7 @@ pub const winsize = extern struct {
328328
329329/// Get the errno from a syscall return value, or 0 for no error.
330330pub fn getErrno(r: usize) -> usize {
331 const signed_r = *@ptrCast(&const isize, &r);
331 const signed_r = @bitCast(isize, r);
332332 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
333333}
334334
......@@ -353,7 +353,7 @@ pub fn getcwd(buf: &u8, size: usize) -> usize {
353353}
354354
355355pub 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)
357357}
358358
359359pub fn isatty(fd: i32) -> bool {
......@@ -365,14 +365,15 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -
365365 arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len)
366366}
367367
368pub fn mkdir(path: &const u8, mode: usize) -> usize {
368pub fn mkdir(path: &const u8, mode: u32) -> usize {
369369 arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode)
370370}
371371
372pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: usize)
372pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize)
373373 -> usize
374374{
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))
376377}
377378
378379pub fn munmap(address: &u8, length: usize) -> usize {
......@@ -415,7 +416,7 @@ pub fn rename(old: &const u8, new: &const u8) -> usize {
415416 arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new))
416417}
417418
418pub fn open(path: &const u8, flags: usize, perm: usize) -> usize {
419pub fn open(path: &const u8, flags: u32, perm: usize) -> usize {
419420 arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm)
420421}
421422
......@@ -431,12 +432,12 @@ pub fn close(fd: i32) -> usize {
431432 arch.syscall1(arch.SYS_close, usize(fd))
432433}
433434
434pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
435 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
435pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize {
436 arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos)
436437}
437438
438439pub fn exit(status: i32) -> noreturn {
439 _ = arch.syscall1(arch.SYS_exit, usize(status));
440 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));
440441 unreachable
441442}
442443
......@@ -453,7 +454,7 @@ pub fn unlink(path: &const u8) -> usize {
453454}
454455
455456pub 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)
457458}
458459
459460const NSIG = 65;
......@@ -461,11 +462,11 @@ const sigset_t = [128]u8;
461462const all_mask = []u8 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, };
462463const app_mask = []u8 { 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, };
463464
464pub fn raise(sig: i32) -> i32 {
465pub fn raise(sig: i32) -> usize {
465466 var set: sigset_t = undefined;
466467 blockAppSignals(&set);
467468 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));
469470 restoreSignals(&set);
470471 return ret;
471472}
......@@ -630,9 +631,9 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags:
630631// return ifr.ifr_ifindex;
631632// }
632633
633pub const stat = arch.stat;
634pub const Stat = arch.Stat;
634635pub const timespec = arch.timespec;
635636
636pub fn fstat(fd: i32, stat_buf: &stat) -> usize {
637pub fn fstat(fd: i32, stat_buf: &Stat) -> usize {
637638 arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf))
638639}
std/os/linux_x86_64.zig+2-1
......@@ -454,7 +454,8 @@ pub const msghdr = extern struct {
454454 msg_flags: i32,
455455};
456456
457pub const stat = extern struct {
457/// Renamed to Stat to not conflict with the stat function.
458pub const Stat = extern struct {
458459 dev: u64,
459460 ino: u64,
460461 nlink: usize,
test/cases/asm.zig+2-2
......@@ -2,7 +2,7 @@ const config = @import("builtin");
22const assert = @import("std").debug.assert;
33
44comptime {
5 if (config.arch == config.Arch.x86_64) {
5 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {
66 asm volatile (
77 \\.globl aoeu;
88 \\.type aoeu, @function;
......@@ -12,7 +12,7 @@ comptime {
1212}
1313
1414test "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) {
1616 assert(aoeu() == 1234);
1717 }
1818}