SetModeMemory 函数 (usermode_accessors.h)

The SetModeMemory function fills a memory region with a specified byte value, based on the specified processor mode.

Syntax

VOID SetModeMemory(
  VOID            *Destination,
  UCHAR           Fill,
  SIZE_T          Length,
  KPROCESSOR_MODE Mode
);

Parameters

Destination

[out]指向要填充的内存块起始地址的指针。

Fill

[in] The byte value used to fill the first Length bytes of Destination.

Length

[in] The number of bytes to fill with the Fill value.

Mode

[in]确定内存访问的执行方式的处理器模式。 Mode can be one of the following values.

Value Meaning
KernelMode Destination points to kernel-mode memory. The function performs a direct memory fill operation with memory_order_relaxed semantics. 有关更多详细信息,请参阅“备注”。
UserMode Destination points to user-mode memory. The function raises an exception if Destination doesn't point to user-mode memory; otherwise it performs a fill operation at the specified address with memory_order_relaxed semantics. 有关更多详细信息,请参阅“备注”。

Return value

None

Remarks

此函数提供了一种安全的方式来使用指定的字节值填充内存区域,以及由指定的处理器模式确定的填充机制。

该函数具有以下属性:

  • When Mode is KernelMode, the function performs a direct memory fill without additional safety checks.

  • When Mode is UserMode, the function validates the pointer is a user-mode address and then performs the fill. The memory access is performed with memory_order_relaxed semantics.

  • 此函数不识别为编译器内联,因此编译器永远不会优化调用(完全或用等效指令序列替换调用)。

  • When the call returns, the first Length bytes of the buffer have been overwritten with the specified Fill value. This function's memory accesses to the Destination will only be performed within the function (for example, the compiler can't move memory accesses out of this function).

  • 如果平台允许它,该函数可能会执行未对齐的内存访问。

  • 该函数在填充作过程中可能会多次访问内存位置。

如果填充作失败(例如目标地址对指定模式无效或不可访问),该函数将引发结构化异常。

此函数适用于所有版本的 Windows,而不仅仅是最新版本。 You need to consume the latest WDK to get the function declaration from the usermode_accessors.h header. You also need the library (umaccess.lib) from the latest WDK. 但是,生成的驱动程序将在较旧版本的 Windows 上运行。

Requirements

Requirement Value
最低支持的客户端 See Remarks
Header usermode_accessors.h
Library umaccess.lib
IRQL 小于或等于APC_LEVEL

See also

SetUserMemory

FillModeMemory

ZeroModeMemory

CopyToMode