From 01dafea51fef3775e2c31f54979f4699ba1bdcae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 1 Jul 2025 06:51:51 +0200 Subject: [PATCH 1/4] Revert "Exit with quick_exit when using debug UCRT (#109006)" This reverts commit e1d7398072966e20b01d2e3bd4af724f82a98f04. --- src/coreclr/nativeaot/Bootstrap/main.cpp | 6 ------ src/coreclr/nativeaot/Runtime/startup.cpp | 4 ---- 2 files changed, 10 deletions(-) diff --git a/src/coreclr/nativeaot/Bootstrap/main.cpp b/src/coreclr/nativeaot/Bootstrap/main.cpp index 8c89f6ff7d2426..6254d0bd9a1d6d 100644 --- a/src/coreclr/nativeaot/Bootstrap/main.cpp +++ b/src/coreclr/nativeaot/Bootstrap/main.cpp @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. #include -#include // // This is the mechanism whereby multiple linked modules contribute their global data for initialization at @@ -223,12 +222,7 @@ int main(int argc, char* argv[]) if (initval != 0) return initval; -#if defined(DEBUG) && defined(_WIN32) - // quick_exit works around Debug UCRT shutdown issues: https://github.com/dotnet/runtime/issues/108640 - quick_exit(__managed__Main(argc, argv)); -#else return __managed__Main(argc, argv); -#endif } #ifdef HAS_ADDRESS_SANITIZER diff --git a/src/coreclr/nativeaot/Runtime/startup.cpp b/src/coreclr/nativeaot/Runtime/startup.cpp index 486e285cf37c65..c80ae2069abe48 100644 --- a/src/coreclr/nativeaot/Runtime/startup.cpp +++ b/src/coreclr/nativeaot/Runtime/startup.cpp @@ -350,10 +350,6 @@ extern "C" bool RhInitialize(bool isDll) #endif #if defined(HOST_WINDOWS) || defined(FEATURE_PERFTRACING) -#if defined(DEBUG) && defined(HOST_WINDOWS) - // quick_exit works around Debug UCRT shutdown issues: https://github.com/dotnet/runtime/issues/108640 - at_quick_exit(&OnProcessExit); -#endif atexit(&OnProcessExit); #endif From 22a5ca3481f35ecb58603d5c5f946aac8893bfb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 1 Jul 2025 12:09:49 +0200 Subject: [PATCH 2/4] Update src/coreclr/nativeaot/Bootstrap/main.cpp Co-authored-by: Jan Kotas --- src/coreclr/nativeaot/Bootstrap/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/coreclr/nativeaot/Bootstrap/main.cpp b/src/coreclr/nativeaot/Bootstrap/main.cpp index 6254d0bd9a1d6d..4f13e927b36713 100644 --- a/src/coreclr/nativeaot/Bootstrap/main.cpp +++ b/src/coreclr/nativeaot/Bootstrap/main.cpp @@ -222,7 +222,14 @@ int main(int argc, char* argv[]) if (initval != 0) return initval; +#if defined(DEBUG) && defined(_WIN32) + // work around Debug UCRT shutdown issues: https://github.com/dotnet/runtime/issues/108640 + int exitCode = __managed__Main(argc, argv); + _cexit(); + ExitProcess(exitCode); +#else return __managed__Main(argc, argv); +#endif } #ifdef HAS_ADDRESS_SANITIZER From bbff8f1bcbbfe9291884b5465de5797c4cbf5def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 1 Jul 2025 04:08:15 -0700 Subject: [PATCH 3/4] Update main.cpp --- src/coreclr/nativeaot/Bootstrap/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/coreclr/nativeaot/Bootstrap/main.cpp b/src/coreclr/nativeaot/Bootstrap/main.cpp index 4f13e927b36713..68e7678e128312 100644 --- a/src/coreclr/nativeaot/Bootstrap/main.cpp +++ b/src/coreclr/nativeaot/Bootstrap/main.cpp @@ -3,6 +3,11 @@ #include +#if defined(DEBUG) && defined(_WIN32) +#include +#include +#endif + // // This is the mechanism whereby multiple linked modules contribute their global data for initialization at // startup of the application. From ba94e6b89fcc10b8217a24c268c49517e4bee04d Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Tue, 1 Jul 2025 17:54:36 -0700 Subject: [PATCH 4/4] Build breaks --- src/coreclr/nativeaot/Bootstrap/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/nativeaot/Bootstrap/main.cpp b/src/coreclr/nativeaot/Bootstrap/main.cpp index 68e7678e128312..f682a92793868e 100644 --- a/src/coreclr/nativeaot/Bootstrap/main.cpp +++ b/src/coreclr/nativeaot/Bootstrap/main.cpp @@ -111,16 +111,16 @@ void* PalGetModuleHandleFromPointer(void* pointer); #if defined(HOST_X86) && defined(HOST_WINDOWS) #define STRINGIFY(s) #s #define MANAGED_RUNTIME_EXPORT_ALTNAME(_method) STRINGIFY(/alternatename:_##_method=_method) +#define MANAGED_RUNTIME_EXPORT_CALLCONV __cdecl #define MANAGED_RUNTIME_EXPORT(_name) \ __pragma(comment (linker, MANAGED_RUNTIME_EXPORT_ALTNAME(_name))) \ - extern "C" void __cdecl _name(); + extern "C" void MANAGED_RUNTIME_EXPORT_CALLCONV _name(); #define MANAGED_RUNTIME_EXPORT_NAME(_name) _name -#define CDECL __cdecl #else +#define MANAGED_RUNTIME_EXPORT_CALLCONV #define MANAGED_RUNTIME_EXPORT(_name) \ extern "C" void _name(); #define MANAGED_RUNTIME_EXPORT_NAME(_name) _name -#define CDECL #endif MANAGED_RUNTIME_EXPORT(GetRuntimeException) @@ -138,7 +138,7 @@ MANAGED_RUNTIME_EXPORT(ObjectiveCMarshalGetOnEnteredFinalizerQueueCallback) MANAGED_RUNTIME_EXPORT(ObjectiveCMarshalGetUnhandledExceptionPropagationHandler) #endif -typedef void (CDECL *pfn)(); +typedef void (MANAGED_RUNTIME_EXPORT_CALLCONV *pfn)(); static const pfn c_classlibFunctions[] = { &MANAGED_RUNTIME_EXPORT_NAME(GetRuntimeException), @@ -218,7 +218,7 @@ static int InitializeRuntime() #ifndef NATIVEAOT_DLL #if defined(_WIN32) -int CDECL wmain(int argc, wchar_t* argv[]) +int __cdecl wmain(int argc, wchar_t* argv[]) #else int main(int argc, char* argv[]) #endif