Skip to content

Commit aa0b580

Browse files
monojenkinsluhenry
authored andcommitted
Fix issue where togglerefs might be incorrectly pinned. (#12933)
Due to current order, process togglerefs and then take current threads stack could cause a problem where toogleref references might be left in registers after native code process the list and those reference would then be put into current thread context, incorrectly pinning the toggleref, preventing it from being GC:ed. The problem was observed on Windows (in debug build) running sgen-toggleref.exe runtime test since the native compile of sgen_process_togglerefs used a register when walking the list of togglerefs that was then not re-used until the current threads stack was taken, causing incorrect pinning. This problem could in theory happen on any platform depending on how sgen_process_togglerefs would been compiled and what register will be used. Fix is to take current threads context before walking the togglerefs to make sure we are not getting managed references into registers as part of managing the toggleref list in native code.
1 parent a4b5c76 commit aa0b580

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mono/metadata/sgen-stw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ sgen_client_stop_world (int generation, gboolean serial_collection)
112112

113113
MONO_PROFILER_RAISE (gc_event, (MONO_GC_EVENT_PRE_STOP_WORLD_LOCKED, generation, serial_collection));
114114

115+
update_current_thread_stack (&generation);
116+
115117
/* We start to scan after locks are taking, this ensures we won't be interrupted. */
116118
sgen_process_togglerefs ();
117119

118-
update_current_thread_stack (&generation);
119-
120120
sgen_global_stop_count++;
121121
SGEN_LOG (3, "stopping world n %d from %p %p", sgen_global_stop_count, mono_thread_info_current (), (gpointer) (gsize) mono_native_thread_id_get ());
122122
TV_GETTIME (stop_world_time);

0 commit comments

Comments
 (0)