diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-04-24 03:13:12 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-04-24 03:13:12 +0000 |
commit | 2b8885c2d51c7e7f4b0ed41ea26b08e93ca58cc3 (patch) | |
tree | ee4b71a7dab847d0264050f09d213291c10f2dc2 | |
parent | 9c05ada92ce6d6b7043b1fd970f2f78d0b05022f (diff) | |
parent | c1e587fb8d7867c4d7bea3d77078aedd9adca2cb (diff) | |
download | libhidl-2b8885c2d51c7e7f4b0ed41ea26b08e93ca58cc3.tar.gz |
Snap for 5499134 from c1e587fb8d7867c4d7bea3d77078aedd9adca2cb to qt-release
Change-Id: Icb64d3fb7ecca7ef75bbb82077d4f2053e9ffb6c
-rw-r--r-- | transport/HidlBinderSupport.cpp | 8 | ||||
-rw-r--r-- | transport/HidlPassthroughSupport.cpp | 2 | ||||
-rw-r--r-- | transport/HidlTransportSupport.cpp | 12 | ||||
-rw-r--r-- | transport/InternalStatic.h | 6 | ||||
-rw-r--r-- | transport/Static.cpp | 17 | ||||
-rw-r--r-- | transport/include/hidl/ConcurrentMap.h | 17 | ||||
-rw-r--r-- | transport/include/hidl/Static.h | 13 | ||||
-rw-r--r-- | vintfdata/Android.mk | 7 |
8 files changed, 55 insertions, 27 deletions
diff --git a/transport/HidlBinderSupport.cpp b/transport/HidlBinderSupport.cpp index caf7cf8..62b1755 100644 --- a/transport/HidlBinderSupport.cpp +++ b/transport/HidlBinderSupport.cpp @@ -256,16 +256,16 @@ sp<IBinder> getOrCreateCachedBinder(::android::hidl::base::V1_0::IBase* ifacePtr } // for get + set - std::unique_lock<std::mutex> _lock = details::gBnMap.lock(); + std::unique_lock<std::mutex> _lock = details::gBnMap->lock(); - wp<BHwBinder> wBnObj = details::gBnMap.getLocked(ifacePtr, nullptr); + wp<BHwBinder> wBnObj = details::gBnMap->getLocked(ifacePtr, nullptr); sp<IBinder> sBnObj = wBnObj.promote(); if (sBnObj == nullptr) { auto func = details::getBnConstructorMap().get(descriptor, nullptr); if (!func) { // TODO(b/69122224): remove this static variable when prebuilts updated - func = details::gBnConstructorMap.get(descriptor, nullptr); + func = details::gBnConstructorMap->get(descriptor, nullptr); } LOG_ALWAYS_FATAL_IF(func == nullptr, "%s gBnConstructorMap returned null for %s", __func__, descriptor.c_str()); @@ -274,7 +274,7 @@ sp<IBinder> getOrCreateCachedBinder(::android::hidl::base::V1_0::IBase* ifacePtr LOG_ALWAYS_FATAL_IF(sBnObj == nullptr, "%s Bn constructor function returned null for %s", __func__, descriptor.c_str()); - details::gBnMap.setLocked(ifacePtr, static_cast<BHwBinder*>(sBnObj.get())); + details::gBnMap->setLocked(ifacePtr, static_cast<BHwBinder*>(sBnObj.get())); } return sBnObj; diff --git a/transport/HidlPassthroughSupport.cpp b/transport/HidlPassthroughSupport.cpp index ff68a1e..bc67656 100644 --- a/transport/HidlPassthroughSupport.cpp +++ b/transport/HidlPassthroughSupport.cpp @@ -31,7 +31,7 @@ static sp<IBase> tryWrap(const std::string& descriptor, sp<IBase> iface) { auto func = getBsConstructorMap().get(descriptor, nullptr); if (!func) { // TODO(b/69122224): remove this when prebuilts don't reference it - func = gBsConstructorMap.get(descriptor, nullptr); + func = gBsConstructorMap->get(descriptor, nullptr); } if (func) { return func(static_cast<void*>(iface.get())); diff --git a/transport/HidlTransportSupport.cpp b/transport/HidlTransportSupport.cpp index db70438..b433b70 100644 --- a/transport/HidlTransportSupport.cpp +++ b/transport/HidlTransportSupport.cpp @@ -85,9 +85,9 @@ bool setMinSchedulerPolicy(const sp<IBase>& service, int policy, int priority) { // Due to ABI considerations, IBase cannot have a destructor to clean this up. // So, because this API is so infrequently used, (expected to be usually only // one time for a process, but it can be more), we are cleaning it up here. - std::unique_lock<std::mutex> lock = details::gServicePrioMap.lock(); - pruneMapLocked(details::gServicePrioMap); - details::gServicePrioMap.setLocked(service, {policy, priority}); + std::unique_lock<std::mutex> lock = details::gServicePrioMap->lock(); + pruneMapLocked(details::gServicePrioMap.get()); + details::gServicePrioMap->setLocked(service, {policy, priority}); return true; } @@ -101,9 +101,9 @@ bool setRequestingSid(const sp<IBase>& service, bool requesting) { // Due to ABI considerations, IBase cannot have a destructor to clean this up. // So, because this API is so infrequently used, (expected to be usually only // one time for a process, but it can be more), we are cleaning it up here. - std::unique_lock<std::mutex> lock = details::gServiceSidMap.lock(); - pruneMapLocked(details::gServiceSidMap); - details::gServiceSidMap.setLocked(service, requesting); + std::unique_lock<std::mutex> lock = details::gServiceSidMap->lock(); + pruneMapLocked(details::gServiceSidMap.get()); + details::gServiceSidMap->setLocked(service, requesting); return true; } diff --git a/transport/InternalStatic.h b/transport/InternalStatic.h index b0fefa9..1dfaae4 100644 --- a/transport/InternalStatic.h +++ b/transport/InternalStatic.h @@ -26,10 +26,12 @@ namespace android { namespace hardware { namespace details { +// TODO(b/69122224): remove this // deprecated; use getBnConstructorMap instead. -extern BnConstructorMap gBnConstructorMap; +extern DoNotDestruct<BnConstructorMap> gBnConstructorMap; +// TODO(b/69122224): remove this // deprecated; use getBsConstructorMap instead. -extern BsConstructorMap gBsConstructorMap; +extern DoNotDestruct<BsConstructorMap> gBsConstructorMap; } // namespace details } // namespace hardware 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 hardware { 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; } diff --git a/transport/include/hidl/ConcurrentMap.h b/transport/include/hidl/ConcurrentMap.h index 1b06dfd..329752c 100644 --- a/transport/include/hidl/ConcurrentMap.h +++ b/transport/include/hidl/ConcurrentMap.h @@ -90,6 +90,23 @@ public: std::map<K, V> mMap; }; +namespace details { + +// TODO(b/69122224): remove this type and usages of it +// DO NOT ADD USAGES +template <typename T> +class DoNotDestruct { + public: + DoNotDestruct() { new (buffer) T(); } + T& get() { return *reinterpret_cast<T*>(buffer); } + T* operator->() { return reinterpret_cast<T*>(buffer); } + + private: + alignas(T) char buffer[sizeof(T)]; +}; + +} // namespace details + } // namespace hardware } // namespace android diff --git a/transport/include/hidl/Static.h b/transport/include/hidl/Static.h index cc711b7..be74bae 100644 --- a/transport/include/hidl/Static.h +++ b/transport/include/hidl/Static.h @@ -37,12 +37,17 @@ struct SchedPrio { int prio; }; -extern ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, SchedPrio> gServicePrioMap; -extern ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, bool> gServiceSidMap; +// TODO(b/69122224): remove this +extern DoNotDestruct<ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, SchedPrio>> + gServicePrioMap; +// TODO(b/69122224): remove this +extern DoNotDestruct<ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, bool>> gServiceSidMap; +// TODO(b/69122224): remove this // For HidlBinderSupport and autogenerated code -extern ConcurrentMap<const ::android::hidl::base::V1_0::IBase*, wp<::android::hardware::BHwBinder>> - gBnMap; +extern DoNotDestruct<ConcurrentMap<const ::android::hidl::base::V1_0::IBase*, + wp<::android::hardware::BHwBinder>>> + gBnMap; using BnConstructorMap = ConcurrentMap<std::string, std::function<sp<IBinder>(void*)>>; // For HidlBinderSupport and autogenerated code diff --git a/vintfdata/Android.mk b/vintfdata/Android.mk index 3db7065..78351fe 100644 --- a/vintfdata/Android.mk +++ b/vintfdata/Android.mk @@ -44,10 +44,13 @@ LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/vintf GEN := $(local-generated-sources-dir)/compatibility_matrix.xml $(GEN): PRIVATE_VINTF_VNDK_VERSION := $(VINTF_VNDK_VERSION) +$(GEN): PRIVATE_DEVICE_MATRIX_INPUT_FILE := $(DEVICE_MATRIX_INPUT_FILE) $(GEN): $(DEVICE_MATRIX_INPUT_FILE) $(HOST_OUT_EXECUTABLES)/assemble_vintf REQUIRED_VNDK_VERSION=$(PRIVATE_VINTF_VNDK_VERSION) \ BOARD_SYSTEMSDK_VERSIONS="$(BOARD_SYSTEMSDK_VERSIONS)" \ - $(HOST_OUT_EXECUTABLES)/assemble_vintf -i $< -o $@ + $(HOST_OUT_EXECUTABLES)/assemble_vintf \ + -i $(call normalize-path-list,$(PRIVATE_DEVICE_MATRIX_INPUT_FILE)) \ + -o $@ LOCAL_PREBUILT_MODULE_FILE := $(GEN) include $(BUILD_PREBUILT) @@ -77,4 +80,4 @@ BUILT_SYSTEM_MANIFEST := $(LOCAL_BUILT_MODULE) VINTF_VNDK_VERSION := FRAMEWORK_MANIFEST_INPUT_FILES := -DEVICE_MATRIX_INPUT_FILE :=
\ No newline at end of file +DEVICE_MATRIX_INPUT_FILE := |