mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 14:55:25 +00:00
std.heap: make wasm32 PageAllocator handle large allocation
When a number of bytes to be allocated is so great that alignForward() is not possible, return `error.OutOfMemory`. Companion commit to 3f3003097cbf5a6ad9e0dfc29b2cafbe2e35dded.
This commit is contained in:
parent
ef761c2cbc
commit
d02242661e
@ -523,6 +523,9 @@ const WasmPageAllocator = struct {
|
||||
|
||||
fn alloc(_: *anyopaque, len: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 {
|
||||
_ = ra;
|
||||
if (len > maxInt(usize) - (mem.page_size - 1)) {
|
||||
return error.OutOfMemory;
|
||||
}
|
||||
const page_count = nPages(len);
|
||||
const page_idx = try allocPages(page_count, alignment);
|
||||
return @intToPtr([*]u8, page_idx * mem.page_size)[0..alignPageAllocLen(page_count * mem.page_size, len, len_align)];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user