mirror of
https://github.com/ziglang/zig.git
synced 2025-12-07 14:53:08 +00:00
std.os.uefi: fix allocators compiling
This commit is contained in:
parent
8453fb09a2
commit
3fe981e1ad
@ -15,14 +15,14 @@ const UefiPoolAllocator = struct {
|
|||||||
fn alloc(
|
fn alloc(
|
||||||
_: *anyopaque,
|
_: *anyopaque,
|
||||||
len: usize,
|
len: usize,
|
||||||
log2_ptr_align: u8,
|
alignment: mem.Alignment,
|
||||||
ret_addr: usize,
|
ret_addr: usize,
|
||||||
) ?[*]u8 {
|
) ?[*]u8 {
|
||||||
_ = ret_addr;
|
_ = ret_addr;
|
||||||
|
|
||||||
assert(len > 0);
|
assert(len > 0);
|
||||||
|
|
||||||
const ptr_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align));
|
const ptr_align = alignment.toByteUnits();
|
||||||
|
|
||||||
const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align);
|
const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align);
|
||||||
|
|
||||||
@ -43,24 +43,38 @@ const UefiPoolAllocator = struct {
|
|||||||
fn resize(
|
fn resize(
|
||||||
_: *anyopaque,
|
_: *anyopaque,
|
||||||
buf: []u8,
|
buf: []u8,
|
||||||
log2_old_ptr_align: u8,
|
alignment: mem.Alignment,
|
||||||
new_len: usize,
|
new_len: usize,
|
||||||
ret_addr: usize,
|
ret_addr: usize,
|
||||||
) bool {
|
) bool {
|
||||||
_ = ret_addr;
|
_ = ret_addr;
|
||||||
_ = log2_old_ptr_align;
|
_ = alignment;
|
||||||
|
|
||||||
if (new_len > buf.len) return false;
|
if (new_len > buf.len) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn remap(
|
||||||
|
_: *anyopaque,
|
||||||
|
buf: []u8,
|
||||||
|
alignment: mem.Alignment,
|
||||||
|
new_len: usize,
|
||||||
|
ret_addr: usize,
|
||||||
|
) ?[*]u8 {
|
||||||
|
_ = alignment;
|
||||||
|
_ = ret_addr;
|
||||||
|
|
||||||
|
if (new_len > buf.len) return null;
|
||||||
|
return buf.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
fn free(
|
fn free(
|
||||||
_: *anyopaque,
|
_: *anyopaque,
|
||||||
buf: []u8,
|
buf: []u8,
|
||||||
log2_old_ptr_align: u8,
|
alignment: mem.Alignment,
|
||||||
ret_addr: usize,
|
ret_addr: usize,
|
||||||
) void {
|
) void {
|
||||||
_ = log2_old_ptr_align;
|
_ = alignment;
|
||||||
_ = ret_addr;
|
_ = ret_addr;
|
||||||
_ = uefi.system_table.boot_services.?.freePool(getHeader(buf.ptr).*);
|
_ = uefi.system_table.boot_services.?.freePool(getHeader(buf.ptr).*);
|
||||||
}
|
}
|
||||||
@ -76,6 +90,7 @@ pub const pool_allocator = Allocator{
|
|||||||
const pool_allocator_vtable = Allocator.VTable{
|
const pool_allocator_vtable = Allocator.VTable{
|
||||||
.alloc = UefiPoolAllocator.alloc,
|
.alloc = UefiPoolAllocator.alloc,
|
||||||
.resize = UefiPoolAllocator.resize,
|
.resize = UefiPoolAllocator.resize,
|
||||||
|
.remap = UefiPoolAllocator.remap,
|
||||||
.free = UefiPoolAllocator.free,
|
.free = UefiPoolAllocator.free,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,18 +103,19 @@ pub const raw_pool_allocator = Allocator{
|
|||||||
const raw_pool_allocator_table = Allocator.VTable{
|
const raw_pool_allocator_table = Allocator.VTable{
|
||||||
.alloc = uefi_alloc,
|
.alloc = uefi_alloc,
|
||||||
.resize = uefi_resize,
|
.resize = uefi_resize,
|
||||||
|
.remap = uefi_remap,
|
||||||
.free = uefi_free,
|
.free = uefi_free,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn uefi_alloc(
|
fn uefi_alloc(
|
||||||
_: *anyopaque,
|
_: *anyopaque,
|
||||||
len: usize,
|
len: usize,
|
||||||
log2_ptr_align: u8,
|
alignment: mem.Alignment,
|
||||||
ret_addr: usize,
|
ret_addr: usize,
|
||||||
) ?[*]u8 {
|
) ?[*]u8 {
|
||||||
_ = ret_addr;
|
_ = ret_addr;
|
||||||
|
|
||||||
std.debug.assert(log2_ptr_align <= 3);
|
std.debug.assert(@intFromEnum(alignment) <= 3);
|
||||||
|
|
||||||
var ptr: [*]align(8) u8 = undefined;
|
var ptr: [*]align(8) u8 = undefined;
|
||||||
if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, len, &ptr) != .Success) return null;
|
if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, len, &ptr) != .Success) return null;
|
||||||
@ -110,25 +126,40 @@ fn uefi_alloc(
|
|||||||
fn uefi_resize(
|
fn uefi_resize(
|
||||||
_: *anyopaque,
|
_: *anyopaque,
|
||||||
buf: []u8,
|
buf: []u8,
|
||||||
log2_old_ptr_align: u8,
|
alignment: mem.Alignment,
|
||||||
new_len: usize,
|
new_len: usize,
|
||||||
ret_addr: usize,
|
ret_addr: usize,
|
||||||
) bool {
|
) bool {
|
||||||
_ = ret_addr;
|
_ = ret_addr;
|
||||||
|
|
||||||
std.debug.assert(log2_old_ptr_align <= 3);
|
std.debug.assert(@intFromEnum(alignment) <= 3);
|
||||||
|
|
||||||
if (new_len > buf.len) return false;
|
if (new_len > buf.len) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn uefi_remap(
|
||||||
|
_: *anyopaque,
|
||||||
|
buf: []u8,
|
||||||
|
alignment: mem.Alignment,
|
||||||
|
new_len: usize,
|
||||||
|
ret_addr: usize,
|
||||||
|
) ?[*]u8 {
|
||||||
|
_ = ret_addr;
|
||||||
|
|
||||||
|
std.debug.assert(@intFromEnum(alignment) <= 3);
|
||||||
|
|
||||||
|
if (new_len > buf.len) return null;
|
||||||
|
return buf.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
fn uefi_free(
|
fn uefi_free(
|
||||||
_: *anyopaque,
|
_: *anyopaque,
|
||||||
buf: []u8,
|
buf: []u8,
|
||||||
log2_old_ptr_align: u8,
|
alignment: mem.Alignment,
|
||||||
ret_addr: usize,
|
ret_addr: usize,
|
||||||
) void {
|
) void {
|
||||||
_ = log2_old_ptr_align;
|
_ = alignment;
|
||||||
_ = ret_addr;
|
_ = ret_addr;
|
||||||
_ = uefi.system_table.boot_services.?.freePool(@alignCast(buf.ptr));
|
_ = uefi.system_table.boot_services.?.freePool(@alignCast(buf.ptr));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user