/*++ Copyright (c) 2024, Quinn Stephens. Provided under the BSD 3-Clause license. Module Name: ntdef.h Abstract: Provides basic NT definitions. --*/ #ifndef _NTDEF_H #define _NTDEF_H #include #ifndef IN #define IN #endif #ifndef OUT #define OUT #endif #ifndef OPTIONAL #define OPTIONAL #endif #ifndef FASTCALL #define FASTCALL #endif #ifndef NTAPI #define NTAPI #endif #ifndef VOID #define VOID void #endif #ifndef CONST #define CONST const #endif #ifndef ANYSIZE_ARRAY #define ANYSIZE_ARRAY 1 #endif #ifndef FORCEINLINE #if defined(_MSC_EXTENSIONS) #define FORCEINLINE __inline #else #define FORCEINLINE static inline #endif #endif #ifndef NULL #ifdef __cplusplus #define NULL 0 #else #define NULL ((VOID *)0) #endif #endif // // Basic types. // typedef char CHAR; typedef short SHORT; typedef long LONG; typedef unsigned char UCHAR; typedef unsigned short USHORT; typedef unsigned long ULONG; // // Basic pointer types. // typedef VOID *PVOID; typedef CHAR *PCHAR; typedef SHORT *PSHORT; typedef UCHAR *PUCHAR; typedef USHORT *PUSHORT; typedef ULONG *PULONG; // // Logical value types. // typedef ULONG LOGICAL; typedef ULONG *PLOGICAL; // // String types. // typedef CHAR *LPSTR; typedef CONST CHAR *LPCSTR; // // Wide character/string types. // typedef USHORT WCHAR; typedef WCHAR *PWCHAR, *LPWSTR; typedef CONST WCHAR *LPCWSTR; // // Status codes. // typedef LONG NTSTATUS; typedef NTSTATUS *PNTSTATUS; // // Status code utilities. // #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0) #define NT_INFORMATION(Status) ((ULONG)(Status) >> 30 == 1) #define NT_WARNING(Status) ((ULONG)(Status) >> 30 == 2) #define NT_ERROR(Status) ((ULONG)(Status) >> 30 == 3) // // Long long type definitions. // #if defined(_MSC_EXTENSIONS) typedef unsigned __int64 ULONGLONG; typedef __int64 LONGLONG; #elif defined(UNIX_LP64) typedef unsigned long ULONGLONG; typedef long LONGLONG; #else typedef unsigned long long ULONGLONG; typedef long long LONGLONG; #endif // // Large (64-bit) integer value. // typedef union LARGE_INTEGER { struct { ULONG LowPart; LONG HighPart; }; LONGLONG QuadPart; } LARGE_INTEGER, *PLARGE_INTEGER; // // Large (64-bit) unsigned integer value. // typedef union ULARGE_INTEGER { struct { ULONG LowPart; ULONG HighPart; }; ULONGLONG QuadPart; } ULARGE_INTEGER, *PULARGE_INTEGER; // // Struct field offset helper. // #if !defined(__GNUC__) && !defined(__clang__) #define FIELD_OFFSET(type, field) ((ULONG)&(((type *)0)->field)) #else #define FIELD_OFFSET(type, field) ((ULONG)__builtin_offsetof(type, field)) #endif // // Alignment helpers. // #define ALIGN_DOWN(x, a) ((x) & ~((a) - 1)) #define ALIGN_UP(x, a) ALIGN_DOWN((x) + (a) - 1, a) // // Doubly-linked list entry. // typedef struct _LIST_ENTRY { struct _LIST_ENTRY *ForwardLink; struct _LIST_ENTRY *BackLink; } LIST_ENTRY, *PLIST_ENTRY; #endif /* !_NTDEF_H */