1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// use core::{alloc::Layout, ptr::NonNull};
// use alloc::alloc::Allocator;
// use wdk_sys::{
// ntddk::{ExAllocatePool, ExFreePool},
// SIZE_T,
// _POOL_TYPE::NonPagedPoolExecute,
// };
// pub struct NPPAllocator;
// unsafe impl Allocator for NPPAllocator {
// fn allocate(
// &self,
// layout: Layout,
// ) -> Result<core::ptr::NonNull<[u8]>, alloc::alloc::AllocError> {
// let ptr =
// // SAFETY: `ExAllocatePool2` is safe to call from any `IRQL` <= `DISPATCH_LEVEL` since its allocating from `POOL_FLAG_NON_PAGED`
// unsafe {
// ExAllocatePool(NonPagedPoolExecute, layout.size() as SIZE_T)
// };
// if ptr.is_null() {
// return Err(alloc::alloc::AllocError {});
// }
// let pp = unsafe { core::slice::from_raw_parts_mut(ptr as *mut u8, layout.size() as _) };
// let p = NonNull::new(pp as _).ok_or(alloc::alloc::AllocError)?;
// Ok(p)
// }
// unsafe fn deallocate(&self, ptr: core::ptr::NonNull<u8>, _layout: Layout) {
// unsafe {
// ExFreePool(ptr.as_ptr() as _);
// }
// }
// }