|
| 1 | +Rediffed against 6.6.0.161 with condition improved based on feedback |
| 2 | +from Ignacio Etcheverry. |
| 3 | + |
| 4 | +From 995768f7dc3af7b3d19fcedd1244087a4a89bc5c Mon Sep 17 00:00:00 2001 |
| 5 | +From: Josh Peterson <petersonjm1@gmail.com> |
| 6 | +Date: Tue, 30 Aug 2016 14:47:30 -0400 |
| 7 | +Subject: [PATCH] Clear TLS instead of aborting |
| 8 | + |
| 9 | +Often in Unity native code will attach to a managed thread, detach, then |
| 10 | +attach again. This occurs most regularly in the audio code. Whent this |
| 11 | +happens the debugger thread local storage will already be allocated for |
| 12 | +the thread. This is acceptable, so instead of asserting, we clear the |
| 13 | +previous thread local storage and create a new one. |
| 14 | + |
| 15 | +This was originally changed in the Unity fork at: https://github.com/Unity-Technologies/mono/commit/70736c0c548af244d2a16c39790f32711fefee5b |
| 16 | +--- |
| 17 | + mono/mini/debugger-agent.c | 6 ++++-- |
| 18 | + 1 file changed, 4 insertions(+), 2 deletions(-) |
| 19 | + |
| 20 | +diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c |
| 21 | +index df6329391df..05f30d5b4dc 100644 |
| 22 | +--- a/mono/mini/debugger-agent.c |
| 23 | ++++ b/mono/mini/debugger-agent.c |
| 24 | +@@ -4088,8 +4088,12 @@ thread_startup (MonoProfiler *prof, uintptr_t tid) |
| 25 | + } |
| 26 | + |
| 27 | + tls = (DebuggerTlsData *)mono_native_tls_get_value (debugger_tls_id); |
| 28 | +- g_assert (!tls); |
| 29 | +- // FIXME: Free this somewhere |
| 30 | ++ if (tls) { |
| 31 | ++ if (!tls->terminated) { |
| 32 | ++ MONO_GC_UNREGISTER_ROOT(tls->thread); |
| 33 | ++ } |
| 34 | ++ g_free (tls); |
| 35 | ++ } |
| 36 | + tls = g_new0 (DebuggerTlsData, 1); |
| 37 | + MONO_GC_REGISTER_ROOT_SINGLE (tls->thread, MONO_ROOT_SOURCE_DEBUGGER, NULL, "Debugger Thread Reference"); |
| 38 | + tls->thread = thread; |
0 commit comments