ZeroUserMemory 函数 (usermode_accessors.h)

The ZeroUserMemory function fills a user-mode memory region with zeros.

Syntax

VOID ZeroUserMemory(
  volatile VOID *Destination,
  SIZE_T        Length
);

Parameters

Destination

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

Length

[in]字节数到零。

Return value

None

Remarks

此函数提供了一种安全方法,用于零用户模式内存区域。 这允许在内核模式代码需要将用户模式内存缓冲区初始化为零时灵活内存作。

该函数具有以下属性:

  • 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

ZeroModeMemory

SetUserMemory

FillUserMemory

CopyToUser