Lock accesses to mClazz in AIBinder with a mutex
The associateClass method mutates the mClazz member of AIBinder in a
non-thread-safe way. This patch fixes this problem by adding a
std::mutex locking that variable, fixing test flakiness in the Rust
tests for the AIDL compiler
Test: atest libbinder_ndk_unit_test binderVendorDoubleLoadTest CtsNdkBinderTestCases
Test: atest aidl_integration_test for AIDL Rust tests
Change-Id: I4b0ec21755a9995c1f591ab937e9a3280992be80
diff --git a/libs/binder/ndk/ibinder_internal.h b/libs/binder/ndk/ibinder_internal.h
index 5779427..f4e2704 100644
--- a/libs/binder/ndk/ibinder_internal.h
+++ b/libs/binder/ndk/ibinder_internal.h
@@ -22,6 +22,7 @@
#include <atomic>
#include <mutex>
+#include <optional>
#include <vector>
#include <binder/Binder.h>
@@ -52,10 +53,14 @@
}
private:
+ std::optional<bool> associateClassInternal(const AIBinder_Class* clazz,
+ const ::android::String8& newDescriptor, bool set);
+
// AIBinder instance is instance of this class for a local object. In order to transact on a
// remote object, this also must be set for simplicity (although right now, only the
// interfaceDescriptor from it is used).
const AIBinder_Class* mClazz;
+ std::mutex mClazzMutex;
};
// This is a local AIBinder object with a known class.