Permalink
Browse files

[amd64] Make code patching smp safe for the case where we emit a mov …

…+ call_reg. Hopefully fixes #57959. (#5452)
  • Loading branch information...
vargaz committed Aug 28, 2017
1 parent a2cf047 commit 9a634c1810aad46d30a674f3a97ab263dcd4272e
Showing with 8 additions and 2 deletions.
  1. +2 −2 mono/mini/cpu-amd64.md
  2. +5 −0 mono/mini/mini-amd64.c
  3. +1 −0 mono/mini/tramp-amd64.c
@@ -99,8 +99,8 @@ long_min_un: dest:i src1:i src2:i len:16 clob:1
long_max: dest:i src1:i src2:i len:16 clob:1
long_max_un: dest:i src1:i src2:i len:16 clob:1
throw: src1:i len:18
rethrow: src1:i len:18
throw: src1:i len:24
rethrow: src1:i len:24
start_handler: len:16
endfinally: len:9
endfilter: src1:a len:9
@@ -2870,6 +2870,11 @@ emit_call_body (MonoCompile *cfg, guint8 *code, MonoJumpInfoType patch_type, gco
amd64_call_code (code, 0);
}
else {
if (!no_patch && ((guint32)(code + 2 - cfg->native_code) % 8) != 0) {
guint32 pad_size = 8 - ((guint32)(code + 2 - cfg->native_code) % 8);
amd64_padding (code, pad_size);
g_assert ((guint64)(code + 2 - cfg->native_code) % 8 == 0);
}
mono_add_patch_info (cfg, code - cfg->native_code, patch_type, data);
amd64_set_reg_template (code, GP_SCRATCH_REG);
amd64_call_reg (code, GP_SCRATCH_REG);
@@ -144,6 +144,7 @@ mono_arch_patch_callsite (guint8 *method_start, guint8 *orig_code, guint8 *addr)
if (((code [-13] == 0x49) && (code [-12] == 0xbb)) || (code [-5] == 0xe8)) {
if (code [-5] != 0xe8) {
if (can_write) {
g_assert ((guint64)(orig_code - 11) % 8 == 0);
InterlockedExchangePointer ((gpointer*)(orig_code - 11), addr);
VALGRIND_DISCARD_TRANSLATIONS (orig_code - 11, sizeof (gpointer));
}

0 comments on commit 9a634c1

Please sign in to comment.