[PSDK][NTOS:KD64] Rename GCC_ULONG64 to ULPTR64 to self-document the fact it stores a pointer as a 64-bit quantity.

But the underlying GCC stupidity is still there (15 years later).

However, enable it only in 32-bit GCC builds, not in 64-bits nor with MSVC.
See commit b9cd3f2d9 (r25845) for some details.

GCC is indeed still incapable of casting 32-bit pointers up to 64-bits,
when static-initializing arrays (**outside** a function) without emitting
the error:

  "error: initializer element is not constant"

(which might somehow indicate it actually tries to generate executable
code for casting the pointers, instead of doing it at compile-time).

Going down the rabbit hole, other stupidities show up:

Our PVOID64 type and the related POINTER_64 (in 32-bit archs), or the
PVOID32 and POINTER_32 (in 64-bit archs), are all silently broken in
GCC builds, because the pointer size attributes __ptr64 and __ptr32,
which are originally MSVC-specific, are defined to nothing in _mingw.h.
(And similarly for the __uptr and __sptr sign-extension attributes.)

Clang and other sane ompilers has since then implemented those (enabled
with -fms-extensions), but not GCC. The closest thing that could exist
for GCC is to do:

  #define __ptr64 __attribute__((mode(DI)))

in order to get a 64-bit-sized pointer type with

  typedef void* __ptr64 PVOID64;

but even this does not work, with the error:

  "error: invalid pointer mode 'DI'"
This commit is contained in:
Hermès Bélusca-Maïto 2022-11-23 16:46:35 +01:00
parent 1c0950b557
commit de81021bab
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 182 additions and 170 deletions

View file

@ -174,110 +174,116 @@ typedef struct _DBGKD_DEBUG_DATA_HEADER64
ULONG Size;
} DBGKD_DEBUG_DATA_HEADER64, *PDBGKD_DEBUG_DATA_HEADER64;
typedef union _GCC_ULONG64
/* Self-documenting type: stores a pointer as a 64-bit quantity */
#if defined(__GNUC__) && defined(_M_IX86) // See commit b9cd3f2d9 (r25845)
typedef union _ULPTR64
{
ULONG_PTR Pointer;
ULONG64 RealPointer;
} GCC_ULONG64, *PGCC_ULONG64;
ULONG_PTR ptr;
ULONG64 ptr64;
} ULPTR64;
#else
// #define ULPTR64 PVOID64
#define ULPTR64 ULONG64
#endif
typedef struct _KDDEBUGGER_DATA64
{
DBGKD_DEBUG_DATA_HEADER64 Header;
ULONG64 KernBase;
GCC_ULONG64 BreakpointWithStatus;
ULPTR64 BreakpointWithStatus;
ULONG64 SavedContext;
USHORT ThCallbackStack;
USHORT NextCallback;
USHORT FramePointer;
USHORT PaeEnabled:1;
GCC_ULONG64 KiCallUserMode;
ULPTR64 KiCallUserMode;
ULONG64 KeUserCallbackDispatcher;
GCC_ULONG64 PsLoadedModuleList;
GCC_ULONG64 PsActiveProcessHead;
GCC_ULONG64 PspCidTable;
GCC_ULONG64 ExpSystemResourcesList;
GCC_ULONG64 ExpPagedPoolDescriptor;
GCC_ULONG64 ExpNumberOfPagedPools;
GCC_ULONG64 KeTimeIncrement;
GCC_ULONG64 KeBugCheckCallbackListHead;
GCC_ULONG64 KiBugcheckData;
GCC_ULONG64 IopErrorLogListHead;
GCC_ULONG64 ObpRootDirectoryObject;
GCC_ULONG64 ObpTypeObjectType;
GCC_ULONG64 MmSystemCacheStart;
GCC_ULONG64 MmSystemCacheEnd;
GCC_ULONG64 MmSystemCacheWs;
GCC_ULONG64 MmPfnDatabase;
GCC_ULONG64 MmSystemPtesStart;
GCC_ULONG64 MmSystemPtesEnd;
GCC_ULONG64 MmSubsectionBase;
GCC_ULONG64 MmNumberOfPagingFiles;
GCC_ULONG64 MmLowestPhysicalPage;
GCC_ULONG64 MmHighestPhysicalPage;
GCC_ULONG64 MmNumberOfPhysicalPages;
GCC_ULONG64 MmMaximumNonPagedPoolInBytes;
GCC_ULONG64 MmNonPagedSystemStart;
GCC_ULONG64 MmNonPagedPoolStart;
GCC_ULONG64 MmNonPagedPoolEnd;
GCC_ULONG64 MmPagedPoolStart;
GCC_ULONG64 MmPagedPoolEnd;
GCC_ULONG64 MmPagedPoolInformation;
ULPTR64 PsLoadedModuleList;
ULPTR64 PsActiveProcessHead;
ULPTR64 PspCidTable;
ULPTR64 ExpSystemResourcesList;
ULPTR64 ExpPagedPoolDescriptor;
ULPTR64 ExpNumberOfPagedPools;
ULPTR64 KeTimeIncrement;
ULPTR64 KeBugCheckCallbackListHead;
ULPTR64 KiBugcheckData;
ULPTR64 IopErrorLogListHead;
ULPTR64 ObpRootDirectoryObject;
ULPTR64 ObpTypeObjectType;
ULPTR64 MmSystemCacheStart;
ULPTR64 MmSystemCacheEnd;
ULPTR64 MmSystemCacheWs;
ULPTR64 MmPfnDatabase;
ULPTR64 MmSystemPtesStart;
ULPTR64 MmSystemPtesEnd;
ULPTR64 MmSubsectionBase;
ULPTR64 MmNumberOfPagingFiles;
ULPTR64 MmLowestPhysicalPage;
ULPTR64 MmHighestPhysicalPage;
ULPTR64 MmNumberOfPhysicalPages;
ULPTR64 MmMaximumNonPagedPoolInBytes;
ULPTR64 MmNonPagedSystemStart;
ULPTR64 MmNonPagedPoolStart;
ULPTR64 MmNonPagedPoolEnd;
ULPTR64 MmPagedPoolStart;
ULPTR64 MmPagedPoolEnd;
ULPTR64 MmPagedPoolInformation;
ULONG64 MmPageSize;
GCC_ULONG64 MmSizeOfPagedPoolInBytes;
GCC_ULONG64 MmTotalCommitLimit;
GCC_ULONG64 MmTotalCommittedPages;
GCC_ULONG64 MmSharedCommit;
GCC_ULONG64 MmDriverCommit;
GCC_ULONG64 MmProcessCommit;
GCC_ULONG64 MmPagedPoolCommit;
GCC_ULONG64 MmExtendedCommit;
GCC_ULONG64 MmZeroedPageListHead;
GCC_ULONG64 MmFreePageListHead;
GCC_ULONG64 MmStandbyPageListHead;
GCC_ULONG64 MmModifiedPageListHead;
GCC_ULONG64 MmModifiedNoWritePageListHead;
GCC_ULONG64 MmAvailablePages;
GCC_ULONG64 MmResidentAvailablePages;
GCC_ULONG64 PoolTrackTable;
GCC_ULONG64 NonPagedPoolDescriptor;
GCC_ULONG64 MmHighestUserAddress;
GCC_ULONG64 MmSystemRangeStart;
GCC_ULONG64 MmUserProbeAddress;
GCC_ULONG64 KdPrintCircularBuffer;
GCC_ULONG64 KdPrintCircularBufferEnd;
GCC_ULONG64 KdPrintWritePointer;
GCC_ULONG64 KdPrintRolloverCount;
GCC_ULONG64 MmLoadedUserImageList;
ULPTR64 MmSizeOfPagedPoolInBytes;
ULPTR64 MmTotalCommitLimit;
ULPTR64 MmTotalCommittedPages;
ULPTR64 MmSharedCommit;
ULPTR64 MmDriverCommit;
ULPTR64 MmProcessCommit;
ULPTR64 MmPagedPoolCommit;
ULPTR64 MmExtendedCommit;
ULPTR64 MmZeroedPageListHead;
ULPTR64 MmFreePageListHead;
ULPTR64 MmStandbyPageListHead;
ULPTR64 MmModifiedPageListHead;
ULPTR64 MmModifiedNoWritePageListHead;
ULPTR64 MmAvailablePages;
ULPTR64 MmResidentAvailablePages;
ULPTR64 PoolTrackTable;
ULPTR64 NonPagedPoolDescriptor;
ULPTR64 MmHighestUserAddress;
ULPTR64 MmSystemRangeStart;
ULPTR64 MmUserProbeAddress;
ULPTR64 KdPrintCircularBuffer;
ULPTR64 KdPrintCircularBufferEnd;
ULPTR64 KdPrintWritePointer;
ULPTR64 KdPrintRolloverCount;
ULPTR64 MmLoadedUserImageList;
#if (NTDDI_VERSION >= NTDDI_WINXP)
GCC_ULONG64 NtBuildLab;
GCC_ULONG64 KiNormalSystemCall;
ULPTR64 NtBuildLab;
ULPTR64 KiNormalSystemCall;
#endif
/* NOTE: Documented as "NT 5.0 hotfix (QFE) addition" */
#if (NTDDI_VERSION >= NTDDI_WIN2KSP4)
GCC_ULONG64 KiProcessorBlock;
GCC_ULONG64 MmUnloadedDrivers;
GCC_ULONG64 MmLastUnloadedDriver;
GCC_ULONG64 MmTriageActionTaken;
GCC_ULONG64 MmSpecialPoolTag;
GCC_ULONG64 KernelVerifier;
GCC_ULONG64 MmVerifierData;
GCC_ULONG64 MmAllocatedNonPagedPool;
GCC_ULONG64 MmPeakCommitment;
GCC_ULONG64 MmTotalCommitLimitMaximum;
GCC_ULONG64 CmNtCSDVersion;
ULPTR64 KiProcessorBlock;
ULPTR64 MmUnloadedDrivers;
ULPTR64 MmLastUnloadedDriver;
ULPTR64 MmTriageActionTaken;
ULPTR64 MmSpecialPoolTag;
ULPTR64 KernelVerifier;
ULPTR64 MmVerifierData;
ULPTR64 MmAllocatedNonPagedPool;
ULPTR64 MmPeakCommitment;
ULPTR64 MmTotalCommitLimitMaximum;
ULPTR64 CmNtCSDVersion;
#endif
#if (NTDDI_VERSION >= NTDDI_WINXP)
GCC_ULONG64 MmPhysicalMemoryBlock;
GCC_ULONG64 MmSessionBase;
GCC_ULONG64 MmSessionSize;
GCC_ULONG64 MmSystemParentTablePage;
ULPTR64 MmPhysicalMemoryBlock;
ULPTR64 MmSessionBase;
ULPTR64 MmSessionSize;
ULPTR64 MmSystemParentTablePage;
#endif
#if (NTDDI_VERSION >= NTDDI_WS03)
GCC_ULONG64 MmVirtualTranslationBase;
ULPTR64 MmVirtualTranslationBase;
USHORT OffsetKThreadNextProcessor;
USHORT OffsetKThreadTeb;
USHORT OffsetKThreadKernelStack;
@ -299,9 +305,9 @@ typedef struct _KDDEBUGGER_DATA64
USHORT OffsetPrcbProcStateContext;
USHORT OffsetPrcbNumber;
USHORT SizeEThread;
GCC_ULONG64 KdPrintCircularBufferPtr;
GCC_ULONG64 KdPrintBufferSize;
GCC_ULONG64 KeLoaderBlock;
ULPTR64 KdPrintCircularBufferPtr;
ULPTR64 KdPrintBufferSize;
ULPTR64 KeLoaderBlock;
USHORT SizePcr;
USHORT OffsetPcrSelfPcr;
USHORT OffsetPcrCurrentPrcb;
@ -322,18 +328,18 @@ typedef struct _KDDEBUGGER_DATA64
USHORT GdtTss;
USHORT Gdt64R3CmCode;
USHORT Gdt64R3CmTeb;
GCC_ULONG64 IopNumTriageDumpDataBlocks;
GCC_ULONG64 IopTriageDumpDataBlocks;
ULPTR64 IopNumTriageDumpDataBlocks;
ULPTR64 IopTriageDumpDataBlocks;
#endif
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
GCC_ULONG64 VfCrashDataBlock;
GCC_ULONG64 MmBadPagesDetected;
GCC_ULONG64 MmZeroedPageSingleBitErrorsDetected;
ULPTR64 VfCrashDataBlock;
ULPTR64 MmBadPagesDetected;
ULPTR64 MmZeroedPageSingleBitErrorsDetected;
#endif
#if (NTDDI_VERSION >= NTDDI_WIN7)
GCC_ULONG64 EtwpDebuggerData;
ULPTR64 EtwpDebuggerData;
USHORT OffsetPrcbContext;
#endif
@ -358,11 +364,11 @@ typedef struct _KDDEBUGGER_DATA64
#if (NTDDI_VERSION >= NTDDI_WIN10_RS1)
USHORT Padding;
GCC_ULONG64 PteBase;
ULPTR64 PteBase;
#endif
#if (NTDDI_VERSION >= NTDDI_WIN10_RS5)
GCC_ULONG64 RetpolineStubFunctionTable;
ULPTR64 RetpolineStubFunctionTable;
ULONG RetpolineStubFunctionTableSize;
ULONG RetpolineStubOffset;
ULONG RetpolineStubSize;