Поделиться через


Макрос RtlSecureZeroMemory (wdm.h)

The RtlSecureZeroMemory routine securely fills a block of memory with zeros in a way that is guaranteed not to be optimized away by the compiler.

Syntax

PVOID RtlSecureZeroMemory(
  [in, out] PVOID  Ptr,
  [in]      SIZE_T cnt
);

Parameters

[in, out] Ptr

Указатель на блок памяти для безопасного заполнения нулями.

[in] cnt

Число байтов для заполнения нулями.

Return value

RtlSecureZeroMemory returns a pointer to the memory block that was filled (Ptr).

Remarks

  • Функция использует доступ к переменной памяти, чтобы гарантировать, что компилятор не может оптимизировать операцию нуля, даже если память, как представляется, не используется после вызова.

  • This differs from RtlZeroMemory, which may be optimized away by the compiler if the memory is not accessed again.

  • Функция гарантирует, что все указанные байты будут равны нулю, и эта операция не будет удалена оптимизацией компилятора.

Callers of RtlSecureZeroMemory can be running at any IRQL if the destination memory block is in nonpaged system memory. В противном случае вызывающий объект должен работать в IRQL <= APC_LEVEL.

Example

UCHAR SensitiveData[256];
UCHAR CryptographicKey[32];

// Use sensitive data
ProcessSensitiveInformation(SensitiveData);
PerformCryptographicOperation(CryptographicKey);

// Securely clear sensitive data from memory
// This will not be optimized away by the compiler
RtlSecureZeroMemory(SensitiveData, sizeof(SensitiveData));
RtlSecureZeroMemory(CryptographicKey, sizeof(CryptographicKey));

Requirements

Requirement Value
Target Platform Universal
Header wdm.h (включите Wdm.h, Ntddk.h, Ntifs.h)
Library NtosKrnl.lib
DLL NtosKrnl.exe
IRQL Любой уровень (см. раздел "Примечания")

See also

RtlZeroMemory

RtlFillVolatileMemory

RtlSetVolatileMemory