다음을 통해 공유


RtlCompareDeviceMemory 함수(wdm.h)

The RtlCompareDeviceMemory function compares two blocks of device memory and returns the number of bytes that match until the first difference. 이 함수는 지정된 대로 수행되도록 보장되는 바이트 수준 액세스를 사용하기 때문에 디바이스 메모리에서 사용하기에 안전합니다.

Syntax

SIZE_T RtlCompareDeviceMemory(
  [in] const VOID *Source1,
  [in] const VOID *Source2,
  [in] SIZE_T     Length
);

Parameters

[in] Source1

비교할 첫 번째 메모리 블록에 대한 포인터입니다.

[in] Source2

비교할 두 번째 메모리 블록에 대한 포인터입니다.

[in] Length

비교할 바이트 수입니다.

Return value

RtlCompareDeviceMemory returns the number of bytes in the two blocks that match. If all bytes match up to the specified Length value, the Length value is returned.

Remarks

  • 함수는 컴파일러 내장 함수로 인식되지 않으므로 컴파일러가 호출을 최적화하지 않습니다(완전히 또는 동일한 명령 시퀀스로 호출 대체). This differs from RtlCompareMemory which is subject to various compiler optimizations.

  • 이 함수는 바이트 수준 액세스를 사용하여 부작용 또는 특수 액세스 요구 사항이 있을 수 있는 디바이스 메모리의 적절한 처리를 보장합니다.

  • 루틴은 첫 번째 블록의 첫 번째 바이트를 두 번째 블록의 첫 번째 바이트와 비교하여 시작하고 바이트가 일치하는 동안 두 블록의 연속 바이트를 계속 비교합니다. The routine stops comparing bytes when it encounters the first pair of bytes that are not equal, or when the number of matching bytes equals the Length parameter value, whichever occurs first.

  • 플랫폼이 허용하는 경우 함수는 정렬되지 않은 메모리 액세스를 수행할 수 있습니다.

이 함수는 최신 버전뿐만 아니라 모든 버전의 Windows에서 작동합니다. wdm.h 헤더에서 함수 선언을 얻으려면 최신 WDK를 사용해야 합니다. 최신 WDK의 라이브러리(volatileaccessk.lib)도 필요합니다. 그러나 결과 드라이버는 이전 버전의 Windows에서 잘 실행됩니다.

Example

UCHAR DeviceBuffer1[256];
UCHAR DeviceBuffer2[256];

// Read data from device memory into buffers
ReadFromDevice(DeviceBuffer1, sizeof(DeviceBuffer1));
ReadFromDevice(DeviceBuffer2, sizeof(DeviceBuffer2));

// Compare the device memory buffers
size_t matchingBytes = RtlCompareDeviceMemory(DeviceBuffer1, DeviceBuffer2, sizeof(DeviceBuffer1));

if (matchingBytes == sizeof(DeviceBuffer1)) {
    // All bytes matched
    DbgPrint("Device buffers are identical\n");
} else {
    // Difference found at byte offset 'matchingBytes'
    DbgPrint("Device buffers differ starting at byte %zu\n", matchingBytes);
}

Requirements

Requirement Value
Header wdm.h(Wdm.h 포함)
Library volatileaccessk.lib(커널 모드), volatileaccessu.lib(사용자 모드)

See also

RtlCompareMemory

RtlFillVolatileMemory