diff options
| author | 2020-03-06 17:35:29 +0000 | |
|---|---|---|
| committer | 2020-03-06 17:35:29 +0000 | |
| commit | 5a451b705b9bbd74ceed8628996680c9d93a98e0 (patch) | |
| tree | 2617ac109c4f46577f298b82b4b3ce6e5fde9eea | |
| parent | 9751b7b39b3b341fb7e370ba77e084151f72cc39 (diff) | |
| parent | a562a490ce15c4cff8b5c8ff6f0bc998b471aa43 (diff) | |
Merge "libbinder: avoid attached objects for stability" into rvc-dev
| -rw-r--r-- | libs/binder/Binder.cpp | 2 | ||||
| -rw-r--r-- | libs/binder/BpBinder.cpp | 1 | ||||
| -rw-r--r-- | libs/binder/Stability.cpp | 22 | ||||
| -rw-r--r-- | libs/binder/include/binder/Binder.h | 11 | ||||
| -rw-r--r-- | libs/binder/include/binder/BpBinder.h | 7 |
5 files changed, 34 insertions, 9 deletions
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp index 2f6e9c3a1b..e0fb54384e 100644 --- a/libs/binder/Binder.cpp +++ b/libs/binder/Binder.cpp @@ -141,7 +141,7 @@ public: // --------------------------------------------------------------------------- -BBinder::BBinder() : mExtras(nullptr) +BBinder::BBinder() : mExtras(nullptr), mStability(0) { } diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp index f16c39cdc1..d2b9b8f018 100644 --- a/libs/binder/BpBinder.cpp +++ b/libs/binder/BpBinder.cpp @@ -138,6 +138,7 @@ BpBinder* BpBinder::create(int32_t handle) { BpBinder::BpBinder(int32_t handle, int32_t trackedUid) : mHandle(handle) + , mStability(0) , mAlive(1) , mObitsSent(0) , mObituaries(nullptr) diff --git a/libs/binder/Stability.cpp b/libs/binder/Stability.cpp index 7ce5e36292..e1565fac43 100644 --- a/libs/binder/Stability.cpp +++ b/libs/binder/Stability.cpp @@ -15,6 +15,9 @@ */ #include <binder/Stability.h> +#include <binder/BpBinder.h> +#include <binder/Binder.h> + namespace android { namespace internal { @@ -78,11 +81,12 @@ status_t Stability::set(IBinder* binder, int32_t stability, bool log) { if (currentStability == stability) return OK; - binder->attachObject( - reinterpret_cast<void*>(&Stability::get), - reinterpret_cast<void*>(stability), - nullptr /*cleanupCookie*/, - nullptr /*cleanup function*/); + BBinder* local = binder->localBinder(); + if (local != nullptr) { + local->mStability = static_cast<int32_t>(stability); + } else { + binder->remoteBinder()->mStability = static_cast<int32_t>(stability); + } return OK; } @@ -90,8 +94,12 @@ status_t Stability::set(IBinder* binder, int32_t stability, bool log) { Stability::Level Stability::get(IBinder* binder) { if (binder == nullptr) return UNDECLARED; - return static_cast<Level>(reinterpret_cast<intptr_t>( - binder->findObject(reinterpret_cast<void*>(&Stability::get)))); + BBinder* local = binder->localBinder(); + if (local != nullptr) { + return static_cast<Stability::Level>(local->mStability); + } + + return static_cast<Stability::Level>(binder->remoteBinder()->mStability); } bool Stability::check(int32_t provided, Level required) { diff --git a/libs/binder/include/binder/Binder.h b/libs/binder/include/binder/Binder.h index 3be61f9409..74e52db53f 100644 --- a/libs/binder/include/binder/Binder.h +++ b/libs/binder/include/binder/Binder.h @@ -24,6 +24,10 @@ // --------------------------------------------------------------------------- namespace android { +namespace internal { +class Stability; +} + class BBinder : public IBinder { public: @@ -88,7 +92,12 @@ private: Extras* getOrCreateExtras(); std::atomic<Extras*> mExtras; - void* mReserved0; + + friend ::android::internal::Stability; + union { + int32_t mStability; + void* mReserved0; + }; }; // --------------------------------------------------------------------------- diff --git a/libs/binder/include/binder/BpBinder.h b/libs/binder/include/binder/BpBinder.h index 7dca733b52..8e871b8214 100644 --- a/libs/binder/include/binder/BpBinder.h +++ b/libs/binder/include/binder/BpBinder.h @@ -27,6 +27,10 @@ // --------------------------------------------------------------------------- namespace android { +namespace internal { +class Stability; +}; + using binder_proxy_limit_callback = void(*)(int); class BpBinder : public IBinder @@ -116,6 +120,9 @@ protected: private: const int32_t mHandle; + friend ::android::internal::Stability; + int32_t mStability; + struct Obituary { wp<DeathRecipient> recipient; void* cookie; |