Skip to content

Commit

Permalink
delete unnecessary dlopen
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Ishikawa <sykwer@gmail.com>
  • Loading branch information
sykwer committed Dec 5, 2024
1 parent d15186e commit db76147
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/agnocast_heaphook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ static ORIGINAL_MEMALIGN: LazyLock<MemalignType> = LazyLock::new(|| {
static MEMPOOL_START: AtomicUsize = AtomicUsize::new(0);
static MEMPOOL_END: AtomicUsize = AtomicUsize::new(0);

extern "C" {
fn initialize_agnocast(size: usize) -> *mut c_void;
}

const FLLEN: usize = 28; // The maximum block size is (32 << 28) - 1 = 8_589_934_591 (nearly 8GiB)
const SLLEN: usize = 64; // The worst-case internal fragmentation is ((32 << 28) / 64 - 2) = 134_217_726 (nearly 128MiB)
type FLBitmap = u32; // FLBitmap should contain at least FLLEN bits
Expand All @@ -99,26 +103,6 @@ static TLSF: LazyLock<Mutex<TlsfType>> = LazyLock::new(|| {
let page_size: usize = unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize };
let aligned_size: usize = (mempool_size + page_size - 1) & !(page_size - 1);

let agnocast_lib: *mut c_void = unsafe {
libc::dlopen(
b"libagnocast.so\0".as_ptr() as *const c_char,
libc::RTLD_NOW,
)
};
if agnocast_lib.is_null() {
panic!("[ERROR] [Agnocast] Failed to load libagnocast.so");
}

let symbol: &CStr = CStr::from_bytes_with_nul(b"initialize_agnocast\0").unwrap();
let initialize_agnocast_ptr: *mut c_void =
unsafe { libc::dlsym(agnocast_lib, symbol.as_ptr()) };
if initialize_agnocast_ptr.is_null() {
panic!("[ERROR] [Agnocast] Failed to find initialize_agnocast() function");
}

let initialize_agnocast: InitializeAgnocastType =
unsafe { std::mem::transmute(initialize_agnocast_ptr) };

let mempool_ptr: *mut c_void = unsafe { initialize_agnocast(aligned_size) };

let pool: &mut [MaybeUninit<u8>] = unsafe {
Expand Down

0 comments on commit db76147

Please sign in to comment.