diff --git a/lib/compiler_rt/emutls.zig b/lib/compiler_rt/emutls.zig index 265fcb8782..db14ad04ee 100644 --- a/lib/compiler_rt/emutls.zig +++ b/lib/compiler_rt/emutls.zig @@ -246,7 +246,7 @@ const emutls_control = extern struct { // Two threads could race against the same emutls_control. // Use atomic for reading coherent value lockless. - const index_lockless = @atomicLoad(usize, &self.object.index, .Acquire); + const index_lockless = @atomicLoad(usize, &self.object.index, .acquire); if (index_lockless != 0) { // index is already initialized, return it. @@ -264,7 +264,7 @@ const emutls_control = extern struct { } // Store a new index atomically (for having coherent index_lockless reading). - @atomicStore(usize, &self.object.index, emutls_control.next_index, .Release); + @atomicStore(usize, &self.object.index, emutls_control.next_index, .release); // Increment the next available index emutls_control.next_index += 1; diff --git a/lib/std/Thread/Futex.zig b/lib/std/Thread/Futex.zig index 160d983c71..764d3f13e1 100644 --- a/lib/std/Thread/Futex.zig +++ b/lib/std/Thread/Futex.zig @@ -801,7 +801,7 @@ const PosixImpl = struct { assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS); defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS); - cancelled = ptr.load(.Monotonic) != expect; + cancelled = ptr.load(.monotonic) != expect; if (cancelled) { return; } @@ -855,14 +855,14 @@ const PosixImpl = struct { // The pending count increment in wait() must also now use seq_cst for the update + this pending load // to be in the same modification order as our load isn't using release/acquire to guarantee it. bucket.pending.fence(.seq_cst); - if (bucket.pending.load(.Monotonic) == 0) { + if (bucket.pending.load(.monotonic) == 0) { return; } // Keep a list of all the waiters notified and wake then up outside the mutex critical section. var notified = WaitList{}; defer if (notified.len > 0) { - const pending = bucket.pending.fetchSub(notified.len, .Monotonic); + const pending = bucket.pending.fetchSub(notified.len, .monotonic); assert(pending >= notified.len); while (notified.pop()) |waiter| { @@ -875,7 +875,7 @@ const PosixImpl = struct { defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS); // Another pending check again to avoid the WaitQueue lookup if not necessary. - if (bucket.pending.load(.Monotonic) > 0) { + if (bucket.pending.load(.monotonic) > 0) { notified = WaitQueue.remove(&bucket.treap, address, max_waiters); } } diff --git a/lib/std/Thread/RwLock.zig b/lib/std/Thread/RwLock.zig index 2152c0756c..c4a8755907 100644 --- a/lib/std/Thread/RwLock.zig +++ b/lib/std/Thread/RwLock.zig @@ -375,5 +375,5 @@ test "concurrent access" { try testing.expectEqual(num_writes, runner.writes); - //std.debug.print("reads={}\n", .{ runner.reads.load(.Unordered)}); + //std.debug.print("reads={}\n", .{ runner.reads.load(.unordered)}); } diff --git a/lib/std/atomic.zig b/lib/std/atomic.zig index bc8b181715..a485572140 100644 --- a/lib/std/atomic.zig +++ b/lib/std/atomic.zig @@ -159,7 +159,7 @@ test Value { // acquire ensures count decrement and code before // previous unrefs()s happens-before we call dropFn // below. - // Another alternative is to use .AcqRel on the + // Another alternative is to use .acq_rel on the // fetchSub count decrement but it's extra barrier in // possibly hot path. rc.count.fence(.acquire); diff --git a/lib/std/c.zig b/lib/std/c.zig index 6d3818afcb..d9062a125d 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -1502,25 +1502,19 @@ pub extern "c" fn closedir(dp: *DIR) c_int; pub extern "c" fn telldir(dp: *DIR) c_long; pub extern "c" fn seekdir(dp: *DIR, loc: c_long) void; -pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; -pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int; -pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int; -pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int; - -pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int; - -pub extern "c" fn sched_yield() c_int; - -pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int; -pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int; -pub extern "c" fn sigfillset(set: ?*c.sigset_t) void; pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int; -pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; - pub extern "c" fn alarm(seconds: c_uint) c_uint; -pub extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int; +pub const clock_getres = switch (native_os) { + .netbsd => private.__clock_getres50, + else => private.clock_getres, +}; + +pub const clock_gettime = switch (native_os) { + .netbsd => private.__clock_gettime50, + else => private.clock_gettime, +}; pub const fstat = switch (native_os) { .macos => switch (native_arch) { @@ -1539,6 +1533,31 @@ pub const fstatat = switch (native_os) { else => private.fstatat, }; +pub const getdirentries = switch (native_os) { + .macos, .ios, .tvos, .watchos => private.__getdirentries64, + else => private.getdirentries, +}; + +pub const getrusage = switch (native_os) { + .netbsd => private.__getrusage50, + else => private.getrusage, +}; + +pub const gettimeofday = switch (native_os) { + .netbsd => private.__gettimeofday50, + else => private.gettimeofday, +}; + +pub const msync = switch (native_os) { + .netbsd => private.__msync13, + else => private.msync, +}; + +pub const nanosleep = switch (native_os) { + .netbsd => private.__nanosleep50, + else => private.nanosleep, +}; + pub const readdir = switch (native_os) { .macos => switch (native_arch) { .x86_64 => private.@"readdir$INODE64", @@ -1549,10 +1568,35 @@ pub const readdir = switch (native_os) { }; pub const realpath = switch (native_os) { - .macos, .ios, .watchos, .tvos => private.@"realpath$DARWIN_EXTSN", + .macos, .ios, .tvos, .watchos => private.@"realpath$DARWIN_EXTSN", else => private.realpath, }; +pub const sched_yield = switch (native_os) { + .netbsd => private.__libc_thr_yield, + else => private.sched_yield, +}; + +pub const sigaction = switch (native_os) { + .netbsd => private.__sigaction14, + else => private.sigaction, +}; + +pub const sigfillset = switch (native_os) { + .netbsd => private.__sigfillset14, + else => private.sigfillset, +}; + +pub const sigprocmask = switch (native_os) { + .netbsd => private.__sigprocmask14, + else => private.sigprocmask, +}; + +pub const socket = switch (native_os) { + .netbsd => private.__socket30, + else => private.socket, +}; + pub const stat = switch (native_os) { .macos => switch (native_arch) { .x86_64 => private.@"stat$INODE64", @@ -1680,7 +1724,6 @@ pub extern "c" fn recvfrom( pub extern "c" fn recvmsg(sockfd: c.fd_t, msg: *c.msghdr, flags: u32) isize; pub extern "c" fn kill(pid: c.pid_t, sig: c_int) c_int; -pub extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize; pub extern "c" fn setuid(uid: c.uid_t) c_int; pub extern "c" fn setgid(gid: c.gid_t) c_int; @@ -1878,10 +1921,22 @@ else }; const private = struct { + extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int; + extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int; extern "c" fn fstatat(dirfd: c.fd_t, path: [*:0]const u8, buf: *c.Stat, flag: u32) c_int; + extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize; + extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int; + extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int; + extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int; + extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int; extern "c" fn readdir(dir: *c.DIR) ?*c.dirent; extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8; + extern "c" fn sched_yield() c_int; + extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int; + extern "c" fn sigfillset(set: ?*c.sigset_t) void; + extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int; + extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int; /// macos modernized symbols. @@ -1894,7 +1949,20 @@ const private = struct { /// macos modernized symbols. extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8; + extern "c" fn __getdirentries64(fd: c.fd_t, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize; /// netbsd modernized symbols. + extern "c" fn __clock_getres50(clk_id: c_int, tp: *c.timespec) c_int; + extern "c" fn __clock_gettime50(clk_id: c_int, tp: *c.timespec) c_int; extern "c" fn __fstat50(fd: c.fd_t, buf: *c.Stat) c_int; + extern "c" fn __getrusage50(who: c_int, usage: *c.rusage) c_int; + extern "c" fn __gettimeofday50(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int; + extern "c" fn __libc_thr_yield() c_int; + extern "c" fn __msync13(addr: *align(std.mem.page_size) const anyopaque, len: usize, flags: c_int) c_int; + extern "c" fn __nanosleep50(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int; + extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int; + extern "c" fn __sigfillset14(set: ?*c.sigset_t) void; + extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int; + extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; + extern "c" fn __stat50(path: [*:0]const u8, buf: *c.Stat) c_int; }; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index a58ce6e2dd..8dd122c3ba 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -924,9 +924,6 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool; pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void; pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void; -// XXX: close -> close$NOCANCEL -// XXX: getdirentries -> _getdirentries64 - // See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html // TODO: audit mode_t/pid_t, should likely be u16/i32 pub const blkcnt_t = i64; diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig index 500b04bcb7..8cbdd22c40 100644 --- a/lib/std/c/dragonfly.zig +++ b/lib/std/c/dragonfly.zig @@ -494,6 +494,12 @@ pub const sockaddr = extern struct { addr: [16]u8, scope_id: u32, }; + + pub const un = extern struct { + len: u8 = @sizeOf(un), + family: sa_family_t = AF.UNIX, + path: [104]u8, + }; }; pub const Kevent = extern struct { diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index ae0cdf45d3..475fd55e22 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -18,47 +18,14 @@ pub extern "c" fn _lwp_self() lwpid_t; pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int; pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void; -pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int; -pub const stat = __stat50; - -pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int; -pub const clock_gettime = __clock_gettime50; - -pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int; -pub const clock_getres = __clock_getres50; - pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int; pub const getdents = __getdents30; pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int; pub const sigaltstack = __sigaltstack14; -pub extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int; -pub const nanosleep = __nanosleep50; - -pub extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int; -pub const sigaction = __sigaction14; - -pub extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; -pub const sigprocmask = __sigaction14; - -pub extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; -pub const socket = __socket30; - -pub extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; -pub const gettimeofday = __gettimeofday50; - -pub extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int; -pub const getrusage = __getrusage50; - -pub extern "c" fn __libc_thr_yield() c_int; -pub const sched_yield = __libc_thr_yield; - pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int; -pub extern "c" fn __msync13(addr: *align(std.mem.page_size) const anyopaque, len: usize, flags: c_int) c_int; -pub const msync = __msync13; - pub const pthread_spin_t = switch (builtin.cpu.arch) { .aarch64, .aarch64_be, .aarch64_32 => u8, .mips, .mipsel, .mips64, .mips64el => u32, diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index f82eb8cd47..11fbc13c41 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -49,7 +49,7 @@ pub const Iterator = switch (builtin.os.tag) { posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions self.first_iter = false; } - const rc = posix.system.__getdirentries64( + const rc = posix.system.getdirentries( self.dir.fd, &self.buf, self.buf.len, @@ -161,10 +161,7 @@ pub const Iterator = switch (builtin.os.tag) { posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions self.first_iter = false; } - const rc = if (builtin.os.tag == .netbsd) - posix.system.__getdents30(self.dir.fd, &self.buf, self.buf.len) - else - posix.system.getdents(self.dir.fd, &self.buf, self.buf.len); + const rc = posix.system.getdents(self.dir.fd, &self.buf, self.buf.len); switch (posix.errno(rc)) { .SUCCESS => {}, .BADF => unreachable, // Dir is invalid or was opened without iteration ability diff --git a/src/Air.zig b/src/Air.zig index e014e225e0..5513abdbfb 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -727,11 +727,11 @@ pub const Inst = struct { /// Result type is always `void`. /// Uses the `bin_op` field. LHS is pointer, RHS is element. atomic_store_unordered, - /// Same as `atomic_store_unordered` but with `AtomicOrder.Monotonic`. + /// Same as `atomic_store_unordered` but with `AtomicOrder.monotonic`. atomic_store_monotonic, - /// Same as `atomic_store_unordered` but with `AtomicOrder.Release`. + /// Same as `atomic_store_unordered` but with `AtomicOrder.release`. atomic_store_release, - /// Same as `atomic_store_unordered` but with `AtomicOrder.SeqCst`. + /// Same as `atomic_store_unordered` but with `AtomicOrder.seq_cst`. atomic_store_seq_cst, /// Atomically read-modify-write via a pointer. /// Result type is the element type of the pointer. diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index 0ab82abdd6..b6b3f30879 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -647,10 +647,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { .call_never_tail => try self.airCall(inst, .never_tail), .call_never_inline => try self.airCall(inst, .never_inline), - .atomic_store_unordered => @panic("TODO try self.airAtomicStore(inst, .Unordered)"), - .atomic_store_monotonic => @panic("TODO try self.airAtomicStore(inst, .Monotonic)"), - .atomic_store_release => @panic("TODO try self.airAtomicStore(inst, .Release)"), - .atomic_store_seq_cst => @panic("TODO try self.airAtomicStore(inst, .SeqCst)"), + .atomic_store_unordered => @panic("TODO try self.airAtomicStore(inst, .unordered)"), + .atomic_store_monotonic => @panic("TODO try self.airAtomicStore(inst, .monotonic)"), + .atomic_store_release => @panic("TODO try self.airAtomicStore(inst, .release)"), + .atomic_store_seq_cst => @panic("TODO try self.airAtomicStore(inst, .seq_cst)"), .struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0), .struct_field_ptr_index_1 => try self.airStructFieldPtrIndex(inst, 1),