Поделиться через


Функция InterlockedCompareExchange64ToMode (usermode_accessors.h)

The InterlockedCompareExchange64ToMode function performs an atomic compare-and-exchange operation on a 64-bit value, based on the specified processor mode.

Syntax

LONG64 InterlockedCompareExchange64ToMode(
  LONG64 volatile *Destination,
  LONG64          ExChange,
  LONG64          Comperand,
  KPROCESSOR_MODE Mode
);

Parameters

Destination

[in, out] Указатель на расположение памяти, содержащее целевое значение. The pointer must be naturally aligned for the data type; that is, the memory location must be 8-byte aligned since Destination points to an 8-byte type.

ExChange

[in] Значение обмена.

Comperand

[in] The value to compare to Destination.

Mode

[in] Режим процессора, определяющий, как выполняется доступ к памяти. Mode can be one of the following values.

Value Meaning
KernelMode Destination points to kernel-mode memory. Функция выполняет прямую атомарную операцию сравнения и обмена. Дополнительные сведения см. в примечаниях.
UserMode Destination points to user-mode memory. The function raises an exception if Destination doesn't point to user-mode memory; otherwise it performs an atomic compare-and-exchange operation at the specified address. Дополнительные сведения см. в примечаниях.

Return value

The function returns the initial value of the Destination parameter.

Remarks

Межблокированные функции предоставляют простой механизм синхронизации доступа к переменной, к которой используется несколько потоков. Эта функция атомарна относительно вызовов других взаимоблокируемых функций. Он создает полный барьер памяти, чтобы обеспечить выполнение операций памяти в порядке.

Эта функция обеспечивает атомарный доступ к 64-разрядному значению в памяти. The function compares the Destination value with the Comperand value. If the Destination value is equal to the Comperand value, the ExChange value is stored in the address specified by Destination. В противном случае операция не выполняется. Поведение зависит от указанного режима процессора:

  • When Mode is UserMode, the function ensures that the destination address is a valid user-mode address and performs the operation safely for user-mode memory access.
  • When Mode is KernelMode, the function operates directly on kernel-mode addresses.

Функция вызывает структурированное исключение, если операция завершается ошибкой, например если целевой адрес недоступен или недопустим для указанного режима.

Эта функция работает во всех версиях Windows, а не только на последних версиях. You need to consume the latest WDK to get the function declaration from the usermode_accessors.h header. You also need the library (umaccess.lib) from the latest WDK. Однако результирующий драйвер будет работать в более ранних версиях Windows.

Requirements

Requirement Value
Минимальный поддерживаемый клиент See Remarks
Header usermode_accessors.h
Library umaccess.lib
IRQL Меньше или равно APC_LEVEL

See also

InterlockedCompareExchange64ToUser

InterlockedCompareExchangeToMode