Fix issue where togglerefs might be incorrectly pinned.
commitc432251142b997d1bf6e2cf0a652e509df8df75f
authorlateralusX <lateralusx.github@gmail.com>
Tue, 5 Feb 2019 11:58:25 +0000 (5 12:58 +0100)
committerlateralusX <lateralusx.github@gmail.com>
Tue, 5 Feb 2019 17:37:05 +0000 (5 18:37 +0100)
tree48e1e088c72ca9250a2e496c13785c37f69b8dcd
parent667925b987e1141f77ba6958f9891d133b6cbea8
Fix issue where togglerefs might be incorrectly pinned.

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.
mono/metadata/sgen-stw.c