Skip to content

Change g_fEEShutDown to be Volatile #116885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2025
Merged

Change g_fEEShutDown to be Volatile #116885

merged 2 commits into from
Jun 21, 2025

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Jun 20, 2025

g_fEEShutDown is read without locks. Make it volatile to ensure that the up-to-date value is read with Arm64 weak memory model.

Cleanup g_fEEShutDown flags

Fixes #106242

g_fEEShutDown is read without locks. Make it volatile to ensure that the
up-to-date value is read with Arm64 weak memory model.

Cleanup g_fEEShutDown flags

Fixes dotnet#106242
@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 23:37
@@ -90,12 +90,8 @@
#include <minipal/mutex.h>

#define ShutDown_Start 0x00000001
#define ShutDown_Finalize1 0x00000002
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug-only bit, only used for low-value assert

Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

#define ShutDown_Finalize2 0x00000004
#define ShutDown_Profiler 0x00000008
#define ShutDown_COM 0x00000010
#define ShutDown_SyncBlock 0x00000020
#define ShutDown_IUnknown 0x00000040
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused or low-value debug-only bits

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR makes g_fEEShutDown a volatile variable for correct ordering on weak-memory models and cleans up obsolete shutdown flag usage throughout the VM.

  • Mark g_fEEShutDown as Volatile<DWORD> (except in DACCESS builds) and update its implementation.
  • Remove deprecated shutdown mask constants and their associated bitwise logic.
  • Simplify and update conditional checks and cleanup logic that depended on the old flags.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/coreclr/vm/vars.hpp Switched g_fEEShutDown to Volatile<DWORD> and removed profiling vars.
src/coreclr/vm/vars.cpp Updated GVAL_IMPL for g_fEEShutDown to use the volatile type.
src/coreclr/vm/threads.cpp Removed legacy if (g_fEEShutDown == 0) guard around thread termination.
src/coreclr/vm/runtimecallablewrapper.cpp Simplified PRECONDITION to drop shutdown-based branch.
src/coreclr/vm/interoputil.cpp Removed shutdown-specific sync block cleanup in CleanupSyncBlockComData.
src/coreclr/vm/crst.h Dropped obsolete ShutDown_* mask definitions.
src/coreclr/vm/ceemain.cpp Cleared out assignments to removed shutdown flags.
src/coreclr/vm/appdomain.cpp Updated assertion to use boolean g_fEEShutDown instead of a mask.
src/coreclr/inc/dacvars.h Changed DACVAR definition to DEFINE_DACVAR_VOLATILE for shutdown flag.
Comments suppressed due to low confidence (2)

src/coreclr/vm/threads.cpp:868

  • The original if (g_fEEShutDown == 0) guard was removed, so OnThreadTerminate now runs unconditionally even during shutdown. This changes shutdown semantics and may invoke CLR state incorrectly; consider restoring a volatile-based check to gate termination calls.
    th->SetThreadState(Thread::TS_ReportDead);

src/coreclr/vm/interoputil.cpp:1202

  • The shutdown-specific call to MinorCleanupSyncBlockComData was removed, so COM SyncBlock data may no longer be cleaned up during shutdown. If this cleanup is still required at process exit, reintroduce the appropriate volatile-check logic.
void CleanupSyncBlockComData(InteropSyncBlockInfo* pInteropInfo)

@@ -1209,9 +1209,6 @@ void CleanupSyncBlockComData(InteropSyncBlockInfo* pInteropInfo)
}
CONTRACTL_END;

if ((g_fEEShutDown & ShutDown_SyncBlock) && IsAtProcessExit() )
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ShutDown_SyncBlock was never set in release build, so this condition was always false in the shipping bits. Better to align non-release builds to do the same

@@ -865,11 +865,8 @@ void DestroyThread(Thread *th)
th->UnmarkThreadForAbort();
}

if (g_fEEShutDown == 0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary check (also, the way it is written triggered a build error after changing g_fEEShutDown to Volatile)

@@ -151,9 +151,6 @@ GVAL_IMPL_INIT(DWORD, g_externalMethodFixupTraceActiveCount, 0);
#endif // DEBUGGING_SUPPORTED

#if defined(PROFILING_SUPPORTED_DATA) || defined(PROFILING_SUPPPORTED)
// Profiling support
HINSTANCE g_pDebuggerDll = NULL;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code that I happen to notice

GVAL_DECL(DWORD, g_fEEShutDown);
#else
GVAL_DECL(Volatile<DWORD>, g_fEEShutDown);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual fix

@jkotas jkotas changed the title Change g_fEEShutDown to Volatile Change g_fEEShutDown to be Volatile Jun 20, 2025
@jkotas jkotas requested review from mangod9 and jkoritzinsky June 21, 2025 12:53
@jkotas jkotas merged commit f0168ee into dotnet:main Jun 21, 2025
96 checks passed
@jkotas jkotas deleted the issue-106242 branch June 21, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assert failure: (g_fEEShutDown&ShutDown_Finalize1) && GetThread() == FinalizerThread::GetFinalizerThread()
3 participants