From ba58b7b88143f93f671a53a4809c9724de898b8d Mon Sep 17 00:00:00 2001 From: David Rubin Date: Mon, 15 Jul 2024 01:52:08 -0700 Subject: [PATCH] heap: create a work-around page-allocator the risc-v backend doesn't have `@cmpxchg*` implemented and so it can't use the hint that the current page-allocator uses. this work-around branch can be removed when I implement the atomic built-in. --- lib/std/heap/PageAllocator.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/std/heap/PageAllocator.zig b/lib/std/heap/PageAllocator.zig index 4188c25528..92c8ca6b28 100644 --- a/lib/std/heap/PageAllocator.zig +++ b/lib/std/heap/PageAllocator.zig @@ -34,6 +34,20 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 { return @ptrCast(addr); } + if (builtin.zig_backend == .stage2_riscv64) { + const aligned_len = mem.alignForward(usize, n, mem.page_size); + const slice = posix.mmap( + null, + aligned_len, + posix.PROT.READ | posix.PROT.WRITE, + .{ .TYPE = .PRIVATE, .ANONYMOUS = true }, + -1, + 0, + ) catch return null; + assert(mem.isAligned(@intFromPtr(slice.ptr), mem.page_size)); + return slice.ptr; + } + const aligned_len = mem.alignForward(usize, n, mem.page_size); const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .unordered); const slice = posix.mmap(