Skip to content

Commit

Permalink
[mono][jit] Add some barriers to the delegate invoke code.
Browse files Browse the repository at this point in the history
  • Loading branch information
vargaz committed Mar 20, 2023
1 parent 61ce091 commit cf30f80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/mono/mono/mini/mini-arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/mini-trampolines.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cf30f80

Please sign in to comment.