authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-15 16:59:05-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-03-15 16:59:05-07:00
logce4245f873c68cfcc431deb303383f25f6d50855
treebe29f6d6d6bfa1c8fc7a8f20d61f19215a62554a
parentcb419a1a8692cdbd612c6b63b65ba9a02e23c6c1
parentd7cf25f5ca40e5cbcd739911e773769a62c2abe1
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #19312 from mikdusan/bsd-debitrot

bsd: debitrot

11 files changed, 108 insertions(+), 73 deletions(-)

lib/compiler_rt/emutls.zig+2-2
......@@ -246,7 +246,7 @@ const emutls_control = extern struct {
246246 // Two threads could race against the same emutls_control.
247247
248248 // Use atomic for reading coherent value lockless.
249 const index_lockless = @atomicLoad(usize, &self.object.index, .Acquire);
249 const index_lockless = @atomicLoad(usize, &self.object.index, .acquire);
250250
251251 if (index_lockless != 0) {
252252 // index is already initialized, return it.
......@@ -264,7 +264,7 @@ const emutls_control = extern struct {
264264 }
265265
266266 // Store a new index atomically (for having coherent index_lockless reading).
267 @atomicStore(usize, &self.object.index, emutls_control.next_index, .Release);
267 @atomicStore(usize, &self.object.index, emutls_control.next_index, .release);
268268
269269 // Increment the next available index
270270 emutls_control.next_index += 1;
lib/std/Thread/Futex.zig+4-4
......@@ -801,7 +801,7 @@ const PosixImpl = struct {
801801 assert(std.c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);
802802 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
803803
804 cancelled = ptr.load(.Monotonic) != expect;
804 cancelled = ptr.load(.monotonic) != expect;
805805 if (cancelled) {
806806 return;
807807 }
......@@ -855,14 +855,14 @@ const PosixImpl = struct {
855855 // The pending count increment in wait() must also now use seq_cst for the update + this pending load
856856 // to be in the same modification order as our load isn't using release/acquire to guarantee it.
857857 bucket.pending.fence(.seq_cst);
858 if (bucket.pending.load(.Monotonic) == 0) {
858 if (bucket.pending.load(.monotonic) == 0) {
859859 return;
860860 }
861861
862862 // Keep a list of all the waiters notified and wake then up outside the mutex critical section.
863863 var notified = WaitList{};
864864 defer if (notified.len > 0) {
865 const pending = bucket.pending.fetchSub(notified.len, .Monotonic);
865 const pending = bucket.pending.fetchSub(notified.len, .monotonic);
866866 assert(pending >= notified.len);
867867
868868 while (notified.pop()) |waiter| {
......@@ -875,7 +875,7 @@ const PosixImpl = struct {
875875 defer assert(std.c.pthread_mutex_unlock(&bucket.mutex) == .SUCCESS);
876876
877877 // Another pending check again to avoid the WaitQueue lookup if not necessary.
878 if (bucket.pending.load(.Monotonic) > 0) {
878 if (bucket.pending.load(.monotonic) > 0) {
879879 notified = WaitQueue.remove(&bucket.treap, address, max_waiters);
880880 }
881881 }
lib/std/Thread/RwLock.zig+1-1
......@@ -375,5 +375,5 @@ test "concurrent access" {
375375
376376 try testing.expectEqual(num_writes, runner.writes);
377377
378 //std.debug.print("reads={}\n", .{ runner.reads.load(.Unordered)});
378 //std.debug.print("reads={}\n", .{ runner.reads.load(.unordered)});
379379}
lib/std/atomic.zig+1-1
......@@ -159,7 +159,7 @@ test Value {
159159 // acquire ensures count decrement and code before
160160 // previous unrefs()s happens-before we call dropFn
161161 // below.
162 // Another alternative is to use .AcqRel on the
162 // Another alternative is to use .acq_rel on the
163163 // fetchSub count decrement but it's extra barrier in
164164 // possibly hot path.
165165 rc.count.fence(.acquire);
lib/std/c.zig+85-17
......@@ -1502,25 +1502,19 @@ pub extern "c" fn closedir(dp: *DIR) c_int;
15021502pub extern "c" fn telldir(dp: *DIR) c_long;
15031503pub extern "c" fn seekdir(dp: *DIR, loc: c_long) void;
15041504
1505pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int;
1506pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int;
1507pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
1508pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
1509
1510pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int;
1511
1512pub extern "c" fn sched_yield() c_int;
1513
1514pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
1515pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
1516pub extern "c" fn sigfillset(set: ?*c.sigset_t) void;
15171505pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int;
15181506
1519pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
1520
15211507pub extern "c" fn alarm(seconds: c_uint) c_uint;
15221508
1523pub extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
1509pub const clock_getres = switch (native_os) {
1510 .netbsd => private.__clock_getres50,
1511 else => private.clock_getres,
1512};
1513
1514pub const clock_gettime = switch (native_os) {
1515 .netbsd => private.__clock_gettime50,
1516 else => private.clock_gettime,
1517};
15241518
15251519pub const fstat = switch (native_os) {
15261520 .macos => switch (native_arch) {
......@@ -1539,6 +1533,31 @@ pub const fstatat = switch (native_os) {
15391533 else => private.fstatat,
15401534};
15411535
1536pub const getdirentries = switch (native_os) {
1537 .macos, .ios, .tvos, .watchos => private.__getdirentries64,
1538 else => private.getdirentries,
1539};
1540
1541pub const getrusage = switch (native_os) {
1542 .netbsd => private.__getrusage50,
1543 else => private.getrusage,
1544};
1545
1546pub const gettimeofday = switch (native_os) {
1547 .netbsd => private.__gettimeofday50,
1548 else => private.gettimeofday,
1549};
1550
1551pub const msync = switch (native_os) {
1552 .netbsd => private.__msync13,
1553 else => private.msync,
1554};
1555
1556pub const nanosleep = switch (native_os) {
1557 .netbsd => private.__nanosleep50,
1558 else => private.nanosleep,
1559};
1560
15421561pub const readdir = switch (native_os) {
15431562 .macos => switch (native_arch) {
15441563 .x86_64 => private.@"readdir$INODE64",
......@@ -1549,10 +1568,35 @@ pub const readdir = switch (native_os) {
15491568};
15501569
15511570pub const realpath = switch (native_os) {
1552 .macos, .ios, .watchos, .tvos => private.@"realpath$DARWIN_EXTSN",
1571 .macos, .ios, .tvos, .watchos => private.@"realpath$DARWIN_EXTSN",
15531572 else => private.realpath,
15541573};
15551574
1575pub const sched_yield = switch (native_os) {
1576 .netbsd => private.__libc_thr_yield,
1577 else => private.sched_yield,
1578};
1579
1580pub const sigaction = switch (native_os) {
1581 .netbsd => private.__sigaction14,
1582 else => private.sigaction,
1583};
1584
1585pub const sigfillset = switch (native_os) {
1586 .netbsd => private.__sigfillset14,
1587 else => private.sigfillset,
1588};
1589
1590pub const sigprocmask = switch (native_os) {
1591 .netbsd => private.__sigprocmask14,
1592 else => private.sigprocmask,
1593};
1594
1595pub const socket = switch (native_os) {
1596 .netbsd => private.__socket30,
1597 else => private.socket,
1598};
1599
15561600pub const stat = switch (native_os) {
15571601 .macos => switch (native_arch) {
15581602 .x86_64 => private.@"stat$INODE64",
......@@ -1680,7 +1724,6 @@ pub extern "c" fn recvfrom(
16801724pub extern "c" fn recvmsg(sockfd: c.fd_t, msg: *c.msghdr, flags: u32) isize;
16811725
16821726pub extern "c" fn kill(pid: c.pid_t, sig: c_int) c_int;
1683pub extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
16841727
16851728pub extern "c" fn setuid(uid: c.uid_t) c_int;
16861729pub extern "c" fn setgid(gid: c.gid_t) c_int;
......@@ -1878,10 +1921,22 @@ else
18781921 };
18791922
18801923const private = struct {
1924 extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int;
1925 extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int;
18811926 extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int;
18821927 extern "c" fn fstatat(dirfd: c.fd_t, path: [*:0]const u8, buf: *c.Stat, flag: u32) c_int;
1928 extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
1929 extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int;
1930 extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
1931 extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
1932 extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
18831933 extern "c" fn readdir(dir: *c.DIR) ?*c.dirent;
18841934 extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
1935 extern "c" fn sched_yield() c_int;
1936 extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
1937 extern "c" fn sigfillset(set: ?*c.sigset_t) void;
1938 extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
1939 extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
18851940 extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int;
18861941
18871942 /// macos modernized symbols.
......@@ -1894,7 +1949,20 @@ const private = struct {
18941949
18951950 /// macos modernized symbols.
18961951 extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
1952 extern "c" fn __getdirentries64(fd: c.fd_t, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
18971953
18981954 /// netbsd modernized symbols.
1955 extern "c" fn __clock_getres50(clk_id: c_int, tp: *c.timespec) c_int;
1956 extern "c" fn __clock_gettime50(clk_id: c_int, tp: *c.timespec) c_int;
18991957 extern "c" fn __fstat50(fd: c.fd_t, buf: *c.Stat) c_int;
1958 extern "c" fn __getrusage50(who: c_int, usage: *c.rusage) c_int;
1959 extern "c" fn __gettimeofday50(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
1960 extern "c" fn __libc_thr_yield() c_int;
1961 extern "c" fn __msync13(addr: *align(std.mem.page_size) const anyopaque, len: usize, flags: c_int) c_int;
1962 extern "c" fn __nanosleep50(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
1963 extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
1964 extern "c" fn __sigfillset14(set: ?*c.sigset_t) void;
1965 extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
1966 extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
1967 extern "c" fn __stat50(path: [*:0]const u8, buf: *c.Stat) c_int;
19001968};
lib/std/c/darwin.zig-3
......@@ -924,9 +924,6 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
924924pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
925925pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
926926
927// XXX: close -> close$NOCANCEL
928// XXX: getdirentries -> _getdirentries64
929
930927// See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html
931928// TODO: audit mode_t/pid_t, should likely be u16/i32
932929pub const blkcnt_t = i64;
lib/std/c/dragonfly.zig+6
......@@ -494,6 +494,12 @@ pub const sockaddr = extern struct {
494494 addr: [16]u8,
495495 scope_id: u32,
496496 };
497
498 pub const un = extern struct {
499 len: u8 = @sizeOf(un),
500 family: sa_family_t = AF.UNIX,
501 path: [104]u8,
502 };
497503};
498504
499505pub const Kevent = extern struct {
lib/std/c/netbsd.zig-33
......@@ -18,47 +18,14 @@ pub extern "c" fn _lwp_self() lwpid_t;
1818pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
1919pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
2020
21pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int;
22pub const stat = __stat50;
23
24pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int;
25pub const clock_gettime = __clock_gettime50;
26
27pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int;
28pub const clock_getres = __clock_getres50;
29
3021pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
3122pub const getdents = __getdents30;
3223
3324pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
3425pub const sigaltstack = __sigaltstack14;
3526
36pub extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int;
37pub const nanosleep = __nanosleep50;
38
39pub extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
40pub const sigaction = __sigaction14;
41
42pub extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
43pub const sigprocmask = __sigaction14;
44
45pub extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
46pub const socket = __socket30;
47
48pub extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
49pub const gettimeofday = __gettimeofday50;
50
51pub extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int;
52pub const getrusage = __getrusage50;
53
54pub extern "c" fn __libc_thr_yield() c_int;
55pub const sched_yield = __libc_thr_yield;
56
5727pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
5828
59pub extern "c" fn __msync13(addr: *align(std.mem.page_size) const anyopaque, len: usize, flags: c_int) c_int;
60pub const msync = __msync13;
61
6229pub const pthread_spin_t = switch (builtin.cpu.arch) {
6330 .aarch64, .aarch64_be, .aarch64_32 => u8,
6431 .mips, .mipsel, .mips64, .mips64el => u32,
lib/std/fs/Dir.zig+2-5
......@@ -49,7 +49,7 @@ pub const Iterator = switch (builtin.os.tag) {
4949 posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions
5050 self.first_iter = false;
5151 }
52 const rc = posix.system.__getdirentries64(
52 const rc = posix.system.getdirentries(
5353 self.dir.fd,
5454 &self.buf,
5555 self.buf.len,
......@@ -161,10 +161,7 @@ pub const Iterator = switch (builtin.os.tag) {
161161 posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions
162162 self.first_iter = false;
163163 }
164 const rc = if (builtin.os.tag == .netbsd)
165 posix.system.__getdents30(self.dir.fd, &self.buf, self.buf.len)
166 else
167 posix.system.getdents(self.dir.fd, &self.buf, self.buf.len);
164 const rc = posix.system.getdents(self.dir.fd, &self.buf, self.buf.len);
168165 switch (posix.errno(rc)) {
169166 .SUCCESS => {},
170167 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
src/Air.zig+3-3
......@@ -727,11 +727,11 @@ pub const Inst = struct {
727727 /// Result type is always `void`.
728728 /// Uses the `bin_op` field. LHS is pointer, RHS is element.
729729 atomic_store_unordered,
730 /// Same as `atomic_store_unordered` but with `AtomicOrder.Monotonic`.
730 /// Same as `atomic_store_unordered` but with `AtomicOrder.monotonic`.
731731 atomic_store_monotonic,
732 /// Same as `atomic_store_unordered` but with `AtomicOrder.Release`.
732 /// Same as `atomic_store_unordered` but with `AtomicOrder.release`.
733733 atomic_store_release,
734 /// Same as `atomic_store_unordered` but with `AtomicOrder.SeqCst`.
734 /// Same as `atomic_store_unordered` but with `AtomicOrder.seq_cst`.
735735 atomic_store_seq_cst,
736736 /// Atomically read-modify-write via a pointer.
737737 /// Result type is the element type of the pointer.
src/arch/sparc64/CodeGen.zig+4-4
......@@ -647,10 +647,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
647647 .call_never_tail => try self.airCall(inst, .never_tail),
648648 .call_never_inline => try self.airCall(inst, .never_inline),
649649
650 .atomic_store_unordered => @panic("TODO try self.airAtomicStore(inst, .Unordered)"),
651 .atomic_store_monotonic => @panic("TODO try self.airAtomicStore(inst, .Monotonic)"),
652 .atomic_store_release => @panic("TODO try self.airAtomicStore(inst, .Release)"),
653 .atomic_store_seq_cst => @panic("TODO try self.airAtomicStore(inst, .SeqCst)"),
650 .atomic_store_unordered => @panic("TODO try self.airAtomicStore(inst, .unordered)"),
651 .atomic_store_monotonic => @panic("TODO try self.airAtomicStore(inst, .monotonic)"),
652 .atomic_store_release => @panic("TODO try self.airAtomicStore(inst, .release)"),
653 .atomic_store_seq_cst => @panic("TODO try self.airAtomicStore(inst, .seq_cst)"),
654654
655655 .struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0),
656656 .struct_field_ptr_index_1 => try self.airStructFieldPtrIndex(inst, 1),