luaur_code_gen/methods/
code_allocator_allocate_new_block.rs1use crate::macros::codegen_assert::CODEGEN_ASSERT;
2use crate::records::code_allocator::CodeAllocator;
3
4impl CodeAllocator {
5 pub fn allocate_new_block(&mut self, unwind_info_size: &mut usize) -> bool {
6 if (self.blocks.len() + 1) * self.block_size > self.max_total_size {
7 return false;
8 }
9
10 let block = self.allocate_pages(self.block_size);
11
12 if block.is_null() {
13 return false;
14 }
15
16 self.block_pos = block;
17 self.block_end = unsafe { block.add(self.block_size) };
18 self.blocks.push(block);
19
20 if let Some(create_block_unwind_info) = self.create_block_unwind_info {
21 let unwind_info = unsafe {
22 create_block_unwind_info(self.context, block, self.block_size, unwind_info_size)
23 };
24
25 const K_CODE_ALIGNMENT: usize = 32;
26 *unwind_info_size =
27 (*unwind_info_size + (K_CODE_ALIGNMENT - 1)) & !(K_CODE_ALIGNMENT - 1);
28
29 CODEGEN_ASSERT!(*unwind_info_size <= CodeAllocator::kMaxReservedDataSize);
30
31 if unwind_info.is_null() {
32 return false;
33 }
34
35 self.unwind_infos.push(unwind_info);
36 }
37
38 true
39 }
40}