authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-07-15 01:52:08-07:00
committergravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-07-26 04:05:41-07:00
logba58b7b88143f93f671a53a4809c9724de898b8d
tree1c9e923abd948a471b60f34f948413942a325a29
parentd3f75522d7e18188748558c2ae20928b83d173bf
signaturelock-open Commit is signed but in an unrecognized format.

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.

1 files changed, 14 insertions(+), 0 deletions(-)

lib/std/heap/PageAllocator.zig+14
......@@ -34,6 +34,20 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {
3434 return @ptrCast(addr);
3535 }
3636
37 if (builtin.zig_backend == .stage2_riscv64) {
38 const aligned_len = mem.alignForward(usize, n, mem.page_size);
39 const slice = posix.mmap(
40 null,
41 aligned_len,
42 posix.PROT.READ | posix.PROT.WRITE,
43 .{ .TYPE = .PRIVATE, .ANONYMOUS = true },
44 -1,
45 0,
46 ) catch return null;
47 assert(mem.isAligned(@intFromPtr(slice.ptr), mem.page_size));
48 return slice.ptr;
49 }
50
3751 const aligned_len = mem.alignForward(usize, n, mem.page_size);
3852 const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .unordered);
3953 const slice = posix.mmap(