authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 12:41:22-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:12-08:00
log98e9716c082aa7e134e11ed14db8c2f631fedc8a
tree1579ad131ca73c4461dc740ed0f85e97c052738c
parent7788fd62330bf4c9b4b03700c27e88b16ebd1f46

std: fix compilation on NetBSD


1 files changed, 14 insertions(+), 8 deletions(-)

lib/std/Io/Threaded.zig+14-8
......@@ -372,7 +372,10 @@ const Thread = struct {
372372 };
373373 },
374374 else => if (std.Thread.use_pthreads) {
375 return pthreads_futex.wait(ptr, expect, timeout_ns);
375 // TODO integrate the following function being called with robust cancelation.
376 return pthreads_futex.wait(ptr, expect, timeout_ns) catch |err| switch (err) {
377 error.Timeout => {},
378 };
376379 } else {
377380 @compileError("unimplemented: futexWait");
378381 },
......@@ -11583,7 +11586,7 @@ const pthreads_futex = struct {
1158311586 // This can be changed with pthread_condattr_setclock, but it's an extension and may not be available everywhere.
1158411587 var ts: c.timespec = undefined;
1158511588 if (timeout) |timeout_ns| {
11586 ts = std.posix.clock_gettime(c.CLOCK.REALTIME) catch unreachable;
11589 ts = std.posix.clock_gettime(c.CLOCK.REALTIME) catch return error.Timeout;
1158711590 ts.sec +|= @as(@TypeOf(ts.sec), @intCast(timeout_ns / std.time.ns_per_s));
1158811591 ts.nsec += @as(@TypeOf(ts.nsec), @intCast(timeout_ns % std.time.ns_per_s));
1158911592
......@@ -11617,9 +11620,9 @@ const pthreads_futex = struct {
1161711620 self.state = .empty;
1161811621 return error.Timeout;
1161911622 },
11620 .INVAL => unreachable, // cond, mutex, and potentially ts should all be valid
11621 .PERM => unreachable, // mutex is locked when cond_*wait() functions are called
11622 else => unreachable,
11623 .INVAL => recoverableOsBugDetected(), // cond, mutex, and potentially ts should all be valid
11624 .PERM => recoverableOsBugDetected(), // mutex is locked when cond_*wait() functions are called
11625 else => recoverableOsBugDetected(),
1162311626 }
1162411627 }
1162511628 }
......@@ -11866,9 +11869,12 @@ const pthreads_futex = struct {
1186611869 }
1186711870
1186811871 waiter.event.wait(timeout) catch {
11869 // If we fail to cancel after a timeout, it means a wake() thread dequeued us and will wake us up.
11870 // We must wait until the event is set as that's a signal that the wake() thread won't access the waiter memory anymore.
11871 // If we return early without waiting, the waiter on the stack would be invalidated and the wake() thread risks a UAF.
11872 // If we fail to cancel after a timeout, it means a wake() thread
11873 // dequeued us and will wake us up. We must wait until the event is
11874 // set as that's a signal that the wake() thread won't access the
11875 // waiter memory anymore. If we return early without waiting, the
11876 // waiter on the stack would be invalidated and the wake() thread
11877 // risks a UAF.
1187211878 defer if (!canceled) waiter.event.wait(null) catch unreachable;
1187311879
1187411880 assert(c.pthread_mutex_lock(&bucket.mutex) == .SUCCESS);