mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +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 3f3003097c.
This commit is contained in:
parent
ef761c2cbc
commit
d02242661e
1 changed files with 3 additions and 0 deletions
|
|
@ -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…
Add table
Reference in a new issue