From bcdbd8d1697725992cb08eb1c3c59bd63fda6dc7 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 28 May 2019 15:22:19 +0200 Subject: Add sigaltstack syscall --- std/os/bits/linux.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'std/os/bits/linux.zig') diff --git a/std/os/bits/linux.zig b/std/os/bits/linux.zig index 6532e72362..b9386e9b05 100644 --- a/std/os/bits/linux.zig +++ b/std/os/bits/linux.zig @@ -929,3 +929,24 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t { //#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) //#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) //#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) + +pub const MINSIGSTKSZ = switch (builtin.arch) { + .i386, .x86_64, .arm => 2048, + .aarch64 => 5120, + else => @compileError("MINSIGSTKSZ not defined for this architecture"), +}; +pub const SIGSTKSZ = switch (builtin.arch) { + .i386, .x86_64, .arm => 8192, + .aarch64 => 16384, + else => @compileError("SIGSTKSZ not defined for this architecture"), +}; + +pub const SS_ONSTACK = 1; +pub const SS_DISABLE = 2; +pub const SS_AUTODISARM = 1 << 31; + +pub const stack_t = extern struct { + ss_sp: [*]u8, + ss_flags: i32, + ss_size: isize, +}; -- cgit v1.2.3 From bfc86776d501dc317737be09e8ed8d13da18f67c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 29 May 2019 18:55:42 -0400 Subject: run zig fmt to update `use` to `usingnamespace` --- src-self-hosted/c.zig | 2 +- src-self-hosted/translate_c.zig | 2 +- std/c.zig | 4 ++-- std/c/darwin.zig | 2 +- std/c/linux.zig | 2 +- std/math/big.zig | 4 ++-- std/os.zig | 2 +- std/os/bits.zig | 2 +- std/os/bits/linux.zig | 6 +++--- std/os/bits/windows.zig | 2 +- std/os/darwin.zig | 2 +- std/os/freebsd.zig | 2 +- std/os/linux.zig | 4 ++-- std/os/linux/x86_64.zig | 2 +- std/os/netbsd.zig | 2 +- std/os/wasi.zig | 2 +- std/os/windows.zig | 2 +- std/os/windows/advapi32.zig | 2 +- std/os/windows/kernel32.zig | 2 +- std/os/windows/ntdll.zig | 2 +- std/os/windows/ole32.zig | 2 +- std/os/windows/shell32.zig | 2 +- std/os/zen.zig | 2 +- test/stage1/behavior/alignof.zig | 1 - test/stage1/behavior/bugs/1076.zig | 1 - test/stage1/behavior/bugs/1486.zig | 1 - test/stage1/behavior/bugs/421.zig | 1 - test/stage1/behavior/bugs/529.zig | 1 - test/stage1/behavior/bugs/726.zig | 1 - test/stage1/behavior/fn.zig | 1 - test/stage1/behavior/import.zig | 2 +- test/stage1/behavior/popcount.zig | 1 - test/stage1/behavior/reflection.zig | 1 - test/stage1/behavior/struct.zig | 2 +- test/stage1/behavior/this.zig | 1 - test/stage1/behavior/undefined.zig | 1 - test/stage1/behavior/union.zig | 2 +- test/stage1/behavior/widening.zig | 1 - test/standalone/use_alias/c.zig | 2 +- 39 files changed, 32 insertions(+), 44 deletions(-) (limited to 'std/os/bits/linux.zig') diff --git a/src-self-hosted/c.zig b/src-self-hosted/c.zig index 778d851240..1de2b6a24c 100644 --- a/src-self-hosted/c.zig +++ b/src-self-hosted/c.zig @@ -1,4 +1,4 @@ -pub use @cImport({ +pub usingnamespace @cImport({ @cDefine("__STDC_CONSTANT_MACROS", ""); @cDefine("__STDC_LIMIT_MACROS", ""); @cInclude("inttypes.h"); diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index dac4c2b1ca..b7ced4a89f 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -6,7 +6,7 @@ const builtin = @import("builtin"); const assert = std.debug.assert; const ast = std.zig.ast; const Token = std.zig.Token; -use @import("clang.zig"); +usingnamespace @import("clang.zig"); pub const Mode = enum { import, diff --git a/std/c.zig b/std/c.zig index 4a223cc9e2..029b92e549 100644 --- a/std/c.zig +++ b/std/c.zig @@ -2,9 +2,9 @@ const builtin = @import("builtin"); const std = @import("std"); const page_size = std.mem.page_size; -pub use @import("os/bits.zig"); +pub usingnamespace @import("os/bits.zig"); -pub use switch (builtin.os) { +pub usingnamespace switch (builtin.os) { .linux => @import("c/linux.zig"), .windows => @import("c/windows.zig"), .macosx, .ios, .tvos, .watchos => @import("c/darwin.zig"), diff --git a/std/c/darwin.zig b/std/c/darwin.zig index e45a158f68..156429e7b9 100644 --- a/std/c/darwin.zig +++ b/std/c/darwin.zig @@ -3,7 +3,7 @@ const assert = std.debug.assert; const builtin = @import("builtin"); const macho = std.macho; -use @import("../os/bits.zig"); +usingnamespace @import("../os/bits.zig"); extern "c" fn __error() *c_int; pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int; diff --git a/std/c/linux.zig b/std/c/linux.zig index 9e028728c7..83c6bdfe5b 100644 --- a/std/c/linux.zig +++ b/std/c/linux.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -use std.c; +usingnamespace std.c; extern "c" fn __errno_location() *c_int; pub const _errno = __errno_location; diff --git a/std/math/big.zig b/std/math/big.zig index 44b5ce675f..8105beb506 100644 --- a/std/math/big.zig +++ b/std/math/big.zig @@ -1,5 +1,5 @@ -pub use @import("big/int.zig"); -pub use @import("big/rational.zig"); +pub usingnamespace @import("big/int.zig"); +pub usingnamespace @import("big/rational.zig"); test "math.big" { _ = @import("big/int.zig"); diff --git a/std/os.zig b/std/os.zig index 6f1f0135ce..631cc266a8 100644 --- a/std/os.zig +++ b/std/os.zig @@ -46,7 +46,7 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) { else => struct {}, }; -pub use @import("os/bits.zig"); +pub usingnamespace @import("os/bits.zig"); /// See also `getenv`. Populated by startup code before main(). pub var environ: [][*]u8 = undefined; diff --git a/std/os/bits.zig b/std/os/bits.zig index 7b87cc6e4d..f16da2487b 100644 --- a/std/os/bits.zig +++ b/std/os/bits.zig @@ -3,7 +3,7 @@ const builtin = @import("builtin"); -pub use switch (builtin.os) { +pub usingnamespace switch (builtin.os) { .macosx, .ios, .tvos, .watchos => @import("bits/darwin.zig"), .freebsd => @import("bits/freebsd.zig"), .linux => @import("bits/linux.zig"), diff --git a/std/os/bits/linux.zig b/std/os/bits/linux.zig index 6532e72362..44e713b15f 100644 --- a/std/os/bits/linux.zig +++ b/std/os/bits/linux.zig @@ -1,10 +1,10 @@ const builtin = @import("builtin"); const std = @import("../../std.zig"); const maxInt = std.math.maxInt; -use @import("../bits.zig"); +usingnamespace @import("../bits.zig"); -pub use @import("linux/errno.zig"); -pub use switch (builtin.arch) { +pub usingnamespace @import("linux/errno.zig"); +pub usingnamespace switch (builtin.arch) { .x86_64 => @import("linux/x86_64.zig"), .aarch64 => @import("linux/arm64.zig"), else => struct {}, diff --git a/std/os/bits/windows.zig b/std/os/bits/windows.zig index 4959249a9a..fc148d812f 100644 --- a/std/os/bits/windows.zig +++ b/std/os/bits/windows.zig @@ -1,6 +1,6 @@ // The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime). -use @import("../windows/bits.zig"); +usingnamespace @import("../windows/bits.zig"); pub const fd_t = HANDLE; pub const pid_t = HANDLE; diff --git a/std/os/darwin.zig b/std/os/darwin.zig index d6e0a1b77c..67ce9a06cf 100644 --- a/std/os/darwin.zig +++ b/std/os/darwin.zig @@ -4,4 +4,4 @@ pub const is_the_target = switch (builtin.os) { .macosx, .tvos, .watchos, .ios => true, else => false, }; -pub use std.c; +pub usingnamespace std.c; diff --git a/std/os/freebsd.zig b/std/os/freebsd.zig index c0f3382bd0..d418ccd415 100644 --- a/std/os/freebsd.zig +++ b/std/os/freebsd.zig @@ -1,4 +1,4 @@ const std = @import("../std.zig"); const builtin = @import("builtin"); pub const is_the_target = builtin.os == .freebsd; -pub use std.c; +pub usingnamespace std.c; diff --git a/std/os/linux.zig b/std/os/linux.zig index 282aa19bf1..5d26446682 100644 --- a/std/os/linux.zig +++ b/std/os/linux.zig @@ -14,12 +14,12 @@ const vdso = @import("linux/vdso.zig"); const dl = @import("../dynamic_library.zig"); pub const is_the_target = builtin.os == .linux; -pub use switch (builtin.arch) { +pub usingnamespace switch (builtin.arch) { .x86_64 => @import("linux/x86_64.zig"), .aarch64 => @import("linux/arm64.zig"), else => struct {}, }; -pub use @import("bits.zig"); +pub usingnamespace @import("bits.zig"); pub const tls = @import("linux/tls.zig"); /// Set by startup code, used by `getauxval`. diff --git a/std/os/linux/x86_64.zig b/std/os/linux/x86_64.zig index fa866cff4c..82eed0256b 100644 --- a/std/os/linux/x86_64.zig +++ b/std/os/linux/x86_64.zig @@ -1,4 +1,4 @@ -use @import("../bits.zig"); +usingnamespace @import("../bits.zig"); pub fn syscall0(number: usize) usize { return asm volatile ("syscall" diff --git a/std/os/netbsd.zig b/std/os/netbsd.zig index 25e72c10a8..cd63e40f5c 100644 --- a/std/os/netbsd.zig +++ b/std/os/netbsd.zig @@ -1,4 +1,4 @@ const builtin = @import("builtin"); const std = @import("../std.zig"); pub const is_the_target = builtin.os == .netbsd; -pub use std.c; +pub usingnamespace std.c; diff --git a/std/os/wasi.zig b/std/os/wasi.zig index adfe9e821d..57b708395c 100644 --- a/std/os/wasi.zig +++ b/std/os/wasi.zig @@ -5,7 +5,7 @@ const std = @import("std"); const assert = std.debug.assert; pub const is_the_target = builtin.os == .wasi; -pub use @import("bits.zig"); +pub usingnamespace @import("bits.zig"); comptime { assert(@alignOf(i8) == 1); diff --git a/std/os/windows.zig b/std/os/windows.zig index 526ac1cfd6..1d59004012 100644 --- a/std/os/windows.zig +++ b/std/os/windows.zig @@ -18,7 +18,7 @@ pub const ntdll = @import("windows/ntdll.zig"); pub const ole32 = @import("windows/ole32.zig"); pub const shell32 = @import("windows/shell32.zig"); -pub use @import("windows/bits.zig"); +pub usingnamespace @import("windows/bits.zig"); pub const CreateFileError = error{ SharingViolation, diff --git a/std/os/windows/advapi32.zig b/std/os/windows/advapi32.zig index df3220e24c..165a2c10a3 100644 --- a/std/os/windows/advapi32.zig +++ b/std/os/windows/advapi32.zig @@ -1,4 +1,4 @@ -use @import("bits.zig"); +usingnamespace @import("bits.zig"); pub extern "advapi32" stdcallcc fn RegOpenKeyExW( hKey: HKEY, diff --git a/std/os/windows/kernel32.zig b/std/os/windows/kernel32.zig index 2bd1824620..852369df20 100644 --- a/std/os/windows/kernel32.zig +++ b/std/os/windows/kernel32.zig @@ -1,4 +1,4 @@ -use @import("bits.zig"); +usingnamespace @import("bits.zig"); pub extern "kernel32" stdcallcc fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) BOOL; diff --git a/std/os/windows/ntdll.zig b/std/os/windows/ntdll.zig index 60c03ffc07..e5469cdcf9 100644 --- a/std/os/windows/ntdll.zig +++ b/std/os/windows/ntdll.zig @@ -1,3 +1,3 @@ -use @import("bits.zig"); +usingnamespace @import("bits.zig"); pub extern "NtDll" stdcallcc fn RtlCaptureStackBackTrace(FramesToSkip: DWORD, FramesToCapture: DWORD, BackTrace: **c_void, BackTraceHash: ?*DWORD) WORD; diff --git a/std/os/windows/ole32.zig b/std/os/windows/ole32.zig index 80f5bebc36..39c12d074c 100644 --- a/std/os/windows/ole32.zig +++ b/std/os/windows/ole32.zig @@ -1,4 +1,4 @@ -use @import("bits.zig"); +usingnamespace @import("bits.zig"); pub extern "ole32" stdcallcc fn CoTaskMemFree(pv: LPVOID) void; pub extern "ole32" stdcallcc fn CoUninitialize() void; diff --git a/std/os/windows/shell32.zig b/std/os/windows/shell32.zig index 9f24acc5c4..c178997aad 100644 --- a/std/os/windows/shell32.zig +++ b/std/os/windows/shell32.zig @@ -1,3 +1,3 @@ -use @import("bits.zig"); +usingnamespace @import("bits.zig"); pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT; diff --git a/std/os/zen.zig b/std/os/zen.zig index 8d2f963486..727f55fa6d 100644 --- a/std/os/zen.zig +++ b/std/os/zen.zig @@ -80,7 +80,7 @@ pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; // FIXME: let's borrow Linux's error numbers for now. -use @import("bits/linux/errno.zig"); +usingnamespace @import("bits/linux/errno.zig"); // Get the errno from a syscall return value, or 0 for no error. pub fn getErrno(r: usize) usize { const signed_r = @bitCast(isize, r); diff --git a/test/stage1/behavior/alignof.zig b/test/stage1/behavior/alignof.zig index d4d9661ead..f923fd9355 100644 --- a/test/stage1/behavior/alignof.zig +++ b/test/stage1/behavior/alignof.zig @@ -15,4 +15,3 @@ test "@alignOf(T) before referencing T" { comptime expect(@alignOf(Foo) == 4); } } - diff --git a/test/stage1/behavior/bugs/1076.zig b/test/stage1/behavior/bugs/1076.zig index 9dc1d111ea..550ee9703a 100644 --- a/test/stage1/behavior/bugs/1076.zig +++ b/test/stage1/behavior/bugs/1076.zig @@ -13,4 +13,3 @@ fn testCastPtrOfArrayToSliceAndPtr() void { x[0] += 1; expect(mem.eql(u8, array[0..], "boeu")); } - diff --git a/test/stage1/behavior/bugs/1486.zig b/test/stage1/behavior/bugs/1486.zig index d1bb8d7053..1b8e5ca4a1 100644 --- a/test/stage1/behavior/bugs/1486.zig +++ b/test/stage1/behavior/bugs/1486.zig @@ -8,4 +8,3 @@ test "constant pointer to global variable causes runtime load" { expect(&global == ptr); expect(ptr.* == 1234); } - diff --git a/test/stage1/behavior/bugs/421.zig b/test/stage1/behavior/bugs/421.zig index e5f67f61b7..a618876e00 100644 --- a/test/stage1/behavior/bugs/421.zig +++ b/test/stage1/behavior/bugs/421.zig @@ -13,4 +13,3 @@ fn extractOne64(a: u128) u64 { const x = @bitCast([2]u64, a); return x[1]; } - diff --git a/test/stage1/behavior/bugs/529.zig b/test/stage1/behavior/bugs/529.zig index 08d6768f7c..6aeb73c331 100644 --- a/test/stage1/behavior/bugs/529.zig +++ b/test/stage1/behavior/bugs/529.zig @@ -12,4 +12,3 @@ test "issue 529 fixed" { @import("529_other_file.zig").issue529(null); issue529(null); } - diff --git a/test/stage1/behavior/bugs/726.zig b/test/stage1/behavior/bugs/726.zig index dd2a135b56..632d3b1511 100644 --- a/test/stage1/behavior/bugs/726.zig +++ b/test/stage1/behavior/bugs/726.zig @@ -13,4 +13,3 @@ test "@ptrCast from var in empty struct to nullable" { var x: ?*const u8 = @ptrCast(?*const u8, &container.c); expect(x.?.* == 4); } - diff --git a/test/stage1/behavior/fn.zig b/test/stage1/behavior/fn.zig index 3f78c80290..86f382674c 100644 --- a/test/stage1/behavior/fn.zig +++ b/test/stage1/behavior/fn.zig @@ -205,4 +205,3 @@ test "extern struct with stdcallcc fn pointer" { s.ptr = S.foo; expect(s.ptr() == 1234); } - diff --git a/test/stage1/behavior/import.zig b/test/stage1/behavior/import.zig index 11d696f81e..aa6e9d82ba 100644 --- a/test/stage1/behavior/import.zig +++ b/test/stage1/behavior/import.zig @@ -12,7 +12,7 @@ test "importing the same thing gives the same import" { test "import in non-toplevel scope" { const S = struct { - use @import("import/a_namespace.zig"); + usingnamespace @import("import/a_namespace.zig"); }; expectEqual(i32(1234), S.foo()); } diff --git a/test/stage1/behavior/popcount.zig b/test/stage1/behavior/popcount.zig index 327bee62a1..044864cede 100644 --- a/test/stage1/behavior/popcount.zig +++ b/test/stage1/behavior/popcount.zig @@ -41,4 +41,3 @@ fn testPopCount() void { expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24); } } - diff --git a/test/stage1/behavior/reflection.zig b/test/stage1/behavior/reflection.zig index 55efc85b97..739e0b318a 100644 --- a/test/stage1/behavior/reflection.zig +++ b/test/stage1/behavior/reflection.zig @@ -93,4 +93,3 @@ const Bar = union(enum) { Three: bool, Four: f64, }; - diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig index d7bbee5d15..7a84fcc763 100644 --- a/test/stage1/behavior/struct.zig +++ b/test/stage1/behavior/struct.zig @@ -552,7 +552,7 @@ test "packed struct with fp fields" { test "use within struct scope" { const S = struct { - use struct { + usingnamespace struct { pub fn inner() i32 { return 42; } diff --git a/test/stage1/behavior/this.zig b/test/stage1/behavior/this.zig index a0bee3a3ee..927c0808ea 100644 --- a/test/stage1/behavior/this.zig +++ b/test/stage1/behavior/this.zig @@ -32,4 +32,3 @@ test "this refer to container" { expect(pt.x == 13); expect(pt.y == 35); } - diff --git a/test/stage1/behavior/undefined.zig b/test/stage1/behavior/undefined.zig index 4c233576cd..4f2cbed3bc 100644 --- a/test/stage1/behavior/undefined.zig +++ b/test/stage1/behavior/undefined.zig @@ -66,4 +66,3 @@ test "type name of undefined" { const x = undefined; expect(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)")); } - diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig index b8bb9a51b8..58a5203e8a 100644 --- a/test/stage1/behavior/union.zig +++ b/test/stage1/behavior/union.zig @@ -374,7 +374,7 @@ const Attribute = union(enum) { fn setAttribute(attr: Attribute) void {} fn Setter(attr: Attribute) type { - return struct{ + return struct { fn set() void { setAttribute(attr); } diff --git a/test/stage1/behavior/widening.zig b/test/stage1/behavior/widening.zig index f7c238ee8d..d79270b811 100644 --- a/test/stage1/behavior/widening.zig +++ b/test/stage1/behavior/widening.zig @@ -25,4 +25,3 @@ test "float widening" { var d: f128 = c; expect(d == a); } - diff --git a/test/standalone/use_alias/c.zig b/test/standalone/use_alias/c.zig index 1bc325b117..2835a51615 100644 --- a/test/standalone/use_alias/c.zig +++ b/test/standalone/use_alias/c.zig @@ -1 +1 @@ -pub use @cImport(@cInclude("foo.h")); +pub usingnamespace @cImport(@cInclude("foo.h")); -- cgit v1.2.3 From 477ee9c8b992612c952dfd13c4f951d4e04adb22 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 30 May 2019 16:28:33 +0200 Subject: Fix some syscalls on arm64 --- std/c/linux.zig | 2 +- std/event/loop.zig | 2 +- std/os.zig | 2 +- std/os/bits/linux.zig | 12 ++++++------ std/os/linux.zig | 46 +++++++++++++++++++++++++++------------------- 5 files changed, 36 insertions(+), 28 deletions(-) (limited to 'std/os/bits/linux.zig') diff --git a/std/c/linux.zig b/std/c/linux.zig index 50c4b185d8..9689f61082 100644 --- a/std/c/linux.zig +++ b/std/c/linux.zig @@ -7,7 +7,7 @@ pub const _errno = __errno_location; pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int; pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int; pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int; -pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: *epoll_event) c_int; +pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int; pub extern "c" fn epoll_create1(flags: c_uint) c_int; pub extern "c" fn epoll_wait(epfd: fd_t, events: [*]epoll_event, maxevents: c_uint, timeout: c_int) c_int; pub extern "c" fn epoll_pwait( diff --git a/std/event/loop.zig b/std/event/loop.zig index 61732d78f5..6cddb50ef5 100644 --- a/std/event/loop.zig +++ b/std/event/loop.zig @@ -421,7 +421,7 @@ pub const Loop = struct { } pub fn linuxRemoveFd(self: *Loop, fd: i32) void { - os.epoll_ctl(self.os_data.epollfd, os.linux.EPOLL_CTL_DEL, fd, undefined) catch {}; + os.epoll_ctl(self.os_data.epollfd, os.linux.EPOLL_CTL_DEL, fd, null) catch {}; self.finishOneEvent(); } diff --git a/std/os.zig b/std/os.zig index ee476258ae..07c9f880c7 100644 --- a/std/os.zig +++ b/std/os.zig @@ -1509,7 +1509,7 @@ pub const EpollCtlError = error{ Unexpected, }; -pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: *epoll_event) EpollCtlError!void { +pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void { const rc = system.epoll_ctl(epfd, op, fd, event); switch (errno(rc)) { 0 => return, diff --git a/std/os/bits/linux.zig b/std/os/bits/linux.zig index 4a1734a145..ff541077d9 100644 --- a/std/os/bits/linux.zig +++ b/std/os/bits/linux.zig @@ -762,16 +762,16 @@ pub const epoll_data = extern union { // On x86_64 the structure is packed so that it matches the definition of its // 32bit counterpart -pub const epoll_event = if (builtin.arch != .x86_64) - extern struct { +pub const epoll_event = switch (builtin.arch) { + .x86_64 => packed struct { events: u32, data: epoll_data, - } -else - packed struct { + }, + else => extern struct { events: u32, data: epoll_data, - }; + }, +}; pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330; pub const _LINUX_CAPABILITY_U32S_1 = 1; diff --git a/std/os/linux.zig b/std/os/linux.zig index aee34b10a2..61a13ff164 100644 --- a/std/os/linux.zig +++ b/std/os/linux.zig @@ -131,7 +131,7 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz if (@hasDecl(@This(), "SYS_readlink")) { return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); } else { - return syscall4(SYS_readlinkat, AT_FDCWD, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); + return syscall4(SYS_readlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); } } @@ -145,7 +145,7 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize { if (@hasDecl(@This(), "SYS_mkdir")) { return syscall2(SYS_mkdir, @ptrToInt(path), mode); } else { - return syscall3(SYS_mkdirat, AT_FDCWD, @ptrToInt(path), mode); + return syscall3(SYS_mkdirat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode); } } @@ -206,7 +206,7 @@ pub fn rmdir(path: [*]const u8) usize { if (@hasDecl(@This(), "SYS_rmdir")) { return syscall1(SYS_rmdir, @ptrToInt(path)); } else { - return syscall3(SYS_unlinkat, AT_FDCWD, @ptrToInt(path), AT_REMOVEDIR); + return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR); } } @@ -215,7 +215,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { if (@hasDecl(@This(), "SYS_symlink")) { return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); } else { - return syscall3(SYS_symlinkat, @ptrToInt(existing), AT_FDCWD, @ptrToInt(new)); + return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new)); } } @@ -231,12 +231,16 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { // TODO https://github.com/ziglang/zig/issues/265 pub fn access(path: [*]const u8, mode: u32) usize { - return syscall2(SYS_access, @ptrToInt(path), mode); + if (@hasDecl(@This(), "SYS_access")) { + return syscall2(SYS_access, @ptrToInt(path), mode); + } else { + return syscall4(SYS_faccessat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode, 0); + } } // TODO https://github.com/ziglang/zig/issues/265 -pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32) usize { - return syscall3(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode); +pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize { + return syscall4(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode, flags); } pub fn pipe(fd: *[2]i32) usize { @@ -264,9 +268,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize { if (@hasDecl(@This(), "SYS_rename")) { return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); } else if (@hasDecl(@This(), "SYS_renameat")) { - return syscall4(SYS_renameat, AT_FDCWD, @ptrToInt(old), AT_FDCWD, @ptrToInt(new)); + return syscall4(SYS_renameat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new)); } else { - return syscall5(SYS_renameat2, AT_FDCWD, @ptrToInt(old), AT_FDCWD, @ptrToInt(new), 0); + return syscall5(SYS_renameat2, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new), 0); } } @@ -305,7 +309,17 @@ pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const // TODO https://github.com/ziglang/zig/issues/265 pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { - return syscall3(SYS_open, @ptrToInt(path), flags, perm); + if (@hasDecl(@This(), "SYS_open")) { + return syscall3(SYS_open, @ptrToInt(path), flags, perm); + } else { + return syscall4( + SYS_openat, + @bitCast(usize, isize(AT_FDCWD)), + @ptrToInt(path), + flags, + perm, + ); + } } // TODO https://github.com/ziglang/zig/issues/265 @@ -373,7 +387,7 @@ pub fn unlink(path: [*]const u8) usize { if (@hasDecl(@This(), "SYS_unlink")) { return syscall1(SYS_unlink, @ptrToInt(path)); } else { - return syscall3(SYS_unlinkat, AT_FDCWD, @ptrToInt(path), 0); + return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), 0); } } @@ -759,18 +773,12 @@ pub fn epoll_create1(flags: usize) usize { return syscall1(SYS_epoll_create1, flags); } -pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize { +pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize { return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev)); } pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { - return syscall4( - SYS_epoll_wait, - @bitCast(usize, isize(epoll_fd)), - @ptrToInt(events), - maxevents, - @bitCast(usize, isize(timeout)), - ); + return epoll_pwait(epoll_fd, events, maxevents, timeout, null); } pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { -- cgit v1.2.3