From cf30f80ec701646dfe6b9ce78f90d2b60c77d30f Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Mon, 20 Mar 2023 10:49:48 -0400 Subject: [PATCH] [mono][jit] Add some barriers to the delegate invoke code. Re: https://github.com/dotnet/runtime/issues/81123. --- src/mono/mono/mini/mini-arm64.c | 6 ++++-- src/mono/mono/mini/mini-trampolines.c | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/mini-arm64.c b/src/mono/mono/mini/mini-arm64.c index d54b3137a0f77..5125541551b1d 100644 --- a/src/mono/mono/mini/mini-arm64.c +++ b/src/mono/mono/mini/mini-arm64.c @@ -168,14 +168,16 @@ get_delegate_invoke_impl (gboolean has_target, gboolean param_count, guint32 *co MINI_BEGIN_CODEGEN (); if (has_target) { - start = code = mono_global_codeman_reserve (12); + int size = 16; + start = code = mono_global_codeman_reserve (size); /* Replace the this argument with the target */ + arm_dmb (code, ARM_DMB_ISHLD); arm_ldrx (code, ARMREG_IP0, ARMREG_R0, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr)); arm_ldrx (code, ARMREG_R0, ARMREG_R0, MONO_STRUCT_OFFSET (MonoDelegate, target)); code = mono_arm_emit_brx (code, ARMREG_IP0); - g_assert ((code - start) <= 12); + g_assert ((code - start) <= size); } else { int size, i; diff --git a/src/mono/mono/mini/mini-trampolines.c b/src/mono/mono/mini/mini-trampolines.c index ebb21872aa232..d4506c347812d 100644 --- a/src/mono/mono/mini/mini-trampolines.c +++ b/src/mono/mono/mini/mini-trampolines.c @@ -1122,6 +1122,8 @@ mono_delegate_trampoline (host_mgreg_t *regs, guint8 *code, gpointer *arg, guint code = (guint8 *)mini_add_method_trampoline (m, code, mono_method_needs_static_rgctx_invoke (m, FALSE), FALSE); } + mono_memory_barrier (); + delegate->invoke_impl = mono_get_addr_from_ftnptr (code); if (enable_caching && !callvirt && tramp_info->method) { tramp_info->method_ptr = delegate->method_ptr;