diff options
author | monojenkins <jo.shields+jenkins@xamarin.com> | 2020-10-20 21:35:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-20 21:35:24 +0300 |
commit | 3db5b3584135cf636b95d4b3aa56be522dee2257 (patch) | |
tree | b9491908649d0779f7693c6f1e104efabc5bb767 | |
parent | af315f44c40dfb8767d64920bae2cdb8da7cc3f8 (diff) |
[debugger] Switch to GC Unsafe in signal handler callbacks (#20495)mono-6.12.0.103
If the runtime gets a single step or breakpoint signal while it is already
running native code for a P/Invoke, it will be in GC Safe mode. Switch back to
GC Unsafe to run the debugger engine steps.
Addresses https://github.com/mono/mono/issues/20490
Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
-rw-r--r-- | mono/mini/debugger-agent.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index c94750657f1..54c0ca97801 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -2829,6 +2829,8 @@ process_suspend (DebuggerTlsData *tls, MonoContext *ctx) static gboolean try_process_suspend (void *the_tls, MonoContext *ctx, gboolean from_breakpoint) { + MONO_REQ_GC_UNSAFE_MODE; + DebuggerTlsData *tls = (DebuggerTlsData*)the_tls; /* if there is a suspend pending that is not executed yes */ if (suspend_count > 0) { @@ -4946,7 +4948,13 @@ debugger_agent_single_step_from_context (MonoContext *ctx) mono_thread_state_init_from_monoctx (&tls->restore_state, ctx); memcpy (&tls->handler_ctx, ctx, sizeof (MonoContext)); + /* We might be called while the thread is already running some native + * code after an native-to-managed transition, so the thread might be + * in GC Safe mode. + */ + MONO_ENTER_GC_UNSAFE; mono_de_process_single_step (tls, FALSE); + MONO_EXIT_GC_UNSAFE; memcpy (ctx, &tls->restore_state.ctx, sizeof (MonoContext)); memcpy (&tls->restore_state, &orig_restore_state, sizeof (MonoThreadUnwindState)); @@ -4976,7 +4984,13 @@ debugger_agent_breakpoint_from_context (MonoContext *ctx) mono_thread_state_init_from_monoctx (&tls->restore_state, ctx); memcpy (&tls->handler_ctx, ctx, sizeof (MonoContext)); + /* We might be called while the thread is already running some native + * code after an native-to-managed transition, so the thread might be + * in GC Safe mode. + */ + MONO_ENTER_GC_UNSAFE; mono_de_process_breakpoint (tls, FALSE); + MONO_EXIT_GC_UNSAFE; memcpy (ctx, &tls->restore_state.ctx, sizeof (MonoContext)); memcpy (&tls->restore_state, &orig_restore_state, sizeof (MonoThreadUnwindState)); |