287 lines
5.1 KiB
C
287 lines
5.1 KiB
C
/*++
|
|
|
|
Copyright (c) 2024-2025, 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 <string.h>
|
|
|
|
#ifndef IN
|
|
#define IN
|
|
#endif
|
|
|
|
#ifndef OUT
|
|
#define OUT
|
|
#endif
|
|
|
|
#ifndef OPTIONAL
|
|
#define OPTIONAL
|
|
#endif
|
|
|
|
#ifndef VOID
|
|
#define VOID void
|
|
#endif
|
|
|
|
#ifndef CONST
|
|
#define CONST const
|
|
#endif
|
|
|
|
#ifndef ANYSIZE_ARRAY
|
|
#define ANYSIZE_ARRAY 1
|
|
#endif
|
|
|
|
#ifndef NULL
|
|
#if defined(__cplusplus)
|
|
#if __cplusplus >= 201103L
|
|
#define NULL nullptr
|
|
#else
|
|
#define NULL 0
|
|
#endif
|
|
#else
|
|
#define NULL ((VOID *) 0)
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef FORCEINLINE
|
|
#if defined(_MSC_EXTENSIONS)
|
|
#define FORCEINLINE __forceinline
|
|
#elif defined(__clang__) || defined(__GNUC__)
|
|
#define FORCEINLINE __attribute__((always_inline))
|
|
#else
|
|
#warning Unable to define FORCEINLINE
|
|
#define FORCEINLINE static inline
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef FASTCALL
|
|
#if defined(_M_IX86)
|
|
#define FASTCALL __fastcall
|
|
#elif defined(__clang__) || defined(__GNUC__)
|
|
#define FASTCALL __attribute__((fastcall))
|
|
#else
|
|
#warning Unable to defined FASTCALL
|
|
#define FASTCALL
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef NTAPI
|
|
#if !defined(_M_AMD64)
|
|
#if defined(_MSC_EXTENSIONS)
|
|
#define NTAPI __stdcall
|
|
#elif defined(__clang__) || defined(__GNUC__)
|
|
#define NTAPI __attribute__((stdcall))
|
|
#else
|
|
#warning Unable to define NTAPI
|
|
#define NTAPI
|
|
#endif
|
|
#else
|
|
#define NTAPI
|
|
#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;
|
|
|
|
//
|
|
// Minimum/maximum values of basic types.
|
|
//
|
|
#define MINCHAR 0x80
|
|
#define MAXCHAR 0x7F
|
|
#define MINSHORT 0x8000
|
|
#define MAXSHORT 0x7FFF
|
|
#define MINLONG 0x80000000
|
|
#define MAXLONG 0x7FFFFFFF
|
|
#define MAXUCHAR 0xFF
|
|
#define MAXUSHORT 0xFFFF
|
|
#define MAXULONG 0xFFFFFFFF
|
|
|
|
//
|
|
// Long long types.
|
|
//
|
|
#if defined(_MSC_EXTENSIONS)
|
|
typedef __int64 LONGLONG;
|
|
typedef unsigned __int64 ULONGLONG;
|
|
#elif defined(UNIX_LP64)
|
|
typedef long LONGLONG;
|
|
typedef unsigned long ULONGLONG;
|
|
#else
|
|
typedef long long LONGLONG;
|
|
typedef unsigned long long ULONGLONG;
|
|
#endif
|
|
|
|
#define MAXLONGLONG 0x7FFFFFFFFFFFFFFF
|
|
#define MAXULONGLONG 0xFFFFFFFFFFFFFFFF
|
|
|
|
//
|
|
// Logical/boolean value types.
|
|
//
|
|
typedef ULONG LOGICAL;
|
|
typedef int BOOL;
|
|
typedef UCHAR BOOLEAN;
|
|
|
|
#define TRUE 1
|
|
#define FALSE 0
|
|
|
|
//
|
|
// Numeric pointer types.
|
|
//
|
|
#ifdef _WIN64
|
|
typedef LONGLONG LONG_PTR;
|
|
typedef ULONGLONG ULONG_PTR;
|
|
#else
|
|
typedef LONG LONG_PTR;
|
|
typedef ULONG ULONG_PTR;
|
|
#endif
|
|
|
|
//
|
|
// Basic type pointers.
|
|
//
|
|
typedef VOID *PVOID;
|
|
typedef CHAR *PCHAR;
|
|
typedef SHORT *PSHORT;
|
|
typedef UCHAR *PUCHAR;
|
|
typedef USHORT *PUSHORT;
|
|
typedef ULONG *PULONG;
|
|
|
|
//
|
|
// Long long type pointers.
|
|
//
|
|
typedef LONGLONG *PLONGLONG;
|
|
typedef ULONGLONG *PULONGLONG;
|
|
|
|
//
|
|
// Logical/boolean type pointers.
|
|
//
|
|
typedef ULONG *PLOGICAL;
|
|
typedef BOOL *PBOOL;
|
|
typedef BOOLEAN *PBOOLEAN;
|
|
|
|
//
|
|
// String types.
|
|
//
|
|
typedef CHAR *PSTR, *LPSTR;
|
|
typedef CONST CHAR *PCSTR, *LPCSTR;
|
|
|
|
//
|
|
// Wide character/string types.
|
|
//
|
|
typedef USHORT WCHAR;
|
|
typedef WCHAR *PWCHAR, *PWSTR, *LPWSTR;
|
|
typedef CONST WCHAR *PCWSTR, *LPCWSTR;
|
|
|
|
//
|
|
// Handle types.
|
|
//
|
|
typedef PVOID HANDLE;
|
|
typedef HANDLE *PHANDLE;
|
|
|
|
#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR) -1)
|
|
|
|
//
|
|
// Status code types.
|
|
//
|
|
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)
|
|
|
|
//
|
|
// Struct field offset helper.
|
|
//
|
|
#if defined(__clang__) || defined(__GNUC__)
|
|
#define FIELD_OFFSET(type, field) ((ULONG)__builtin_offsetof(type, field))
|
|
#else
|
|
#define FIELD_OFFSET(type, field) ((ULONG)&(((type *)0)->field))
|
|
#endif
|
|
|
|
//
|
|
// Alignment helpers.
|
|
//
|
|
#define ALIGN_DOWN(x, a) ((x) & ~((a) - 1))
|
|
#define ALIGN_UP(x, a) ALIGN_DOWN((x) + (a) - 1, a)
|
|
|
|
//
|
|
// Bit extraction helpers.
|
|
//
|
|
#define LODWORD(x) ((ULONG)(x))
|
|
#define HIDWORD(x) ((ULONG)((x) >> 32))
|
|
#define LOWORD(x) ((USHORT)(x))
|
|
#define HIWORD(x) ((USHORT)((x) >> 16))
|
|
#define LOBYTE(x) ((UCHAR)(x))
|
|
#define HIBYTE(x) ((UCHAR)((x) >> 8))
|
|
|
|
//
|
|
// 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;
|
|
|
|
//
|
|
// Unicode string.
|
|
//
|
|
typedef struct _UNICODE_STRING {
|
|
USHORT Length;
|
|
USHORT MaximumLength;
|
|
PWSTR Buffer;
|
|
} UNICODE_STRING, *PUNICODE_STRING;
|
|
typedef CONST UNICODE_STRING *PCUNICODE_STRING;
|
|
|
|
#define UNICODE_NULL ((WCHAR) 0)
|
|
|
|
#define MAX_USTRING ALIGN_DOWN(MAXUSHORT, sizeof(WCHAR))
|
|
|
|
//
|
|
// Doubly-linked list entry.
|
|
//
|
|
typedef struct _LIST_ENTRY {
|
|
struct _LIST_ENTRY *Flink;
|
|
struct _LIST_ENTRY *Blink;
|
|
} LIST_ENTRY, *PLIST_ENTRY;
|
|
|
|
#include <guiddef.h>
|
|
|
|
#endif /* !_NTDEF_H */
|