ZeroModeMemory 函数 (usermode_accessors.h)

The ZeroModeMemory function fills a memory region with zeros, based on the specified processor mode.

Syntax

VOID ZeroModeMemory(
  VOID            *Destination,
  SIZE_T          Length,
  KPROCESSOR_MODE Mode
);

Parameters

Destination

[out]指向内存块起始地址的指针,指向零。

Length

[in]字节数到零。

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 zero 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 zero operation at the specified address with memory_order_relaxed semantics.

Return value

None

Remarks

此函数提供了一种安全的方式来零内存区域,零机制由指定的处理器模式确定。 这允许灵活的内存作,这些作可以适应不同的执行上下文,同时将内存块初始化为零。

When Mode is KernelMode:

  • The function performs a volatile zero operation using memory_order_relaxed semantics.

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

  • 调用返回时,缓冲区已被零覆盖。 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

ZeroUserMemory

SetModeMemory

FillModeMemory

CopyToMode