Skip to content

Commit b2cd926

Browse files
std.os.uefi: fix allocators compiling
1 parent 6a6e72f commit b2cd926

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

lib/std/os/uefi/pool_allocator.zig

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ const UefiPoolAllocator = struct {
1515
fn alloc(
1616
_: *anyopaque,
1717
len: usize,
18-
log2_ptr_align: u8,
18+
alignment: mem.Alignment,
1919
ret_addr: usize,
2020
) ?[*]u8 {
2121
_ = ret_addr;
2222

2323
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

2727
const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align);
2828

@@ -43,24 +43,38 @@ const UefiPoolAllocator = struct {
4343
fn resize(
4444
_: *anyopaque,
4545
buf: []u8,
46-
log2_old_ptr_align: u8,
46+
alignment: mem.Alignment,
4747
new_len: usize,
4848
ret_addr: usize,
4949
) bool {
5050
_ = ret_addr;
51-
_ = log2_old_ptr_align;
51+
_ = alignment;
5252

5353
if (new_len > buf.len) return false;
5454
return true;
5555
}
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+
5771
fn free(
5872
_: *anyopaque,
5973
buf: []u8,
60-
log2_old_ptr_align: u8,
74+
alignment: mem.Alignment,
6175
ret_addr: usize,
6276
) void {
63-
_ = log2_old_ptr_align;
77+
_ = alignment;
6478
_ = ret_addr;
6579
_ = uefi.system_table.boot_services.?.freePool(getHeader(buf.ptr).*);
6680
}
@@ -76,6 +90,7 @@ pub const pool_allocator = Allocator{
7690
const pool_allocator_vtable = Allocator.VTable{
7791
.alloc = UefiPoolAllocator.alloc,
7892
.resize = UefiPoolAllocator.resize,
93+
.remap = UefiPoolAllocator.remap,
7994
.free = UefiPoolAllocator.free,
8095
};
8196

@@ -88,18 +103,19 @@ pub const raw_pool_allocator = Allocator{
88103
const raw_pool_allocator_table = Allocator.VTable{
89104
.alloc = uefi_alloc,
90105
.resize = uefi_resize,
106+
.remap = uefi_remap,
91107
.free = uefi_free,
92108
};
93109

94110
fn uefi_alloc(
95111
_: *anyopaque,
96112
len: usize,
97-
log2_ptr_align: u8,
113+
alignment: mem.Alignment,
98114
ret_addr: usize,
99115
) ?[*]u8 {
100116
_ = ret_addr;
101117

102-
std.debug.assert(log2_ptr_align <= 3);
118+
std.debug.assert(@intFromEnum(alignment) <= 3);
103119

104120
var ptr: [*]align(8) u8 = undefined;
105121
if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, len, &ptr) != .Success) return null;
@@ -110,25 +126,40 @@ fn uefi_alloc(
110126
fn uefi_resize(
111127
_: *anyopaque,
112128
buf: []u8,
113-
log2_old_ptr_align: u8,
129+
alignment: mem.Alignment,
114130
new_len: usize,
115131
ret_addr: usize,
116132
) bool {
117133
_ = ret_addr;
118134

119-
std.debug.assert(log2_old_ptr_align <= 3);
135+
std.debug.assert(@intFromEnum(alignment) <= 3);
120136

121137
if (new_len > buf.len) return false;
122138
return true;
123139
}
124140

141+
fn 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+
125156
fn uefi_free(
126157
_: *anyopaque,
127158
buf: []u8,
128-
log2_old_ptr_align: u8,
159+
alignment: mem.Alignment,
129160
ret_addr: usize,
130161
) void {
131-
_ = log2_old_ptr_align;
162+
_ = alignment;
132163
_ = ret_addr;
133164
_ = uefi.system_table.boot_services.?.freePool(@alignCast(buf.ptr));
134165
}

0 commit comments

Comments
 (0)