rtlSecureZeroMemory2 函数 (wdm.h)

RtlSecureZeroMemory2 函数是 RtlFillVolatileMemory 的便捷包装器,与 RtlZeroVolatileMemory 相同。

语法

volatile void * RtlSecureZeroMemory2(
  [out] volatile void *Destination,
  [in]  size_t        Length
);

参数

[out] Destination

指向要用零填充的内存块的起始地址的指针。

[in] Length

要用零填充的内存块的大小(以字节为单位)。

返回值

返回 Destination 的值。

注解

RtlSecureZeroMemory2 函数是 RtlFillVolatileMemory 的便捷包装器,与 RtlZeroVolatileMemory 相同。

有关详细信息,请参阅 RtlFillVolatileMemory 的备注部分。

注意

此函数适用于所有版本的 Windows,而不仅仅是最新版本。 需要使用最新的 WDK 才能从 wdm.h 标头获取函数声明。 还需要从最新 WDK (volatileaccessk.lib) 库。 但是,生成的驱动程序将在较旧版本的 Windows 上运行正常。

示例

UCHAR SensitiveData[100];

// Imagine we temporarily store some sensitive cryptographic
// material in a buffer.

StoreCryptographicKey(&SensitiveData);

DoCryptographicOperation(&SensitiveData);

// Now that we are done using the sensitive data we want to
// erase it from the stack. We cannot call RtlFillMemory because
// if the compiler realizes that "SensitiveData" is not
// referenced again the compiler can remove the call to RtlFillMemory.
// Instead we can call RtlSecureZeroMemory2, RtlZeroVolatileMemory, or RtlFillVolatileMemory
// (the former two are convenience wrappers around the latter). These
// calls will not be optimized away by the compiler.
// Note that RtlSecureZeroMemory2 performs better than
// RtlSecureZeroMemory function.

RtlSecureZeroMemory2(&SensitiveData, sizeof(SensitiveData));

要求

要求
Header wdm.h (包括 Wdm.h)
Library volatileaccessk.lib (内核模式) ,volatileaccessu.lib (用户模式)

另请参阅

RtlFillVolatileMemory

RtlZeroVolatileMemory