Skip to content

Commit 71d34e5

Browse files
authored
Merge pull request #181 from Ghabry/3ds-icu-fix
3DS: Disable Mutex code in ICU because it crashes
2 parents 3658e1e + db9d07d commit 71d34e5

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

3ds/2_build_toolchain.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ if [ ! -f .patches-applied ]; then
6060

6161
# Fix icu build
6262
patch -Np0 < $SCRIPT_DIR/icu-3ds.patch
63+
# Patch mutex support out
64+
patch -Np0 < $SCRIPT_DIR/icu-3ds-no-mutex.patch
6365

6466
touch .patches-applied
6567
fi

3ds/icu-3ds-no-mutex.patch

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
diff -Naur icu-orig/source/common/umutex.cpp icu/source/common/umutex.cpp
2+
--- icu-orig/source/common/umutex.cpp 2024-09-01 18:41:49.755849773 +0200
3+
+++ icu/source/common/umutex.cpp 2024-09-01 18:42:05.278763995 +0200
4+
@@ -44,20 +44,25 @@
5+
*************************************************************************************************/
6+
7+
namespace {
8+
+#if 0
9+
std::mutex *initMutex;
10+
std::condition_variable *initCondition;
11+
+#endif
12+
13+
// The ICU global mutex.
14+
// Used when ICU implementation code passes nullptr for the mutex pointer.
15+
UMutex globalMutex;
16+
17+
+#if 0
18+
std::once_flag initFlag;
19+
std::once_flag *pInitFlag = &initFlag;
20+
+#endif
21+
22+
} // Anonymous namespace
23+
24+
U_CDECL_BEGIN
25+
static UBool U_CALLCONV umtx_cleanup() {
26+
+#if 0
27+
initMutex->~mutex();
28+
initCondition->~condition_variable();
29+
UMutex::cleanup();
30+
@@ -66,17 +71,20 @@
31+
// Do not use this trick anywhere else in ICU; use umtx_initOnce, not std::call_once().
32+
pInitFlag->~once_flag();
33+
pInitFlag = new(&initFlag) std::once_flag();
34+
+#endif
35+
return true;
36+
}
37+
38+
static void U_CALLCONV umtx_init() {
39+
+#if 0
40+
initMutex = STATIC_NEW(std::mutex);
41+
initCondition = STATIC_NEW(std::condition_variable);
42+
ucln_common_registerCleanup(UCLN_COMMON_MUTEX, umtx_cleanup);
43+
+#endif
44+
}
45+
U_CDECL_END
46+
47+
-
48+
+#if 0
49+
std::mutex *UMutex::getMutex() {
50+
std::mutex *retPtr = fMutex.load(std::memory_order_acquire);
51+
if (retPtr == nullptr) {
52+
@@ -106,7 +114,7 @@
53+
}
54+
gListHead = nullptr;
55+
}
56+
-
57+
+#endif
58+
59+
U_CAPI void U_EXPORT2
60+
umtx_lock(UMutex *mutex) {
61+
@@ -143,6 +151,7 @@
62+
//
63+
U_COMMON_API UBool U_EXPORT2
64+
umtx_initImplPreInit(UInitOnce &uio) {
65+
+#if 0
66+
std::call_once(*pInitFlag, umtx_init);
67+
std::unique_lock<std::mutex> lock(*initMutex);
68+
if (umtx_loadAcquire(uio.fState) == 0) {
69+
@@ -157,6 +166,8 @@
70+
U_ASSERT(uio.fState == 2);
71+
return false;
72+
}
73+
+#endif
74+
+ return true;
75+
}
76+
77+
78+
@@ -168,11 +179,13 @@
79+
80+
U_COMMON_API void U_EXPORT2
81+
umtx_initImplPostInit(UInitOnce &uio) {
82+
+#if 0
83+
{
84+
std::unique_lock<std::mutex> lock(*initMutex);
85+
umtx_storeRelease(uio.fState, 2);
86+
}
87+
initCondition->notify_all();
88+
+#endif
89+
}
90+
91+
U_NAMESPACE_END
92+
diff '--color=auto' -Naur icu-orig/source/common/umutex.h icu/source/common/umutex.h
93+
--- icu-orig/source/common/umutex.h 2024-09-01 18:41:49.732517070 +0200
94+
+++ icu/source/common/umutex.h 2024-09-01 18:42:05.278763995 +0200
95+
@@ -227,15 +227,22 @@
96+
97+
// requirements for C++ BasicLockable, allows UMutex to work with std::lock_guard
98+
void lock() {
99+
+#if 0
100+
std::mutex *m = fMutex.load(std::memory_order_acquire);
101+
if (m == nullptr) { m = getMutex(); }
102+
m->lock();
103+
+#endif
104+
+ }
105+
+ void unlock() {
106+
+#if 0
107+
+ fMutex.load(std::memory_order_relaxed)->unlock();
108+
+#endif
109+
}
110+
- void unlock() { fMutex.load(std::memory_order_relaxed)->unlock(); }
111+
112+
static void cleanup();
113+
114+
private:
115+
+#if 0
116+
alignas(std::mutex) char fStorage[sizeof(std::mutex)] {};
117+
std::atomic<std::mutex *> fMutex { nullptr };
118+
119+
@@ -250,6 +257,7 @@
120+
* be nullptr.
121+
*/
122+
std::mutex *getMutex();
123+
+#endif
124+
};
125+
126+

0 commit comments

Comments
 (0)