Do not destruct static maps.
In case they are deleted while some threads are using them (this
happens sometimes depending on how these libraries are loaded and how
they are being used).
Noting that b/69122224 is filed to move these into functions.
Bug: 129726097
Test: HIDL's run_all_device_tests.sh
Test: no longer see error where it repro'd before:
FORTIFY: pthread_mutex_lock called on a destroyed mutex
Change-Id: I66eb9aa24e31d7fc652f0426361c17600b4716ec
diff --git a/transport/Static.cpp b/transport/Static.cpp
index 0bbd48d..af16e8f 100644
--- a/transport/Static.cpp
+++ b/transport/Static.cpp
@@ -28,27 +28,28 @@
namespace details {
// Deprecated; kept for ABI compatibility. Use getBnConstructorMap.
-BnConstructorMap gBnConstructorMap{};
+DoNotDestruct<BnConstructorMap> gBnConstructorMap{};
-ConcurrentMap<const ::android::hidl::base::V1_0::IBase*, wp<::android::hardware::BHwBinder>>
- gBnMap{};
+DoNotDestruct<ConcurrentMap<const ::android::hidl::base::V1_0::IBase*,
+ wp<::android::hardware::BHwBinder>>>
+ gBnMap{};
// TODO(b/122472540): replace with single, hidden map
-ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, SchedPrio> gServicePrioMap{};
-ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, bool> gServiceSidMap{};
+DoNotDestruct<ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, SchedPrio>> gServicePrioMap{};
+DoNotDestruct<ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, bool>> gServiceSidMap{};
// Deprecated; kept for ABI compatibility. Use getBsConstructorMap.
-BsConstructorMap gBsConstructorMap{};
+DoNotDestruct<BsConstructorMap> gBsConstructorMap{};
// For static executables, it is not guaranteed that gBnConstructorMap are initialized before
// used in HAL definition libraries.
BnConstructorMap& getBnConstructorMap() {
- static BnConstructorMap map{};
+ static BnConstructorMap& map = *new BnConstructorMap();
return map;
}
BsConstructorMap& getBsConstructorMap() {
- static BsConstructorMap map{};
+ static BsConstructorMap& map = *new BsConstructorMap();
return map;
}