Commit 9baed28
Fix token memory ordering issue reading from the MethodDef and FieldDef token tables (#123557)
We have logic which loads a typedef, and if the typedef is loaded then
we assume the method can be loaded via lookup in the MethodDef/FieldDef
token map tables. HOWEVER, what this boils down to is we do a load from
the TypeDef table, and if that succeeds we will do a load from the
FieldDef/MethodDef token map tables, but that second load is done
without an explicit memory barrier. Unfortunately, through the wonder of
memory ordering behavior, its legal (and not actually all that uncommon)
for the CPU to do the load from the FieldDef/MethodDef tables BEFORE it
actually loads from the TypeDef table. So what can happen is that the
fielddef table read can happen, then the typedef table read can happen,
then the CPU does the if check to see if its ok to do the fielddef table
read, then we use the value from the fielddef table read which happened
earlier.
This fix should fix that problem by using a VolatileLoad for all reads
from the lookup maps. This is slightly slower but avoids the extremely
easy to mess up dependency ordering rules.
Fixes #120754
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>1 parent 687c8d9 commit 9baed28
1 file changed
+14
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
22 | 28 | | |
23 | 29 | | |
24 | 30 | | |
| |||
51 | 57 | | |
52 | 58 | | |
53 | 59 | | |
54 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
55 | 67 | | |
56 | 68 | | |
57 | 69 | | |
| |||
0 commit comments