[amd64] Make code patching smp safe for the case where we emit a mov + call_reg....
authorZoltan Varga <vargaz@gmail.com>
Mon, 28 Aug 2017 08:37:53 +0000 (04:37 -0400)
committerGitHub <noreply@github.com>
Mon, 28 Aug 2017 08:37:53 +0000 (04:37 -0400)
mono/mini/cpu-amd64.md
mono/mini/mini-amd64.c
mono/mini/tramp-amd64.c

index d35a867778fe49e99c74ab07296a3d58d6bc935b..b2354f176286a27a1ebc08ac029f2b253234aaff 100755 (executable)
@@ -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
index 02f056f694d4c81251766673338a371789a0c452..949e5a362a6f7a4a413fcc0d3d19757f3fd72d1b 100644 (file)
@@ -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);
index ea912ba6ce94a94a9c7e0735b15c05a0c24fa550..365b0ae81630cb6ef7d753bb016931ba1d2bcaf6 100644 (file)
@@ -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));
                        }