Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
kernel-alloc-rs
A custom memory allocator tailored for the Windows kernel space.
Why?
Rust has many useful abstractions and utils that require heap allocations, such as String
, Vec
, and Box
. To be able to use them in the Windows kernel space, we need to allocate memory at runtime, which requires a custom allocator. This crate provides such allocators tailored for the Windows kernel.
For more information on custom allocators in Rust, refer to the alloc::GlobalAllocator and alloc::Allocator documentation. Additionally, the Rust book provides details on global_allocator and allocator_api.
Example
To use KernelAlloc
or PhysicalAllocator
as your global allocator, add the appropriate code to your kernel module:
For KernelAlloc
:
use KernelAlloc;
static GLOBAL: KernelAlloc = KernelAlloc;
For PhysicalAllocator
:
use PhysicalAllocator;
static GLOBAL: PhysicalAllocator = PhysicalAllocator;
Using with Box
Once you've set up KernelAlloc
or PhysicalAllocator
as your global allocator, you can use Box
and other heap-allocated types just like you would in a standard Rust environment.
Here's an example demonstrating how to use both KernelAlloc
and PhysicalAllocator
with Box
to allocate memory for different structs in the Windows kernel:
use ;
use mem;
pub const PAGE_SIZE: usize = 0x1000;
pub const KERNEL_STACK_SIZE: usize = 0x6000;
pub const STACK_CONTENTS_SIZE: usize = KERNEL_STACK_SIZE - ;
Credits / References
- Vergilius Project
- @not-matthias
- @jessiep_
- @memN0ps