1use once_cell::sync::Lazy;
2
3use crate::{alloc, arch, error::Result, pic};
4use std::sync::Mutex;
5
6pub static POOL: Lazy<Mutex<alloc::ThreadAllocator>> = Lazy::new(|| {
8 Mutex::new(alloc::ThreadAllocator::new(arch::meta::DETOUR_RANGE))
10});
11
12pub fn allocate_pic(
14 pool: &mut alloc::ThreadAllocator,
15 emitter: &pic::CodeEmitter,
16 origin: *const (),
17) -> Result<alloc::ExecutableMemory> {
18 pool.allocate(origin, emitter.len()).map(|mut memory| {
20 let code = emitter.emit(memory.as_ptr() as *const _);
22 memory.copy_from_slice(code.as_slice());
23 memory
24 })
25}