Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › os › uefi › pool_allocator › UefiPoolAllocator › alloc Private Function alloc Doc Source Private Function std.os.uefi.pool_allocator.UefiPoolAllocator.alloc
fn alloc (
_ : *anyopaque ,
len : usize ,
alignment : mem .Alignment ,
ret_addr : usize ,
) ?[*]u8 Params _ : *anyopaque len : usize alignment : mem .Alignment ret_addr : usize File os/uefi/pool_allocator.zig: 15
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 fn alloc (
_ : *anyopaque ,
len : usize ,
alignment : mem .Alignment ,
ret_addr : usize ,
) ?[*]u8 {
_ = ret_addr ;
assert (len > 0 );
const ptr_align = alignment .toByteUnits ();
const metadata_len = mem .alignForward (usize , @sizeOf (usize ), ptr_align );
const full_len = metadata_len + len ;
const unaligned_slice = uefi .system_table .boot_services .?.allocatePool (
uefi .efi_pool_memory_type ,
full_len ,
) catch return null ;
const unaligned_addr = @intFromPtr (unaligned_slice .ptr );
const aligned_addr = mem .alignForward (usize , unaligned_addr + @sizeOf (usize ), ptr_align );
const aligned_ptr = unaligned_slice .ptr + (aligned_addr - unaligned_addr );
getHeader (aligned_ptr ).* = unaligned_slice .ptr ;
return aligned_ptr ;
}