1
- const std = @import ("../../ std.zig" );
1
+ const std = @import ("../std.zig" );
2
2
3
3
const mem = std .mem ;
4
4
const uefi = std .os .uefi ;
@@ -7,13 +7,16 @@ const Allocator = mem.Allocator;
7
7
8
8
const assert = std .debug .assert ;
9
9
10
+ pub var global_page_allocator = PageAllocator {};
11
+ pub var global_pool_allocator = PoolAllocator {};
12
+
10
13
/// Allocates memory in pages.
11
14
///
12
15
/// This allocator is backed by `allocatePages` and is therefore only suitable for usage when Boot Services are available.
13
- pub const Page = struct {
14
- memory_type : uefi.tables.MemoryType = .LoaderData ,
16
+ pub const PageAllocator = struct {
17
+ memory_type : uefi.tables.MemoryType = .loader_data ,
15
18
16
- pub fn allocator (self : * Page ) Allocator {
19
+ pub fn allocator (self : * PageAllocator ) Allocator {
17
20
return Allocator {
18
21
.ptr = self ,
19
22
.vtable = & vtable ,
@@ -36,7 +39,7 @@ pub const Page = struct {
36
39
_ = alignment ;
37
40
_ = ret_addr ;
38
41
39
- const self : * Page = @ptrCast (@alignCast (ctx ));
42
+ const self : * PageAllocator = @ptrCast (@alignCast (ctx ));
40
43
41
44
assert (len > 0 );
42
45
const pages = mem .alignForward (usize , len , 4096 ) / 4096 ;
@@ -55,7 +58,7 @@ pub const Page = struct {
55
58
_ = alignment ;
56
59
_ = ret_addr ;
57
60
58
- const self : * Page = @ptrCast (@alignCast (ctx ));
61
+ const self : * PageAllocator = @ptrCast (@alignCast (ctx ));
59
62
60
63
// If the buffer was originally larger than the new length, we can grow or shrink it in place.
61
64
const original_len = mem .alignForward (usize , buf .len , 4096 );
@@ -109,10 +112,10 @@ pub const Page = struct {
109
112
/// Supports the full std.mem.Allocator interface, including up to page alignment.
110
113
///
111
114
/// This allocator is backed by `allocatePool` and is therefore only suitable for usage when Boot Services are available.
112
- pub const Pool = struct {
113
- memory_type : uefi.tables.MemoryType = .LoaderData ,
115
+ pub const PoolAllocator = struct {
116
+ memory_type : uefi.tables.MemoryType = .loader_data ,
114
117
115
- pub fn allocator (self : * Pool ) Allocator {
118
+ pub fn allocator (self : * PoolAllocator ) Allocator {
116
119
return Allocator {
117
120
.ptr = self ,
118
121
.vtable = & vtable ,
@@ -142,7 +145,7 @@ pub const Pool = struct {
142
145
ret_addr : usize ,
143
146
) ? [* ]u8 {
144
147
_ = ret_addr ;
145
- const self : * Pool = @ptrCast (@alignCast (ctx ));
148
+ const self : * PoolAllocator = @ptrCast (@alignCast (ctx ));
146
149
147
150
assert (len > 0 );
148
151
@@ -218,10 +221,10 @@ pub const Pool = struct {
218
221
/// Asserts all allocations are at most 8 byte aligned. This is the highest alignment UEFI will give us directly.
219
222
///
220
223
/// This allocator is backed by `allocatePool` and is therefore only suitable for usage when Boot Services are available.
221
- pub const RawPool = struct {
224
+ pub const RawPoolAllocator = struct {
222
225
memory_type : uefi.tables.MemoryType = .LoaderData ,
223
226
224
- pub fn allocator (self : * RawPool ) Allocator {
227
+ pub fn allocator (self : * RawPoolAllocator ) Allocator {
225
228
return Allocator {
226
229
.ptr = self ,
227
230
.vtable = & vtable ,
@@ -242,7 +245,7 @@ pub const RawPool = struct {
242
245
ret_addr : usize ,
243
246
) ? [* ]u8 {
244
247
_ = ret_addr ;
245
- const self : * RawPool = @ptrCast (@alignCast (ctx ));
248
+ const self : * RawPoolAllocator = @ptrCast (@alignCast (ctx ));
246
249
247
250
// UEFI pool allocations are 8 byte aligned, so we can't do better than that.
248
251
std .debug .assert (@intFromEnum (alignment ) <= 3 );
0 commit comments