From 2d5371e07895aeb2b2965044656e03b71e1c0bd3 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Mon, 19 Jan 2026 17:08:04 +0200 Subject: [PATCH] [NTOSKRNL] Fix GCC 13 stringop-overflow warnings regarding KiNtVdmState GCC 13 thinks that a global 'const PULONG' that is initialized to a non-NULL value points to an object that is "likely at address zero". - Turn the macros that cause the issue into inline functions and wrap them with a GCC diagnostic pragma to silence the warning - Use KiNtVdmState in vdm/vdmexec.c - Remove the (duplicated) VdmState macro In function '_InterlockedAnd', inlined from 'KiVdmOpcodePOPF' at C:/ReactOS/reactos/ntoskrnl/ke/i386/v86vdm.c:164:5: C:/ReactOS/reactos/sdk/include/vcruntime/mingw32/intrin_x86.h:245:16: error: '__sync_fetch_and_and_4' writing 4 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=] 245 | return __sync_fetch_and_and(value, mask); | ^~~~~~~~~~~~~~~~~~~~ In function 'KiVdmOpcodePOPF': cc1.exe: note: destination object is likely at address zero --- ntoskrnl/include/internal/i386/ke.h | 23 +++++++++++++++++++++-- ntoskrnl/include/internal/vdm.h | 6 ------ ntoskrnl/ke/i386/v86vdm.c | 2 +- ntoskrnl/vdm/vdmexec.c | 8 ++++---- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/ntoskrnl/include/internal/i386/ke.h b/ntoskrnl/include/internal/i386/ke.h index dacc0a816d7..c40cf711482 100644 --- a/ntoskrnl/include/internal/i386/ke.h +++ b/ntoskrnl/include/internal/i386/ke.h @@ -196,6 +196,11 @@ typedef union _KTRAP_EXIT_SKIP_BITS #define PFX_FLAG_REPNE 0x00020000 #define PFX_FLAG_REP 0x00040000 +// +// VDM State Pointer +// +extern const PULONG KiNtVdmState; + // // VDM Helper Macros // @@ -218,8 +223,22 @@ typedef union _KTRAP_EXIT_SKIP_BITS // more time, this way we don't redefine ALL opcode handlers to have 3 parameters, // which would be forcing stack usage in all other scenarios. // -#define KiVdmSetVdmEFlags(x) InterlockedOr((PLONG)KiNtVdmState, (x)); -#define KiVdmClearVdmEFlags(x) InterlockedAnd((PLONG)KiNtVdmState, ~(x)) +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif +FORCEINLINE ULONG KiVdmSetVdmEFlags(ULONG EFlags) +{ + return InterlockedOr((PLONG)KiNtVdmState, EFlags); +} +FORCEINLINE ULONG KiVdmClearVdmEFlags(ULONG EFlags) +{ + return InterlockedAnd((PLONG)KiNtVdmState, ~EFlags); +} +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #define KiCallVdmHandler(x) KiVdmOpcode##x(TrapFrame, Flags) #define KiCallVdmPrefixHandler(x) KiVdmOpcodePrefix(TrapFrame, Flags | x) #define KiVdmUnhandledOpcode(x) \ diff --git a/ntoskrnl/include/internal/vdm.h b/ntoskrnl/include/internal/vdm.h index 81e47a64944..9d3e7adc874 100644 --- a/ntoskrnl/include/internal/vdm.h +++ b/ntoskrnl/include/internal/vdm.h @@ -42,12 +42,6 @@ // #define TRAMPOLINE_BOP 0xFEC4C4 -// -// VDM State Pointer -// -#define VdmState \ - (PULONG)FIXED_NTVDMSTATE_LINEAR_PC_AT - // // VDM Event Types // diff --git a/ntoskrnl/ke/i386/v86vdm.c b/ntoskrnl/ke/i386/v86vdm.c index b4790d146f6..0cf2674b489 100644 --- a/ntoskrnl/ke/i386/v86vdm.c +++ b/ntoskrnl/ke/i386/v86vdm.c @@ -652,7 +652,7 @@ Ke386CallBios(IN ULONG Int, VdmTib->Size = sizeof(VDM_TIB); /* Set a blank VDM state */ - *VdmState = 0; + *KiNtVdmState = 0; /* Copy the context */ RtlCopyMemory(&VdmTib->VdmContext, Context, ContextSize); diff --git a/ntoskrnl/vdm/vdmexec.c b/ntoskrnl/vdm/vdmexec.c index 8d8ce7a248a..8fc626865ed 100644 --- a/ntoskrnl/vdm/vdmexec.c +++ b/ntoskrnl/vdm/vdmexec.c @@ -193,7 +193,7 @@ VdmpStartExecution(VOID) Interrupts = (BOOLEAN)(VdmTib->VdmContext.EFlags & EFLAGS_INTERRUPT_MASK); /* We don't support full VDM yet, this shouldn't happen */ - ASSERT(*VdmState == 0); + ASSERT(*KiNtVdmState == 0); ASSERT(VdmTib->VdmContext.EFlags & EFLAGS_V86_MASK); /* Check if VME is supported and V86 mode was enabled */ @@ -219,12 +219,12 @@ VdmpStartExecution(VOID) if (VdmTib->VdmContext.EFlags & EFLAGS_INTERRUPT_MASK) { /* Enable them as well */ - InterlockedOr((PLONG)VdmState, EFLAGS_INTERRUPT_MASK); + InterlockedOr((PLONG)KiNtVdmState, EFLAGS_INTERRUPT_MASK); } else { /* Disable them */ - InterlockedAnd((PLONG)VdmState, ~EFLAGS_INTERRUPT_MASK); + InterlockedAnd((PLONG)KiNtVdmState, ~EFLAGS_INTERRUPT_MASK); } /* Enable the interrupt flag */ @@ -300,7 +300,7 @@ VdmEndExecution(IN PKTRAP_FRAME TrapFrame, { /* Set the EFLAGS based on our software copy of EFLAGS */ VdmTib->VdmContext.EFlags = (VdmTib->VdmContext.EFlags & ~EFLAGS_INTERRUPT_MASK) | - (*VdmState & EFLAGS_INTERRUPT_MASK); + (*KiNtVdmState & EFLAGS_INTERRUPT_MASK); } }