Process Hacker
filepool.h File Reference

Go to the source code of this file.

Data Structures

struct  _PH_FP_BLOCK_HEADER
 
struct  _PH_FP_SEGMENT_HEADER
 
struct  _PH_FP_FILE_HEADER
 
struct  _PH_FILE_POOL_PARAMETERS
 
struct  _PH_FILE_POOL
 

Macros

#define PH_FP_BITMAP_SIZE   64
 The number of 32-bit integers used for each allocation bitmap.
 
#define PH_FP_BITMAP_SIZE_SHIFT   6
 The power-of-two index of the bitmap size.
 
#define PH_FP_BLOCK_COUNT   (PH_FP_BITMAP_SIZE * 32)
 The number of blocks that are available in each segment.
 
#define PH_FP_BLOCK_COUNT_SHIFT   (PH_FP_BITMAP_SIZE_SHIFT + 5)
 The power-of-two index of the block count.
 
#define PH_FP_FREE_LIST_COUNT   8
 The number of free lists for segments.
 
#define PH_FP_BLOCK_LARGE_ALLOCATION   0x1
 The block is the beginning of a large allocation (one that spans several segments).
 
#define PH_FP_MAGIC   ('loPF')
 

Typedefs

typedef struct _PH_FP_BLOCK_HEADER PH_FP_BLOCK_HEADER
 
typedef struct
_PH_FP_BLOCK_HEADER
PPH_FP_BLOCK_HEADER
 
typedef struct
_PH_FP_SEGMENT_HEADER 
PH_FP_SEGMENT_HEADER
 
typedef struct
_PH_FP_SEGMENT_HEADER
PPH_FP_SEGMENT_HEADER
 
typedef struct _PH_FP_FILE_HEADER PH_FP_FILE_HEADER
 
typedef struct _PH_FP_FILE_HEADERPPH_FP_FILE_HEADER
 
typedef struct
_PH_FILE_POOL_PARAMETERS 
PH_FILE_POOL_PARAMETERS
 
typedef struct
_PH_FILE_POOL_PARAMETERS
PPH_FILE_POOL_PARAMETERS
 
typedef struct _PH_FILE_POOL PH_FILE_POOL
 
typedef struct _PH_FILE_POOLPPH_FILE_POOL
 

Functions

NTSTATUS PhCreateFilePool (_Out_ PPH_FILE_POOL *Pool, _In_ HANDLE FileHandle, _In_ BOOLEAN ReadOnly, _In_opt_ PPH_FILE_POOL_PARAMETERS Parameters)
 Creates or opens a file pool.
 
NTSTATUS PhCreateFilePool2 (_Out_ PPH_FILE_POOL *Pool, _In_ PWSTR FileName, _In_ BOOLEAN ReadOnly, _In_ ULONG ShareAccess, _In_ ULONG CreateDisposition, _In_opt_ PPH_FILE_POOL_PARAMETERS Parameters)
 Creates or opens a file pool.
 
VOID PhDestroyFilePool (_In_ _Post_invalid_ PPH_FILE_POOL Pool)
 Frees resources used by a file pool instance.
 
PVOID PhAllocateFilePool (_Inout_ PPH_FILE_POOL Pool, _In_ ULONG Size, _Out_opt_ PULONG Rva)
 Allocates a block from a file pool.
 
VOID PhFreeFilePool (_Inout_ PPH_FILE_POOL Pool, _In_ PVOID Block)
 Frees a block allocated by PhAllocateFilePool().
 
BOOLEAN PhFreeFilePoolByRva (_Inout_ PPH_FILE_POOL Pool, _In_ ULONG Rva)
 Frees a block allocated by PhAllocateFilePool().
 
VOID PhReferenceFilePool (_Inout_ PPH_FILE_POOL Pool, _In_ PVOID Address)
 Increments the reference count for the specified address.
 
VOID PhDereferenceFilePool (_Inout_ PPH_FILE_POOL Pool, _In_ PVOID Address)
 Decrements the reference count for the specified address.
 
PVOID PhReferenceFilePoolByRva (_Inout_ PPH_FILE_POOL Pool, _In_ ULONG Rva)
 Obtains a pointer for a relative virtual address, incrementing the reference count of the address.
 
BOOLEAN PhDereferenceFilePoolByRva (_Inout_ PPH_FILE_POOL Pool, _In_ ULONG Rva)
 Decrements the reference count for the specified relative virtual address.
 
ULONG PhEncodeRvaFilePool (_In_ PPH_FILE_POOL Pool, _In_ PVOID Address)
 Obtains a relative virtual address for a pointer.
 
VOID PhGetUserContextFilePool (_In_ PPH_FILE_POOL Pool, _Out_ PULONGLONG Context)
 Retrieves user data.
 
VOID PhSetUserContextFilePool (_Inout_ PPH_FILE_POOL Pool, _In_ PULONGLONG Context)
 Stores user data.
 

Macro Definition Documentation

#define PH_FP_BITMAP_SIZE   64

The number of 32-bit integers used for each allocation bitmap.

Definition at line 20 of file filepool.h.

#define PH_FP_BITMAP_SIZE_SHIFT   6

The power-of-two index of the bitmap size.

Definition at line 22 of file filepool.h.

#define PH_FP_BLOCK_COUNT   (PH_FP_BITMAP_SIZE * 32)

The number of blocks that are available in each segment.

Definition at line 24 of file filepool.h.

#define PH_FP_BLOCK_COUNT_SHIFT   (PH_FP_BITMAP_SIZE_SHIFT + 5)

The power-of-two index of the block count.

Definition at line 26 of file filepool.h.

#define PH_FP_BLOCK_LARGE_ALLOCATION   0x1

The block is the beginning of a large allocation (one that spans several segments).

Definition at line 32 of file filepool.h.

#define PH_FP_FREE_LIST_COUNT   8

The number of free lists for segments.

Definition at line 28 of file filepool.h.

#define PH_FP_MAGIC   ('loPF')

Definition at line 52 of file filepool.h.

Typedef Documentation

typedef struct _PH_FILE_POOL PH_FILE_POOL
typedef struct _PH_FILE_POOL * PPH_FILE_POOL

Function Documentation

PVOID PhAllocateFilePool ( _Inout_ PPH_FILE_POOL  Pool,
_In_ ULONG  Size,
_Out_opt_ PULONG  Rva 
)

Allocates a block from a file pool.

Parameters
PoolThe file pool.
SizeThe number of bytes to allocate.
RvaA variable which receives the relative virtual address of the allocated block.
Returns
A pointer to the allocated block. You must call PhDereferenceFilePool() or PhDereferenceFilePoolByRva() when you no longer need a reference to the block.
Remarks
The returned pointer is not valid beyond the lifetime of the file pool instance. Use the relative virtual address if you need a permanent reference to the allocated block.

Definition at line 419 of file filepool.c.

NTSTATUS PhCreateFilePool ( _Out_ PPH_FILE_POOL Pool,
_In_ HANDLE  FileHandle,
_In_ BOOLEAN  ReadOnly,
_In_opt_ PPH_FILE_POOL_PARAMETERS  Parameters 
)

Creates or opens a file pool.

Parameters
PoolA variable which receives the file pool instance.
FileHandleA handle to the file.
ReadOnlyTRUE to disallow writes to the file.
ParametersParameters for on-disk and runtime structures.

Definition at line 93 of file filepool.c.

NTSTATUS PhCreateFilePool2 ( _Out_ PPH_FILE_POOL Pool,
_In_ PWSTR  FileName,
_In_ BOOLEAN  ReadOnly,
_In_ ULONG  ShareAccess,
_In_ ULONG  CreateDisposition,
_In_opt_ PPH_FILE_POOL_PARAMETERS  Parameters 
)

Creates or opens a file pool.

Parameters
PoolA variable which receives the file pool instance.
FileNameThe file name of the file pool.
ReadOnlyTRUE to disallow writes to the file.
ShareAccessThe file access granted to other threads.
CreateDispositionThe action to perform if the file does or does not exist. See PhCreateFileWin32() for more information.
ParametersParameters for on-disk and runtime structures.

Definition at line 265 of file filepool.c.

VOID PhDereferenceFilePool ( _Inout_ PPH_FILE_POOL  Pool,
_In_ PVOID  Address 
)

Decrements the reference count for the specified address.

Parameters
PoolThe file pool.
AddressAn address.

Definition at line 618 of file filepool.c.

BOOLEAN PhDereferenceFilePoolByRva ( _Inout_ PPH_FILE_POOL  Pool,
_In_ ULONG  Rva 
)

Decrements the reference count for the specified relative virtual address.

Parameters
PoolThe file pool.
RvaA relative virtual address.

Definition at line 664 of file filepool.c.

VOID PhDestroyFilePool ( _In_ _Post_invalid_ PPH_FILE_POOL  Pool)

Frees resources used by a file pool instance.

Parameters
PoolThe file pool.

Definition at line 321 of file filepool.c.

ULONG PhEncodeRvaFilePool ( _In_ PPH_FILE_POOL  Pool,
_In_ PVOID  Address 
)

Obtains a relative virtual address for a pointer.

Parameters
PoolThe file pool.
AddressA pointer.
Returns
The relative virtual address.
Remarks
No reference counts are changed.

Definition at line 692 of file filepool.c.

VOID PhFreeFilePool ( _Inout_ PPH_FILE_POOL  Pool,
_In_ PVOID  Block 
)

Frees a block allocated by PhAllocateFilePool().

Parameters
PoolThe file pool.
BlockA pointer to the block. The pointer is no longer valid after you call this function. Do not use PhDereferenceFilePool() or PhDereferenceFilePoolByRva().

Definition at line 549 of file filepool.c.

BOOLEAN PhFreeFilePoolByRva ( _Inout_ PPH_FILE_POOL  Pool,
_In_ ULONG  Rva 
)

Frees a block allocated by PhAllocateFilePool().

Parameters
PoolThe file pool.
RvaThe relative virtual address of the block.

Definition at line 573 of file filepool.c.

VOID PhGetUserContextFilePool ( _In_ PPH_FILE_POOL  Pool,
_Out_ PULONGLONG  Context 
)

Retrieves user data.

Parameters
PoolThe file pool.
ContextA variable which receives the user data.

Definition at line 716 of file filepool.c.

VOID PhReferenceFilePool ( _Inout_ PPH_FILE_POOL  Pool,
_In_ PVOID  Address 
)

Increments the reference count for the specified address.

Parameters
PoolThe file pool.
AddressAn address.

Definition at line 604 of file filepool.c.

PVOID PhReferenceFilePoolByRva ( _Inout_ PPH_FILE_POOL  Pool,
_In_ ULONG  Rva 
)

Obtains a pointer for a relative virtual address, incrementing the reference count of the address.

Parameters
PoolThe file pool.
RvaA relative virtual address.

Definition at line 633 of file filepool.c.

VOID PhSetUserContextFilePool ( _Inout_ PPH_FILE_POOL  Pool,
_In_ PULONGLONG  Context 
)

Stores user data.

Parameters
PoolThe file pool.
ContextA variable which contains the user data.

Definition at line 730 of file filepool.c.