次の方法で共有


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). この関数は、満たされたメモリへのポインターを返します。

Syntax

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

Parameters

[out] Destination

入力するメモリ ブロックの開始アドレスへのポインター。

[in] Fill

メモリ ブロックを埋めるバイト値。

[in] Length

埋めるメモリ ブロックのサイズ (バイト単位)。 This value must be less than the size of the Destination buffer.

Return value

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

Remarks

  • 関数はコンパイラ組み込み関数として認識されないため、コンパイラは呼び出しを最適化しません (呼び出しを完全に最適化したり、同等の命令シーケンスに置き換えたりすることはありません)。 This differs from RtlFillMemory which is subject to various compiler optimizations.

  • 呼び出しが返されると、バッファーは目的の値で上書きされています。 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 で動作します。 wdm.h ヘッダーから関数宣言を取得するには、最新の WDK を使用する必要があります。 また、最新の WDK のライブラリ (volatileaccessk.lib) も必要です。 ただし、結果として得られるドライバーは、古いバージョンの 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
サポートされる最小クライアント See Remarks
Header wdm.h (Wdm.h を含む)
Library volatileaccessk.lib (カーネル モード)、volatileaccessu.lib (ユーザー モード)

See also

RtlFillMemory

RtlFillVolatileMemory