blob: 54457fc5686e617d24fd81c95d3b827f441cb820 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Agopianc5b2c0b2009-05-19 19:08:10 -070020#include <binder/BpBinder.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070022#include <binder/IPCThreadState.h>
Dianne Hackborn23eb1e22015-10-07 17:35:27 -070023#include <binder/IResultReceiver.h>
Steven Morelandbdb53ab2021-05-05 17:57:41 +000024#include <binder/RpcSession.h>
Steven Moreland6e5a7752019-08-05 20:30:14 -070025#include <binder/Stability.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
27#include <stdio.h>
28
Steven Moreland32150282021-11-12 22:54:53 +000029#include "BuildFlags.h"
Tomasz Wasilczyk26db5e42023-11-02 11:45:11 -070030#include "file.h"
Sahil Somani2522b072022-08-08 14:07:47 -070031
Steve Block6807e592011-10-20 11:56:00 +010032//#undef ALOGV
33//#define ALOGV(...) fprintf(stderr, __VA_ARGS__)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034
35namespace android {
36
Tomasz Wasilczyk639490b2023-11-01 13:49:41 -070037using android::binder::unique_fd;
38
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039// ---------------------------------------------------------------------------
40
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -070041RpcMutex BpBinder::sTrackingLock;
Martijn Coenena8d509d2021-09-03 18:06:24 +020042std::unordered_map<int32_t, uint32_t> BpBinder::sTrackingMap;
43std::unordered_map<int32_t, uint32_t> BpBinder::sLastLimitCallbackMap;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070044int BpBinder::sNumTrackedUids = 0;
45std::atomic_bool BpBinder::sCountByUidEnabled(false);
46binder_proxy_limit_callback BpBinder::sLimitCallback;
Jing Jibdbe29a2023-10-03 00:03:28 -070047binder_proxy_warning_callback BpBinder::sWarningCallback;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070048bool BpBinder::sBinderProxyThrottleCreate = false;
49
Steven Moreland847d8c52023-05-02 23:56:58 +000050static StaticString16 kDescriptorUninit(u"");
Steven Morelandf2830fe2022-12-21 00:45:34 +000051
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070052// Arbitrarily high value that probably distinguishes a bad behaving app
53uint32_t BpBinder::sBinderProxyCountHighWatermark = 2500;
54// Another arbitrary value a binder count needs to drop below before another callback will be called
55uint32_t BpBinder::sBinderProxyCountLowWatermark = 2000;
Jing Jibdbe29a2023-10-03 00:03:28 -070056// Arbitrary value between low and high watermark on a bad behaving app to
57// trigger a warning callback.
58uint32_t BpBinder::sBinderProxyCountWarningWatermark = 2250;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070059
Jing Ji4c4ac062023-10-07 15:20:23 -070060std::atomic<uint32_t> BpBinder::sBinderProxyCount(0);
61std::atomic<uint32_t> BpBinder::sBinderProxyCountWarned(0);
62
63static constexpr uint32_t kBinderProxyCountWarnInterval = 5000;
64
Martijn Coenen1cad19c2021-10-04 09:19:01 +020065// Log any transactions for which the data exceeds this size
66#define LOG_TRANSACTIONS_OVER_SIZE (300 * 1024)
67
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070068enum {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -070069 LIMIT_REACHED_MASK = 0x80000000, // A flag denoting that the limit has been reached
Jing Jibdbe29a2023-10-03 00:03:28 -070070 WARNING_REACHED_MASK = 0x40000000, // A flag denoting that the warning has been reached
71 COUNTING_VALUE_MASK = 0x3FFFFFFF, // A mask of the remaining bits for the count value
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070072};
73
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074BpBinder::ObjectManager::ObjectManager()
75{
76}
77
78BpBinder::ObjectManager::~ObjectManager()
79{
80 kill();
81}
82
Steven Moreland63a2d512021-06-25 01:10:15 +000083void* BpBinder::ObjectManager::attach(const void* objectID, void* object, void* cleanupCookie,
84 IBinder::object_cleanup_func func) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085 entry_t e;
86 e.object = object;
87 e.cleanupCookie = cleanupCookie;
88 e.func = func;
89
Jiyong Park5970d0a2022-03-08 16:56:13 +090090 if (mObjects.find(objectID) != mObjects.end()) {
Steven Moreland63a2d512021-06-25 01:10:15 +000091 ALOGI("Trying to attach object ID %p to binder ObjectManager %p with object %p, but object "
92 "ID already in use",
93 objectID, this, object);
Jiyong Park5970d0a2022-03-08 16:56:13 +090094 return mObjects[objectID].object;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095 }
96
Jiyong Park5970d0a2022-03-08 16:56:13 +090097 mObjects.insert({objectID, e});
Steven Moreland63a2d512021-06-25 01:10:15 +000098 return nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099}
100
101void* BpBinder::ObjectManager::find(const void* objectID) const
102{
Jiyong Park5970d0a2022-03-08 16:56:13 +0900103 auto i = mObjects.find(objectID);
104 if (i == mObjects.end()) return nullptr;
105 return i->second.object;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106}
107
Steven Moreland63a2d512021-06-25 01:10:15 +0000108void* BpBinder::ObjectManager::detach(const void* objectID) {
Jiyong Park5970d0a2022-03-08 16:56:13 +0900109 auto i = mObjects.find(objectID);
110 if (i == mObjects.end()) return nullptr;
111 void* value = i->second.object;
112 mObjects.erase(i);
Steven Moreland63a2d512021-06-25 01:10:15 +0000113 return value;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800114}
115
Devin Moore3faaa002022-07-27 15:54:06 +0000116namespace {
117struct Tag {
118 wp<IBinder> binder;
119};
120} // namespace
121
122static void cleanWeak(const void* /* id */, void* obj, void* /* cookie */) {
123 delete static_cast<Tag*>(obj);
124}
125
126sp<IBinder> BpBinder::ObjectManager::lookupOrCreateWeak(const void* objectID, object_make_func make,
127 const void* makeArgs) {
128 entry_t& e = mObjects[objectID];
129 if (e.object != nullptr) {
130 if (auto attached = static_cast<Tag*>(e.object)->binder.promote()) {
131 return attached;
132 }
133 } else {
134 e.object = new Tag;
135 LOG_ALWAYS_FATAL_IF(!e.object, "no more memory");
136 }
137 sp<IBinder> newObj = make(makeArgs);
138
139 static_cast<Tag*>(e.object)->binder = newObj;
140 e.cleanupCookie = nullptr;
141 e.func = cleanWeak;
142
143 return newObj;
144}
145
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146void BpBinder::ObjectManager::kill()
147{
148 const size_t N = mObjects.size();
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700149 ALOGV("Killing %zu objects in manager %p", N, this);
Jiyong Park5970d0a2022-03-08 16:56:13 +0900150 for (auto i : mObjects) {
151 const entry_t& e = i.second;
Yi Kongfdd8da92018-06-07 17:52:27 -0700152 if (e.func != nullptr) {
Jiyong Park5970d0a2022-03-08 16:56:13 +0900153 e.func(i.first, e.object, e.cleanupCookie);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800154 }
155 }
156
157 mObjects.clear();
158}
159
160// ---------------------------------------------------------------------------
161
Steven Moreland1a3a8ef2021-04-02 02:52:46 +0000162sp<BpBinder> BpBinder::create(int32_t handle) {
Steven Moreland32150282021-11-12 22:54:53 +0000163 if constexpr (!kEnableKernelIpc) {
164 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
165 return nullptr;
166 }
167
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700168 int32_t trackedUid = -1;
169 if (sCountByUidEnabled) {
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700170 trackedUid = IPCThreadState::self()->getCallingUid();
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700171 RpcMutexUniqueLock _l(sTrackingLock);
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700172 uint32_t trackedValue = sTrackingMap[trackedUid];
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000173 if (trackedValue & LIMIT_REACHED_MASK) [[unlikely]] {
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700174 if (sBinderProxyThrottleCreate) {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700175 return nullptr;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700176 }
Martijn Coenena8d509d2021-09-03 18:06:24 +0200177 trackedValue = trackedValue & COUNTING_VALUE_MASK;
178 uint32_t lastLimitCallbackAt = sLastLimitCallbackMap[trackedUid];
179
180 if (trackedValue > lastLimitCallbackAt &&
Martijn Coenen6711b6d2021-09-23 09:44:29 +0200181 (trackedValue - lastLimitCallbackAt > sBinderProxyCountHighWatermark)) {
Martijn Coenena8d509d2021-09-03 18:06:24 +0200182 ALOGE("Still too many binder proxy objects sent to uid %d from uid %d (%d proxies "
183 "held)",
184 getuid(), trackedUid, trackedValue);
185 if (sLimitCallback) sLimitCallback(trackedUid);
186 sLastLimitCallbackMap[trackedUid] = trackedValue;
187 }
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700188 } else {
Jing Jibdbe29a2023-10-03 00:03:28 -0700189 uint32_t currentValue = trackedValue & COUNTING_VALUE_MASK;
190 if (currentValue >= sBinderProxyCountWarningWatermark
191 && currentValue < sBinderProxyCountHighWatermark
192 && ((trackedValue & WARNING_REACHED_MASK) == 0)) [[unlikely]] {
193 sTrackingMap[trackedUid] |= WARNING_REACHED_MASK;
194 if (sWarningCallback) sWarningCallback(trackedUid);
195 } else if (currentValue >= sBinderProxyCountHighWatermark) {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700196 ALOGE("Too many binder proxy objects sent to uid %d from uid %d (%d proxies held)",
197 getuid(), trackedUid, trackedValue);
198 sTrackingMap[trackedUid] |= LIMIT_REACHED_MASK;
199 if (sLimitCallback) sLimitCallback(trackedUid);
Martijn Coenena8d509d2021-09-03 18:06:24 +0200200 sLastLimitCallbackMap[trackedUid] = trackedValue & COUNTING_VALUE_MASK;
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700201 if (sBinderProxyThrottleCreate) {
202 ALOGI("Throttling binder proxy creates from uid %d in uid %d until binder proxy"
203 " count drops below %d",
204 trackedUid, getuid(), sBinderProxyCountLowWatermark);
205 return nullptr;
206 }
207 }
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700208 }
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700209 sTrackingMap[trackedUid]++;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700210 }
Jing Ji4c4ac062023-10-07 15:20:23 -0700211 uint32_t numProxies = sBinderProxyCount.fetch_add(1, std::memory_order_relaxed);
212 uint32_t numLastWarned = sBinderProxyCountWarned.load(std::memory_order_relaxed);
213 uint32_t numNextWarn = numLastWarned + kBinderProxyCountWarnInterval;
214 if (numProxies >= numNextWarn) {
215 // Multiple threads can get here, make sure only one of them gets to
216 // update the warn counter.
217 if (sBinderProxyCountWarned.compare_exchange_strong(numLastWarned,
218 numNextWarn,
219 std::memory_order_relaxed)) {
220 ALOGW("Unexpectedly many live BinderProxies: %d\n", numProxies);
221 }
222 }
Steven Moreland1a3a8ef2021-04-02 02:52:46 +0000223 return sp<BpBinder>::make(BinderHandle{handle}, trackedUid);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700224}
225
Steven Moreland5623d1a2021-09-10 15:45:34 -0700226sp<BpBinder> BpBinder::create(const sp<RpcSession>& session, uint64_t address) {
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000227 LOG_ALWAYS_FATAL_IF(session == nullptr, "BpBinder::create null session");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800228
Steven Moreland5553ac42020-11-11 02:14:45 +0000229 // These are not currently tracked, since there is no UID or other
230 // identifier to track them with. However, if similar functionality is
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000231 // needed, session objects keep track of all BpBinder objects on a
232 // per-session basis.
Steven Moreland5553ac42020-11-11 02:14:45 +0000233
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000234 return sp<BpBinder>::make(RpcHandle{session, address});
Steven Moreland5553ac42020-11-11 02:14:45 +0000235}
236
237BpBinder::BpBinder(Handle&& handle)
238 : mStability(0),
239 mHandle(handle),
240 mAlive(true),
241 mObitsSent(false),
242 mObituaries(nullptr),
Steven Morelandf2830fe2022-12-21 00:45:34 +0000243 mDescriptorCache(kDescriptorUninit),
Steven Moreland5553ac42020-11-11 02:14:45 +0000244 mTrackedUid(-1) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800245 extendObjectLifetime(OBJECT_LIFETIME_WEAK);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800246}
247
Steven Moreland5553ac42020-11-11 02:14:45 +0000248BpBinder::BpBinder(BinderHandle&& handle, int32_t trackedUid) : BpBinder(Handle(handle)) {
Steven Moreland32150282021-11-12 22:54:53 +0000249 if constexpr (!kEnableKernelIpc) {
250 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
251 return;
252 }
253
Steven Moreland5553ac42020-11-11 02:14:45 +0000254 mTrackedUid = trackedUid;
255
256 ALOGV("Creating BpBinder %p handle %d\n", this, this->binderHandle());
257
258 IPCThreadState::self()->incWeakHandle(this->binderHandle(), this);
259}
260
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000261BpBinder::BpBinder(RpcHandle&& handle) : BpBinder(Handle(handle)) {
262 LOG_ALWAYS_FATAL_IF(rpcSession() == nullptr, "BpBinder created w/o session object");
Steven Moreland5553ac42020-11-11 02:14:45 +0000263}
264
265bool BpBinder::isRpcBinder() const {
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000266 return std::holds_alternative<RpcHandle>(mHandle);
Steven Moreland5553ac42020-11-11 02:14:45 +0000267}
268
Steven Moreland5623d1a2021-09-10 15:45:34 -0700269uint64_t BpBinder::rpcAddress() const {
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000270 return std::get<RpcHandle>(mHandle).address;
Steven Moreland5553ac42020-11-11 02:14:45 +0000271}
272
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000273const sp<RpcSession>& BpBinder::rpcSession() const {
274 return std::get<RpcHandle>(mHandle).session;
Steven Moreland5553ac42020-11-11 02:14:45 +0000275}
276
277int32_t BpBinder::binderHandle() const {
278 return std::get<BinderHandle>(mHandle).handle;
Steven Moreland85180c02019-07-16 14:24:20 -0700279}
280
Devin Mooref6f2e642021-08-05 19:03:47 +0000281std::optional<int32_t> BpBinder::getDebugBinderHandle() const {
282 if (!isRpcBinder()) {
283 return binderHandle();
284 } else {
285 return std::nullopt;
286 }
287}
288
Mathias Agopian83c04462009-05-22 19:00:22 -0700289bool BpBinder::isDescriptorCached() const {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700290 RpcMutexUniqueLock _l(mLock);
Tomasz Wasilczyk0bfea2d2023-08-11 00:06:51 +0000291 return mDescriptorCache.c_str() != kDescriptorUninit.c_str();
Mathias Agopian83c04462009-05-22 19:00:22 -0700292}
293
294const String16& BpBinder::getInterfaceDescriptor() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800295{
Steven Morelandf2830fe2022-12-21 00:45:34 +0000296 if (!isDescriptorCached()) {
Steven Moreland1a3a8ef2021-04-02 02:52:46 +0000297 sp<BpBinder> thiz = sp<BpBinder>::fromExisting(const_cast<BpBinder*>(this));
Steven Moreland4cf688f2021-03-31 01:48:58 +0000298
299 Parcel data;
300 data.markForBinder(thiz);
301 Parcel reply;
Mathias Agopian83c04462009-05-22 19:00:22 -0700302 // do the IPC without a lock held.
Steven Moreland4cf688f2021-03-31 01:48:58 +0000303 status_t err = thiz->transact(INTERFACE_TRANSACTION, data, &reply);
Mathias Agopian83c04462009-05-22 19:00:22 -0700304 if (err == NO_ERROR) {
305 String16 res(reply.readString16());
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700306 RpcMutexUniqueLock _l(mLock);
Mathias Agopian83c04462009-05-22 19:00:22 -0700307 // mDescriptorCache could have been assigned while the lock was
308 // released.
Tomasz Wasilczyk0bfea2d2023-08-11 00:06:51 +0000309 if (mDescriptorCache.c_str() == kDescriptorUninit.c_str()) mDescriptorCache = res;
Mathias Agopian83c04462009-05-22 19:00:22 -0700310 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800311 }
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700312
Mathias Agopian83c04462009-05-22 19:00:22 -0700313 // we're returning a reference to a non-static object here. Usually this
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700314 // is not something smart to do, however, with binder objects it is
Mathias Agopian83c04462009-05-22 19:00:22 -0700315 // (usually) safe because they are reference-counted.
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700316
Mathias Agopian83c04462009-05-22 19:00:22 -0700317 return mDescriptorCache;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800318}
319
320bool BpBinder::isBinderAlive() const
321{
Steven Moreland06074d82020-03-05 23:16:51 +0000322 return mAlive != 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800323}
324
325status_t BpBinder::pingBinder()
326{
Steven Moreland5553ac42020-11-11 02:14:45 +0000327 Parcel data;
Steven Moreland1a3a8ef2021-04-02 02:52:46 +0000328 data.markForBinder(sp<BpBinder>::fromExisting(this));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800329 Parcel reply;
Steven Moreland5553ac42020-11-11 02:14:45 +0000330 return transact(PING_TRANSACTION, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800331}
332
Tomasz Wasilczyk639490b2023-11-01 13:49:41 -0700333status_t BpBinder::startRecordingBinder(const unique_fd& fd) {
Sahil Somani2522b072022-08-08 14:07:47 -0700334 Parcel send, reply;
335 send.writeUniqueFileDescriptor(fd);
336 return transact(START_RECORDING_TRANSACTION, send, &reply);
337}
338
339status_t BpBinder::stopRecordingBinder() {
340 Parcel data, reply;
341 data.markForBinder(sp<BpBinder>::fromExisting(this));
342 return transact(STOP_RECORDING_TRANSACTION, data, &reply);
343}
344
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800345status_t BpBinder::dump(int fd, const Vector<String16>& args)
346{
347 Parcel send;
348 Parcel reply;
349 send.writeFileDescriptor(fd);
350 const size_t numArgs = args.size();
351 send.writeInt32(numArgs);
352 for (size_t i = 0; i < numArgs; i++) {
353 send.writeString16(args[i]);
354 }
355 status_t err = transact(DUMP_TRANSACTION, send, &reply);
356 return err;
357}
358
Jiyong Parkb86c8662018-10-29 23:01:57 +0900359// NOLINTNEXTLINE(google-default-arguments)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800360status_t BpBinder::transact(
361 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
362{
363 // Once a binder has died, it will never come back to life.
364 if (mAlive) {
Steven Moreland46b5fea2019-10-15 11:22:18 -0700365 bool privateVendor = flags & FLAG_PRIVATE_VENDOR;
366 // don't send userspace flags to the kernel
Andrei Homescu7cdf5c22022-04-30 03:41:16 +0000367 flags = flags & ~static_cast<uint32_t>(FLAG_PRIVATE_VENDOR);
Steven Moreland46b5fea2019-10-15 11:22:18 -0700368
Steven Moreland6e5a7752019-08-05 20:30:14 -0700369 // user transactions require a given stability level
370 if (code >= FIRST_CALL_TRANSACTION && code <= LAST_CALL_TRANSACTION) {
371 using android::internal::Stability;
372
Steven Moreland16a41062021-07-23 13:35:25 -0700373 int16_t stability = Stability::getRepr(this);
Steven Moreland89ddfc52020-11-13 02:39:26 +0000374 Stability::Level required = privateVendor ? Stability::VENDOR
375 : Stability::getLocalLevel();
Steven Moreland6e5a7752019-08-05 20:30:14 -0700376
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000377 if (!Stability::check(stability, required)) [[unlikely]] {
Steven Morelandb269b582021-02-10 17:09:11 +0000378 ALOGE("Cannot do a user transaction on a %s binder (%s) in a %s context.",
Steven Moreland16a41062021-07-23 13:35:25 -0700379 Stability::levelString(stability).c_str(),
380 String8(getInterfaceDescriptor()).c_str(),
381 Stability::levelString(required).c_str());
Steven Moreland6e5a7752019-08-05 20:30:14 -0700382 return BAD_TYPE;
383 }
384 }
385
Steven Moreland5553ac42020-11-11 02:14:45 +0000386 status_t status;
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000387 if (isRpcBinder()) [[unlikely]] {
Steven Morelandf5174272021-05-25 00:39:28 +0000388 status = rpcSession()->transact(sp<IBinder>::fromExisting(this), code, data, reply,
389 flags);
Steven Moreland5553ac42020-11-11 02:14:45 +0000390 } else {
Steven Moreland32150282021-11-12 22:54:53 +0000391 if constexpr (!kEnableKernelIpc) {
392 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
393 return INVALID_OPERATION;
394 }
395
Steven Moreland5553ac42020-11-11 02:14:45 +0000396 status = IPCThreadState::self()->transact(binderHandle(), code, data, reply, flags);
397 }
Martijn Coenen1cad19c2021-10-04 09:19:01 +0200398 if (data.dataSize() > LOG_TRANSACTIONS_OVER_SIZE) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700399 RpcMutexUniqueLock _l(mLock);
Martijn Coenen1cad19c2021-10-04 09:19:01 +0200400 ALOGW("Large outgoing transaction of %zu bytes, interface descriptor %s, code %d",
Steven Morelandf2830fe2022-12-21 00:45:34 +0000401 data.dataSize(), String8(mDescriptorCache).c_str(), code);
Martijn Coenen1cad19c2021-10-04 09:19:01 +0200402 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000403
Steven Moreland06074d82020-03-05 23:16:51 +0000404 if (status == DEAD_OBJECT) mAlive = 0;
Steven Morelanda86a3562019-08-01 23:28:34 +0000405
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800406 return status;
407 }
408
409 return DEAD_OBJECT;
410}
411
Jiyong Parkb86c8662018-10-29 23:01:57 +0900412// NOLINTNEXTLINE(google-default-arguments)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800413status_t BpBinder::linkToDeath(
414 const sp<DeathRecipient>& recipient, void* cookie, uint32_t flags)
415{
Devin Moore66d5b7a2022-07-07 21:42:10 +0000416 if (isRpcBinder()) {
417 if (rpcSession()->getMaxIncomingThreads() < 1) {
Devin Moorebd41dc12023-02-08 17:06:22 +0000418 ALOGE("Cannot register a DeathRecipient without any incoming threads. Need to set max "
419 "incoming threads to a value greater than 0 before calling linkToDeath.");
Devin Moore66d5b7a2022-07-07 21:42:10 +0000420 return INVALID_OPERATION;
421 }
422 } else if constexpr (!kEnableKernelIpc) {
Steven Moreland32150282021-11-12 22:54:53 +0000423 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
424 return INVALID_OPERATION;
Devin Moore66d5b7a2022-07-07 21:42:10 +0000425 } else {
426 if (ProcessState::self()->getThreadPoolMaxTotalThreadCount() == 0) {
427 ALOGW("Linking to death on %s but there are no threads (yet?) listening to incoming "
428 "transactions. See ProcessState::startThreadPool and "
429 "ProcessState::setThreadPoolMaxThreadCount. Generally you should setup the "
430 "binder "
431 "threadpool before other initialization steps.",
432 String8(getInterfaceDescriptor()).c_str());
433 }
Steven Moreland32150282021-11-12 22:54:53 +0000434 }
435
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800436 Obituary ob;
437 ob.recipient = recipient;
438 ob.cookie = cookie;
439 ob.flags = flags;
440
Yi Kongfdd8da92018-06-07 17:52:27 -0700441 LOG_ALWAYS_FATAL_IF(recipient == nullptr,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800442 "linkToDeath(): recipient must be non-NULL");
443
444 {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700445 RpcMutexUniqueLock _l(mLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800446
447 if (!mObitsSent) {
448 if (!mObituaries) {
449 mObituaries = new Vector<Obituary>;
450 if (!mObituaries) {
451 return NO_MEMORY;
452 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000453 ALOGV("Requesting death notification: %p handle %d\n", this, binderHandle());
Devin Moore66d5b7a2022-07-07 21:42:10 +0000454 if (!isRpcBinder()) {
455 if constexpr (kEnableKernelIpc) {
456 getWeakRefs()->incWeak(this);
457 IPCThreadState* self = IPCThreadState::self();
458 self->requestDeathNotification(binderHandle(), this);
459 self->flushCommands();
460 }
461 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800462 }
463 ssize_t res = mObituaries->add(ob);
464 return res >= (ssize_t)NO_ERROR ? (status_t)NO_ERROR : res;
465 }
466 }
467
468 return DEAD_OBJECT;
469}
470
Jiyong Parkb86c8662018-10-29 23:01:57 +0900471// NOLINTNEXTLINE(google-default-arguments)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800472status_t BpBinder::unlinkToDeath(
473 const wp<DeathRecipient>& recipient, void* cookie, uint32_t flags,
474 wp<DeathRecipient>* outRecipient)
475{
Devin Moore66d5b7a2022-07-07 21:42:10 +0000476 if (!kEnableKernelIpc && !isRpcBinder()) {
Steven Moreland32150282021-11-12 22:54:53 +0000477 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
478 return INVALID_OPERATION;
479 }
480
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700481 RpcMutexUniqueLock _l(mLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800482
483 if (mObitsSent) {
484 return DEAD_OBJECT;
485 }
486
487 const size_t N = mObituaries ? mObituaries->size() : 0;
488 for (size_t i=0; i<N; i++) {
489 const Obituary& obit = mObituaries->itemAt(i);
490 if ((obit.recipient == recipient
Yi Kongfdd8da92018-06-07 17:52:27 -0700491 || (recipient == nullptr && obit.cookie == cookie))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800492 && obit.flags == flags) {
Yi Kongfdd8da92018-06-07 17:52:27 -0700493 if (outRecipient != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800494 *outRecipient = mObituaries->itemAt(i).recipient;
495 }
496 mObituaries->removeAt(i);
497 if (mObituaries->size() == 0) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000498 ALOGV("Clearing death notification: %p handle %d\n", this, binderHandle());
Devin Moore66d5b7a2022-07-07 21:42:10 +0000499 if (!isRpcBinder()) {
500 if constexpr (kEnableKernelIpc) {
501 IPCThreadState* self = IPCThreadState::self();
502 self->clearDeathNotification(binderHandle(), this);
503 self->flushCommands();
504 }
505 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800506 delete mObituaries;
Yi Kongfdd8da92018-06-07 17:52:27 -0700507 mObituaries = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800508 }
509 return NO_ERROR;
510 }
511 }
512
513 return NAME_NOT_FOUND;
514}
515
516void BpBinder::sendObituary()
517{
Devin Moore66d5b7a2022-07-07 21:42:10 +0000518 if (!kEnableKernelIpc && !isRpcBinder()) {
Steven Moreland32150282021-11-12 22:54:53 +0000519 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
520 return;
521 }
522
Steven Moreland5553ac42020-11-11 02:14:45 +0000523 ALOGV("Sending obituary for proxy %p handle %d, mObitsSent=%s\n", this, binderHandle(),
524 mObitsSent ? "true" : "false");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800525
Steven Moreland06074d82020-03-05 23:16:51 +0000526 mAlive = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800527 if (mObitsSent) return;
528
529 mLock.lock();
530 Vector<Obituary>* obits = mObituaries;
Yi Kongfdd8da92018-06-07 17:52:27 -0700531 if(obits != nullptr) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000532 ALOGV("Clearing sent death notification: %p handle %d\n", this, binderHandle());
Devin Moore66d5b7a2022-07-07 21:42:10 +0000533 if (!isRpcBinder()) {
534 if constexpr (kEnableKernelIpc) {
535 IPCThreadState* self = IPCThreadState::self();
536 self->clearDeathNotification(binderHandle(), this);
537 self->flushCommands();
538 }
539 }
Yi Kongfdd8da92018-06-07 17:52:27 -0700540 mObituaries = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800541 }
Steven Moreland06074d82020-03-05 23:16:51 +0000542 mObitsSent = 1;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800543 mLock.unlock();
544
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700545 ALOGV("Reporting death of proxy %p for %zu recipients\n",
546 this, obits ? obits->size() : 0U);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800547
Yi Kongfdd8da92018-06-07 17:52:27 -0700548 if (obits != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800549 const size_t N = obits->size();
550 for (size_t i=0; i<N; i++) {
551 reportOneDeath(obits->itemAt(i));
552 }
553
554 delete obits;
555 }
556}
557
558void BpBinder::reportOneDeath(const Obituary& obit)
559{
560 sp<DeathRecipient> recipient = obit.recipient.promote();
Steve Block6807e592011-10-20 11:56:00 +0100561 ALOGV("Reporting death to recipient: %p\n", recipient.get());
Yi Kongfdd8da92018-06-07 17:52:27 -0700562 if (recipient == nullptr) return;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800563
Steven Moreland1a3a8ef2021-04-02 02:52:46 +0000564 recipient->binderDied(wp<BpBinder>::fromExisting(this));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800565}
566
Steven Moreland63a2d512021-06-25 01:10:15 +0000567void* BpBinder::attachObject(const void* objectID, void* object, void* cleanupCookie,
568 object_cleanup_func func) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700569 RpcMutexUniqueLock _l(mLock);
Steve Block6807e592011-10-20 11:56:00 +0100570 ALOGV("Attaching object %p to binder %p (manager=%p)", object, this, &mObjects);
Steven Moreland63a2d512021-06-25 01:10:15 +0000571 return mObjects.attach(objectID, object, cleanupCookie, func);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800572}
573
574void* BpBinder::findObject(const void* objectID) const
575{
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700576 RpcMutexUniqueLock _l(mLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800577 return mObjects.find(objectID);
578}
579
Steven Moreland63a2d512021-06-25 01:10:15 +0000580void* BpBinder::detachObject(const void* objectID) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700581 RpcMutexUniqueLock _l(mLock);
Steven Moreland63a2d512021-06-25 01:10:15 +0000582 return mObjects.detach(objectID);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800583}
584
Steven Moreland9e759e82021-06-25 21:30:23 +0000585void BpBinder::withLock(const std::function<void()>& doWithLock) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700586 RpcMutexUniqueLock _l(mLock);
Steven Moreland9e759e82021-06-25 21:30:23 +0000587 doWithLock();
588}
589
Devin Moore3faaa002022-07-27 15:54:06 +0000590sp<IBinder> BpBinder::lookupOrCreateWeak(const void* objectID, object_make_func make,
591 const void* makeArgs) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700592 RpcMutexUniqueLock _l(mLock);
Devin Moore3faaa002022-07-27 15:54:06 +0000593 return mObjects.lookupOrCreateWeak(objectID, make, makeArgs);
594}
595
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800596BpBinder* BpBinder::remoteBinder()
597{
598 return this;
599}
600
Steven Moreland32150282021-11-12 22:54:53 +0000601BpBinder::~BpBinder() {
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000602 if (isRpcBinder()) [[unlikely]] {
603 return;
604 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800605
Steven Moreland32150282021-11-12 22:54:53 +0000606 if constexpr (!kEnableKernelIpc) {
607 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
608 return;
609 }
610
611 ALOGV("Destroying BpBinder %p handle %d\n", this, binderHandle());
612
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800613 IPCThreadState* ipc = IPCThreadState::self();
614
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700615 if (mTrackedUid >= 0) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700616 RpcMutexUniqueLock _l(sTrackingLock);
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700617 uint32_t trackedValue = sTrackingMap[mTrackedUid];
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000618 if ((trackedValue & COUNTING_VALUE_MASK) == 0) [[unlikely]] {
Steven Moreland5553ac42020-11-11 02:14:45 +0000619 ALOGE("Unexpected Binder Proxy tracking decrement in %p handle %d\n", this,
620 binderHandle());
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700621 } else {
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000622 auto countingValue = trackedValue & COUNTING_VALUE_MASK;
Jing Jibdbe29a2023-10-03 00:03:28 -0700623 if ((trackedValue & (LIMIT_REACHED_MASK | WARNING_REACHED_MASK)) &&
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000624 (countingValue <= sBinderProxyCountLowWatermark)) [[unlikely]] {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700625 ALOGI("Limit reached bit reset for uid %d (fewer than %d proxies from uid %d held)",
Martijn Coenena8d509d2021-09-03 18:06:24 +0200626 getuid(), sBinderProxyCountLowWatermark, mTrackedUid);
Jing Jibdbe29a2023-10-03 00:03:28 -0700627 sTrackingMap[mTrackedUid] &= ~(LIMIT_REACHED_MASK | WARNING_REACHED_MASK);
Martijn Coenena8d509d2021-09-03 18:06:24 +0200628 sLastLimitCallbackMap.erase(mTrackedUid);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700629 }
630 if (--sTrackingMap[mTrackedUid] == 0) {
631 sTrackingMap.erase(mTrackedUid);
632 }
633 }
634 }
Jing Ji4c4ac062023-10-07 15:20:23 -0700635 --sBinderProxyCount;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700636
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800637 if (ipc) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000638 ipc->expungeHandle(binderHandle(), this);
639 ipc->decWeakHandle(binderHandle());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800640 }
641}
642
Steven Moreland32150282021-11-12 22:54:53 +0000643void BpBinder::onFirstRef() {
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000644 if (isRpcBinder()) [[unlikely]] {
645 return;
646 }
Steven Moreland32150282021-11-12 22:54:53 +0000647
648 if constexpr (!kEnableKernelIpc) {
649 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
650 return;
651 }
652
653 ALOGV("onFirstRef BpBinder %p handle %d\n", this, binderHandle());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800654 IPCThreadState* ipc = IPCThreadState::self();
Steven Moreland5553ac42020-11-11 02:14:45 +0000655 if (ipc) ipc->incStrongHandle(binderHandle(), this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800656}
657
Steven Moreland32150282021-11-12 22:54:53 +0000658void BpBinder::onLastStrongRef(const void* /*id*/) {
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000659 if (isRpcBinder()) [[unlikely]] {
Steven Moreland4f622fe2021-09-13 17:38:09 -0700660 (void)rpcSession()->sendDecStrong(this);
Steven Moreland5553ac42020-11-11 02:14:45 +0000661 return;
662 }
Steven Moreland32150282021-11-12 22:54:53 +0000663
664 if constexpr (!kEnableKernelIpc) {
665 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
666 return;
667 }
668
669 ALOGV("onLastStrongRef BpBinder %p handle %d\n", this, binderHandle());
Steve Block6807e592011-10-20 11:56:00 +0100670 IF_ALOGV() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800671 printRefs();
672 }
673 IPCThreadState* ipc = IPCThreadState::self();
Steven Moreland5553ac42020-11-11 02:14:45 +0000674 if (ipc) ipc->decStrongHandle(binderHandle());
Steven Moreland80d23932019-06-07 12:43:27 -0700675
676 mLock.lock();
677 Vector<Obituary>* obits = mObituaries;
678 if(obits != nullptr) {
679 if (!obits->isEmpty()) {
Steven Moreland70fcb4e2019-12-13 17:28:58 -0800680 ALOGI("onLastStrongRef automatically unlinking death recipients: %s",
Steven Morelandf2830fe2022-12-21 00:45:34 +0000681 String8(mDescriptorCache).c_str());
Steven Moreland80d23932019-06-07 12:43:27 -0700682 }
683
Steven Moreland5553ac42020-11-11 02:14:45 +0000684 if (ipc) ipc->clearDeathNotification(binderHandle(), this);
Steven Moreland80d23932019-06-07 12:43:27 -0700685 mObituaries = nullptr;
686 }
687 mLock.unlock();
688
689 if (obits != nullptr) {
690 // XXX Should we tell any remaining DeathRecipient
691 // objects that the last strong ref has gone away, so they
692 // are no longer linked?
693 delete obits;
694 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800695}
696
Colin Cross6f4f3ab2014-02-05 17:42:44 -0800697bool BpBinder::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800698{
Steven Moreland5553ac42020-11-11 02:14:45 +0000699 // RPC binder doesn't currently support inc from weak binders
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000700 if (isRpcBinder()) [[unlikely]] {
701 return false;
702 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000703
Steven Moreland32150282021-11-12 22:54:53 +0000704 if constexpr (!kEnableKernelIpc) {
705 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
706 return false;
707 }
708
Steven Moreland5553ac42020-11-11 02:14:45 +0000709 ALOGV("onIncStrongAttempted BpBinder %p handle %d\n", this, binderHandle());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800710 IPCThreadState* ipc = IPCThreadState::self();
Steven Moreland5553ac42020-11-11 02:14:45 +0000711 return ipc ? ipc->attemptIncStrongHandle(binderHandle()) == NO_ERROR : false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800712}
713
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700714uint32_t BpBinder::getBinderProxyCount(uint32_t uid)
715{
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700716 RpcMutexUniqueLock _l(sTrackingLock);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700717 auto it = sTrackingMap.find(uid);
718 if (it != sTrackingMap.end()) {
719 return it->second & COUNTING_VALUE_MASK;
720 }
721 return 0;
722}
723
Jing Ji4c4ac062023-10-07 15:20:23 -0700724uint32_t BpBinder::getBinderProxyCount()
725{
726 return sBinderProxyCount.load();
727}
728
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700729void BpBinder::getCountByUid(Vector<uint32_t>& uids, Vector<uint32_t>& counts)
730{
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700731 RpcMutexUniqueLock _l(sTrackingLock);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700732 uids.setCapacity(sTrackingMap.size());
733 counts.setCapacity(sTrackingMap.size());
734 for (const auto& it : sTrackingMap) {
735 uids.push_back(it.first);
736 counts.push_back(it.second & COUNTING_VALUE_MASK);
737 }
738}
739
740void BpBinder::enableCountByUid() { sCountByUidEnabled.store(true); }
741void BpBinder::disableCountByUid() { sCountByUidEnabled.store(false); }
742void BpBinder::setCountByUidEnabled(bool enable) { sCountByUidEnabled.store(enable); }
743
Jing Jibdbe29a2023-10-03 00:03:28 -0700744void BpBinder::setBinderProxyCountEventCallback(binder_proxy_limit_callback cbl,
745 binder_proxy_warning_callback cbw) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700746 RpcMutexUniqueLock _l(sTrackingLock);
Jing Jibdbe29a2023-10-03 00:03:28 -0700747 sLimitCallback = std::move(cbl);
748 sWarningCallback = std::move(cbw);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700749}
750
Jing Jibdbe29a2023-10-03 00:03:28 -0700751void BpBinder::setBinderProxyCountWatermarks(int high, int low, int warning) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700752 RpcMutexUniqueLock _l(sTrackingLock);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700753 sBinderProxyCountHighWatermark = high;
754 sBinderProxyCountLowWatermark = low;
Jing Jibdbe29a2023-10-03 00:03:28 -0700755 sBinderProxyCountWarningWatermark = warning;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700756}
757
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800758// ---------------------------------------------------------------------------
759
Steven Moreland61ff8492019-09-26 16:05:45 -0700760} // namespace android