Process Hacker
phsup.h File Reference
#include <intrin.h>
#include <wchar.h>
#include <assert.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define PTR_ADD_OFFSET(Pointer, Offset)   ((PVOID)((ULONG_PTR)(Pointer) + (ULONG_PTR)(Offset)))
 
#define PTR_SUB_OFFSET(Pointer, Offset)   ((PVOID)((ULONG_PTR)(Pointer) - (ULONG_PTR)(Offset)))
 
#define ALIGN_UP_BY(Address, Align)   (((ULONG_PTR)(Address) + (Align) - 1) & ~((Align) - 1))
 
#define ALIGN_UP_POINTER_BY(Pointer, Align)   ((PVOID)ALIGN_UP_BY(Pointer, Align))
 
#define ALIGN_UP(Address, Type)   ALIGN_UP_BY(Address, sizeof(Type))
 
#define ALIGN_UP_POINTER(Pointer, Type)   ((PVOID)ALIGN_UP(Pointer, Type))
 
#define PAGE_SIZE   0x1000
 
#define PH_LARGE_BUFFER_SIZE   (256 * 1024 * 1024)
 
#define PhRaiseStatus(Status)   RtlRaiseStatus(Status)
 
#define SIMPLE_EXCEPTION_FILTER(Condition)   ((Condition) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
 
#define ASSUME_ASSERT(Expression)   __assume(Expression)
 
#define ASSUME_NO_DEFAULT   __assume(FALSE)
 
#define PH_TICKS_PER_NS   ((LONG64)1 * 10)
 
#define PH_TICKS_PER_MS   (PH_TICKS_PER_NS * 1000)
 
#define PH_TICKS_PER_SEC   (PH_TICKS_PER_MS * 1000)
 
#define PH_TICKS_PER_MIN   (PH_TICKS_PER_SEC * 60)
 
#define PH_TICKS_PER_HOUR   (PH_TICKS_PER_MIN * 60)
 
#define PH_TICKS_PER_DAY   (PH_TICKS_PER_HOUR * 24)
 
#define PH_TICKS_PARTIAL_MS(Ticks)   (((ULONG64)(Ticks) / PH_TICKS_PER_MS) % 1000)
 
#define PH_TICKS_PARTIAL_SEC(Ticks)   (((ULONG64)(Ticks) / PH_TICKS_PER_SEC) % 60)
 
#define PH_TICKS_PARTIAL_MIN(Ticks)   (((ULONG64)(Ticks) / PH_TICKS_PER_MIN) % 60)
 
#define PH_TICKS_PARTIAL_HOURS(Ticks)   (((ULONG64)(Ticks) / PH_TICKS_PER_HOUR) % 24)
 
#define PH_TICKS_PARTIAL_DAYS(Ticks)   ((ULONG64)(Ticks) / PH_TICKS_PER_DAY)
 
#define PH_TIMEOUT_MS   PH_TICKS_PER_MS
 
#define PH_TIMEOUT_SEC   PH_TICKS_PER_SEC
 
#define _Assume_refs_(count)
 Indicates that a function assumes the specified number of references are available for the object.
 
#define _Callback_
 
#define _May_raise_
 Indicates that a function may raise a software exception.
 
#define _Needs_align_(align)
 Indicates that a function requires the specified value to be aligned at the specified number of bytes.
 
#define C_1uTo2(x)   ((unsigned short)(unsigned char)(x))
 
#define C_1sTo2(x)   ((unsigned short)(signed char)(x))
 
#define C_1uTo4(x)   ((unsigned int)(unsigned char)(x))
 
#define C_1sTo4(x)   ((unsigned int)(signed char)(x))
 
#define C_2uTo4(x)   ((unsigned int)(unsigned short)(x))
 
#define C_2sTo4(x)   ((unsigned int)(signed short)(x))
 
#define C_4uTo8(x)   ((unsigned __int64)(unsigned int)(x))
 
#define C_4sTo8(x)   ((unsigned __int64)(signed int)(x))
 
#define PH_BUILTIN_COMPARE(value1, value2)
 
#define PH_INT32_STR_LEN   12
 
#define PH_INT32_STR_LEN_1   (PH_INT32_STR_LEN + 1)
 
#define PH_INT64_STR_LEN   50
 
#define PH_INT64_STR_LEN_1   (PH_INT64_STR_LEN + 1)
 
#define PH_PTR_STR_LEN   24
 
#define PH_PTR_STR_LEN_1   (PH_PTR_STR_LEN + 1)
 

Typedefs

typedef enum _PH_SORT_ORDER PH_SORT_ORDER
 
typedef enum _PH_SORT_ORDERPPH_SORT_ORDER
 
typedef int(__cdecl * PC_COMPARE_FUNCTION )(void *, const void *, const void *)
 

Enumerations

enum  _PH_SORT_ORDER { NoSortOrder = 0, AscendingSortOrder, DescendingSortOrder }
 

Functions

FORCEINLINE LONG PhModifySort (_In_ LONG Result, _In_ PH_SORT_ORDER Order)
 
FORCEINLINE int charcmp (_In_ signed char value1, _In_ signed char value2)
 
FORCEINLINE int ucharcmp (_In_ unsigned char value1, _In_ unsigned char value2)
 
FORCEINLINE int shortcmp (_In_ signed short value1, _In_ signed short value2)
 
FORCEINLINE int ushortcmp (_In_ unsigned short value1, _In_ unsigned short value2)
 
FORCEINLINE int intcmp (_In_ int value1, _In_ int value2)
 
FORCEINLINE int uintcmp (_In_ unsigned int value1, _In_ unsigned int value2)
 
FORCEINLINE int int64cmp (_In_ __int64 value1, _In_ __int64 value2)
 
FORCEINLINE int uint64cmp (_In_ unsigned __int64 value1, _In_ unsigned __int64 value2)
 
FORCEINLINE int intptrcmp (_In_ LONG_PTR value1, _In_ LONG_PTR value2)
 
FORCEINLINE int uintptrcmp (_In_ ULONG_PTR value1, _In_ ULONG_PTR value2)
 
FORCEINLINE int singlecmp (_In_ float value1, _In_ float value2)
 
FORCEINLINE int doublecmp (_In_ double value1, _In_ double value2)
 
FORCEINLINE int wcsicmp2 (_In_opt_ PWSTR Value1, _In_opt_ PWSTR Value2)
 
void * _InterlockedCompareExchangePointer (void *volatile *Destination, void *Exchange, void *Comparand)
 
FORCEINLINE void * _InterlockedExchangePointer (void *volatile *Destination, void *Exchange)
 
FORCEINLINE LONG_PTR _InterlockedExchangeAddPointer (_Inout_ _Interlocked_operand_ LONG_PTR volatile *Addend, _In_ LONG_PTR Value)
 
FORCEINLINE LONG_PTR _InterlockedIncrementPointer (_Inout_ _Interlocked_operand_ LONG_PTR volatile *Addend)
 
FORCEINLINE LONG_PTR _InterlockedDecrementPointer (_Inout_ _Interlocked_operand_ LONG_PTR volatile *Addend)
 
FORCEINLINE BOOLEAN _InterlockedBitTestAndResetPointer (_Inout_ _Interlocked_operand_ LONG_PTR volatile *Base, _In_ LONG_PTR Bit)
 
FORCEINLINE BOOLEAN _InterlockedBitTestAndSetPointer (_Inout_ _Interlocked_operand_ LONG_PTR volatile *Base, _In_ LONG_PTR Bit)
 
FORCEINLINE BOOLEAN _InterlockedIncrementNoZero (_Inout_ _Interlocked_operand_ LONG volatile *Addend)
 
FORCEINLINE VOID PhPrintInt32 (_Out_writes_(PH_INT32_STR_LEN_1) PWSTR Destination, _In_ LONG Int32)
 
FORCEINLINE VOID PhPrintUInt32 (_Out_writes_(PH_INT32_STR_LEN_1) PWSTR Destination, _In_ ULONG UInt32)
 
FORCEINLINE VOID PhPrintInt64 (_Out_writes_(PH_INT64_STR_LEN_1) PWSTR Destination, _In_ LONG64 Int64)
 
FORCEINLINE VOID PhPrintUInt64 (_Out_writes_(PH_INT64_STR_LEN_1) PWSTR Destination, _In_ ULONG64 UInt64)
 
FORCEINLINE VOID PhPrintPointer (_Out_writes_(PH_PTR_STR_LEN_1) PWSTR Destination, _In_ PVOID Pointer)
 
FORCEINLINE ULONG PhCountBits (_In_ ULONG Value)
 
FORCEINLINE ULONG PhRoundNumber (_In_ ULONG Value, _In_ ULONG Multiplier)
 
FORCEINLINE VOID PhProbeAddress (_In_ PVOID UserAddress, _In_ SIZE_T UserLength, _In_ PVOID BufferAddress, _In_ SIZE_T BufferLength, _In_ ULONG Alignment)
 
FORCEINLINE PLARGE_INTEGER PhTimeoutFromMilliseconds (_Out_ PLARGE_INTEGER Timeout, _In_ ULONG Milliseconds)
 
FORCEINLINE NTSTATUS PhGetLastWin32ErrorAsNtStatus ()
 
FORCEINLINE PVOID PhGetModuleProcAddress (_In_ PWSTR ModuleName, _In_ PSTR ProcName)
 

Macro Definition Documentation

#define _Assume_refs_ (   count)

Indicates that a function assumes the specified number of references are available for the object.

Remarks
Usually functions reference objects if they store them for later usage; this annotation specifies that the caller must supply these extra references itself. In effect these references are "transferred" to the function and must not be used. E.g. if you create an object and immediately call a function with Assume_refs(1), you may no longer use the object since that one reference you held is no longer yours.

Definition at line 74 of file phsup.h.

#define _Callback_

Definition at line 76 of file phsup.h.

#define _May_raise_

Indicates that a function may raise a software exception.

Remarks
Do not use this annotation for temporary usages of exceptions, e.g. unimplemented functions.

Definition at line 86 of file phsup.h.

#define _Needs_align_ (   align)

Indicates that a function requires the specified value to be aligned at the specified number of bytes.

Definition at line 92 of file phsup.h.

#define ALIGN_UP (   Address,
  Type 
)    ALIGN_UP_BY(Address, sizeof(Type))

Definition at line 17 of file phsup.h.

#define ALIGN_UP_BY (   Address,
  Align 
)    (((ULONG_PTR)(Address) + (Align) - 1) & ~((Align) - 1))

Definition at line 15 of file phsup.h.

#define ALIGN_UP_POINTER (   Pointer,
  Type 
)    ((PVOID)ALIGN_UP(Pointer, Type))

Definition at line 18 of file phsup.h.

#define ALIGN_UP_POINTER_BY (   Pointer,
  Align 
)    ((PVOID)ALIGN_UP_BY(Pointer, Align))

Definition at line 16 of file phsup.h.

#define ASSUME_ASSERT (   Expression)    __assume(Expression)

Definition at line 37 of file phsup.h.

#define ASSUME_NO_DEFAULT   __assume(FALSE)

Definition at line 38 of file phsup.h.

#define C_1sTo2 (   x)    ((unsigned short)(signed char)(x))

Definition at line 98 of file phsup.h.

#define C_1sTo4 (   x)    ((unsigned int)(signed char)(x))

Definition at line 100 of file phsup.h.

#define C_1uTo2 (   x)    ((unsigned short)(unsigned char)(x))

Definition at line 97 of file phsup.h.

#define C_1uTo4 (   x)    ((unsigned int)(unsigned char)(x))

Definition at line 99 of file phsup.h.

#define C_2sTo4 (   x)    ((unsigned int)(signed short)(x))

Definition at line 102 of file phsup.h.

#define C_2uTo4 (   x)    ((unsigned int)(unsigned short)(x))

Definition at line 101 of file phsup.h.

#define C_4sTo8 (   x)    ((unsigned __int64)(signed int)(x))

Definition at line 104 of file phsup.h.

#define C_4uTo8 (   x)    ((unsigned __int64)(unsigned int)(x))

Definition at line 103 of file phsup.h.

#define PAGE_SIZE   0x1000

Definition at line 20 of file phsup.h.

#define PH_BUILTIN_COMPARE (   value1,
  value2 
)
Value:
if (value1 > value2) \
return 1; \
else if (value1 < value2) \
return -1; \
\
return 0

Definition at line 128 of file phsup.h.

#define PH_INT32_STR_LEN   12

Definition at line 361 of file phsup.h.

#define PH_INT32_STR_LEN_1   (PH_INT32_STR_LEN + 1)

Definition at line 362 of file phsup.h.

#define PH_INT64_STR_LEN   50

Definition at line 364 of file phsup.h.

#define PH_INT64_STR_LEN_1   (PH_INT64_STR_LEN + 1)

Definition at line 365 of file phsup.h.

#define PH_LARGE_BUFFER_SIZE   (256 * 1024 * 1024)

Definition at line 22 of file phsup.h.

#define PH_PTR_STR_LEN   24

Definition at line 367 of file phsup.h.

#define PH_PTR_STR_LEN_1   (PH_PTR_STR_LEN + 1)

Definition at line 368 of file phsup.h.

#define PH_TICKS_PARTIAL_DAYS (   Ticks)    ((ULONG64)(Ticks) / PH_TICKS_PER_DAY)

Definition at line 54 of file phsup.h.

#define PH_TICKS_PARTIAL_HOURS (   Ticks)    (((ULONG64)(Ticks) / PH_TICKS_PER_HOUR) % 24)

Definition at line 53 of file phsup.h.

#define PH_TICKS_PARTIAL_MIN (   Ticks)    (((ULONG64)(Ticks) / PH_TICKS_PER_MIN) % 60)

Definition at line 52 of file phsup.h.

#define PH_TICKS_PARTIAL_MS (   Ticks)    (((ULONG64)(Ticks) / PH_TICKS_PER_MS) % 1000)

Definition at line 50 of file phsup.h.

#define PH_TICKS_PARTIAL_SEC (   Ticks)    (((ULONG64)(Ticks) / PH_TICKS_PER_SEC) % 60)

Definition at line 51 of file phsup.h.

#define PH_TICKS_PER_DAY   (PH_TICKS_PER_HOUR * 24)

Definition at line 48 of file phsup.h.

#define PH_TICKS_PER_HOUR   (PH_TICKS_PER_MIN * 60)

Definition at line 47 of file phsup.h.

#define PH_TICKS_PER_MIN   (PH_TICKS_PER_SEC * 60)

Definition at line 46 of file phsup.h.

#define PH_TICKS_PER_MS   (PH_TICKS_PER_NS * 1000)

Definition at line 44 of file phsup.h.

#define PH_TICKS_PER_NS   ((LONG64)1 * 10)

Definition at line 43 of file phsup.h.

#define PH_TICKS_PER_SEC   (PH_TICKS_PER_MS * 1000)

Definition at line 45 of file phsup.h.

#define PH_TIMEOUT_MS   PH_TICKS_PER_MS

Definition at line 56 of file phsup.h.

#define PH_TIMEOUT_SEC   PH_TICKS_PER_SEC

Definition at line 57 of file phsup.h.

#define PhRaiseStatus (   Status)    RtlRaiseStatus(Status)

Definition at line 26 of file phsup.h.

#define PTR_ADD_OFFSET (   Pointer,
  Offset 
)    ((PVOID)((ULONG_PTR)(Pointer) + (ULONG_PTR)(Offset)))

Definition at line 13 of file phsup.h.

#define PTR_SUB_OFFSET (   Pointer,
  Offset 
)    ((PVOID)((ULONG_PTR)(Pointer) - (ULONG_PTR)(Offset)))

Definition at line 14 of file phsup.h.

#define SIMPLE_EXCEPTION_FILTER (   Condition)    ((Condition) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)

Definition at line 28 of file phsup.h.

Typedef Documentation

typedef int(__cdecl * PC_COMPARE_FUNCTION)(void *, const void *, const void *)

Definition at line 245 of file phsup.h.

Enumeration Type Documentation

Enumerator:
NoSortOrder 
AscendingSortOrder 
DescendingSortOrder 

Definition at line 108 of file phsup.h.

Function Documentation

FORCEINLINE BOOLEAN _InterlockedBitTestAndResetPointer ( _Inout_ _Interlocked_operand_ LONG_PTR volatile *  Base,
_In_ LONG_PTR  Bit 
)

Definition at line 308 of file phsup.h.

FORCEINLINE BOOLEAN _InterlockedBitTestAndSetPointer ( _Inout_ _Interlocked_operand_ LONG_PTR volatile *  Base,
_In_ LONG_PTR  Bit 
)

Definition at line 320 of file phsup.h.

void* _InterlockedCompareExchangePointer ( void *volatile *  Destination,
void *  Exchange,
void *  Comparand 
)
FORCEINLINE LONG_PTR _InterlockedDecrementPointer ( _Inout_ _Interlocked_operand_ LONG_PTR volatile *  Addend)

Definition at line 297 of file phsup.h.

FORCEINLINE LONG_PTR _InterlockedExchangeAddPointer ( _Inout_ _Interlocked_operand_ LONG_PTR volatile *  Addend,
_In_ LONG_PTR  Value 
)

Definition at line 274 of file phsup.h.

FORCEINLINE void* _InterlockedExchangePointer ( void *volatile *  Destination,
void *  Exchange 
)

Definition at line 260 of file phsup.h.

FORCEINLINE BOOLEAN _InterlockedIncrementNoZero ( _Inout_ _Interlocked_operand_ LONG volatile *  Addend)

Definition at line 332 of file phsup.h.

FORCEINLINE LONG_PTR _InterlockedIncrementPointer ( _Inout_ _Interlocked_operand_ LONG_PTR volatile *  Addend)

Definition at line 286 of file phsup.h.

FORCEINLINE int charcmp ( _In_ signed char  value1,
_In_ signed char  value2 
)

Definition at line 136 of file phsup.h.

FORCEINLINE int doublecmp ( _In_ double  value1,
_In_ double  value2 
)

Definition at line 224 of file phsup.h.

FORCEINLINE int int64cmp ( _In_ __int64  value1,
_In_ __int64  value2 
)

Definition at line 184 of file phsup.h.

FORCEINLINE int intcmp ( _In_ int  value1,
_In_ int  value2 
)

Definition at line 168 of file phsup.h.

FORCEINLINE int intptrcmp ( _In_ LONG_PTR  value1,
_In_ LONG_PTR  value2 
)

Definition at line 200 of file phsup.h.

FORCEINLINE ULONG PhCountBits ( _In_ ULONG  Value)

Definition at line 418 of file phsup.h.

FORCEINLINE NTSTATUS PhGetLastWin32ErrorAsNtStatus ( )

Definition at line 493 of file phsup.h.

FORCEINLINE PVOID PhGetModuleProcAddress ( _In_ PWSTR  ModuleName,
_In_ PSTR  ProcName 
)

Definition at line 503 of file phsup.h.

FORCEINLINE LONG PhModifySort ( _In_ LONG  Result,
_In_ PH_SORT_ORDER  Order 
)

Definition at line 115 of file phsup.h.

FORCEINLINE VOID PhPrintInt32 ( _Out_writes_(PH_INT32_STR_LEN_1) PWSTR  Destination,
_In_ LONG  Int32 
)

Definition at line 370 of file phsup.h.

FORCEINLINE VOID PhPrintInt64 ( _Out_writes_(PH_INT64_STR_LEN_1) PWSTR  Destination,
_In_ LONG64  Int64 
)

Definition at line 386 of file phsup.h.

FORCEINLINE VOID PhPrintPointer ( _Out_writes_(PH_PTR_STR_LEN_1) PWSTR  Destination,
_In_ PVOID  Pointer 
)

Definition at line 402 of file phsup.h.

FORCEINLINE VOID PhPrintUInt32 ( _Out_writes_(PH_INT32_STR_LEN_1) PWSTR  Destination,
_In_ ULONG  UInt32 
)

Definition at line 378 of file phsup.h.

FORCEINLINE VOID PhPrintUInt64 ( _Out_writes_(PH_INT64_STR_LEN_1) PWSTR  Destination,
_In_ ULONG64  UInt64 
)

Definition at line 394 of file phsup.h.

FORCEINLINE VOID PhProbeAddress ( _In_ PVOID  UserAddress,
_In_ SIZE_T  UserLength,
_In_ PVOID  BufferAddress,
_In_ SIZE_T  BufferLength,
_In_ ULONG  Alignment 
)

Definition at line 458 of file phsup.h.

FORCEINLINE ULONG PhRoundNumber ( _In_ ULONG  Value,
_In_ ULONG  Multiplier 
)

Definition at line 433 of file phsup.h.

FORCEINLINE PLARGE_INTEGER PhTimeoutFromMilliseconds ( _Out_ PLARGE_INTEGER  Timeout,
_In_ ULONG  Milliseconds 
)

Definition at line 480 of file phsup.h.

FORCEINLINE int shortcmp ( _In_ signed short  value1,
_In_ signed short  value2 
)

Definition at line 152 of file phsup.h.

FORCEINLINE int singlecmp ( _In_ float  value1,
_In_ float  value2 
)

Definition at line 216 of file phsup.h.

FORCEINLINE int ucharcmp ( _In_ unsigned char  value1,
_In_ unsigned char  value2 
)

Definition at line 144 of file phsup.h.

FORCEINLINE int uint64cmp ( _In_ unsigned __int64  value1,
_In_ unsigned __int64  value2 
)

Definition at line 192 of file phsup.h.

FORCEINLINE int uintcmp ( _In_ unsigned int  value1,
_In_ unsigned int  value2 
)

Definition at line 176 of file phsup.h.

FORCEINLINE int uintptrcmp ( _In_ ULONG_PTR  value1,
_In_ ULONG_PTR  value2 
)

Definition at line 208 of file phsup.h.

FORCEINLINE int ushortcmp ( _In_ unsigned short  value1,
_In_ unsigned short  value2 
)

Definition at line 160 of file phsup.h.

FORCEINLINE int wcsicmp2 ( _In_opt_ PWSTR  Value1,
_In_opt_ PWSTR  Value2 
)

Definition at line 232 of file phsup.h.