use once_cell::sync::Lazy;
use crate::{alloc, arch, error::Result, pic};
use std::sync::Mutex;
pub static POOL: Lazy<Mutex<alloc::ThreadAllocator>> = Lazy::new(|| {
Mutex::new(alloc::ThreadAllocator::new(arch::meta::DETOUR_RANGE))
});
pub fn allocate_pic(
pool: &mut alloc::ThreadAllocator,
emitter: &pic::CodeEmitter,
origin: *const (),
) -> Result<alloc::ExecutableMemory> {
pool.allocate(origin, emitter.len()).map(|mut memory| {
let code = emitter.emit(memory.as_ptr() as *const _);
memory.copy_from_slice(code.as_slice());
memory
})
}