From 68040e2922992c9ae024839f505f095cb3a76d03 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 7 Mar 2023 22:07:03 -0700 Subject: [PATCH] windows: add brave new mingw compat hook for gcc 12.2.0+ --- libraries/config/templates/stratosphere.mk | 2 +- .../source/ams/ams_environment_weak.os.windows.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/config/templates/stratosphere.mk b/libraries/config/templates/stratosphere.mk index 39e83bc16..d0bbf3f85 100644 --- a/libraries/config/templates/stratosphere.mk +++ b/libraries/config/templates/stratosphere.mk @@ -58,7 +58,7 @@ export CXXWRAPS := -Wl,--wrap,__cxa_pure_virtual \ -Wl,--wrap,exit else ifeq ($(ATMOSPHERE_BOARD),generic_windows) export CXXREQUIRED := -export CXXWRAPS := -Wl,--wrap,__p__acmdln +export CXXWRAPS := -Wl,--wrap,__p__acmdln -Wl,--wrap,_set_invalid_parameter_handler else export CXXREQUIRED := export CXXWRAPS := diff --git a/libraries/libstratosphere/source/ams/ams_environment_weak.os.windows.cpp b/libraries/libstratosphere/source/ams/ams_environment_weak.os.windows.cpp index 5162e1b24..c672270c5 100644 --- a/libraries/libstratosphere/source/ams/ams_environment_weak.os.windows.cpp +++ b/libraries/libstratosphere/source/ams/ams_environment_weak.os.windows.cpp @@ -16,6 +16,7 @@ #include extern "C" char **__real___p__acmdln(void); +extern "C" _invalid_parameter_handler __real__set_invalid_parameter_handler(_invalid_parameter_handler); namespace ams { @@ -65,4 +66,11 @@ extern "C" { return __real___p__acmdln(); } + /* On some mingw gcc versions, acmdln isn't used, so we need to hook a different part of crt init. */ + _invalid_parameter_handler __wrap__set_invalid_parameter_handler(_invalid_parameter_handler handler) { + ::ams::os::Initialize(); + return __real__set_invalid_parameter_handler(handler); + + } + }