Skip to content

Commit c92fae9

Browse files
Exit with ExitProcess when using debug UCRT (#117187)
* Revert "Exit with quick_exit when using debug UCRT (#109006)" This reverts commit e1d7398. * Exit with ExitProcess when using debug UCRT Co-authored-by: Jan Kotas <jkotas@microsoft.com>
1 parent e4bbf7e commit c92fae9

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/coreclr/nativeaot/Bootstrap/main.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
#include <stdint.h>
5-
#include <stdlib.h>
5+
6+
#if defined(DEBUG) && defined(_WIN32)
7+
#include <process.h>
8+
#include <windows.h>
9+
#endif
610

711
//
812
// This is the mechanism whereby multiple linked modules contribute their global data for initialization at
@@ -107,16 +111,16 @@ void* PalGetModuleHandleFromPointer(void* pointer);
107111
#if defined(HOST_X86) && defined(HOST_WINDOWS)
108112
#define STRINGIFY(s) #s
109113
#define MANAGED_RUNTIME_EXPORT_ALTNAME(_method) STRINGIFY(/alternatename:_##_method=_method)
114+
#define MANAGED_RUNTIME_EXPORT_CALLCONV __cdecl
110115
#define MANAGED_RUNTIME_EXPORT(_name) \
111116
__pragma(comment (linker, MANAGED_RUNTIME_EXPORT_ALTNAME(_name))) \
112-
extern "C" void __cdecl _name();
117+
extern "C" void MANAGED_RUNTIME_EXPORT_CALLCONV _name();
113118
#define MANAGED_RUNTIME_EXPORT_NAME(_name) _name
114-
#define CDECL __cdecl
115119
#else
120+
#define MANAGED_RUNTIME_EXPORT_CALLCONV
116121
#define MANAGED_RUNTIME_EXPORT(_name) \
117122
extern "C" void _name();
118123
#define MANAGED_RUNTIME_EXPORT_NAME(_name) _name
119-
#define CDECL
120124
#endif
121125

122126
MANAGED_RUNTIME_EXPORT(GetRuntimeException)
@@ -132,7 +136,7 @@ MANAGED_RUNTIME_EXPORT(ObjectiveCMarshalGetOnEnteredFinalizerQueueCallback)
132136
MANAGED_RUNTIME_EXPORT(ObjectiveCMarshalGetUnhandledExceptionPropagationHandler)
133137
#endif
134138

135-
typedef void (CDECL *pfn)();
139+
typedef void (MANAGED_RUNTIME_EXPORT_CALLCONV *pfn)();
136140

137141
static const pfn c_classlibFunctions[] = {
138142
&MANAGED_RUNTIME_EXPORT_NAME(GetRuntimeException),
@@ -210,7 +214,7 @@ static int InitializeRuntime()
210214
#ifndef NATIVEAOT_DLL
211215

212216
#if defined(_WIN32)
213-
int CDECL wmain(int argc, wchar_t* argv[])
217+
int __cdecl wmain(int argc, wchar_t* argv[])
214218
#else
215219
int main(int argc, char* argv[])
216220
#endif
@@ -220,8 +224,10 @@ int main(int argc, char* argv[])
220224
return initval;
221225

222226
#if defined(DEBUG) && defined(_WIN32)
223-
// quick_exit works around Debug UCRT shutdown issues: https://github.com/dotnet/runtime/issues/108640
224-
quick_exit(__managed__Main(argc, argv));
227+
// work around Debug UCRT shutdown issues: https://github.com/dotnet/runtime/issues/108640
228+
int exitCode = __managed__Main(argc, argv);
229+
_cexit();
230+
ExitProcess(exitCode);
225231
#else
226232
return __managed__Main(argc, argv);
227233
#endif

src/coreclr/nativeaot/Runtime/startup.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,6 @@ extern "C" bool RhInitialize(bool isDll)
350350
#endif
351351

352352
#if defined(HOST_WINDOWS) || defined(FEATURE_PERFTRACING)
353-
#if defined(DEBUG) && defined(HOST_WINDOWS)
354-
// quick_exit works around Debug UCRT shutdown issues: https://github.com/dotnet/runtime/issues/108640
355-
at_quick_exit(&OnProcessExit);
356-
#endif
357353
atexit(&OnProcessExit);
358354
#endif
359355

0 commit comments

Comments
 (0)