Skip to content

Commit 00b62a5

Browse files
authored
[mono] Register static rgctx trampolines in the JIT info tables. (#89142)
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.
1 parent 8c27281 commit 00b62a5

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/mono/mono/mini/jit-icalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ mono_ldftn (MonoMethod *method)
6565
} else {
6666
addr = mono_create_jump_trampoline (method, FALSE, error);
6767
if (mono_method_needs_static_rgctx_invoke (method, FALSE))
68-
addr = mono_create_static_rgctx_trampoline (method, addr);
68+
addr = mono_create_static_rgctx_trampoline (method, addr);
6969
}
7070
if (!is_ok (error)) {
7171
mono_error_set_pending_exception (error);

src/mono/mono/mini/mini-runtime.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,6 +4029,7 @@ mini_init_delegate (MonoDelegateHandle delegate, MonoObjectHandle target, gpoint
40294029
MonoDelegateTrampInfo *info = NULL;
40304030

40314031
if (mono_use_interpreter) {
4032+
g_assert (method || del->interp_method);
40324033
mini_get_interp_callbacks ()->init_delegate (del, &info, error);
40334034
return_if_nok (error);
40344035
}

src/mono/mono/mini/mini-trampolines.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ mono_create_static_rgctx_trampoline (MonoMethod *m, gpointer addr)
129129
else
130130
res = mono_arch_get_static_rgctx_trampoline (jit_mm->mem_manager, ctx, addr);
131131

132+
/* This address might be passed to mini_init_delegate () which needs to look up the method */
133+
MonoJitInfo *ji;
134+
135+
ji = mini_alloc_jinfo (jit_mm, MONO_SIZEOF_JIT_INFO);
136+
ji->code_start = MINI_FTNPTR_TO_ADDR (res);
137+
/* Doesn't matter, just need to be able to look up the exact address */
138+
ji->code_size = 4;
139+
ji->d.method = m;
140+
mono_jit_info_table_add (ji);
141+
132142
jit_mm_lock (jit_mm);
133143
/* Duplicates inserted while we didn't hold the lock are OK */
134144
info = (RgctxTrampInfo *)m_method_alloc (m, sizeof (RgctxTrampInfo));

0 commit comments

Comments
 (0)