diff options
| author | Harry Fei <[email protected]> | 2018-09-30 17:53:14 +0800 |
|---|---|---|
| committer | Harry Fei <[email protected]> | 2018-10-08 16:54:05 +0800 |
| commit | c22b255d6f91d7b2420fe20038cefb2b116821bf (patch) | |
| tree | 038239674bf2f5daa2a98ff6871fe5df1dd615b5 /src | |
| download | win-kmd-alloc-master.tar.xz win-kmd-alloc-master.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/alloc_sys.rs | 12 | ||||
| -rw-r--r-- | src/lib.rs | 20 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/alloc_sys.rs b/src/alloc_sys.rs new file mode 100644 index 0000000..5d46f02 --- /dev/null +++ b/src/alloc_sys.rs @@ -0,0 +1,12 @@ +#[repr(C)] +pub enum POOL_TYPE { + PagedPool, +} + +pub type PVOID = *mut u8; + +#[link(name = "ntoskrnl")] +extern "system" { + pub fn ExAllocatePoolWithTag(PoolType: POOL_TYPE, NumberOfBytes: usize, Tag: u32) -> PVOID; + pub fn ExFreePoolWithTag(P: PVOID, Tag: u32); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..678735d --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,20 @@ +#![no_std] + +mod alloc_sys; + +use self::alloc_sys::*; +use core::alloc::{GlobalAlloc, Layout}; + +const KMRS_TAG: u32 = 0x4B4D5253; // 'KMRS' + +pub struct KernelAlloc; + +unsafe impl GlobalAlloc for KernelAlloc { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + ExAllocatePoolWithTag(POOL_TYPE::PagedPool, layout.size(), KMRS_TAG) + } + + unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { + ExFreePoolWithTag(ptr, KMRS_TAG); + } +} |