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 {
306306 }
307307
308308 const rc = os.freebsd._umtx_op(
309 @intFromPtr(&ptr.value),
309 @intFromPtr(&ptr.raw),
310310 @intFromEnum(os.freebsd.UMTX_OP.WAIT_UINT_PRIVATE),
311311 @as(c_ulong, expect),
312312 tm_size,
......@@ -328,7 +328,7 @@ const FreebsdImpl = struct {
328328
329329 fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
330330 const rc = os.freebsd._umtx_op(
331 @intFromPtr(&ptr.value),
331 @intFromPtr(&ptr.raw),
332332 @intFromEnum(os.freebsd.UMTX_OP.WAKE_PRIVATE),
333333 @as(c_ulong, max_waiters),
334334 0, // there is no timeout struct
......@@ -354,7 +354,7 @@ const OpenbsdImpl = struct {
354354 }
355355
356356 const rc = os.openbsd.futex(
357 @as(*const volatile u32, @ptrCast(&ptr.value)),
357 @as(*const volatile u32, @ptrCast(&ptr.raw)),
358358 os.openbsd.FUTEX_WAIT | os.openbsd.FUTEX_PRIVATE_FLAG,
359359 @as(c_int, @bitCast(expect)),
360360 if (timeout != null) &ts else null,
......@@ -379,7 +379,7 @@ const OpenbsdImpl = struct {
379379
380380 fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
381381 const rc = os.openbsd.futex(
382 @as(*const volatile u32, @ptrCast(&ptr.value)),
382 @as(*const volatile u32, @ptrCast(&ptr.raw)),
383383 os.openbsd.FUTEX_WAKE | os.openbsd.FUTEX_PRIVATE_FLAG,
384384 std.math.cast(c_int, max_waiters) orelse std.math.maxInt(c_int),
385385 null, // FUTEX_WAKE takes no timeout ptr
......@@ -414,7 +414,7 @@ const DragonflyImpl = struct {
414414 }
415415
416416 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));
418418 const rc = os.dragonfly.umtx_sleep(addr, value, timeout_us);
419419
420420 switch (os.errno(rc)) {
......@@ -443,7 +443,7 @@ const DragonflyImpl = struct {
443443 // https://man.dragonflybsd.org/?command=umtx&section=2
444444 // > umtx_wakeup() will generally return 0 unless the address is bad.
445445 // 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));
447447 _ = os.dragonfly.umtx_wakeup(addr, to_wake);
448448 }
449449};
......@@ -461,7 +461,7 @@ const WasmImpl = struct {
461461 \\memory.atomic.wait32 0
462462 \\local.set %[ret]
463463 : [ret] "=r" (-> u32),
464 : [ptr] "r" (&ptr.value),
464 : [ptr] "r" (&ptr.raw),
465465 [expected] "r" (@as(i32, @bitCast(expect))),
466466 [timeout] "r" (to),
467467 );
......@@ -484,7 +484,7 @@ const WasmImpl = struct {
484484 \\memory.atomic.notify 0
485485 \\local.set %[ret]
486486 : [ret] "=r" (-> u32),
487 : [ptr] "r" (&ptr.value),
487 : [ptr] "r" (&ptr.raw),
488488 [waiters] "r" (max_waiters),
489489 );
490490 _ = 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
23872387 else => unreachable,
23882388 };
23892389
2390 const code = if (native_os == .netbsd) info.info.code else info.code;
23902391 nosuspend switch (panic_stage) {
23912392 0 => {
23922393 panic_stage = 1;
......@@ -2396,14 +2397,14 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
23962397 panic_mutex.lock();
23972398 defer panic_mutex.unlock();
23982399
2399 dumpSegfaultInfoPosix(sig, info.code, addr, ctx_ptr);
2400 dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr);
24002401 }
24012402
24022403 waitForOtherThreadToFinishPanicking();
24032404 },
24042405 else => {
24052406 // panic mutex already locked
2406 dumpSegfaultInfoPosix(sig, info.code, addr, ctx_ptr);
2407 dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr);
24072408 },
24082409 };
24092410