From 5a884c4ca9e672d78f962884c2904c42ff00a806 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:02:01 +0200 Subject: [PATCH] Fix TryAcquireSRWLockShared being implicitly defined and causing UB --- CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf4c54e81..fb8a1e03d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -751,9 +751,8 @@ include(CheckTrezor) # mingw doesn't support LTO (multiple definition errors at link time) set(USE_LTO_DEFAULT false) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,10485760") - if(NOT BUILD_64) - add_definitions(-DWINVER=0x0600 -D_WIN32_WINNT=0x0600) - endif() + # TryAcquireSRWLock* requires Windows 7 or later. + add_definitions(-DWINVER=0x0601 -D_WIN32_WINNT=0x0601) endif() set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes") set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers") @@ -837,6 +836,11 @@ include(CheckTrezor) add_c_flag_if_supported( -Werror=return-type C_SECURITY_FLAGS) add_cxx_flag_if_supported(-Werror=return-type CXX_SECURITY_FLAGS) + # A missing WinAPI prototype (e.g. TryAcquireSRWLock*) must fail the build + if(MINGW) + add_c_flag_if_supported(-Werror=implicit-function-declaration C_SECURITY_FLAGS) + endif() + message(STATUS "Using C security hardening flags: ${C_SECURITY_FLAGS}") message(STATUS "Using C++ security hardening flags: ${CXX_SECURITY_FLAGS}") message(STATUS "Using linker security hardening flags: ${LD_SECURITY_FLAGS}")