Skip to content
16 changes: 14 additions & 2 deletions src/mono/mono/mini/mini-exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,15 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu
* mono_resume_unwind () will call us again to continue
* the unwinding.
*/
jit_tls->resume_state.ex_obj = obj;
/*
* Keep the exception object alive across the (managed) finally
* handler using a pinned GC handle. The handler can reach a GC
* safepoint, and a moving GC would otherwise invalidate a raw
* pointer stored here (see mono_resume_unwind ()).
*/
if (jit_tls->resume_state.ex_gchandle)
mono_gchandle_free_internal (jit_tls->resume_state.ex_gchandle);
jit_tls->resume_state.ex_gchandle = mono_gchandle_new_internal (obj, TRUE);
Comment thread
BrzVlad marked this conversation as resolved.
Outdated
jit_tls->resume_state.ji = ji;
Comment thread
pavelsavara marked this conversation as resolved.
jit_tls->resume_state.clause_index = i + 1;
jit_tls->resume_state.ctx = *ctx;
Expand Down Expand Up @@ -3095,7 +3103,11 @@ mono_resume_unwind (MonoContext *ctx)
MONO_CONTEXT_SET_SP (ctx, MONO_CONTEXT_GET_SP (&jit_tls->resume_state.ctx));
new_ctx = *ctx;

mono_handle_exception_internal (&new_ctx, (MonoObject *)jit_tls->resume_state.ex_obj, TRUE, NULL);
MonoObject *ex_obj = mono_gchandle_get_target_internal (jit_tls->resume_state.ex_gchandle);
mono_gchandle_free_internal (jit_tls->resume_state.ex_gchandle);
jit_tls->resume_state.ex_gchandle = NULL;

mono_handle_exception_internal (&new_ctx, ex_obj, TRUE, NULL);

mono_restore_context (&new_ctx);
}
Expand Down
2 changes: 0 additions & 2 deletions src/mono/mono/mini/mini-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ typedef struct {
MonoJitInfo *ji;
int clause_index;
MonoContext ctx, new_ctx;
/* FIXME: GC */
gpointer ex_obj;
MonoLMF *lmf;
Comment thread
pavelsavara marked this conversation as resolved.
int first_filter_idx, filter_idx;
/* MonoMethodILState */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
.custom instance void [xunit.core]Xunit.FactAttribute::.ctor() = (
01 00 00 00
)
.custom instance void [Microsoft.DotNet.XUnitExtensions]Xunit.ActiveIssueAttribute::.ctor(string, valuetype [Microsoft.DotNet.XUnitExtensions]Xunit.TestRuntimes) = {
string('https://github.com/dotnet/runtime/issues/129508')
int32(0x2) // Mono
}
.entrypoint
.maxstack 3
.locals init (class [System.Threading.Thread]System.Threading.Thread V_0,
Expand Down
Loading