Skip to content

Commit a33cbb8

Browse files
authored
[interp] Fix native to interp transition (mono#6868)
When using the interp_wrapper to enter interp from native we don't need to save the lmf since it doesn't make sense to unwind to native. Also make sure we have the interp context set up if we weren't attached at interp transition time.
1 parent 7cac757 commit a33cbb8

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

mono/mini/interp/interp.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4581,11 +4581,18 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
45814581
++ip;
45824582

45834583
context->original_domain = NULL;
4584-
MonoDomain *tls_domain = (MonoDomain *) ((gpointer (*)(void)) mono_tls_get_tls_getter (TLS_KEY_DOMAIN, FALSE)) ();
4585-
gpointer tls_jit = ((gpointer (*)(void)) mono_tls_get_tls_getter (TLS_KEY_JIT_TLS, FALSE)) ();
4584+
MonoDomain *tls_domain = (MonoDomain *) mono_tls_get_domain ();
4585+
gpointer tls_jit = mono_tls_get_jit_tls ();
45864586

4587-
if (tls_domain != rtm->domain || !tls_jit)
4587+
if (tls_domain != rtm->domain || !tls_jit) {
45884588
context->original_domain = mono_jit_thread_attach (rtm->domain);
4589+
/*
4590+
* Make sure the JitTlsData contains the interp context, in case
4591+
* we weren't yet attached at interp_entry time.
4592+
*/
4593+
g_assert (context == mono_native_tls_get_value (thread_context_id));
4594+
set_context (context);
4595+
}
45894596
MINT_IN_BREAK;
45904597
}
45914598
MINT_IN_CASE(MINT_MONO_JIT_DETACH)

mono/mini/mini-generic-sharing.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,8 +1504,13 @@ mini_get_interp_in_wrapper (MonoMethodSignature *sig)
15041504

15051505
mb = mono_mb_new (mono_defaults.object_class, name, MONO_WRAPPER_UNKNOWN);
15061506

1507-
/* This is needed to be able to unwind out of interpreted code */
1508-
mb->method->save_lmf = 1;
1507+
/*
1508+
* This is needed to be able to unwind out of interpreted code to managed.
1509+
* When we are called from native code we can't unwind and we might also not
1510+
* be attached.
1511+
*/
1512+
if (!sig->pinvoke)
1513+
mb->method->save_lmf = 1;
15091514

15101515
#ifndef DISABLE_JIT
15111516
if (sig->ret->type != MONO_TYPE_VOID)

mono/tests/Makefile.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,6 @@ INTERP_DISABLED_TESTS = \
10281028
bug-415577.exe \
10291029
bug-45841-fpstack-exceptions.exe \
10301030
bug-48015.exe \
1031-
bug-58782-capture-and-throw.exe \
1032-
bug-58782-plain-throw.exe \
10331031
bug445361.exe \
10341032
bug-60862.exe \
10351033
calliGenericTest.exe \

0 commit comments

Comments
 (0)