RtlFillDeviceMemory - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
// wdm.h

volatile void * RtlFillDeviceMemory(
  [out] volatile void *Destination,
  [in]  size_t        Length,
  [in]  int           Fill
);
View the official Windows Driver Kit DDI reference

NtDoc

No description available.

Windows Driver Kit DDI reference (nf-wdm-rtlfilldevicememory)

Description

The RtlFillDeviceMemory routine fills a block of device memory with the specified fill value and returns a pointer to the filled memory. This function is safe for use on device memory because it uses appropriate access patterns for device memory regions.

Parameters

Destination [out]

A pointer to the starting address of the volatile device memory block to fill.

Length [in]

The size of the block of memory to fill, in bytes. This value must be less than or equal to the size of the Destination buffer.

Fill [in]

The byte value with which to fill the memory block.

Return value

RtlFillDeviceMemory returns a pointer to the filled volatile device memory block (Destination).

Remarks

The RtlFillDeviceMemory routine is designed for safe filling of device memory regions where standard memory filling functions might not be appropriate due to the special characteristics of device memory.

This function provides RtlFillMemory behavior specifically designed for device memory regions.

Callers of RtlFillDeviceMemory can be running at any IRQL if the destination memory block is in nonpaged system memory. Otherwise, the caller must be running at IRQL <= APC_LEVEL.

This function works on all versions of Windows, not just the latest. You need to consume the latest WDK to get the function declaration from the wdm.h header. You also need the library (volatileaccessk.lib) from the latest WDK. However, the resulting driver will run fine on older versions of Windows.

Example

volatile UCHAR* DeviceBuffer;
SIZE_T BufferSize = 1024;

// Allocate or map device memory
DeviceBuffer = MapDeviceMemory(BufferSize);

// Fill the device memory with a specific pattern
volatile void* result = RtlFillDeviceMemory(DeviceBuffer, BufferSize, 0xAA);

// Use the filled device memory
ProcessDeviceData(DeviceBuffer, BufferSize);

// Clean up
UnmapDeviceMemory(DeviceBuffer);

See also

RtlFillMemory

RtlSetVolatileMemory

RtlCompareDeviceMemory

RtlEqualDeviceMemory