Compartir a través de


Función RtlSetVolatileMemory (wdm.h)

The RtlSetVolatileMemory function provides RtlFillMemory behavior (for example, setting the contents of a buffer) in situations where the developer needs to be sure that the setting operation occurs (for example, isn't subject to compiler optimizations). La función devuelve un puntero a la memoria rellenada.

Syntax

volatile void * RtlSetVolatileMemory(
  [out] volatile void *Destination,
  [in]  int           Fill,
  [in]  size_t        Length
);

Parameters

[out] Destination

Puntero a la dirección inicial del bloque de memoria que se va a rellenar.

[in] Fill

Valor de byte con el que se va a rellenar el bloque de memoria.

[in] Length

Tamaño del bloque de memoria que se va a rellenar, en bytes. This value must be less than the size of the Destination buffer.

Return value

Returns a pointer to the filled memory block (Destination).

Remarks

  • La función no se reconoce como intrínseca del compilador, por lo que el compilador nunca optimizará la llamada (por completo o reemplazará la llamada por una secuencia equivalente de instrucciones). This differs from RtlFillMemory which is subject to various compiler optimizations.

  • Cuando se devuelve la llamada, el búfer se ha sobrescribido con el valor deseado. 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).

  • La función puede realizar accesos a memoria no asignadas si la plataforma lo permite.

  • La función puede acceder a las ubicaciones de memoria más de una vez como parte de su operación.

Esta función funciona en todas las versiones de Windows, no solo en la más reciente. Debe consumir el WDK más reciente para obtener la declaración de función del encabezado wdm.h. También necesita la biblioteca (volatileaccessk.lib) del WDK más reciente. Sin embargo, el controlador resultante se ejecutará correctamente en versiones anteriores de Windows.

Example

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 can use RtlSetVolatileMemory
// to fill the buffer and get a pointer to the filled memory.
// This call will not be optimized away by the compiler.

volatile VOID* clearedBuffer = RtlSetVolatileMemory(&SensitiveData, 0, sizeof(SensitiveData));

Requirements

Requirement Value
Cliente mínimo compatible See Remarks
Header wdm.h (incluya Wdm.h)
Library volatileaccessk.lib (modo kernel), volatileaccessu.lib (modo de usuario)

See also

RtlFillMemory

RtlFillVolatileMemory