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

The WideStringLengthFromMode function calculates the length of a null-terminated wide character string, based on the specified processor mode.

Syntax

SIZE_T WideStringLengthFromMode(
  volatile const WCHAR *String,
  KPROCESSOR_MODE      Mode
);

Parameters

String

[in] Указатель на строку символов, завершаемую значением NULL.

Mode

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

Value Meaning
KernelMode String points to kernel-mode memory. Функция выполняет вычисление прямой длины строки. Дополнительные сведения см. в примечаниях.
UserMode String points to user-mode memory. The function raises an exception if String doesn't point to user-mode memory; otherwise it performs a safe string length calculation at the specified address. Дополнительные сведения см. в примечаниях.

Return value

Функция возвращает длину строки в широких символах, не включая завершающийся символ NULL.

Remarks

Эта функция обеспечивает безопасный доступ для вычисления длины строки, завершаемой значением NULL, в памяти. Поведение зависит от указанного режима процессора:

  • When Mode is UserMode, the function ensures that the string 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.

When the mode is UserMode, the function includes validation to prevent kernel crashes when accessing potentially invalid user-mode pointers. When the mode is KernelMode, it operates on known-safe kernel addresses for optimal performance.

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

Эта функция работает во всех версиях 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

WideStringLengthFromUser

StringLengthFromMode