moon-driver-utils 0.1.0

Windows Kernel Utils
// 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 _);
//         }
//     }
// }