Skip to content

Commit

Permalink
[mono] Register static rgctx trampolines in the JIT info tables. (#89142
Browse files Browse the repository at this point in the history
)

mini_init_delegate () needs to do a reverse lookup from address
to method, and its possible for the address to be a static rgctx
trampoline if the address is the result of mono_ldftn ().

Fixes #89076.
  • Loading branch information
vargaz committed Jul 19, 2023
1 parent 8c27281 commit 00b62a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mono/mono/mini/jit-icalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ mono_ldftn (MonoMethod *method)
} else {
addr = mono_create_jump_trampoline (method, FALSE, error);
if (mono_method_needs_static_rgctx_invoke (method, FALSE))
addr = mono_create_static_rgctx_trampoline (method, addr);
addr = mono_create_static_rgctx_trampoline (method, addr);
}
if (!is_ok (error)) {
mono_error_set_pending_exception (error);
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -4029,6 +4029,7 @@ mini_init_delegate (MonoDelegateHandle delegate, MonoObjectHandle target, gpoint
MonoDelegateTrampInfo *info = NULL;

if (mono_use_interpreter) {
g_assert (method || del->interp_method);
mini_get_interp_callbacks ()->init_delegate (del, &info, error);
return_if_nok (error);
}
Expand Down
10 changes: 10 additions & 0 deletions src/mono/mono/mini/mini-trampolines.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ mono_create_static_rgctx_trampoline (MonoMethod *m, gpointer addr)
else
res = mono_arch_get_static_rgctx_trampoline (jit_mm->mem_manager, ctx, addr);

/* This address might be passed to mini_init_delegate () which needs to look up the method */
MonoJitInfo *ji;

ji = mini_alloc_jinfo (jit_mm, MONO_SIZEOF_JIT_INFO);
ji->code_start = MINI_FTNPTR_TO_ADDR (res);
/* Doesn't matter, just need to be able to look up the exact address */
ji->code_size = 4;
ji->d.method = m;
mono_jit_info_table_add (ji);

jit_mm_lock (jit_mm);
/* Duplicates inserted while we didn't hold the lock are OK */
info = (RgctxTrampInfo *)m_method_alloc (m, sizeof (RgctxTrampInfo));
Expand Down

0 comments on commit 00b62a5

Please sign in to comment.