Skip to content

Commit

Permalink
[amd64] Make code patching smp safe for the case where we emit a mov …
Browse files Browse the repository at this point in the history
…+ call_reg. Hopefully fixes #57959. (#5452)
  • Loading branch information
vargaz committed Aug 28, 2017
1 parent c843b3f commit fe214b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mono/mini/cpu-amd64.md
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions mono/mini/mini-amd64.c
Expand Up @@ -2869,6 +2869,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);
Expand Down
1 change: 1 addition & 0 deletions mono/mini/tramp-amd64.c
Expand Up @@ -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));
}
Expand Down

0 comments on commit fe214b4

Please sign in to comment.