RtlFillVolatileMemory 関数 (wdm.h)

RtlFillVolatileMemory 関数は、開発者が設定操作が実行されることを確認する必要がある場合 (たとえば、コンパイラの最適化の対象ではない) 場合に、RtlFillMemory 動作 (バッファーの内容の設定など) を提供します。

構文

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

パラメーター

[out] Destination

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

[in] Length

埋めるメモリ ブロックのサイズ (バイト単位)。 この値は 、宛先 バッファーのサイズより小さくする必要があります。

[in] Fill

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

戻り値

Destination の値を返 します

注釈

  • 関数はコンパイラの組み込みとして認識されないため、コンパイラは呼び出しを最適化することはありません (呼び出しを完全に最適化するか、同等の命令シーケンスに置き換えます)。 これは、さまざまなコンパイラ最適化の対象となる RtlFillMemory とは異なります。

  • 呼び出しが返されると、バッファーは目的の値で上書きされています。 この関数の Destination へのメモリ アクセスは、関数内でのみ実行されます (たとえば、コンパイラはこの関数からメモリ アクセスを移動できません)。

  • プラットフォームで許可されている場合、関数は整列されていないメモリ アクセスを実行できます。

  • 関数は、操作の一環としてメモリの場所に複数回アクセスできます。

注意

この関数は、最新バージョンだけでなく、すべてのバージョンの Windows で動作します。 wdm.h ヘッダーから関数宣言を取得するには、最新の WDK を使用する必要があります。 また、最新の 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.

RtlFillVolatileMemory(&SensitiveData, sizeof(SensitiveData), 0);

要件

要件
Header wdm.h (Wdm.h を含む)
Library volatileaccessk.lib (カーネル モード)、volatileaccessu.lib (ユーザー モード)

こちらもご覧ください

RtlFillMemory