diff options
| author | Jay Petacat <jay@jayschwa.net> | 2023-10-09 22:24:14 -0600 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-01-16 15:05:38 -0800 |
| commit | fd43baa9ad37217a5715c1e3cfad2d2d78558d1f (patch) | |
| tree | c0d75d8a8c92038f05ea78f961b5dd7b23e0efbc /lib/std/debug.zig | |
| parent | a338c279f82bfeb68e37b40cd4fc59557336b6ce (diff) | |
| download | zig-fd43baa9ad37217a5715c1e3cfad2d2d78558d1f.tar.gz zig-fd43baa9ad37217a5715c1e3cfad2d2d78558d1f.zip | |
byos: Ease `GeneralPurposeAllocator` integration
These changes enable me to use `GeneralPurposeAllocator` with my "Bring
Your Own OS" package. The previous checks for a freestanding target have
been expanded to `@hasDecl` checks.
- `root.os.heap.page_allocator` is used if it exists.
- `debug.isValidMemory` only calls `os.msync` if it's supported.
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 4670c49dfa..5976e52684 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -667,20 +667,7 @@ pub const StackIterator = struct { if (aligned_address == 0) return false; const aligned_memory = @as([*]align(mem.page_size) u8, @ptrFromInt(aligned_address))[0..mem.page_size]; - if (native_os != .windows) { - if (native_os != .wasi) { - os.msync(aligned_memory, os.MSF.ASYNC) catch |err| { - switch (err) { - os.MSyncError.UnmappedMemory => { - return false; - }, - else => unreachable, - } - }; - } - - return true; - } else { + if (native_os == .windows) { const w = os.windows; var memory_info: w.MEMORY_BASIC_INFORMATION = undefined; @@ -701,6 +688,20 @@ pub const StackIterator = struct { } return true; + } else if (@hasDecl(os.system, "msync") and native_os != .wasi) { + os.msync(aligned_memory, os.MSF.ASYNC) catch |err| { + switch (err) { + os.MSyncError.UnmappedMemory => { + return false; + }, + else => unreachable, + } + }; + + return true; + } else { + // We are unable to determine validity of memory on this target. + return true; } } |
