authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-17 10:48:37+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-17 18:21:04+01:00
logfdee7dd60dccd184a4fd4023ad03c4236f6a20b3
tree81220e0bcc142c185300922dce2f480a7574e7de
parent4012fcb0a383dbf5564ef15e4c607705a1859a20

debug: msync only current page when validation frame pointer

This fixes lack of stack traces on arm64 macOS which were regressed and not getting generated at all after this addition to write current stack traces. Prior to this, function `isValidMemory` would sync two subsequent pages if the aligned (base) address was different than the frame pointer. I fail to see what the logic for such assumption here is as the manual of `msync` clearly states it will fail with error if the passed in memory region length contains unmapped regions. This was the very reason why there were no stack traces print on arm64 macOS as the second page was unmapped thus incorrectly flagging the frame pointer as invalid.

1 files changed, 2 insertions(+), 7 deletions(-)

lib/std/debug.zig+2-7
......@@ -429,11 +429,7 @@ pub const StackIterator = struct {
429429 if (native_os == .freestanding) return true;
430430
431431 const aligned_address = address & ~@intCast(usize, (mem.page_size - 1));
432
433 // If the address does not span 2 pages, query only the first one
434 const length: usize = if (aligned_address == address) mem.page_size else 2 * mem.page_size;
435
436 const aligned_memory = @intToPtr([*]align(mem.page_size) u8, aligned_address)[0..length];
432 const aligned_memory = @intToPtr([*]align(mem.page_size) u8, aligned_address)[0..mem.page_size];
437433
438434 if (native_os != .windows) {
439435 if (native_os != .wasi) {
......@@ -451,11 +447,10 @@ pub const StackIterator = struct {
451447 } else {
452448 const w = os.windows;
453449 var memory_info: w.MEMORY_BASIC_INFORMATION = undefined;
454 //const memory_info_ptr = @ptrCast(w.PMEMORY_BASIC_INFORMATION, buffer);
455450
456451 // The only error this function can throw is ERROR_INVALID_PARAMETER.
457452 // supply an address that invalid i'll be thrown.
458 const rc = w.VirtualQuery(aligned_memory.ptr, &memory_info, aligned_memory.len) catch {
453 const rc = w.VirtualQuery(aligned_memory, &memory_info, aligned_memory.len) catch {
459454 return false;
460455 };
461456