authorgravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2025-02-07 15:59:35-08:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-02-08 12:33:36+01:00
log3fe981e1ad746f9e3dfa2006fc69c907c92ddce6
tree91effe83a66d6943d6cd9399ecc0cd171c68e2e4
parent8453fb09a20dbf9a31c7986accbee727e511f40b

std.os.uefi: fix allocators compiling


1 files changed, 43 insertions(+), 12 deletions(-)

lib/std/os/uefi/pool_allocator.zig+43-12
...@@ -15,14 +15,14 @@ const UefiPoolAllocator = struct {...@@ -15,14 +15,14 @@ const UefiPoolAllocator = struct {
15 fn alloc(15 fn alloc(
16 _: *anyopaque,16 _: *anyopaque,
17 len: usize,17 len: usize,
18 log2_ptr_align: u8,18 alignment: mem.Alignment,
19 ret_addr: usize,19 ret_addr: usize,
20 ) ?[*]u8 {20 ) ?[*]u8 {
21 _ = ret_addr;21 _ = ret_addr;
2222
23 assert(len > 0);23 assert(len > 0);
2424
25 const ptr_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align));25 const ptr_align = alignment.toByteUnits();
2626
27 const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align);27 const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align);
2828
...@@ -43,24 +43,38 @@ const UefiPoolAllocator = struct {...@@ -43,24 +43,38 @@ const UefiPoolAllocator = struct {
43 fn resize(43 fn resize(
44 _: *anyopaque,44 _: *anyopaque,
45 buf: []u8,45 buf: []u8,
46 log2_old_ptr_align: u8,46 alignment: mem.Alignment,
47 new_len: usize,47 new_len: usize,
48 ret_addr: usize,48 ret_addr: usize,
49 ) bool {49 ) bool {
50 _ = ret_addr;50 _ = ret_addr;
51 _ = log2_old_ptr_align;51 _ = alignment;
5252
53 if (new_len > buf.len) return false;53 if (new_len > buf.len) return false;
54 return true;54 return true;
55 }55 }
5656
57 fn remap(
58 _: *anyopaque,
59 buf: []u8,
60 alignment: mem.Alignment,
61 new_len: usize,
62 ret_addr: usize,
63 ) ?[*]u8 {
64 _ = alignment;
65 _ = ret_addr;
66
67 if (new_len > buf.len) return null;
68 return buf.ptr;
69 }
70
57 fn free(71 fn free(
58 _: *anyopaque,72 _: *anyopaque,
59 buf: []u8,73 buf: []u8,
60 log2_old_ptr_align: u8,74 alignment: mem.Alignment,
61 ret_addr: usize,75 ret_addr: usize,
62 ) void {76 ) void {
63 _ = log2_old_ptr_align;77 _ = alignment;
64 _ = ret_addr;78 _ = ret_addr;
65 _ = uefi.system_table.boot_services.?.freePool(getHeader(buf.ptr).*);79 _ = uefi.system_table.boot_services.?.freePool(getHeader(buf.ptr).*);
66 }80 }
...@@ -76,6 +90,7 @@ pub const pool_allocator = Allocator{...@@ -76,6 +90,7 @@ pub const pool_allocator = Allocator{
76const pool_allocator_vtable = Allocator.VTable{90const pool_allocator_vtable = Allocator.VTable{
77 .alloc = UefiPoolAllocator.alloc,91 .alloc = UefiPoolAllocator.alloc,
78 .resize = UefiPoolAllocator.resize,92 .resize = UefiPoolAllocator.resize,
93 .remap = UefiPoolAllocator.remap,
79 .free = UefiPoolAllocator.free,94 .free = UefiPoolAllocator.free,
80};95};
8196
...@@ -88,18 +103,19 @@ pub const raw_pool_allocator = Allocator{...@@ -88,18 +103,19 @@ pub const raw_pool_allocator = Allocator{
88const raw_pool_allocator_table = Allocator.VTable{103const raw_pool_allocator_table = Allocator.VTable{
89 .alloc = uefi_alloc,104 .alloc = uefi_alloc,
90 .resize = uefi_resize,105 .resize = uefi_resize,
106 .remap = uefi_remap,
91 .free = uefi_free,107 .free = uefi_free,
92};108};
93109
94fn uefi_alloc(110fn uefi_alloc(
95 _: *anyopaque,111 _: *anyopaque,
96 len: usize,112 len: usize,
97 log2_ptr_align: u8,113 alignment: mem.Alignment,
98 ret_addr: usize,114 ret_addr: usize,
99) ?[*]u8 {115) ?[*]u8 {
100 _ = ret_addr;116 _ = ret_addr;
101117
102 std.debug.assert(log2_ptr_align <= 3);118 std.debug.assert(@intFromEnum(alignment) <= 3);
103119
104 var ptr: [*]align(8) u8 = undefined;120 var ptr: [*]align(8) u8 = undefined;
105 if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, len, &ptr) != .Success) return null;121 if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, len, &ptr) != .Success) return null;
...@@ -110,25 +126,40 @@ fn uefi_alloc(...@@ -110,25 +126,40 @@ fn uefi_alloc(
110fn uefi_resize(126fn uefi_resize(
111 _: *anyopaque,127 _: *anyopaque,
112 buf: []u8,128 buf: []u8,
113 log2_old_ptr_align: u8,129 alignment: mem.Alignment,
114 new_len: usize,130 new_len: usize,
115 ret_addr: usize,131 ret_addr: usize,
116) bool {132) bool {
117 _ = ret_addr;133 _ = ret_addr;
118134
119 std.debug.assert(log2_old_ptr_align <= 3);135 std.debug.assert(@intFromEnum(alignment) <= 3);
120136
121 if (new_len > buf.len) return false;137 if (new_len > buf.len) return false;
122 return true;138 return true;
123}139}
124140
141fn uefi_remap(
142 _: *anyopaque,
143 buf: []u8,
144 alignment: mem.Alignment,
145 new_len: usize,
146 ret_addr: usize,
147) ?[*]u8 {
148 _ = ret_addr;
149
150 std.debug.assert(@intFromEnum(alignment) <= 3);
151
152 if (new_len > buf.len) return null;
153 return buf.ptr;
154}
155
125fn uefi_free(156fn uefi_free(
126 _: *anyopaque,157 _: *anyopaque,
127 buf: []u8,158 buf: []u8,
128 log2_old_ptr_align: u8,159 alignment: mem.Alignment,
129 ret_addr: usize,160 ret_addr: usize,
130) void {161) void {
131 _ = log2_old_ptr_align;162 _ = alignment;
132 _ = ret_addr;163 _ = ret_addr;
133 _ = uefi.system_table.boot_services.?.freePool(@alignCast(buf.ptr));164 _ = uefi.system_table.boot_services.?.freePool(@alignCast(buf.ptr));
134}165}