The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "BpBinder" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 20 | #include <binder/BpBinder.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 22 | #include <binder/IPCThreadState.h> |
Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 23 | #include <binder/IResultReceiver.h> |
Steven Moreland | bdb53ab | 2021-05-05 17:57:41 +0000 | [diff] [blame] | 24 | #include <binder/RpcSession.h> |
Steven Moreland | 6e5a775 | 2019-08-05 20:30:14 -0700 | [diff] [blame] | 25 | #include <binder/Stability.h> |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 26 | #include <cutils/compiler.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <utils/Log.h> |
| 28 | |
| 29 | #include <stdio.h> |
| 30 | |
Steve Block | 6807e59 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 31 | //#undef ALOGV |
| 32 | //#define ALOGV(...) fprintf(stderr, __VA_ARGS__) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | // --------------------------------------------------------------------------- |
| 37 | |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 38 | Mutex BpBinder::sTrackingLock; |
Martijn Coenen | a8d509d | 2021-09-03 18:06:24 +0200 | [diff] [blame] | 39 | std::unordered_map<int32_t, uint32_t> BpBinder::sTrackingMap; |
| 40 | std::unordered_map<int32_t, uint32_t> BpBinder::sLastLimitCallbackMap; |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 41 | int BpBinder::sNumTrackedUids = 0; |
| 42 | std::atomic_bool BpBinder::sCountByUidEnabled(false); |
| 43 | binder_proxy_limit_callback BpBinder::sLimitCallback; |
| 44 | bool BpBinder::sBinderProxyThrottleCreate = false; |
| 45 | |
| 46 | // Arbitrarily high value that probably distinguishes a bad behaving app |
| 47 | uint32_t BpBinder::sBinderProxyCountHighWatermark = 2500; |
| 48 | // Another arbitrary value a binder count needs to drop below before another callback will be called |
| 49 | uint32_t BpBinder::sBinderProxyCountLowWatermark = 2000; |
| 50 | |
Martijn Coenen | 1cad19c | 2021-10-04 09:19:01 +0200 | [diff] [blame] | 51 | // Log any transactions for which the data exceeds this size |
| 52 | #define LOG_TRANSACTIONS_OVER_SIZE (300 * 1024) |
| 53 | |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 54 | enum { |
Michael Wachenschwanz | 74d967a | 2018-05-15 15:03:57 -0700 | [diff] [blame] | 55 | LIMIT_REACHED_MASK = 0x80000000, // A flag denoting that the limit has been reached |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 56 | COUNTING_VALUE_MASK = 0x7FFFFFFF, // A mask of the remaining bits for the count value |
| 57 | }; |
| 58 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | BpBinder::ObjectManager::ObjectManager() |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | BpBinder::ObjectManager::~ObjectManager() |
| 64 | { |
| 65 | kill(); |
| 66 | } |
| 67 | |
Steven Moreland | 63a2d51 | 2021-06-25 01:10:15 +0000 | [diff] [blame] | 68 | void* BpBinder::ObjectManager::attach(const void* objectID, void* object, void* cleanupCookie, |
| 69 | IBinder::object_cleanup_func func) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | entry_t e; |
| 71 | e.object = object; |
| 72 | e.cleanupCookie = cleanupCookie; |
| 73 | e.func = func; |
| 74 | |
Jiyong Park | 5970d0a | 2022-03-08 16:56:13 +0900 | [diff] [blame] | 75 | if (mObjects.find(objectID) != mObjects.end()) { |
Steven Moreland | 63a2d51 | 2021-06-25 01:10:15 +0000 | [diff] [blame] | 76 | ALOGI("Trying to attach object ID %p to binder ObjectManager %p with object %p, but object " |
| 77 | "ID already in use", |
| 78 | objectID, this, object); |
Jiyong Park | 5970d0a | 2022-03-08 16:56:13 +0900 | [diff] [blame] | 79 | return mObjects[objectID].object; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Jiyong Park | 5970d0a | 2022-03-08 16:56:13 +0900 | [diff] [blame] | 82 | mObjects.insert({objectID, e}); |
Steven Moreland | 63a2d51 | 2021-06-25 01:10:15 +0000 | [diff] [blame] | 83 | return nullptr; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void* BpBinder::ObjectManager::find(const void* objectID) const |
| 87 | { |
Jiyong Park | 5970d0a | 2022-03-08 16:56:13 +0900 | [diff] [blame] | 88 | auto i = mObjects.find(objectID); |
| 89 | if (i == mObjects.end()) return nullptr; |
| 90 | return i->second.object; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Steven Moreland | 63a2d51 | 2021-06-25 01:10:15 +0000 | [diff] [blame] | 93 | void* BpBinder::ObjectManager::detach(const void* objectID) { |
Jiyong Park | 5970d0a | 2022-03-08 16:56:13 +0900 | [diff] [blame] | 94 | auto i = mObjects.find(objectID); |
| 95 | if (i == mObjects.end()) return nullptr; |
| 96 | void* value = i->second.object; |
| 97 | mObjects.erase(i); |
Steven Moreland | 63a2d51 | 2021-06-25 01:10:15 +0000 | [diff] [blame] | 98 | return value; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void BpBinder::ObjectManager::kill() |
| 102 | { |
| 103 | const size_t N = mObjects.size(); |
Mark Salyzyn | d4ecccf | 2014-05-30 16:35:57 -0700 | [diff] [blame] | 104 | ALOGV("Killing %zu objects in manager %p", N, this); |
Jiyong Park | 5970d0a | 2022-03-08 16:56:13 +0900 | [diff] [blame] | 105 | for (auto i : mObjects) { |
| 106 | const entry_t& e = i.second; |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 107 | if (e.func != nullptr) { |
Jiyong Park | 5970d0a | 2022-03-08 16:56:13 +0900 | [diff] [blame] | 108 | e.func(i.first, e.object, e.cleanupCookie); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | mObjects.clear(); |
| 113 | } |
| 114 | |
| 115 | // --------------------------------------------------------------------------- |
| 116 | |
Steven Moreland | 1a3a8ef | 2021-04-02 02:52:46 +0000 | [diff] [blame] | 117 | sp<BpBinder> BpBinder::create(int32_t handle) { |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 118 | int32_t trackedUid = -1; |
| 119 | if (sCountByUidEnabled) { |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 120 | trackedUid = IPCThreadState::self()->getCallingUid(); |
| 121 | AutoMutex _l(sTrackingLock); |
Michael Wachenschwanz | 74d967a | 2018-05-15 15:03:57 -0700 | [diff] [blame] | 122 | uint32_t trackedValue = sTrackingMap[trackedUid]; |
| 123 | if (CC_UNLIKELY(trackedValue & LIMIT_REACHED_MASK)) { |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 124 | if (sBinderProxyThrottleCreate) { |
Michael Wachenschwanz | 74d967a | 2018-05-15 15:03:57 -0700 | [diff] [blame] | 125 | return nullptr; |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 126 | } |
Martijn Coenen | a8d509d | 2021-09-03 18:06:24 +0200 | [diff] [blame] | 127 | trackedValue = trackedValue & COUNTING_VALUE_MASK; |
| 128 | uint32_t lastLimitCallbackAt = sLastLimitCallbackMap[trackedUid]; |
| 129 | |
| 130 | if (trackedValue > lastLimitCallbackAt && |
Martijn Coenen | 6711b6d | 2021-09-23 09:44:29 +0200 | [diff] [blame] | 131 | (trackedValue - lastLimitCallbackAt > sBinderProxyCountHighWatermark)) { |
Martijn Coenen | a8d509d | 2021-09-03 18:06:24 +0200 | [diff] [blame] | 132 | ALOGE("Still too many binder proxy objects sent to uid %d from uid %d (%d proxies " |
| 133 | "held)", |
| 134 | getuid(), trackedUid, trackedValue); |
| 135 | if (sLimitCallback) sLimitCallback(trackedUid); |
| 136 | sLastLimitCallbackMap[trackedUid] = trackedValue; |
| 137 | } |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 138 | } else { |
Michael Wachenschwanz | 74d967a | 2018-05-15 15:03:57 -0700 | [diff] [blame] | 139 | if ((trackedValue & COUNTING_VALUE_MASK) >= sBinderProxyCountHighWatermark) { |
| 140 | ALOGE("Too many binder proxy objects sent to uid %d from uid %d (%d proxies held)", |
| 141 | getuid(), trackedUid, trackedValue); |
| 142 | sTrackingMap[trackedUid] |= LIMIT_REACHED_MASK; |
| 143 | if (sLimitCallback) sLimitCallback(trackedUid); |
Martijn Coenen | a8d509d | 2021-09-03 18:06:24 +0200 | [diff] [blame] | 144 | sLastLimitCallbackMap[trackedUid] = trackedValue & COUNTING_VALUE_MASK; |
Michael Wachenschwanz | 74d967a | 2018-05-15 15:03:57 -0700 | [diff] [blame] | 145 | if (sBinderProxyThrottleCreate) { |
| 146 | ALOGI("Throttling binder proxy creates from uid %d in uid %d until binder proxy" |
| 147 | " count drops below %d", |
| 148 | trackedUid, getuid(), sBinderProxyCountLowWatermark); |
| 149 | return nullptr; |
| 150 | } |
| 151 | } |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 152 | } |
Michael Wachenschwanz | 74d967a | 2018-05-15 15:03:57 -0700 | [diff] [blame] | 153 | sTrackingMap[trackedUid]++; |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 154 | } |
Steven Moreland | 1a3a8ef | 2021-04-02 02:52:46 +0000 | [diff] [blame] | 155 | return sp<BpBinder>::make(BinderHandle{handle}, trackedUid); |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Steven Moreland | 5623d1a | 2021-09-10 15:45:34 -0700 | [diff] [blame] | 158 | sp<BpBinder> BpBinder::create(const sp<RpcSession>& session, uint64_t address) { |
Steven Moreland | bdb53ab | 2021-05-05 17:57:41 +0000 | [diff] [blame] | 159 | LOG_ALWAYS_FATAL_IF(session == nullptr, "BpBinder::create null session"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 161 | // These are not currently tracked, since there is no UID or other |
| 162 | // identifier to track them with. However, if similar functionality is |
Steven Moreland | bdb53ab | 2021-05-05 17:57:41 +0000 | [diff] [blame] | 163 | // needed, session objects keep track of all BpBinder objects on a |
| 164 | // per-session basis. |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 165 | |
Steven Moreland | bdb53ab | 2021-05-05 17:57:41 +0000 | [diff] [blame] | 166 | return sp<BpBinder>::make(RpcHandle{session, address}); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | BpBinder::BpBinder(Handle&& handle) |
| 170 | : mStability(0), |
| 171 | mHandle(handle), |
| 172 | mAlive(true), |
| 173 | mObitsSent(false), |
| 174 | mObituaries(nullptr), |
| 175 | mTrackedUid(-1) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | extendObjectLifetime(OBJECT_LIFETIME_WEAK); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 179 | BpBinder::BpBinder(BinderHandle&& handle, int32_t trackedUid) : BpBinder(Handle(handle)) { |
| 180 | mTrackedUid = trackedUid; |
| 181 | |
| 182 | ALOGV("Creating BpBinder %p handle %d\n", this, this->binderHandle()); |
| 183 | |
| 184 | IPCThreadState::self()->incWeakHandle(this->binderHandle(), this); |
| 185 | } |
| 186 | |
Steven Moreland | bdb53ab | 2021-05-05 17:57:41 +0000 | [diff] [blame] | 187 | BpBinder::BpBinder(RpcHandle&& handle) : BpBinder(Handle(handle)) { |
| 188 | LOG_ALWAYS_FATAL_IF(rpcSession() == nullptr, "BpBinder created w/o session object"); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | bool BpBinder::isRpcBinder() const { |
Steven Moreland | bdb53ab | 2021-05-05 17:57:41 +0000 | [diff] [blame] | 192 | return std::holds_alternative<RpcHandle>(mHandle); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Steven Moreland | 5623d1a | 2021-09-10 15:45:34 -0700 | [diff] [blame] | 195 | uint64_t BpBinder::rpcAddress() const { |
Steven Moreland | bdb53ab | 2021-05-05 17:57:41 +0000 | [diff] [blame] | 196 | return std::get<RpcHandle>(mHandle).address; |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Steven Moreland | bdb53ab | 2021-05-05 17:57:41 +0000 | [diff] [blame] | 199 | const sp<RpcSession>& BpBinder::rpcSession() const { |
| 200 | return std::get<RpcHandle>(mHandle).session; |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | int32_t BpBinder::binderHandle() const { |
| 204 | return std::get<BinderHandle>(mHandle).handle; |
Steven Moreland | 85180c0 | 2019-07-16 14:24:20 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Devin Moore | f6f2e64 | 2021-08-05 19:03:47 +0000 | [diff] [blame] | 207 | std::optional<int32_t> BpBinder::getDebugBinderHandle() const { |
| 208 | if (!isRpcBinder()) { |
| 209 | return binderHandle(); |
| 210 | } else { |
| 211 | return std::nullopt; |
| 212 | } |
| 213 | } |
| 214 | |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 215 | bool BpBinder::isDescriptorCached() const { |
| 216 | Mutex::Autolock _l(mLock); |
| 217 | return mDescriptorCache.size() ? true : false; |
| 218 | } |
| 219 | |
| 220 | const String16& BpBinder::getInterfaceDescriptor() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 222 | if (isDescriptorCached() == false) { |
Steven Moreland | 1a3a8ef | 2021-04-02 02:52:46 +0000 | [diff] [blame] | 223 | sp<BpBinder> thiz = sp<BpBinder>::fromExisting(const_cast<BpBinder*>(this)); |
Steven Moreland | 4cf688f | 2021-03-31 01:48:58 +0000 | [diff] [blame] | 224 | |
| 225 | Parcel data; |
| 226 | data.markForBinder(thiz); |
| 227 | Parcel reply; |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 228 | // do the IPC without a lock held. |
Steven Moreland | 4cf688f | 2021-03-31 01:48:58 +0000 | [diff] [blame] | 229 | status_t err = thiz->transact(INTERFACE_TRANSACTION, data, &reply); |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 230 | if (err == NO_ERROR) { |
| 231 | String16 res(reply.readString16()); |
| 232 | Mutex::Autolock _l(mLock); |
| 233 | // mDescriptorCache could have been assigned while the lock was |
| 234 | // released. |
| 235 | if (mDescriptorCache.size() == 0) |
| 236 | mDescriptorCache = res; |
| 237 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | } |
Mark Salyzyn | d4ecccf | 2014-05-30 16:35:57 -0700 | [diff] [blame] | 239 | |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 240 | // we're returning a reference to a non-static object here. Usually this |
Mark Salyzyn | d4ecccf | 2014-05-30 16:35:57 -0700 | [diff] [blame] | 241 | // is not something smart to do, however, with binder objects it is |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 242 | // (usually) safe because they are reference-counted. |
Mark Salyzyn | d4ecccf | 2014-05-30 16:35:57 -0700 | [diff] [blame] | 243 | |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 244 | return mDescriptorCache; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | bool BpBinder::isBinderAlive() const |
| 248 | { |
Steven Moreland | 06074d8 | 2020-03-05 23:16:51 +0000 | [diff] [blame] | 249 | return mAlive != 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | status_t BpBinder::pingBinder() |
| 253 | { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 254 | Parcel data; |
Steven Moreland | 1a3a8ef | 2021-04-02 02:52:46 +0000 | [diff] [blame] | 255 | data.markForBinder(sp<BpBinder>::fromExisting(this)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | Parcel reply; |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 257 | return transact(PING_TRANSACTION, data, &reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | status_t BpBinder::dump(int fd, const Vector<String16>& args) |
| 261 | { |
| 262 | Parcel send; |
| 263 | Parcel reply; |
| 264 | send.writeFileDescriptor(fd); |
| 265 | const size_t numArgs = args.size(); |
| 266 | send.writeInt32(numArgs); |
| 267 | for (size_t i = 0; i < numArgs; i++) { |
| 268 | send.writeString16(args[i]); |
| 269 | } |
| 270 | status_t err = transact(DUMP_TRANSACTION, send, &reply); |
| 271 | return err; |
| 272 | } |
| 273 | |
Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 274 | // NOLINTNEXTLINE(google-default-arguments) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | status_t BpBinder::transact( |
| 276 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 277 | { |
| 278 | // Once a binder has died, it will never come back to life. |
| 279 | if (mAlive) { |
Steven Moreland | 46b5fea | 2019-10-15 11:22:18 -0700 | [diff] [blame] | 280 | bool privateVendor = flags & FLAG_PRIVATE_VENDOR; |
| 281 | // don't send userspace flags to the kernel |
| 282 | flags = flags & ~FLAG_PRIVATE_VENDOR; |
| 283 | |
Steven Moreland | 6e5a775 | 2019-08-05 20:30:14 -0700 | [diff] [blame] | 284 | // user transactions require a given stability level |
| 285 | if (code >= FIRST_CALL_TRANSACTION && code <= LAST_CALL_TRANSACTION) { |
| 286 | using android::internal::Stability; |
| 287 | |
Steven Moreland | 16a4106 | 2021-07-23 13:35:25 -0700 | [diff] [blame] | 288 | int16_t stability = Stability::getRepr(this); |
Steven Moreland | 89ddfc5 | 2020-11-13 02:39:26 +0000 | [diff] [blame] | 289 | Stability::Level required = privateVendor ? Stability::VENDOR |
| 290 | : Stability::getLocalLevel(); |
Steven Moreland | 6e5a775 | 2019-08-05 20:30:14 -0700 | [diff] [blame] | 291 | |
Steven Moreland | 16a4106 | 2021-07-23 13:35:25 -0700 | [diff] [blame] | 292 | if (CC_UNLIKELY(!Stability::check(stability, required))) { |
Steven Moreland | b269b58 | 2021-02-10 17:09:11 +0000 | [diff] [blame] | 293 | ALOGE("Cannot do a user transaction on a %s binder (%s) in a %s context.", |
Steven Moreland | 16a4106 | 2021-07-23 13:35:25 -0700 | [diff] [blame] | 294 | Stability::levelString(stability).c_str(), |
| 295 | String8(getInterfaceDescriptor()).c_str(), |
| 296 | Stability::levelString(required).c_str()); |
Steven Moreland | 6e5a775 | 2019-08-05 20:30:14 -0700 | [diff] [blame] | 297 | return BAD_TYPE; |
| 298 | } |
| 299 | } |
| 300 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 301 | status_t status; |
| 302 | if (CC_UNLIKELY(isRpcBinder())) { |
Steven Moreland | f517427 | 2021-05-25 00:39:28 +0000 | [diff] [blame] | 303 | status = rpcSession()->transact(sp<IBinder>::fromExisting(this), code, data, reply, |
| 304 | flags); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 305 | } else { |
| 306 | status = IPCThreadState::self()->transact(binderHandle(), code, data, reply, flags); |
| 307 | } |
Martijn Coenen | 1cad19c | 2021-10-04 09:19:01 +0200 | [diff] [blame] | 308 | if (data.dataSize() > LOG_TRANSACTIONS_OVER_SIZE) { |
| 309 | Mutex::Autolock _l(mLock); |
| 310 | ALOGW("Large outgoing transaction of %zu bytes, interface descriptor %s, code %d", |
| 311 | data.dataSize(), |
| 312 | mDescriptorCache.size() ? String8(mDescriptorCache).c_str() |
| 313 | : "<uncached descriptor>", |
| 314 | code); |
| 315 | } |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 316 | |
Steven Moreland | 06074d8 | 2020-03-05 23:16:51 +0000 | [diff] [blame] | 317 | if (status == DEAD_OBJECT) mAlive = 0; |
Steven Moreland | a86a356 | 2019-08-01 23:28:34 +0000 | [diff] [blame] | 318 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | return status; |
| 320 | } |
| 321 | |
| 322 | return DEAD_OBJECT; |
| 323 | } |
| 324 | |
Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 325 | // NOLINTNEXTLINE(google-default-arguments) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | status_t BpBinder::linkToDeath( |
| 327 | const sp<DeathRecipient>& recipient, void* cookie, uint32_t flags) |
| 328 | { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 329 | if (isRpcBinder()) return UNKNOWN_TRANSACTION; |
| 330 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | Obituary ob; |
| 332 | ob.recipient = recipient; |
| 333 | ob.cookie = cookie; |
| 334 | ob.flags = flags; |
| 335 | |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 336 | LOG_ALWAYS_FATAL_IF(recipient == nullptr, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | "linkToDeath(): recipient must be non-NULL"); |
| 338 | |
| 339 | { |
| 340 | AutoMutex _l(mLock); |
| 341 | |
| 342 | if (!mObitsSent) { |
| 343 | if (!mObituaries) { |
| 344 | mObituaries = new Vector<Obituary>; |
| 345 | if (!mObituaries) { |
| 346 | return NO_MEMORY; |
| 347 | } |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 348 | ALOGV("Requesting death notification: %p handle %d\n", this, binderHandle()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | getWeakRefs()->incWeak(this); |
| 350 | IPCThreadState* self = IPCThreadState::self(); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 351 | self->requestDeathNotification(binderHandle(), this); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | self->flushCommands(); |
| 353 | } |
| 354 | ssize_t res = mObituaries->add(ob); |
| 355 | return res >= (ssize_t)NO_ERROR ? (status_t)NO_ERROR : res; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | return DEAD_OBJECT; |
| 360 | } |
| 361 | |
Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 362 | // NOLINTNEXTLINE(google-default-arguments) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | status_t BpBinder::unlinkToDeath( |
| 364 | const wp<DeathRecipient>& recipient, void* cookie, uint32_t flags, |
| 365 | wp<DeathRecipient>* outRecipient) |
| 366 | { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 367 | if (isRpcBinder()) return UNKNOWN_TRANSACTION; |
| 368 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | AutoMutex _l(mLock); |
| 370 | |
| 371 | if (mObitsSent) { |
| 372 | return DEAD_OBJECT; |
| 373 | } |
| 374 | |
| 375 | const size_t N = mObituaries ? mObituaries->size() : 0; |
| 376 | for (size_t i=0; i<N; i++) { |
| 377 | const Obituary& obit = mObituaries->itemAt(i); |
| 378 | if ((obit.recipient == recipient |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 379 | || (recipient == nullptr && obit.cookie == cookie)) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | && obit.flags == flags) { |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 381 | if (outRecipient != nullptr) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | *outRecipient = mObituaries->itemAt(i).recipient; |
| 383 | } |
| 384 | mObituaries->removeAt(i); |
| 385 | if (mObituaries->size() == 0) { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 386 | ALOGV("Clearing death notification: %p handle %d\n", this, binderHandle()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | IPCThreadState* self = IPCThreadState::self(); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 388 | self->clearDeathNotification(binderHandle(), this); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | self->flushCommands(); |
| 390 | delete mObituaries; |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 391 | mObituaries = nullptr; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | } |
| 393 | return NO_ERROR; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | return NAME_NOT_FOUND; |
| 398 | } |
| 399 | |
| 400 | void BpBinder::sendObituary() |
| 401 | { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 402 | LOG_ALWAYS_FATAL_IF(isRpcBinder(), "Cannot send obituary for remote binder."); |
| 403 | |
| 404 | ALOGV("Sending obituary for proxy %p handle %d, mObitsSent=%s\n", this, binderHandle(), |
| 405 | mObitsSent ? "true" : "false"); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | |
Steven Moreland | 06074d8 | 2020-03-05 23:16:51 +0000 | [diff] [blame] | 407 | mAlive = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | if (mObitsSent) return; |
| 409 | |
| 410 | mLock.lock(); |
| 411 | Vector<Obituary>* obits = mObituaries; |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 412 | if(obits != nullptr) { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 413 | ALOGV("Clearing sent death notification: %p handle %d\n", this, binderHandle()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | IPCThreadState* self = IPCThreadState::self(); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 415 | self->clearDeathNotification(binderHandle(), this); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | self->flushCommands(); |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 417 | mObituaries = nullptr; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | } |
Steven Moreland | 06074d8 | 2020-03-05 23:16:51 +0000 | [diff] [blame] | 419 | mObitsSent = 1; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | mLock.unlock(); |
| 421 | |
Mark Salyzyn | d4ecccf | 2014-05-30 16:35:57 -0700 | [diff] [blame] | 422 | ALOGV("Reporting death of proxy %p for %zu recipients\n", |
| 423 | this, obits ? obits->size() : 0U); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 425 | if (obits != nullptr) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | const size_t N = obits->size(); |
| 427 | for (size_t i=0; i<N; i++) { |
| 428 | reportOneDeath(obits->itemAt(i)); |
| 429 | } |
| 430 | |
| 431 | delete obits; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | void BpBinder::reportOneDeath(const Obituary& obit) |
| 436 | { |
| 437 | sp<DeathRecipient> recipient = obit.recipient.promote(); |
Steve Block | 6807e59 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 438 | ALOGV("Reporting death to recipient: %p\n", recipient.get()); |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 439 | if (recipient == nullptr) return; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | |
Steven Moreland | 1a3a8ef | 2021-04-02 02:52:46 +0000 | [diff] [blame] | 441 | recipient->binderDied(wp<BpBinder>::fromExisting(this)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | } |
| 443 | |
Steven Moreland | 63a2d51 | 2021-06-25 01:10:15 +0000 | [diff] [blame] | 444 | void* BpBinder::attachObject(const void* objectID, void* object, void* cleanupCookie, |
| 445 | object_cleanup_func func) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | AutoMutex _l(mLock); |
Steve Block | 6807e59 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 447 | ALOGV("Attaching object %p to binder %p (manager=%p)", object, this, &mObjects); |
Steven Moreland | 63a2d51 | 2021-06-25 01:10:15 +0000 | [diff] [blame] | 448 | return mObjects.attach(objectID, object, cleanupCookie, func); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | void* BpBinder::findObject(const void* objectID) const |
| 452 | { |
| 453 | AutoMutex _l(mLock); |
| 454 | return mObjects.find(objectID); |
| 455 | } |
| 456 | |
Steven Moreland | 63a2d51 | 2021-06-25 01:10:15 +0000 | [diff] [blame] | 457 | void* BpBinder::detachObject(const void* objectID) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | AutoMutex _l(mLock); |
Steven Moreland | 63a2d51 | 2021-06-25 01:10:15 +0000 | [diff] [blame] | 459 | return mObjects.detach(objectID); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | } |
| 461 | |
Steven Moreland | 9e759e8 | 2021-06-25 21:30:23 +0000 | [diff] [blame] | 462 | void BpBinder::withLock(const std::function<void()>& doWithLock) { |
| 463 | AutoMutex _l(mLock); |
| 464 | doWithLock(); |
| 465 | } |
| 466 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | BpBinder* BpBinder::remoteBinder() |
| 468 | { |
| 469 | return this; |
| 470 | } |
| 471 | |
| 472 | BpBinder::~BpBinder() |
| 473 | { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 474 | ALOGV("Destroying BpBinder %p handle %d\n", this, binderHandle()); |
| 475 | |
| 476 | if (CC_UNLIKELY(isRpcBinder())) return; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | |
| 478 | IPCThreadState* ipc = IPCThreadState::self(); |
| 479 | |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 480 | if (mTrackedUid >= 0) { |
| 481 | AutoMutex _l(sTrackingLock); |
Michael Wachenschwanz | 74d967a | 2018-05-15 15:03:57 -0700 | [diff] [blame] | 482 | uint32_t trackedValue = sTrackingMap[mTrackedUid]; |
| 483 | if (CC_UNLIKELY((trackedValue & COUNTING_VALUE_MASK) == 0)) { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 484 | ALOGE("Unexpected Binder Proxy tracking decrement in %p handle %d\n", this, |
| 485 | binderHandle()); |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 486 | } else { |
| 487 | if (CC_UNLIKELY( |
Michael Wachenschwanz | 74d967a | 2018-05-15 15:03:57 -0700 | [diff] [blame] | 488 | (trackedValue & LIMIT_REACHED_MASK) && |
| 489 | ((trackedValue & COUNTING_VALUE_MASK) <= sBinderProxyCountLowWatermark) |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 490 | )) { |
Michael Wachenschwanz | 74d967a | 2018-05-15 15:03:57 -0700 | [diff] [blame] | 491 | ALOGI("Limit reached bit reset for uid %d (fewer than %d proxies from uid %d held)", |
Martijn Coenen | a8d509d | 2021-09-03 18:06:24 +0200 | [diff] [blame] | 492 | getuid(), sBinderProxyCountLowWatermark, mTrackedUid); |
Michael Wachenschwanz | 74d967a | 2018-05-15 15:03:57 -0700 | [diff] [blame] | 493 | sTrackingMap[mTrackedUid] &= ~LIMIT_REACHED_MASK; |
Martijn Coenen | a8d509d | 2021-09-03 18:06:24 +0200 | [diff] [blame] | 494 | sLastLimitCallbackMap.erase(mTrackedUid); |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 495 | } |
| 496 | if (--sTrackingMap[mTrackedUid] == 0) { |
| 497 | sTrackingMap.erase(mTrackedUid); |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | if (ipc) { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 503 | ipc->expungeHandle(binderHandle(), this); |
| 504 | ipc->decWeakHandle(binderHandle()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| 508 | void BpBinder::onFirstRef() |
| 509 | { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 510 | ALOGV("onFirstRef BpBinder %p handle %d\n", this, binderHandle()); |
| 511 | if (CC_UNLIKELY(isRpcBinder())) return; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | IPCThreadState* ipc = IPCThreadState::self(); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 513 | if (ipc) ipc->incStrongHandle(binderHandle(), this); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Colin Cross | 6f4f3ab | 2014-02-05 17:42:44 -0800 | [diff] [blame] | 516 | void BpBinder::onLastStrongRef(const void* /*id*/) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 518 | ALOGV("onLastStrongRef BpBinder %p handle %d\n", this, binderHandle()); |
| 519 | if (CC_UNLIKELY(isRpcBinder())) { |
Steven Moreland | 4f622fe | 2021-09-13 17:38:09 -0700 | [diff] [blame] | 520 | (void)rpcSession()->sendDecStrong(this); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 521 | return; |
| 522 | } |
Steve Block | 6807e59 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 523 | IF_ALOGV() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | printRefs(); |
| 525 | } |
| 526 | IPCThreadState* ipc = IPCThreadState::self(); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 527 | if (ipc) ipc->decStrongHandle(binderHandle()); |
Steven Moreland | 80d2393 | 2019-06-07 12:43:27 -0700 | [diff] [blame] | 528 | |
| 529 | mLock.lock(); |
| 530 | Vector<Obituary>* obits = mObituaries; |
| 531 | if(obits != nullptr) { |
| 532 | if (!obits->isEmpty()) { |
Steven Moreland | 70fcb4e | 2019-12-13 17:28:58 -0800 | [diff] [blame] | 533 | ALOGI("onLastStrongRef automatically unlinking death recipients: %s", |
| 534 | mDescriptorCache.size() ? String8(mDescriptorCache).c_str() : "<uncached descriptor>"); |
Steven Moreland | 80d2393 | 2019-06-07 12:43:27 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 537 | if (ipc) ipc->clearDeathNotification(binderHandle(), this); |
Steven Moreland | 80d2393 | 2019-06-07 12:43:27 -0700 | [diff] [blame] | 538 | mObituaries = nullptr; |
| 539 | } |
| 540 | mLock.unlock(); |
| 541 | |
| 542 | if (obits != nullptr) { |
| 543 | // XXX Should we tell any remaining DeathRecipient |
| 544 | // objects that the last strong ref has gone away, so they |
| 545 | // are no longer linked? |
| 546 | delete obits; |
| 547 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Colin Cross | 6f4f3ab | 2014-02-05 17:42:44 -0800 | [diff] [blame] | 550 | bool BpBinder::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | { |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 552 | // RPC binder doesn't currently support inc from weak binders |
| 553 | if (CC_UNLIKELY(isRpcBinder())) return false; |
| 554 | |
| 555 | ALOGV("onIncStrongAttempted BpBinder %p handle %d\n", this, binderHandle()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | IPCThreadState* ipc = IPCThreadState::self(); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 557 | return ipc ? ipc->attemptIncStrongHandle(binderHandle()) == NO_ERROR : false; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Michael Wachenschwanz | d296d0c | 2017-08-15 00:57:14 -0700 | [diff] [blame] | 560 | uint32_t BpBinder::getBinderProxyCount(uint32_t uid) |
| 561 | { |
| 562 | AutoMutex _l(sTrackingLock); |
| 563 | auto it = sTrackingMap.find(uid); |
| 564 | if (it != sTrackingMap.end()) { |
| 565 | return it->second & COUNTING_VALUE_MASK; |
| 566 | } |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | void BpBinder::getCountByUid(Vector<uint32_t>& uids, Vector<uint32_t>& counts) |
| 571 | { |
| 572 | AutoMutex _l(sTrackingLock); |
| 573 | uids.setCapacity(sTrackingMap.size()); |
| 574 | counts.setCapacity(sTrackingMap.size()); |
| 575 | for (const auto& it : sTrackingMap) { |
| 576 | uids.push_back(it.first); |
| 577 | counts.push_back(it.second & COUNTING_VALUE_MASK); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | void BpBinder::enableCountByUid() { sCountByUidEnabled.store(true); } |
| 582 | void BpBinder::disableCountByUid() { sCountByUidEnabled.store(false); } |
| 583 | void BpBinder::setCountByUidEnabled(bool enable) { sCountByUidEnabled.store(enable); } |
| 584 | |
| 585 | void BpBinder::setLimitCallback(binder_proxy_limit_callback cb) { |
| 586 | AutoMutex _l(sTrackingLock); |
| 587 | sLimitCallback = cb; |
| 588 | } |
| 589 | |
| 590 | void BpBinder::setBinderProxyCountWatermarks(int high, int low) { |
| 591 | AutoMutex _l(sTrackingLock); |
| 592 | sBinderProxyCountHighWatermark = high; |
| 593 | sBinderProxyCountLowWatermark = low; |
| 594 | } |
| 595 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | // --------------------------------------------------------------------------- |
| 597 | |
Steven Moreland | 61ff849 | 2019-09-26 16:05:45 -0700 | [diff] [blame] | 598 | } // namespace android |