Skip to content

Commit

Permalink
remove lazystatic in wdk-alloc
Browse files Browse the repository at this point in the history
Signed-off-by: Melvin Wang <[email protected]>
  • Loading branch information
wmmc88 committed Oct 20, 2023
1 parent 3435f2a commit ba47040
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/wdk-alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ categories = ["memory-management", "no-std", "hardware-support"]

[dependencies]
wdk-sys.workspace = true
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }

[dev-dependencies]
wdk-sys = { workspace = true, features = ["test-stubs"] }
18 changes: 4 additions & 14 deletions crates/wdk-alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use core::alloc::{GlobalAlloc, Layout};

use lazy_static::lazy_static;
use wdk_sys::{
ntddk::{ExAllocatePool2, ExFreePool},
POOL_FLAG_NON_PAGED,
Expand All @@ -19,22 +18,13 @@ use wdk_sys::{
};
pub struct WDKAllocator;

// The value of memory tags are stored in little-endian order, so it is
// convenient to reverse the order for readability in tooling(ie. Windbg)
// FIXME: replace lazy_static with std::Lazy once available: https://github.com/rust-lang/rust/issues/109736
lazy_static! {
static ref RUST_TAG: ULONG = u32::from_ne_bytes(
#[allow(clippy::string_lit_as_bytes)] // A u8 slice is required here
"rust"
.as_bytes()
.try_into()
.expect("tag string.as_bytes() should be able to convert into [u8; 4]"),
);
}
// The value of memory tags are stored in little-endian order, so it is
// convenient to reverse the order for readability in tooling (ie. Windbg)
const RUST_TAG: ULONG = u32::from_ne_bytes(*b"rust");

unsafe impl GlobalAlloc for WDKAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let ptr = ExAllocatePool2(POOL_FLAG_NON_PAGED, layout.size() as SIZE_T, *RUST_TAG);
let ptr = ExAllocatePool2(POOL_FLAG_NON_PAGED, layout.size() as SIZE_T, RUST_TAG);
assert!(!ptr.is_null(), "wdk-alloc failed to allocate memory.");
ptr.cast()
}
Expand Down

0 comments on commit ba47040

Please sign in to comment.