Partilhar via


Macro 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

Um ponteiro para o bloco de memória a ser preenchido com segurança com zeros.

[in] cnt

O número de bytes a serem preenchidos com zeros.

Return value

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

Remarks

  • A função usa acessos de memória voláteis para garantir que o compilador não possa otimizar a operação de zero, mesmo que a memória pareça não ser utilizada após a chamada.

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

  • A função garante que todos os bytes especificados serão definidos como zero e que essa operação não será removida por otimizações do compilador.

Callers of RtlSecureZeroMemory can be running at any IRQL if the destination memory block is in nonpaged system memory. Caso contrário, o chamador deverá estar em execução no 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 (include Wdm.h, Ntddk.h, Ntifs.h)
Library NtosKrnl.lib
DLL NtosKrnl.exe
IRQL Qualquer nível (seção Ver Comentários)

See also

RtlZeroMemory

RtlFillVolatileMemory

RtlSetVolatileMemory