diff --git a/Cargo.toml b/Cargo.toml index 548b3de..62af2cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ repository = "https://github.com/OpenByteDev/dlopen2" edition = "2021" [dependencies] -lazy_static = ">= 1.3.0" dlopen_derive = { path = "rust-dlopen-derive", version = "0.1" } +once_cell = "1.12" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["winnt", "minwindef", "winerror", "libloaderapi", "errhandlingapi", "dbghelp", "processthreadsapi", "basetsd"] } diff --git a/src/raw/unix.rs b/src/raw/unix.rs index c91b4ed..557b17e 100644 --- a/src/raw/unix.rs +++ b/src/raw/unix.rs @@ -1,24 +1,20 @@ use super::super::err::Error; use super::common::{AddressInfo, OverlappingSymbol}; -use lazy_static::lazy_static; use libc::{ c_int, c_void, dladdr, dlclose, dlerror, dlopen, dlsym, Dl_info, RTLD_LAZY, RTLD_LOCAL, }; +use once_cell::sync::Lazy; use std::ffi::{CStr, OsStr}; use std::io::{Error as IoError, ErrorKind}; use std::os::unix::ffi::OsStrExt; use std::ptr::{null, null_mut}; +use std::sync::Mutex; const DEFAULT_FLAGS: c_int = RTLD_LOCAL | RTLD_LAZY; -use std::sync::Mutex; - // calls to dlerror are not thread-safe, so we guard them // with a mutex - -lazy_static! { - static ref DLERROR_MUTEX: Mutex<()> = Mutex::new(()); -} +static DLERROR_MUTEX: Lazy> = Lazy::new(|| Mutex::new(())); pub type Handle = *mut c_void; diff --git a/src/raw/windows.rs b/src/raw/windows.rs index 1c4ba09..596bbef 100644 --- a/src/raw/windows.rs +++ b/src/raw/windows.rs @@ -2,7 +2,7 @@ use crate::utils; use super::super::err::Error; use super::common::{AddressInfo, OverlappingSymbol}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::ffi::{CStr, OsStr, OsString}; use std::io::{Error as IoError, ErrorKind}; use std::mem::size_of; @@ -34,13 +34,13 @@ struct SetErrorModeData { pub previous: DWORD, } -lazy_static! { - static ref SET_ERR_MODE_DATA: Mutex = Mutex::new(SetErrorModeData { +static SET_ERR_MODE_DATA: Lazy> = Lazy::new(|| { + Mutex::new(SetErrorModeData { count: 0, - previous: 0 - }); - static ref OBTAINERS_COUNT: Mutex = Mutex::new(0); -} + previous: 0, + }) +}); +static OBTAINERS_COUNT: Lazy> = Lazy::new(|| Mutex::new(0)); pub type Handle = HMODULE;