From 94c29ddb0b16a696444c8a353261be87050d80ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 7 Sep 2023 09:46:27 +0200 Subject: [PATCH 1/6] Revert "Error out when NativeLib has EventPipe enabled (#90811)" This reverts commit e811599bb6ec3a5b65f751815ee2a996064b806d. --- .../BuildIntegration/Microsoft.NETCore.Native.Publish.targets | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets index b3219708a8cd1..09f4a5db9f32b 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets @@ -50,8 +50,6 @@ Text="RuntimeIdentifier is required for native compilation. Try running dotnet publish with the -r option value specified." /> - - From d310536d50739b0b52b1caa99728783d7d86b002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 7 Sep 2023 10:04:14 +0200 Subject: [PATCH 2/6] Don't shut down event pipe in DLLs on Windows Works around #89346. --- src/coreclr/nativeaot/Bootstrap/main.cpp | 10 ++++++++-- src/coreclr/nativeaot/Runtime/startup.cpp | 22 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/coreclr/nativeaot/Bootstrap/main.cpp b/src/coreclr/nativeaot/Bootstrap/main.cpp index cc78cf8d6710a..c2ff85b50e81f 100644 --- a/src/coreclr/nativeaot/Bootstrap/main.cpp +++ b/src/coreclr/nativeaot/Bootstrap/main.cpp @@ -93,7 +93,7 @@ static char& __unbox_z = __stop___unbox; #endif // _MSC_VER -extern "C" bool RhInitialize(); +extern "C" bool RhInitialize(bool isDll); extern "C" void RhSetRuntimeInitializationCallback(int (*fPtr)()); extern "C" bool RhRegisterOSModule(void * pModule, @@ -164,7 +164,13 @@ extern "C" void __managed__Startup(); static int InitializeRuntime() { - if (!RhInitialize()) + if (!RhInitialize( +#ifdef NATIVEAOT_DLL + /* isDll */ true +#else + /* isDll */ false +#endif + )) return -1; void * osModule = PalGetModuleHandleFromPointer((void*)&NATIVEAOT_ENTRYPOINT); diff --git a/src/coreclr/nativeaot/Runtime/startup.cpp b/src/coreclr/nativeaot/Runtime/startup.cpp index 9a6fd2f9c22bb..59968f939cd93 100644 --- a/src/coreclr/nativeaot/Runtime/startup.cpp +++ b/src/coreclr/nativeaot/Runtime/startup.cpp @@ -292,6 +292,10 @@ static void UninitDLL() Thread* g_threadPerformingShutdown = NULL; #endif +#if defined(_WIN32) && defined(FEATURE_PERFTRACING) +bool g_safeToShutdownTracing; +#endif + static void __cdecl OnProcessExit() { #ifdef _WIN32 @@ -304,8 +308,16 @@ static void __cdecl OnProcessExit() #endif #ifdef FEATURE_PERFTRACING - EventPipe_Shutdown(); - DiagnosticServer_Shutdown(); +#ifdef _WIN32 + // We forgo shutting down event pipe if it wouldn't be safe and could lead to a hang. + // If there was an active trace session, the trace will likely be corrupted without + // orderly shutdown. See https://github.com/dotnet/runtime/issues/89346. + if (g_safeToShutdownTracing) +#endif + { + EventPipe_Shutdown(); + DiagnosticServer_Shutdown(); + } #endif } @@ -343,7 +355,7 @@ void RuntimeThreadShutdown(void* thread) #endif } -extern "C" bool RhInitialize() +extern "C" bool RhInitialize(bool isDll) { if (!PalInit()) return false; @@ -352,6 +364,10 @@ extern "C" bool RhInitialize() atexit(&OnProcessExit); #endif +#if defined(_WIN32) && defined(FEATURE_PERFTRACING) + g_safeToShutdownTracing = !isDll; +#endif + if (!InitDLL(PalGetModuleHandleFromPointer((void*)&RhInitialize))) return false; From 8c4069673da759a697b2ec54b49ab9c7d4139817 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 7 Sep 2023 14:24:40 -0700 Subject: [PATCH 3/6] Update src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets Co-authored-by: Elinor Fung --- .../BuildIntegration/Microsoft.NETCore.Native.Publish.targets | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets index 09f4a5db9f32b..f141a17ef5bea 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets @@ -50,6 +50,8 @@ Text="RuntimeIdentifier is required for native compilation. Try running dotnet publish with the -r option value specified." /> + + From c47a068291a18771e6b8427f454fcd5ac3de558c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Fri, 8 Sep 2023 02:14:16 +0200 Subject: [PATCH 4/6] Apply suggestions from code review --- .../BuildIntegration/Microsoft.NETCore.Native.Publish.targets | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets index f141a17ef5bea..3090d483bca44 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets @@ -50,8 +50,7 @@ Text="RuntimeIdentifier is required for native compilation. Try running dotnet publish with the -r option value specified." /> - - + From c04885d0d6f62bd3151562b652f253e49adc4d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 13 Sep 2023 21:56:43 +0200 Subject: [PATCH 5/6] Update src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets Co-authored-by: Andy Gocke --- .../BuildIntegration/Microsoft.NETCore.Native.Publish.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets index 3090d483bca44..0e488cdb4e382 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets @@ -50,7 +50,7 @@ Text="RuntimeIdentifier is required for native compilation. Try running dotnet publish with the -r option value specified." /> - + From 0a55df4bf5ddc2415c7b78faaf2d6ff89808cb58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 14 Sep 2023 06:24:38 +0200 Subject: [PATCH 6/6] Update src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets --- .../BuildIntegration/Microsoft.NETCore.Native.Publish.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets index 0e488cdb4e382..5b1e1e8769bda 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets @@ -50,7 +50,7 @@ Text="RuntimeIdentifier is required for native compilation. Try running dotnet publish with the -r option value specified." /> - +