luaur_code_gen/records/
code_allocator.rs1use crate::type_aliases::allocation_callback::AllocationCallback;
2use alloc::vec::Vec;
3use core::ffi::c_void;
4
5#[derive(Debug)]
6#[repr(C)]
7pub struct CodeAllocator {
8 pub context: *mut c_void,
9 pub create_block_unwind_info: Option<
10 unsafe extern "C" fn(
11 context: *mut c_void,
12 block: *mut u8,
13 block_size: usize,
14 start_offset: &mut usize,
15 ) -> *mut c_void,
16 >,
17 pub destroy_block_unwind_info:
18 Option<unsafe extern "C" fn(context: *mut c_void, unwind_data: *mut c_void)>,
19 pub(crate) block_pos: *mut u8,
20 pub(crate) block_end: *mut u8,
21 pub(crate) blocks: Vec<*mut u8>,
22 pub(crate) unwind_infos: Vec<*mut c_void>,
23 pub(crate) block_size: usize,
24 pub(crate) max_total_size: usize,
25 pub(crate) live_allocations: usize,
26 pub(crate) allocation_callback: Option<AllocationCallback>,
27 pub(crate) allocation_callback_context: *mut c_void,
28 pub(crate) destroyed: bool,
29}
30
31impl CodeAllocator {
32 pub(crate) const kMaxReservedDataSize: usize = 256;
33}
34
35impl Default for CodeAllocator {
36 fn default() -> Self {
37 Self {
38 context: core::ptr::null_mut(),
39 create_block_unwind_info: None,
40 destroy_block_unwind_info: None,
41 block_pos: core::ptr::null_mut(),
42 block_end: core::ptr::null_mut(),
43 blocks: Vec::new(),
44 unwind_infos: Vec::new(),
45 block_size: 0,
46 max_total_size: 0,
47 live_allocations: 0,
48 allocation_callback: None,
49 allocation_callback_context: core::ptr::null_mut(),
50 destroyed: false,
51 }
52 }
53}
54
55impl Drop for CodeAllocator {
56 fn drop(&mut self) {
57 CodeAllocator::drop(self);
58 }
59}