Skip to content

Commit 854a4e4

Browse files
authored
Merge pull request #36 from godotengine/mono-fix-tls-reattach-unity-fork
Mono: Add patch from Unity fork to fix TLS re-attachment
2 parents bf4ea28 + cb26a84 commit 854a4e4

File tree

9 files changed

+49
-4
lines changed

9 files changed

+49
-4
lines changed

Dockerfile.android

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ RUN git clone https://github.com/mono/mono --branch ${mono_version} --single-bra
2222
cd /root/mono && \
2323
if [ ! -z "${mono_commit}" ]; then git checkout ${mono_commit}; fi && \
2424
git submodule update --init && \
25+
git apply -3 /root/files/patches/mono-unity-Clear-TLS-instead-of-aborting.patch && \
2526
export MONO_SOURCE_ROOT=/root/mono && \
2627
export make="make -j" && \
2728
git clone https://github.com/godotengine/godot-mono-builds /root/godot-mono-builds && \

Dockerfile.javascript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ RUN git clone https://github.com/mono/mono --branch ${mono_version} --single-bra
1818
cd /root/mono && \
1919
if [ ! -z "${mono_commit}" ]; then git checkout ${mono_commit}; fi && \
2020
git submodule update --init && \
21+
git apply -3 /root/files/patches/mono-unity-Clear-TLS-instead-of-aborting.patch && \
2122
git apply -3 /root/files/patches/mono-pr16636-wasm-bugfix-and-update.diff && \
2223
export MONO_SOURCE_ROOT=/root/mono && \
2324
export make="make -j" && \

Dockerfile.mono

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ RUN if [ -z "${mono_version}" ]; then echo -e "\n\nargument mono-version is mand
1212
cd /root/mono && \
1313
if [ ! -z "${mono_commit}" ]; then git checkout ${mono_commit}; fi && \
1414
git submodule update --init && \
15+
git apply -3 /root/files/patches/mono-unity-Clear-TLS-instead-of-aborting.patch && \
1516
NOCONFIGURE=1 ./autogen.sh && \
1617
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var/lib/mono --disable-boehm && \
1718
make -j && \

Dockerfile.osx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ RUN git clone https://github.com/mono/mono --branch ${mono_version} --single-bra
2121
cd /root/mono && \
2222
if [ ! -z "${mono_commit}" ]; then git checkout ${mono_commit}; fi && \
2323
git submodule update --init && \
24+
git apply -3 /root/files/patches/mono-unity-Clear-TLS-instead-of-aborting.patch && \
2425
export CMAKE=/root/osxcross/target/bin/x86_64-apple-darwin18-cmake && \
2526
NOCONFIGURE=1 ./autogen.sh && \
2627
./configure --prefix=/root/dependencies/mono \

Dockerfile.ubuntu-32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ RUN cd /root && \
2626
cd /root/mono && \
2727
if [ ! -z "${mono_commit}" ]; then git checkout ${mono_commit}; fi && \
2828
git submodule update --init && \
29+
git apply -3 /root/files/patches/mono-unity-Clear-TLS-instead-of-aborting.patch && \
2930
NOCONFIGURE=1 ./autogen.sh && \
3031
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var/lib/mono --disable-boehm --host=i386-linux-gnu && \
3132
make -j && \

Dockerfile.ubuntu-64

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ RUN cd /root && \
2626
cd /root/mono && \
2727
if [ ! -z "${mono_commit}" ]; then git checkout ${mono_commit}; fi && \
2828
git submodule update --init && \
29+
git apply -3 /root/files/patches/mono-unity-Clear-TLS-instead-of-aborting.patch && \
2930
NOCONFIGURE=1 ./autogen.sh && \
3031
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var/lib/mono --disable-boehm --host=x86_64-linux-gnu && \
3132
make -j && \

Dockerfile.windows

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ RUN if [ -z "${mono_version}" ]; then echo -e "\n\nargument mono-version is mand
1212
cd /root/mono && \
1313
if [ ! -z "${mono_commit}" ]; then git checkout ${mono_commit}; fi && \
1414
git submodule update --init && \
15+
git apply -3 /root/files/patches/mono-unity-Clear-TLS-instead-of-aborting.patch && \
1516
git apply -3 /root/files/patches/wine-mono.patch && \
1617
export WINE_BITS=64 && \
1718
bash /root/files/mono-build-win32.sh --prefix=/root/dependencies/mono-64 --host=x86_64-w64-mingw32 && \

build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ done
4646
mkdir -p logs
4747

4848
export podman_build="$podman build --build-arg img_version=${img_version}"
49-
export podman_build_mono="$podman_build --build-arg mono_version=${mono_version} --build-arg mono_commit=${mono_commit}"
49+
export podman_build_mono="$podman_build --build-arg mono_version=${mono_version} --build-arg mono_commit=${mono_commit} -v $(pwd)/files:/root/files"
5050

5151
$podman build -t godot-fedora:${img_version} -f Dockerfile.base . 2>&1 | tee logs/base.log
5252
$podman_build -t godot-export:${img_version} -f Dockerfile.export . 2>&1 | tee logs/export.log
5353

5454
$podman_build_mono -t godot-mono:${img_version} -f Dockerfile.mono . 2>&1 | tee logs/mono.log
5555
$podman_build_mono -t godot-mono-glue:${img_version} -f Dockerfile.mono-glue . 2>&1 | tee logs/mono-glue.log
56-
$podman_build_mono -v $(pwd)/files:/root/files --ulimit nofile=65536 -t godot-windows:${img_version} -f Dockerfile.windows . 2>&1 | tee logs/windows.log
56+
$podman_build_mono -t godot-windows:${img_version} -f Dockerfile.windows --ulimit nofile=65536 . 2>&1 | tee logs/windows.log
5757
$podman_build_mono -t godot-ubuntu-64:${img_version} -f Dockerfile.ubuntu-64 . 2>&1 | tee logs/ubuntu-64.log
5858
$podman_build_mono -t godot-ubuntu-32:${img_version} -f Dockerfile.ubuntu-32 . 2>&1 | tee logs/ubuntu-32.log
5959
$podman_build_mono -t godot-android:${img_version} -f Dockerfile.android . 2>&1 | tee logs/android.log
60-
$podman_build_mono -v $(pwd)/files:/root/files -t godot-javascript:${img_version} -f Dockerfile.javascript . 2>&1 | tee logs/javascript.log
60+
$podman_build_mono -t godot-javascript:${img_version} -f Dockerfile.javascript . 2>&1 | tee logs/javascript.log
6161

6262
$podman_build -t godot-xcode-packer:${img_version} -f Dockerfile.xcode -v $(pwd)/files:/root/files . 2>&1 | tee logs/xcode.log
6363

@@ -72,7 +72,7 @@ if [ ! -e files/MacOSX10.14.sdk.tar.xz ] || [ ! -e files/iPhoneOS12.4.sdk.tar.xz
7272
fi
7373

7474
$podman_build -t godot-ios:${img_version} -f Dockerfile.ios -v $(pwd)/files:/root/files . 2>&1 | tee logs/ios.log
75-
$podman_build_mono -t godot-osx:${img_version} -f Dockerfile.osx -v $(pwd)/files:/root/files . 2>&1 | tee logs/osx.log
75+
$podman_build_mono -t godot-osx:${img_version} -f Dockerfile.osx . 2>&1 | tee logs/osx.log
7676

7777
if [ ! -e files/msvc2017.tar ]; then
7878
echo
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

Comments
 (0)