Commit 3fe981e1ad

Tristan Ross <tristan.ross@midstall.com>
2025-02-08 00:59:35
std.os.uefi: fix allocators compiling
1 parent 8453fb0
Changed files (1)
lib
std
lib/std/os/uefi/pool_allocator.zig
@@ -15,14 +15,14 @@ const UefiPoolAllocator = struct {
     fn alloc(
         _: *anyopaque,
         len: usize,
-        log2_ptr_align: u8,
+        alignment: mem.Alignment,
         ret_addr: usize,
     ) ?[*]u8 {
         _ = ret_addr;
 
         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);
 
@@ -43,24 +43,38 @@ const UefiPoolAllocator = struct {
     fn resize(
         _: *anyopaque,
         buf: []u8,
-        log2_old_ptr_align: u8,
+        alignment: mem.Alignment,
         new_len: usize,
         ret_addr: usize,
     ) bool {
         _ = ret_addr;
-        _ = log2_old_ptr_align;
+        _ = alignment;
 
         if (new_len > buf.len) return false;
         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(
         _: *anyopaque,
         buf: []u8,
-        log2_old_ptr_align: u8,
+        alignment: mem.Alignment,
         ret_addr: usize,
     ) void {
-        _ = log2_old_ptr_align;
+        _ = alignment;
         _ = ret_addr;
         _ = uefi.system_table.boot_services.?.freePool(getHeader(buf.ptr).*);
     }
@@ -76,6 +90,7 @@ pub const pool_allocator = Allocator{
 const pool_allocator_vtable = Allocator.VTable{
     .alloc = UefiPoolAllocator.alloc,
     .resize = UefiPoolAllocator.resize,
+    .remap = UefiPoolAllocator.remap,
     .free = UefiPoolAllocator.free,
 };
 
@@ -88,18 +103,19 @@ pub const raw_pool_allocator = Allocator{
 const raw_pool_allocator_table = Allocator.VTable{
     .alloc = uefi_alloc,
     .resize = uefi_resize,
+    .remap = uefi_remap,
     .free = uefi_free,
 };
 
 fn uefi_alloc(
     _: *anyopaque,
     len: usize,
-    log2_ptr_align: u8,
+    alignment: mem.Alignment,
     ret_addr: usize,
 ) ?[*]u8 {
     _ = ret_addr;
 
-    std.debug.assert(log2_ptr_align <= 3);
+    std.debug.assert(@intFromEnum(alignment) <= 3);
 
     var ptr: [*]align(8) u8 = undefined;
     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(
     _: *anyopaque,
     buf: []u8,
-    log2_old_ptr_align: u8,
+    alignment: mem.Alignment,
     new_len: usize,
     ret_addr: usize,
 ) bool {
     _ = ret_addr;
 
-    std.debug.assert(log2_old_ptr_align <= 3);
+    std.debug.assert(@intFromEnum(alignment) <= 3);
 
     if (new_len > buf.len) return false;
     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(
     _: *anyopaque,
     buf: []u8,
-    log2_old_ptr_align: u8,
+    alignment: mem.Alignment,
     ret_addr: usize,
 ) void {
-    _ = log2_old_ptr_align;
+    _ = alignment;
     _ = ret_addr;
     _ = uefi.system_table.boot_services.?.freePool(@alignCast(buf.ptr));
 }