Skip to main content

zig_std/
mem.rs

1use crate::util::ReprCSlice;
2use core::ptr::NonNull;
3
4#[non_exhaustive]
5#[repr(u8)]
6pub enum Alignment {
7	A1 = 0,
8	A2 = 1,
9	A4 = 2,
10	A8 = 3,
11	A16 = 4,
12	A32 = 5,
13	A64 = 6
14}
15
16#[repr(C)]
17pub struct Allocator {
18	ptr: NonNull<()>,
19	vtable: VTable
20}
21
22#[repr(C)]
23pub struct VTable {
24	vtable_zig: NonNull<()>,
25
26	alloc_c: extern "C" fn(
27		vtable_zig: NonNull<()>,
28		allocator: NonNull<()>,
29		len: usize,
30		alignment: Alignment,
31		ret_addr: usize
32	) -> ReprCSlice<u8>,
33	resize_c: extern "C" fn(
34		vtable_zig: NonNull<()>,
35		allocator: NonNull<()>,
36		memory: ReprCSlice<u8>,
37		alignment: Alignment,
38		new_len: usize,
39		ret_addr: usize
40	) -> bool,
41	remap_c: extern "C" fn(
42		vtable_zig: NonNull<()>,
43		allocator: NonNull<()>,
44		memory: ReprCSlice<u8>,
45		alignment: Alignment,
46		new_len: usize,
47		ret_addr: usize
48	) -> ReprCSlice<u8>,
49	free_c: extern "C" fn(
50		vtable_zig: NonNull<()>,
51		allocator: NonNull<()>,
52		memory: ReprCSlice<u8>,
53		alignment: Alignment,
54		ret_addr: usize
55	)
56}
57
58// size/align assertions
59const _: () = {
60	assert!(size_of::<Alignment>() == 1);
61	assert!(align_of::<Alignment>() == 1);
62	assert!(size_of::<Allocator>() == 6 * size_of::<usize>());
63	assert!(align_of::<Allocator>() == align_of::<usize>());
64	assert!(size_of::<VTable>() == 5 * size_of::<usize>());
65	assert!(align_of::<VTable>() == align_of::<usize>());
66};