Skip to content

platform.h: detect MSVC ARM64 as 64-bit and raise 32-bit Windows minimum - #409

Merged
bkaradzic merged 1 commit into
bkaradzic:masterfrom
SergioRZMasson:fix-win32-winnt-detection
Jul 23, 2026
Merged

platform.h: detect MSVC ARM64 as 64-bit and raise 32-bit Windows minimum#409
bkaradzic merged 1 commit into
bkaradzic:masterfrom
SergioRZMasson:fix-win32-winnt-detection

Conversation

@SergioRZMasson

Copy link
Copy Markdown
Contributor

Summary

Two related Windows fixes in include/bx/platform.h:

1. Detect MSVC ARM64 as 64-bit

The BX_ARCH_64BIT detection lists __aarch64__ (GCC/Clang) but not MSVC's _M_ARM64 / _M_ARM64EC. As a result, Windows-on-ARM64 built with MSVC is treated as a 32-bit architecture, which is incorrect and affects everything keyed off BX_ARCH_64BIT (pointer-size assumptions, the Windows version default below, etc.). Added _M_ARM64 and _M_ARM64EC to the 64-bit list.

2. Raise the 32-bit Windows minimum

The 32-bit Windows branch defaulted WINVER / _WIN32_WINNT to 0x0502 (Windows XP / Server 2003). That predates APIs modern Windows SDK headers reference unconditionally — e.g. the ETW EventRegister / EventUnregister / EventWriteTransfer family in <evntprov.h>, which is only declared for _WIN32_WINNT >= 0x0600. Building a 32-bit target that transitively includes such headers fails with error C3861: 'EventRegister': identifier not found.

Raised the 32-bit default to 0x0601 (Windows 7), matching the existing 64-bit branch. With both fixes, x86, x64 and ARM64 Windows targets default to a consistent Windows 7 baseline. Callers that need a different target can still define WINVER / _WIN32_WINNT themselves — the defaults remain guarded by !defined(...).

Testing

Compiled a TU including <bx/platform.h> with MSVC for x86, x64 and arm64, asserting _WIN32_WINNT >= 0x0600 (and BX_ARCH_64BIT == 64 for ARM64) — all pass. Against the previous code, the x86 and arm64 targets fail those assertions (they resolved to 0x0502).

Two related Windows fixes:

* BX_ARCH_64BIT missed MSVC's _M_ARM64 / _M_ARM64EC, so Windows on ARM64 was
  treated as a 32-bit architecture. Add them to the 64-bit detection list.

* The 32-bit Windows branch defaulted WINVER / _WIN32_WINNT to 0x0502 (Windows
  XP / Server 2003), which predates APIs that modern SDK headers reference
  (e.g. the ETW EventRegister/EventWriteTransfer family, only declared for
  _WIN32_WINNT >= 0x0600). Raise it to 0x0601 (Windows 7), matching the 64-bit
  branch. Combined with the ARM64 detection fix, x86, x64 and ARM64 Windows
  targets now all default to a Windows 7 baseline.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 45aaf3cc-900d-442b-a7e5-0fb6d3fe6658
@bkaradzic
bkaradzic merged commit cd6720c into bkaradzic:master Jul 23, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants