-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSafeMemoryHelper.cs
More file actions
32 lines (30 loc) · 1.44 KB
/
Copy pathSafeMemoryHelper.cs
File metadata and controls
32 lines (30 loc) · 1.44 KB
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
using WDK.NET.Enums;
using WDK.NET.Kernel;
namespace WDK.NET.SafeHelpers
{
/// <summary>
/// Helper class to support safe memory management.
/// </summary>
public class SafeMemoryHelper
{
/// <summary>
/// Allocates pool memory of the specified type and returns a pointer to the allocated block
/// </summary>
/// <param name="poolType">Specifies the type of pool memory to allocate.</param>
/// <param name="allocationSize">Specifies the number of bytes to allocate.</param>
/// <returns>returns NULL if there is insufficient memory in the free pool to satisfy the request. Otherwise the routine returns a pointer to the allocated memory.</returns>
public static ulong AllocatePoolMemory(PoolType poolType, uint allocationSize)
{
return Wdm.ExAllocatePool(poolType, allocationSize);
}
/// <summary>
/// Allocates non-paged pool memory of the specified allocation size.
/// </summary>
/// <param name="allocataionSize">Specifies the number of bytes to allocate.</param>
/// <returns>returns NULL if there is insufficient memory in the free pool to satisfy the request. Otherwise the routine returns a pointer to the allocated memory.</returns>
public static ulong AllocateNonPagedPoolMemory(uint allocataionSize)
{
return AllocatePoolMemory(PoolType.NonPagedPool, allocataionSize);
}
}
}