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 3f3003097c.
This commit is contained in:
Andrew Kelley 2022-10-30 19:28:26 -07:00
parent ef761c2cbc
commit d02242661e

View file

@ -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)];