Skip to content

Commit

Permalink
Fix issue where togglerefs might be incorrectly pinned. (#12933)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
monojenkins authored and luhenry committed Feb 14, 2019
1 parent a4b5c76 commit aa0b580
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mono/metadata/sgen-stw.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ sgen_client_stop_world (int generation, gboolean serial_collection)

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

update_current_thread_stack (&generation);

/* We start to scan after locks are taking, this ensures we won't be interrupted. */
sgen_process_togglerefs ();

update_current_thread_stack (&generation);

sgen_global_stop_count++;
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 ());
TV_GETTIME (stop_world_time);
Expand Down

0 comments on commit aa0b580

Please sign in to comment.