Skip to main content

luaur_code_gen/methods/
code_allocator_allocate_pages.rs

1use crate::functions::allocate_pages_impl_code_allocator::allocate_pages_impl;
2use crate::records::code_allocator::CodeAllocator;
3
4impl CodeAllocator {
5    pub fn allocate_pages(&self, size: usize) -> *mut u8 {
6        unsafe {
7            let page_aligned_size = CodeAllocator::align_to_page_size(size);
8
9            let mem = allocate_pages_impl(page_aligned_size);
10            if mem.is_null() {
11                return core::ptr::null_mut();
12            }
13
14            if let Some(callback) = self.allocation_callback {
15                callback(
16                    self.allocation_callback_context,
17                    core::ptr::null_mut(),
18                    0,
19                    mem.cast(),
20                    page_aligned_size,
21                );
22            }
23
24            mem
25        }
26    }
27}