RtlUnalignedStringCchLengthW - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTSTRSAFE_H_INCLUDED_
#ifndef NTSTRSAFE_LIB_IMPL
#ifndef NTSTRSAFE_NO_CCH_FUNCTIONS
/*++
  NTSTATUS
  RtlUnalignedStringCchLength(
  _In_ LPCUTSTR    psz,
  _In_ _In_range_(1, NTSTRSAFE_MAX_CCH) size_t  cchMax,
  _Out_opt_ _Deref_out_range_(<, cchMax) size_t*     pcchLength  OPTIONAL
  );
  Routine Description:
  This routine is a version of RtlStringCchLength that accepts an unaligned string pointer.
  This function returns an NTSTATUS value, and not a pointer.  It returns
  STATUS_SUCCESS if the string is non-null and the length including the null
  terminator is less than or equal to cchMax characters.
Arguments:
psz         -   string to check the length of
cchMax      -   maximum number of characters including the null terminator
that psz is allowed to contain
pcch        -   if the function succeeds and pcch is non-null, the current length
in characters of psz excluding the null terminator will be returned.
This out parameter is equivalent to the return value of strlen(psz)
Notes:
psz can be null but the function will fail
cchMax should be greater than zero or the function will fail
Return Value:
STATUS_SUCCESS -   psz is non-null and the length including the null
terminator is less than or equal to cchMax characters
failure        -   you can use the macro NTSTATUS_CODE() to get a win32
error code for all hresult failure cases
It is strongly recommended to use the NT_SUCCESS() macro to test the
return value of this function.
--*/
#ifdef ALIGNMENT_MACHINE

_Must_inspect_result_
NTSTRSAFEDDI
    RtlUnalignedStringCchLengthW(
            _In_reads_or_z_(cchMax) STRSAFE_PCUNZWCH psz,
            _In_ _In_range_(1, NTSTRSAFE_MAX_CCH) size_t cchMax,
            _Out_opt_ _Deref_out_range_(<, cchMax) size_t* pcchLength)
{
    NTSTATUS status;

    if ((psz == NULL) || (cchMax > NTSTRSAFE_MAX_CCH))
    {
        status = STATUS_INVALID_PARAMETER;
    }
    else
    {
        status = RtlUnalignedStringLengthWorkerW(psz, cchMax, pcchLength);
    }

    if (!NT_SUCCESS(status) && pcchLength)
    {
        *pcchLength = 0;
    }

    return status;
}

#endif
#endif
#endif
#endif

View code on GitHub
#ifndef _NTSTRSAFE_H_INCLUDED_
#ifndef NTSTRSAFE_LIB_IMPL
#ifndef NTSTRSAFE_NO_CCH_FUNCTIONS
/*++
  NTSTATUS
  RtlUnalignedStringCchLength(
  _In_ LPCUTSTR    psz,
  _In_ _In_range_(1, NTSTRSAFE_MAX_CCH) size_t  cchMax,
  _Out_opt_ _Deref_out_range_(<, cchMax) size_t*     pcchLength  OPTIONAL
  );
  Routine Description:
  This routine is a version of RtlStringCchLength that accepts an unaligned string pointer.
  This function returns an NTSTATUS value, and not a pointer.  It returns
  STATUS_SUCCESS if the string is non-null and the length including the null
  terminator is less than or equal to cchMax characters.
Arguments:
psz         -   string to check the length of
cchMax      -   maximum number of characters including the null terminator
that psz is allowed to contain
pcch        -   if the function succeeds and pcch is non-null, the current length
in characters of psz excluding the null terminator will be returned.
This out parameter is equivalent to the return value of strlen(psz)
Notes:
psz can be null but the function will fail
cchMax should be greater than zero or the function will fail
Return Value:
STATUS_SUCCESS -   psz is non-null and the length including the null
terminator is less than or equal to cchMax characters
failure        -   you can use the macro NTSTATUS_CODE() to get a win32
error code for all hresult failure cases
It is strongly recommended to use the NT_SUCCESS() macro to test the
return value of this function.
--*/
#ifdef ALIGNMENT_MACHINE
// ...
#else

#define RtlUnalignedStringCchLengthW   RtlStringCchLengthW

#endif
#endif
#endif
#endif

View code on GitHub
// ntstrsafe.h

NTSTRSAFEDDI RtlUnalignedStringCchLengthW(
  [in]            STRSAFE_PCUNZWCH psz,
  [in]            size_t           cchMax,
  [out, optional] size_t           *pcchLength
);
View the official Windows Driver Kit DDI reference

NtDoc

No description available.

Windows Driver Kit DDI reference (nf-ntstrsafe-rtlunalignedstringcchlengthw)

RtlUnalignedStringCchLengthW function

Description

The RtlUnalignedStringCchLengthW function is a version of the RtlStringCchLength function that accepts an unaligned pointer to a string of Unicode characters.

Parameters

psz [in]

Supplies a pointer to a buffer that contains a null-terminated string whose length RtlUnalignedStringCchLengthW will check.

cchMax [in]

Supplies the maximum number of characters that are allowed in the buffer that psz points to, including the terminating NULL character. This value cannot exceed NTSTRSAFE_MAX_CCH.

pcchLength [out, optional]

Optional. If the caller supplies a non-NULL address pointer, the function loads the address with the length, in characters, of the string that is contained in the buffer that psz points to. The length does not include the string's terminating NULL character.

Return value

RtlUnalignedStringCchLengthW returns one of the following NTSTATUS values.

Return code Description
STATUS_SUCCESS This success status means the string that the psz parameter was not NULL, and the length of the string (including the terminating NULL character) was less than or equal to cchMax characters.
STATUS_INVALID_PARAMETER This error status means the value in psz is NULL, cchMax is larger than NTSTRSAFE_MAX_CCH, or psz is longer than cchMax.

For information about how to test NTSTATUS values, see Using NTSTATUS Values.

Remarks

The RtlUnalignedStringCchLengthW function is available for processor architectures, such as Itanium-based and x64-based, that cause alignment exceptions when software attempts to access unaligned data. On those processors, you can use RtlUnalignedStringCchLengthW instead of RtlStringCchLength to avoid alignment exceptions. (For processors that do not cause alignment exceptions, RtlUnalignedStringCchLengthW is equivalent to RtlStringCchLength.)

For more information about the safe string functions, see Using Safe String Functions.

See also

RtlStringCchLength