diff options
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 0ce9f7b132..8c0992faee 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -2401,14 +2401,14 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any panic_mutex.lock(); defer panic_mutex.unlock(); - dumpSegfaultInfoPosix(sig, addr, ctx_ptr); + dumpSegfaultInfoPosix(sig, info.code, addr, ctx_ptr); } waitForOtherThreadToFinishPanicking(); }, else => { // panic mutex already locked - dumpSegfaultInfoPosix(sig, addr, ctx_ptr); + dumpSegfaultInfoPosix(sig, info.code, addr, ctx_ptr); }, }; @@ -2418,10 +2418,20 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any os.abort(); } -fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void { +fn dumpSegfaultInfoPosix(sig: i32, code: i32, addr: usize, ctx_ptr: ?*const anyopaque) void { const stderr = io.getStdErr().writer(); _ = switch (sig) { - os.SIG.SEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}), + os.SIG.SEGV => if (native_arch == .x86_64 and native_os == .linux and code == 128) // SI_KERNEL + // x86_64 doesn't have a full 64-bit virtual address space. + // Addresses outside of that address space are non-canonical + // and the CPU won't provide the faulting address to us. + // This happens when accessing memory addresses such as 0xaaaaaaaaaaaaaaaa + // but can also happen when no addressable memory is involved; + // for example when reading/writing model-specific registers + // by executing `rdmsr` or `wrmsr` in user-space (unprivileged mode). + stderr.print("General protection exception (no address available)\n", .{}) + else + stderr.print("Segmentation fault at address 0x{x}\n", .{addr}), os.SIG.ILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}), os.SIG.BUS => stderr.print("Bus error at address 0x{x}\n", .{addr}), os.SIG.FPE => stderr.print("Arithmetic exception at address 0x{x}\n", .{addr}), |
