authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2023-11-26 02:06:54-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-26 14:28:22-05:00
log50bbb9d960c07d0889d2a54c8715b9c772a883dc
tree938054f7a20d8e7fbaba4f1487f7649777e11b73
parent069a079ddc2ae07cfe1998a364402624f07ce960

bsd: debitrot atomic and debug

closes #18119

2 files changed, 11 insertions(+), 10 deletions(-)

lib/std/Thread/Futex.zig+8-8
...@@ -306,7 +306,7 @@ const FreebsdImpl = struct {...@@ -306,7 +306,7 @@ const FreebsdImpl = struct {
306 }306 }
307307
308 const rc = os.freebsd._umtx_op(308 const rc = os.freebsd._umtx_op(
309 @intFromPtr(&ptr.value),309 @intFromPtr(&ptr.raw),
310 @intFromEnum(os.freebsd.UMTX_OP.WAIT_UINT_PRIVATE),310 @intFromEnum(os.freebsd.UMTX_OP.WAIT_UINT_PRIVATE),
311 @as(c_ulong, expect),311 @as(c_ulong, expect),
312 tm_size,312 tm_size,
...@@ -328,7 +328,7 @@ const FreebsdImpl = struct {...@@ -328,7 +328,7 @@ const FreebsdImpl = struct {
328328
329 fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {329 fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
330 const rc = os.freebsd._umtx_op(330 const rc = os.freebsd._umtx_op(
331 @intFromPtr(&ptr.value),331 @intFromPtr(&ptr.raw),
332 @intFromEnum(os.freebsd.UMTX_OP.WAKE_PRIVATE),332 @intFromEnum(os.freebsd.UMTX_OP.WAKE_PRIVATE),
333 @as(c_ulong, max_waiters),333 @as(c_ulong, max_waiters),
334 0, // there is no timeout struct334 0, // there is no timeout struct
...@@ -354,7 +354,7 @@ const OpenbsdImpl = struct {...@@ -354,7 +354,7 @@ const OpenbsdImpl = struct {
354 }354 }
355355
356 const rc = os.openbsd.futex(356 const rc = os.openbsd.futex(
357 @as(*const volatile u32, @ptrCast(&ptr.value)),357 @as(*const volatile u32, @ptrCast(&ptr.raw)),
358 os.openbsd.FUTEX_WAIT | os.openbsd.FUTEX_PRIVATE_FLAG,358 os.openbsd.FUTEX_WAIT | os.openbsd.FUTEX_PRIVATE_FLAG,
359 @as(c_int, @bitCast(expect)),359 @as(c_int, @bitCast(expect)),
360 if (timeout != null) &ts else null,360 if (timeout != null) &ts else null,
...@@ -379,7 +379,7 @@ const OpenbsdImpl = struct {...@@ -379,7 +379,7 @@ const OpenbsdImpl = struct {
379379
380 fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {380 fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
381 const rc = os.openbsd.futex(381 const rc = os.openbsd.futex(
382 @as(*const volatile u32, @ptrCast(&ptr.value)),382 @as(*const volatile u32, @ptrCast(&ptr.raw)),
383 os.openbsd.FUTEX_WAKE | os.openbsd.FUTEX_PRIVATE_FLAG,383 os.openbsd.FUTEX_WAKE | os.openbsd.FUTEX_PRIVATE_FLAG,
384 std.math.cast(c_int, max_waiters) orelse std.math.maxInt(c_int),384 std.math.cast(c_int, max_waiters) orelse std.math.maxInt(c_int),
385 null, // FUTEX_WAKE takes no timeout ptr385 null, // FUTEX_WAKE takes no timeout ptr
...@@ -414,7 +414,7 @@ const DragonflyImpl = struct {...@@ -414,7 +414,7 @@ const DragonflyImpl = struct {
414 }414 }
415415
416 const value = @as(c_int, @bitCast(expect));416 const value = @as(c_int, @bitCast(expect));
417 const addr = @as(*const volatile c_int, @ptrCast(&ptr.value));417 const addr = @as(*const volatile c_int, @ptrCast(&ptr.raw));
418 const rc = os.dragonfly.umtx_sleep(addr, value, timeout_us);418 const rc = os.dragonfly.umtx_sleep(addr, value, timeout_us);
419419
420 switch (os.errno(rc)) {420 switch (os.errno(rc)) {
...@@ -443,7 +443,7 @@ const DragonflyImpl = struct {...@@ -443,7 +443,7 @@ const DragonflyImpl = struct {
443 // https://man.dragonflybsd.org/?command=umtx&section=2443 // https://man.dragonflybsd.org/?command=umtx&section=2
444 // > umtx_wakeup() will generally return 0 unless the address is bad.444 // > umtx_wakeup() will generally return 0 unless the address is bad.
445 // We are fine with the address being bad (e.g. for Semaphore.post() where Semaphore.wait() frees the Semaphore)445 // We are fine with the address being bad (e.g. for Semaphore.post() where Semaphore.wait() frees the Semaphore)
446 const addr = @as(*const volatile c_int, @ptrCast(&ptr.value));446 const addr = @as(*const volatile c_int, @ptrCast(&ptr.raw));
447 _ = os.dragonfly.umtx_wakeup(addr, to_wake);447 _ = os.dragonfly.umtx_wakeup(addr, to_wake);
448 }448 }
449};449};
...@@ -461,7 +461,7 @@ const WasmImpl = struct {...@@ -461,7 +461,7 @@ const WasmImpl = struct {
461 \\memory.atomic.wait32 0461 \\memory.atomic.wait32 0
462 \\local.set %[ret]462 \\local.set %[ret]
463 : [ret] "=r" (-> u32),463 : [ret] "=r" (-> u32),
464 : [ptr] "r" (&ptr.value),464 : [ptr] "r" (&ptr.raw),
465 [expected] "r" (@as(i32, @bitCast(expect))),465 [expected] "r" (@as(i32, @bitCast(expect))),
466 [timeout] "r" (to),466 [timeout] "r" (to),
467 );467 );
...@@ -484,7 +484,7 @@ const WasmImpl = struct {...@@ -484,7 +484,7 @@ const WasmImpl = struct {
484 \\memory.atomic.notify 0484 \\memory.atomic.notify 0
485 \\local.set %[ret]485 \\local.set %[ret]
486 : [ret] "=r" (-> u32),486 : [ret] "=r" (-> u32),
487 : [ptr] "r" (&ptr.value),487 : [ptr] "r" (&ptr.raw),
488 [waiters] "r" (max_waiters),488 [waiters] "r" (max_waiters),
489 );489 );
490 _ = woken_count; // can be 0 when linker flag 'shared-memory' is not enabled490 _ = woken_count; // can be 0 when linker flag 'shared-memory' is not enabled
lib/std/debug.zig+3-2
...@@ -2387,6 +2387,7 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any...@@ -2387,6 +2387,7 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
2387 else => unreachable,2387 else => unreachable,
2388 };2388 };
23892389
2390 const code = if (native_os == .netbsd) info.info.code else info.code;
2390 nosuspend switch (panic_stage) {2391 nosuspend switch (panic_stage) {
2391 0 => {2392 0 => {
2392 panic_stage = 1;2393 panic_stage = 1;
...@@ -2396,14 +2397,14 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any...@@ -2396,14 +2397,14 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
2396 panic_mutex.lock();2397 panic_mutex.lock();
2397 defer panic_mutex.unlock();2398 defer panic_mutex.unlock();
23982399
2399 dumpSegfaultInfoPosix(sig, info.code, addr, ctx_ptr);2400 dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr);
2400 }2401 }
24012402
2402 waitForOtherThreadToFinishPanicking();2403 waitForOtherThreadToFinishPanicking();
2403 },2404 },
2404 else => {2405 else => {
2405 // panic mutex already locked2406 // panic mutex already locked
2406 dumpSegfaultInfoPosix(sig, info.code, addr, ctx_ptr);2407 dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr);
2407 },2408 },
2408 };2409 };
24092410