Skip to main content

dobby_hook_core/
options.rs

1use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
2
3static NEAR_TRAMPOLINE: AtomicBool = AtomicBool::new(false);
4static ALLOC_NEAR_CODE_CB: AtomicUsize = AtomicUsize::new(0);
5
6pub type AllocNearCodeCallback = unsafe fn(size: u32, pos: usize, range: usize) -> usize;
7
8pub fn set_near_trampoline(enable: bool) {
9    NEAR_TRAMPOLINE.store(enable, Ordering::Relaxed);
10}
11
12pub fn register_alloc_near_code_callback(handler: Option<AllocNearCodeCallback>) {
13    ALLOC_NEAR_CODE_CB.store(handler.map_or(0, |f| f as usize), Ordering::Relaxed);
14}
15
16pub fn set_options(
17    enable_near_trampoline: bool,
18    alloc_near_code_callback: Option<AllocNearCodeCallback>,
19) {
20    set_near_trampoline(enable_near_trampoline);
21    register_alloc_near_code_callback(alloc_near_code_callback);
22}