blob: 7a855e1c5be6cdfb296463182338b9827b1b48da [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"
Tim Murray008e5e72024-05-15 13:10:47 -070018#define ATRACE_TAG ATRACE_TAG_AIDL
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019//#define LOG_NDEBUG 0
20
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070021#include <binder/BpBinder.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/IPCThreadState.h>
Dianne Hackborn23eb1e22015-10-07 17:35:27 -070024#include <binder/IResultReceiver.h>
Steven Morelandbdb53ab2021-05-05 17:57:41 +000025#include <binder/RpcSession.h>
Steven Moreland6e5a7752019-08-05 20:30:14 -070026#include <binder/Stability.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
28#include <stdio.h>
29
Tim Murray008e5e72024-05-15 13:10:47 -070030#ifndef __TRUSTY__
31#include <cutils/trace.h>
32#else
33#define ATRACE_INT(...)
34#endif
35
Steven Moreland32150282021-11-12 22:54:53 +000036#include "BuildFlags.h"
Tomasz Wasilczyk26db5e42023-11-02 11:45:11 -070037#include "file.h"
Sahil Somani2522b072022-08-08 14:07:47 -070038
Steve Block6807e592011-10-20 11:56:00 +010039//#undef ALOGV
40//#define ALOGV(...) fprintf(stderr, __VA_ARGS__)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
42namespace android {
43
Tomasz Wasilczyk639490b2023-11-01 13:49:41 -070044using android::binder::unique_fd;
45
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046// ---------------------------------------------------------------------------
47
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -070048RpcMutex BpBinder::sTrackingLock;
Martijn Coenena8d509d2021-09-03 18:06:24 +020049std::unordered_map<int32_t, uint32_t> BpBinder::sTrackingMap;
50std::unordered_map<int32_t, uint32_t> BpBinder::sLastLimitCallbackMap;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070051int BpBinder::sNumTrackedUids = 0;
52std::atomic_bool BpBinder::sCountByUidEnabled(false);
53binder_proxy_limit_callback BpBinder::sLimitCallback;
Jing Jibdbe29a2023-10-03 00:03:28 -070054binder_proxy_warning_callback BpBinder::sWarningCallback;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070055bool BpBinder::sBinderProxyThrottleCreate = false;
56
Steven Moreland847d8c52023-05-02 23:56:58 +000057static StaticString16 kDescriptorUninit(u"");
Steven Morelandf2830fe2022-12-21 00:45:34 +000058
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070059// Arbitrarily high value that probably distinguishes a bad behaving app
60uint32_t BpBinder::sBinderProxyCountHighWatermark = 2500;
61// Another arbitrary value a binder count needs to drop below before another callback will be called
62uint32_t BpBinder::sBinderProxyCountLowWatermark = 2000;
Jing Jibdbe29a2023-10-03 00:03:28 -070063// Arbitrary value between low and high watermark on a bad behaving app to
64// trigger a warning callback.
65uint32_t BpBinder::sBinderProxyCountWarningWatermark = 2250;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070066
Jing Ji4c4ac062023-10-07 15:20:23 -070067std::atomic<uint32_t> BpBinder::sBinderProxyCount(0);
68std::atomic<uint32_t> BpBinder::sBinderProxyCountWarned(0);
69
70static constexpr uint32_t kBinderProxyCountWarnInterval = 5000;
71
Martijn Coenen1cad19c2021-10-04 09:19:01 +020072// Log any transactions for which the data exceeds this size
73#define LOG_TRANSACTIONS_OVER_SIZE (300 * 1024)
74
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070075enum {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -070076 LIMIT_REACHED_MASK = 0x80000000, // A flag denoting that the limit has been reached
Jing Jibdbe29a2023-10-03 00:03:28 -070077 WARNING_REACHED_MASK = 0x40000000, // A flag denoting that the warning has been reached
78 COUNTING_VALUE_MASK = 0x3FFFFFFF, // A mask of the remaining bits for the count value
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070079};
80
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081BpBinder::ObjectManager::ObjectManager()
82{
83}
84
85BpBinder::ObjectManager::~ObjectManager()
86{
87 kill();
88}
89
Steven Moreland63a2d512021-06-25 01:10:15 +000090void* BpBinder::ObjectManager::attach(const void* objectID, void* object, void* cleanupCookie,
91 IBinder::object_cleanup_func func) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080092 entry_t e;
93 e.object = object;
94 e.cleanupCookie = cleanupCookie;
95 e.func = func;
96
Jiyong Park5970d0a2022-03-08 16:56:13 +090097 if (mObjects.find(objectID) != mObjects.end()) {
Steven Moreland63a2d512021-06-25 01:10:15 +000098 ALOGI("Trying to attach object ID %p to binder ObjectManager %p with object %p, but object "
99 "ID already in use",
100 objectID, this, object);
Jiyong Park5970d0a2022-03-08 16:56:13 +0900101 return mObjects[objectID].object;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 }
103
Jiyong Park5970d0a2022-03-08 16:56:13 +0900104 mObjects.insert({objectID, e});
Steven Moreland63a2d512021-06-25 01:10:15 +0000105 return nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106}
107
108void* BpBinder::ObjectManager::find(const void* objectID) const
109{
Jiyong Park5970d0a2022-03-08 16:56:13 +0900110 auto i = mObjects.find(objectID);
111 if (i == mObjects.end()) return nullptr;
112 return i->second.object;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113}
114
Steven Moreland63a2d512021-06-25 01:10:15 +0000115void* BpBinder::ObjectManager::detach(const void* objectID) {
Jiyong Park5970d0a2022-03-08 16:56:13 +0900116 auto i = mObjects.find(objectID);
117 if (i == mObjects.end()) return nullptr;
118 void* value = i->second.object;
119 mObjects.erase(i);
Steven Moreland63a2d512021-06-25 01:10:15 +0000120 return value;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800121}
122
Devin Moore3faaa002022-07-27 15:54:06 +0000123namespace {
124struct Tag {
125 wp<IBinder> binder;
126};
127} // namespace
128
129static void cleanWeak(const void* /* id */, void* obj, void* /* cookie */) {
130 delete static_cast<Tag*>(obj);
131}
132
133sp<IBinder> BpBinder::ObjectManager::lookupOrCreateWeak(const void* objectID, object_make_func make,
134 const void* makeArgs) {
135 entry_t& e = mObjects[objectID];
136 if (e.object != nullptr) {
137 if (auto attached = static_cast<Tag*>(e.object)->binder.promote()) {
138 return attached;
139 }
140 } else {
141 e.object = new Tag;
142 LOG_ALWAYS_FATAL_IF(!e.object, "no more memory");
143 }
144 sp<IBinder> newObj = make(makeArgs);
145
146 static_cast<Tag*>(e.object)->binder = newObj;
147 e.cleanupCookie = nullptr;
148 e.func = cleanWeak;
149
150 return newObj;
151}
152
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153void BpBinder::ObjectManager::kill()
154{
155 const size_t N = mObjects.size();
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700156 ALOGV("Killing %zu objects in manager %p", N, this);
Jiyong Park5970d0a2022-03-08 16:56:13 +0900157 for (auto i : mObjects) {
158 const entry_t& e = i.second;
Yi Kongfdd8da92018-06-07 17:52:27 -0700159 if (e.func != nullptr) {
Jiyong Park5970d0a2022-03-08 16:56:13 +0900160 e.func(i.first, e.object, e.cleanupCookie);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800161 }
162 }
163
164 mObjects.clear();
165}
166
167// ---------------------------------------------------------------------------
168
Steven Moreland1a3a8ef2021-04-02 02:52:46 +0000169sp<BpBinder> BpBinder::create(int32_t handle) {
Steven Moreland32150282021-11-12 22:54:53 +0000170 if constexpr (!kEnableKernelIpc) {
171 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
172 return nullptr;
173 }
174
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700175 int32_t trackedUid = -1;
176 if (sCountByUidEnabled) {
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700177 trackedUid = IPCThreadState::self()->getCallingUid();
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700178 RpcMutexUniqueLock _l(sTrackingLock);
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700179 uint32_t trackedValue = sTrackingMap[trackedUid];
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000180 if (trackedValue & LIMIT_REACHED_MASK) [[unlikely]] {
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700181 if (sBinderProxyThrottleCreate) {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700182 return nullptr;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700183 }
Martijn Coenena8d509d2021-09-03 18:06:24 +0200184 trackedValue = trackedValue & COUNTING_VALUE_MASK;
185 uint32_t lastLimitCallbackAt = sLastLimitCallbackMap[trackedUid];
186
187 if (trackedValue > lastLimitCallbackAt &&
Martijn Coenen6711b6d2021-09-23 09:44:29 +0200188 (trackedValue - lastLimitCallbackAt > sBinderProxyCountHighWatermark)) {
Martijn Coenena8d509d2021-09-03 18:06:24 +0200189 ALOGE("Still too many binder proxy objects sent to uid %d from uid %d (%d proxies "
190 "held)",
191 getuid(), trackedUid, trackedValue);
192 if (sLimitCallback) sLimitCallback(trackedUid);
193 sLastLimitCallbackMap[trackedUid] = trackedValue;
194 }
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700195 } else {
Jing Jibdbe29a2023-10-03 00:03:28 -0700196 uint32_t currentValue = trackedValue & COUNTING_VALUE_MASK;
197 if (currentValue >= sBinderProxyCountWarningWatermark
198 && currentValue < sBinderProxyCountHighWatermark
199 && ((trackedValue & WARNING_REACHED_MASK) == 0)) [[unlikely]] {
200 sTrackingMap[trackedUid] |= WARNING_REACHED_MASK;
201 if (sWarningCallback) sWarningCallback(trackedUid);
202 } else if (currentValue >= sBinderProxyCountHighWatermark) {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700203 ALOGE("Too many binder proxy objects sent to uid %d from uid %d (%d proxies held)",
204 getuid(), trackedUid, trackedValue);
205 sTrackingMap[trackedUid] |= LIMIT_REACHED_MASK;
206 if (sLimitCallback) sLimitCallback(trackedUid);
Martijn Coenena8d509d2021-09-03 18:06:24 +0200207 sLastLimitCallbackMap[trackedUid] = trackedValue & COUNTING_VALUE_MASK;
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700208 if (sBinderProxyThrottleCreate) {
209 ALOGI("Throttling binder proxy creates from uid %d in uid %d until binder proxy"
210 " count drops below %d",
211 trackedUid, getuid(), sBinderProxyCountLowWatermark);
212 return nullptr;
213 }
214 }
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700215 }
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700216 sTrackingMap[trackedUid]++;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700217 }
Jing Ji4c4ac062023-10-07 15:20:23 -0700218 uint32_t numProxies = sBinderProxyCount.fetch_add(1, std::memory_order_relaxed);
Tim Murray008e5e72024-05-15 13:10:47 -0700219 ATRACE_INT("binder_proxies", numProxies);
Jing Ji4c4ac062023-10-07 15:20:23 -0700220 uint32_t numLastWarned = sBinderProxyCountWarned.load(std::memory_order_relaxed);
221 uint32_t numNextWarn = numLastWarned + kBinderProxyCountWarnInterval;
222 if (numProxies >= numNextWarn) {
223 // Multiple threads can get here, make sure only one of them gets to
224 // update the warn counter.
225 if (sBinderProxyCountWarned.compare_exchange_strong(numLastWarned,
226 numNextWarn,
227 std::memory_order_relaxed)) {
228 ALOGW("Unexpectedly many live BinderProxies: %d\n", numProxies);
229 }
230 }
Steven Moreland1a3a8ef2021-04-02 02:52:46 +0000231 return sp<BpBinder>::make(BinderHandle{handle}, trackedUid);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700232}
233
Steven Moreland5623d1a2021-09-10 15:45:34 -0700234sp<BpBinder> BpBinder::create(const sp<RpcSession>& session, uint64_t address) {
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000235 LOG_ALWAYS_FATAL_IF(session == nullptr, "BpBinder::create null session");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800236
Steven Moreland5553ac42020-11-11 02:14:45 +0000237 // These are not currently tracked, since there is no UID or other
238 // identifier to track them with. However, if similar functionality is
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000239 // needed, session objects keep track of all BpBinder objects on a
240 // per-session basis.
Steven Moreland5553ac42020-11-11 02:14:45 +0000241
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000242 return sp<BpBinder>::make(RpcHandle{session, address});
Steven Moreland5553ac42020-11-11 02:14:45 +0000243}
244
245BpBinder::BpBinder(Handle&& handle)
246 : mStability(0),
247 mHandle(handle),
248 mAlive(true),
249 mObitsSent(false),
250 mObituaries(nullptr),
Steven Morelandf2830fe2022-12-21 00:45:34 +0000251 mDescriptorCache(kDescriptorUninit),
Steven Moreland5553ac42020-11-11 02:14:45 +0000252 mTrackedUid(-1) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800253 extendObjectLifetime(OBJECT_LIFETIME_WEAK);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800254}
255
Steven Moreland5553ac42020-11-11 02:14:45 +0000256BpBinder::BpBinder(BinderHandle&& handle, int32_t trackedUid) : BpBinder(Handle(handle)) {
Steven Moreland32150282021-11-12 22:54:53 +0000257 if constexpr (!kEnableKernelIpc) {
258 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
259 return;
260 }
261
Steven Moreland5553ac42020-11-11 02:14:45 +0000262 mTrackedUid = trackedUid;
263
264 ALOGV("Creating BpBinder %p handle %d\n", this, this->binderHandle());
265
266 IPCThreadState::self()->incWeakHandle(this->binderHandle(), this);
267}
268
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000269BpBinder::BpBinder(RpcHandle&& handle) : BpBinder(Handle(handle)) {
270 LOG_ALWAYS_FATAL_IF(rpcSession() == nullptr, "BpBinder created w/o session object");
Steven Moreland5553ac42020-11-11 02:14:45 +0000271}
272
273bool BpBinder::isRpcBinder() const {
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000274 return std::holds_alternative<RpcHandle>(mHandle);
Steven Moreland5553ac42020-11-11 02:14:45 +0000275}
276
Steven Moreland5623d1a2021-09-10 15:45:34 -0700277uint64_t BpBinder::rpcAddress() const {
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000278 return std::get<RpcHandle>(mHandle).address;
Steven Moreland5553ac42020-11-11 02:14:45 +0000279}
280
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000281const sp<RpcSession>& BpBinder::rpcSession() const {
282 return std::get<RpcHandle>(mHandle).session;
Steven Moreland5553ac42020-11-11 02:14:45 +0000283}
284
285int32_t BpBinder::binderHandle() const {
286 return std::get<BinderHandle>(mHandle).handle;
Steven Moreland85180c02019-07-16 14:24:20 -0700287}
288
Devin Mooref6f2e642021-08-05 19:03:47 +0000289std::optional<int32_t> BpBinder::getDebugBinderHandle() const {
290 if (!isRpcBinder()) {
291 return binderHandle();
292 } else {
293 return std::nullopt;
294 }
295}
296
Mathias Agopian83c04462009-05-22 19:00:22 -0700297bool BpBinder::isDescriptorCached() const {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700298 RpcMutexUniqueLock _l(mLock);
Tomasz Wasilczyk0bfea2d2023-08-11 00:06:51 +0000299 return mDescriptorCache.c_str() != kDescriptorUninit.c_str();
Mathias Agopian83c04462009-05-22 19:00:22 -0700300}
301
302const String16& BpBinder::getInterfaceDescriptor() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800303{
Steven Morelandf2830fe2022-12-21 00:45:34 +0000304 if (!isDescriptorCached()) {
Steven Moreland1a3a8ef2021-04-02 02:52:46 +0000305 sp<BpBinder> thiz = sp<BpBinder>::fromExisting(const_cast<BpBinder*>(this));
Steven Moreland4cf688f2021-03-31 01:48:58 +0000306
307 Parcel data;
308 data.markForBinder(thiz);
309 Parcel reply;
Mathias Agopian83c04462009-05-22 19:00:22 -0700310 // do the IPC without a lock held.
Steven Moreland4cf688f2021-03-31 01:48:58 +0000311 status_t err = thiz->transact(INTERFACE_TRANSACTION, data, &reply);
Mathias Agopian83c04462009-05-22 19:00:22 -0700312 if (err == NO_ERROR) {
313 String16 res(reply.readString16());
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700314 RpcMutexUniqueLock _l(mLock);
Mathias Agopian83c04462009-05-22 19:00:22 -0700315 // mDescriptorCache could have been assigned while the lock was
316 // released.
Tomasz Wasilczyk0bfea2d2023-08-11 00:06:51 +0000317 if (mDescriptorCache.c_str() == kDescriptorUninit.c_str()) mDescriptorCache = res;
Mathias Agopian83c04462009-05-22 19:00:22 -0700318 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800319 }
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700320
Mathias Agopian83c04462009-05-22 19:00:22 -0700321 // we're returning a reference to a non-static object here. Usually this
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700322 // is not something smart to do, however, with binder objects it is
Mathias Agopian83c04462009-05-22 19:00:22 -0700323 // (usually) safe because they are reference-counted.
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700324
Mathias Agopian83c04462009-05-22 19:00:22 -0700325 return mDescriptorCache;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800326}
327
328bool BpBinder::isBinderAlive() const
329{
Steven Moreland06074d82020-03-05 23:16:51 +0000330 return mAlive != 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800331}
332
333status_t BpBinder::pingBinder()
334{
Steven Moreland5553ac42020-11-11 02:14:45 +0000335 Parcel data;
Steven Moreland1a3a8ef2021-04-02 02:52:46 +0000336 data.markForBinder(sp<BpBinder>::fromExisting(this));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800337 Parcel reply;
Steven Moreland5553ac42020-11-11 02:14:45 +0000338 return transact(PING_TRANSACTION, data, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339}
340
Tomasz Wasilczyk639490b2023-11-01 13:49:41 -0700341status_t BpBinder::startRecordingBinder(const unique_fd& fd) {
Sahil Somani2522b072022-08-08 14:07:47 -0700342 Parcel send, reply;
343 send.writeUniqueFileDescriptor(fd);
344 return transact(START_RECORDING_TRANSACTION, send, &reply);
345}
346
347status_t BpBinder::stopRecordingBinder() {
348 Parcel data, reply;
349 data.markForBinder(sp<BpBinder>::fromExisting(this));
350 return transact(STOP_RECORDING_TRANSACTION, data, &reply);
351}
352
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800353status_t BpBinder::dump(int fd, const Vector<String16>& args)
354{
355 Parcel send;
356 Parcel reply;
357 send.writeFileDescriptor(fd);
358 const size_t numArgs = args.size();
359 send.writeInt32(numArgs);
360 for (size_t i = 0; i < numArgs; i++) {
361 send.writeString16(args[i]);
362 }
363 status_t err = transact(DUMP_TRANSACTION, send, &reply);
364 return err;
365}
366
Jiyong Parkb86c8662018-10-29 23:01:57 +0900367// NOLINTNEXTLINE(google-default-arguments)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800368status_t BpBinder::transact(
369 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
370{
371 // Once a binder has died, it will never come back to life.
372 if (mAlive) {
Steven Moreland46b5fea2019-10-15 11:22:18 -0700373 bool privateVendor = flags & FLAG_PRIVATE_VENDOR;
374 // don't send userspace flags to the kernel
Andrei Homescu7cdf5c22022-04-30 03:41:16 +0000375 flags = flags & ~static_cast<uint32_t>(FLAG_PRIVATE_VENDOR);
Steven Moreland46b5fea2019-10-15 11:22:18 -0700376
Steven Moreland6e5a7752019-08-05 20:30:14 -0700377 // user transactions require a given stability level
378 if (code >= FIRST_CALL_TRANSACTION && code <= LAST_CALL_TRANSACTION) {
379 using android::internal::Stability;
380
Steven Moreland16a41062021-07-23 13:35:25 -0700381 int16_t stability = Stability::getRepr(this);
Steven Moreland89ddfc52020-11-13 02:39:26 +0000382 Stability::Level required = privateVendor ? Stability::VENDOR
383 : Stability::getLocalLevel();
Steven Moreland6e5a7752019-08-05 20:30:14 -0700384
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000385 if (!Stability::check(stability, required)) [[unlikely]] {
Steven Morelandb269b582021-02-10 17:09:11 +0000386 ALOGE("Cannot do a user transaction on a %s binder (%s) in a %s context.",
Steven Moreland16a41062021-07-23 13:35:25 -0700387 Stability::levelString(stability).c_str(),
388 String8(getInterfaceDescriptor()).c_str(),
389 Stability::levelString(required).c_str());
Steven Moreland6e5a7752019-08-05 20:30:14 -0700390 return BAD_TYPE;
391 }
392 }
393
Steven Moreland5553ac42020-11-11 02:14:45 +0000394 status_t status;
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000395 if (isRpcBinder()) [[unlikely]] {
Steven Morelandf5174272021-05-25 00:39:28 +0000396 status = rpcSession()->transact(sp<IBinder>::fromExisting(this), code, data, reply,
397 flags);
Steven Moreland5553ac42020-11-11 02:14:45 +0000398 } else {
Steven Moreland32150282021-11-12 22:54:53 +0000399 if constexpr (!kEnableKernelIpc) {
400 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
401 return INVALID_OPERATION;
402 }
403
Steven Moreland5553ac42020-11-11 02:14:45 +0000404 status = IPCThreadState::self()->transact(binderHandle(), code, data, reply, flags);
405 }
Martijn Coenen1cad19c2021-10-04 09:19:01 +0200406 if (data.dataSize() > LOG_TRANSACTIONS_OVER_SIZE) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700407 RpcMutexUniqueLock _l(mLock);
Martijn Coenen1cad19c2021-10-04 09:19:01 +0200408 ALOGW("Large outgoing transaction of %zu bytes, interface descriptor %s, code %d",
Steven Morelandf2830fe2022-12-21 00:45:34 +0000409 data.dataSize(), String8(mDescriptorCache).c_str(), code);
Martijn Coenen1cad19c2021-10-04 09:19:01 +0200410 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000411
Steven Moreland06074d82020-03-05 23:16:51 +0000412 if (status == DEAD_OBJECT) mAlive = 0;
Steven Morelanda86a3562019-08-01 23:28:34 +0000413
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800414 return status;
415 }
416
417 return DEAD_OBJECT;
418}
419
Jiyong Parkb86c8662018-10-29 23:01:57 +0900420// NOLINTNEXTLINE(google-default-arguments)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800421status_t BpBinder::linkToDeath(
422 const sp<DeathRecipient>& recipient, void* cookie, uint32_t flags)
423{
Devin Moore66d5b7a2022-07-07 21:42:10 +0000424 if (isRpcBinder()) {
425 if (rpcSession()->getMaxIncomingThreads() < 1) {
Devin Moorebd41dc12023-02-08 17:06:22 +0000426 ALOGE("Cannot register a DeathRecipient without any incoming threads. Need to set max "
427 "incoming threads to a value greater than 0 before calling linkToDeath.");
Devin Moore66d5b7a2022-07-07 21:42:10 +0000428 return INVALID_OPERATION;
429 }
430 } else if constexpr (!kEnableKernelIpc) {
Steven Moreland32150282021-11-12 22:54:53 +0000431 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
432 return INVALID_OPERATION;
Devin Moore66d5b7a2022-07-07 21:42:10 +0000433 } else {
434 if (ProcessState::self()->getThreadPoolMaxTotalThreadCount() == 0) {
435 ALOGW("Linking to death on %s but there are no threads (yet?) listening to incoming "
436 "transactions. See ProcessState::startThreadPool and "
437 "ProcessState::setThreadPoolMaxThreadCount. Generally you should setup the "
438 "binder "
439 "threadpool before other initialization steps.",
440 String8(getInterfaceDescriptor()).c_str());
441 }
Steven Moreland32150282021-11-12 22:54:53 +0000442 }
443
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800444 Obituary ob;
445 ob.recipient = recipient;
446 ob.cookie = cookie;
447 ob.flags = flags;
448
Yi Kongfdd8da92018-06-07 17:52:27 -0700449 LOG_ALWAYS_FATAL_IF(recipient == nullptr,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800450 "linkToDeath(): recipient must be non-NULL");
451
452 {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700453 RpcMutexUniqueLock _l(mLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800454
455 if (!mObitsSent) {
456 if (!mObituaries) {
457 mObituaries = new Vector<Obituary>;
458 if (!mObituaries) {
459 return NO_MEMORY;
460 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000461 ALOGV("Requesting death notification: %p handle %d\n", this, binderHandle());
Devin Moore66d5b7a2022-07-07 21:42:10 +0000462 if (!isRpcBinder()) {
463 if constexpr (kEnableKernelIpc) {
464 getWeakRefs()->incWeak(this);
465 IPCThreadState* self = IPCThreadState::self();
466 self->requestDeathNotification(binderHandle(), this);
467 self->flushCommands();
468 }
469 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800470 }
471 ssize_t res = mObituaries->add(ob);
472 return res >= (ssize_t)NO_ERROR ? (status_t)NO_ERROR : res;
473 }
474 }
475
476 return DEAD_OBJECT;
477}
478
Jiyong Parkb86c8662018-10-29 23:01:57 +0900479// NOLINTNEXTLINE(google-default-arguments)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800480status_t BpBinder::unlinkToDeath(
481 const wp<DeathRecipient>& recipient, void* cookie, uint32_t flags,
482 wp<DeathRecipient>* outRecipient)
483{
Devin Moore66d5b7a2022-07-07 21:42:10 +0000484 if (!kEnableKernelIpc && !isRpcBinder()) {
Steven Moreland32150282021-11-12 22:54:53 +0000485 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
486 return INVALID_OPERATION;
487 }
488
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700489 RpcMutexUniqueLock _l(mLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800490
491 if (mObitsSent) {
492 return DEAD_OBJECT;
493 }
494
495 const size_t N = mObituaries ? mObituaries->size() : 0;
496 for (size_t i=0; i<N; i++) {
497 const Obituary& obit = mObituaries->itemAt(i);
498 if ((obit.recipient == recipient
Yi Kongfdd8da92018-06-07 17:52:27 -0700499 || (recipient == nullptr && obit.cookie == cookie))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800500 && obit.flags == flags) {
Yi Kongfdd8da92018-06-07 17:52:27 -0700501 if (outRecipient != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800502 *outRecipient = mObituaries->itemAt(i).recipient;
503 }
504 mObituaries->removeAt(i);
505 if (mObituaries->size() == 0) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000506 ALOGV("Clearing death notification: %p handle %d\n", this, binderHandle());
Devin Moore66d5b7a2022-07-07 21:42:10 +0000507 if (!isRpcBinder()) {
508 if constexpr (kEnableKernelIpc) {
509 IPCThreadState* self = IPCThreadState::self();
510 self->clearDeathNotification(binderHandle(), this);
511 self->flushCommands();
512 }
513 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800514 delete mObituaries;
Yi Kongfdd8da92018-06-07 17:52:27 -0700515 mObituaries = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800516 }
517 return NO_ERROR;
518 }
519 }
520
521 return NAME_NOT_FOUND;
522}
523
524void BpBinder::sendObituary()
525{
Devin Moore66d5b7a2022-07-07 21:42:10 +0000526 if (!kEnableKernelIpc && !isRpcBinder()) {
Steven Moreland32150282021-11-12 22:54:53 +0000527 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
528 return;
529 }
530
Steven Moreland5553ac42020-11-11 02:14:45 +0000531 ALOGV("Sending obituary for proxy %p handle %d, mObitsSent=%s\n", this, binderHandle(),
532 mObitsSent ? "true" : "false");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800533
Steven Moreland06074d82020-03-05 23:16:51 +0000534 mAlive = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800535 if (mObitsSent) return;
536
537 mLock.lock();
538 Vector<Obituary>* obits = mObituaries;
Yi Kongfdd8da92018-06-07 17:52:27 -0700539 if(obits != nullptr) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000540 ALOGV("Clearing sent death notification: %p handle %d\n", this, binderHandle());
Devin Moore66d5b7a2022-07-07 21:42:10 +0000541 if (!isRpcBinder()) {
542 if constexpr (kEnableKernelIpc) {
543 IPCThreadState* self = IPCThreadState::self();
544 self->clearDeathNotification(binderHandle(), this);
545 self->flushCommands();
546 }
547 }
Yi Kongfdd8da92018-06-07 17:52:27 -0700548 mObituaries = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800549 }
Steven Moreland06074d82020-03-05 23:16:51 +0000550 mObitsSent = 1;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800551 mLock.unlock();
552
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700553 ALOGV("Reporting death of proxy %p for %zu recipients\n",
554 this, obits ? obits->size() : 0U);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800555
Yi Kongfdd8da92018-06-07 17:52:27 -0700556 if (obits != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800557 const size_t N = obits->size();
558 for (size_t i=0; i<N; i++) {
559 reportOneDeath(obits->itemAt(i));
560 }
561
562 delete obits;
563 }
564}
565
566void BpBinder::reportOneDeath(const Obituary& obit)
567{
568 sp<DeathRecipient> recipient = obit.recipient.promote();
Steve Block6807e592011-10-20 11:56:00 +0100569 ALOGV("Reporting death to recipient: %p\n", recipient.get());
Yi Kongfdd8da92018-06-07 17:52:27 -0700570 if (recipient == nullptr) return;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800571
Steven Moreland1a3a8ef2021-04-02 02:52:46 +0000572 recipient->binderDied(wp<BpBinder>::fromExisting(this));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800573}
574
Steven Moreland63a2d512021-06-25 01:10:15 +0000575void* BpBinder::attachObject(const void* objectID, void* object, void* cleanupCookie,
576 object_cleanup_func func) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700577 RpcMutexUniqueLock _l(mLock);
Steve Block6807e592011-10-20 11:56:00 +0100578 ALOGV("Attaching object %p to binder %p (manager=%p)", object, this, &mObjects);
Steven Moreland63a2d512021-06-25 01:10:15 +0000579 return mObjects.attach(objectID, object, cleanupCookie, func);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800580}
581
582void* BpBinder::findObject(const void* objectID) const
583{
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700584 RpcMutexUniqueLock _l(mLock);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800585 return mObjects.find(objectID);
586}
587
Steven Moreland63a2d512021-06-25 01:10:15 +0000588void* BpBinder::detachObject(const void* objectID) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700589 RpcMutexUniqueLock _l(mLock);
Steven Moreland63a2d512021-06-25 01:10:15 +0000590 return mObjects.detach(objectID);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800591}
592
Steven Moreland9e759e82021-06-25 21:30:23 +0000593void BpBinder::withLock(const std::function<void()>& doWithLock) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700594 RpcMutexUniqueLock _l(mLock);
Steven Moreland9e759e82021-06-25 21:30:23 +0000595 doWithLock();
596}
597
Devin Moore3faaa002022-07-27 15:54:06 +0000598sp<IBinder> BpBinder::lookupOrCreateWeak(const void* objectID, object_make_func make,
599 const void* makeArgs) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700600 RpcMutexUniqueLock _l(mLock);
Devin Moore3faaa002022-07-27 15:54:06 +0000601 return mObjects.lookupOrCreateWeak(objectID, make, makeArgs);
602}
603
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800604BpBinder* BpBinder::remoteBinder()
605{
606 return this;
607}
608
Steven Moreland32150282021-11-12 22:54:53 +0000609BpBinder::~BpBinder() {
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000610 if (isRpcBinder()) [[unlikely]] {
611 return;
612 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800613
Steven Moreland32150282021-11-12 22:54:53 +0000614 if constexpr (!kEnableKernelIpc) {
615 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
616 return;
617 }
618
619 ALOGV("Destroying BpBinder %p handle %d\n", this, binderHandle());
620
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800621 IPCThreadState* ipc = IPCThreadState::self();
622
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700623 if (mTrackedUid >= 0) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700624 RpcMutexUniqueLock _l(sTrackingLock);
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700625 uint32_t trackedValue = sTrackingMap[mTrackedUid];
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000626 if ((trackedValue & COUNTING_VALUE_MASK) == 0) [[unlikely]] {
Steven Moreland5553ac42020-11-11 02:14:45 +0000627 ALOGE("Unexpected Binder Proxy tracking decrement in %p handle %d\n", this,
628 binderHandle());
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700629 } else {
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000630 auto countingValue = trackedValue & COUNTING_VALUE_MASK;
Jing Jibdbe29a2023-10-03 00:03:28 -0700631 if ((trackedValue & (LIMIT_REACHED_MASK | WARNING_REACHED_MASK)) &&
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000632 (countingValue <= sBinderProxyCountLowWatermark)) [[unlikely]] {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700633 ALOGI("Limit reached bit reset for uid %d (fewer than %d proxies from uid %d held)",
Martijn Coenena8d509d2021-09-03 18:06:24 +0200634 getuid(), sBinderProxyCountLowWatermark, mTrackedUid);
Jing Jibdbe29a2023-10-03 00:03:28 -0700635 sTrackingMap[mTrackedUid] &= ~(LIMIT_REACHED_MASK | WARNING_REACHED_MASK);
Martijn Coenena8d509d2021-09-03 18:06:24 +0200636 sLastLimitCallbackMap.erase(mTrackedUid);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700637 }
638 if (--sTrackingMap[mTrackedUid] == 0) {
639 sTrackingMap.erase(mTrackedUid);
640 }
641 }
642 }
Tim Murray008e5e72024-05-15 13:10:47 -0700643 [[maybe_unused]] uint32_t numProxies = --sBinderProxyCount;
644 ATRACE_INT("binder_proxies", numProxies);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800645 if (ipc) {
Steven Moreland5553ac42020-11-11 02:14:45 +0000646 ipc->expungeHandle(binderHandle(), this);
647 ipc->decWeakHandle(binderHandle());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800648 }
649}
650
Steven Moreland32150282021-11-12 22:54:53 +0000651void BpBinder::onFirstRef() {
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000652 if (isRpcBinder()) [[unlikely]] {
653 return;
654 }
Steven Moreland32150282021-11-12 22:54:53 +0000655
656 if constexpr (!kEnableKernelIpc) {
657 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
658 return;
659 }
660
661 ALOGV("onFirstRef BpBinder %p handle %d\n", this, binderHandle());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800662 IPCThreadState* ipc = IPCThreadState::self();
Steven Moreland5553ac42020-11-11 02:14:45 +0000663 if (ipc) ipc->incStrongHandle(binderHandle(), this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800664}
665
Steven Moreland32150282021-11-12 22:54:53 +0000666void BpBinder::onLastStrongRef(const void* /*id*/) {
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000667 if (isRpcBinder()) [[unlikely]] {
Steven Moreland4f622fe2021-09-13 17:38:09 -0700668 (void)rpcSession()->sendDecStrong(this);
Steven Moreland5553ac42020-11-11 02:14:45 +0000669 return;
670 }
Steven Moreland32150282021-11-12 22:54:53 +0000671
672 if constexpr (!kEnableKernelIpc) {
673 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
674 return;
675 }
676
677 ALOGV("onLastStrongRef BpBinder %p handle %d\n", this, binderHandle());
Steve Block6807e592011-10-20 11:56:00 +0100678 IF_ALOGV() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800679 printRefs();
680 }
681 IPCThreadState* ipc = IPCThreadState::self();
Steven Moreland5553ac42020-11-11 02:14:45 +0000682 if (ipc) ipc->decStrongHandle(binderHandle());
Steven Moreland80d23932019-06-07 12:43:27 -0700683
684 mLock.lock();
685 Vector<Obituary>* obits = mObituaries;
686 if(obits != nullptr) {
687 if (!obits->isEmpty()) {
Steven Moreland70fcb4e2019-12-13 17:28:58 -0800688 ALOGI("onLastStrongRef automatically unlinking death recipients: %s",
Steven Morelandf2830fe2022-12-21 00:45:34 +0000689 String8(mDescriptorCache).c_str());
Steven Moreland80d23932019-06-07 12:43:27 -0700690 }
691
Steven Moreland5553ac42020-11-11 02:14:45 +0000692 if (ipc) ipc->clearDeathNotification(binderHandle(), this);
Steven Moreland80d23932019-06-07 12:43:27 -0700693 mObituaries = nullptr;
694 }
695 mLock.unlock();
696
697 if (obits != nullptr) {
698 // XXX Should we tell any remaining DeathRecipient
699 // objects that the last strong ref has gone away, so they
700 // are no longer linked?
701 delete obits;
702 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800703}
704
Colin Cross6f4f3ab2014-02-05 17:42:44 -0800705bool BpBinder::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800706{
Steven Moreland5553ac42020-11-11 02:14:45 +0000707 // RPC binder doesn't currently support inc from weak binders
Tomasz Wasilczyk32746ae2023-10-09 19:57:58 +0000708 if (isRpcBinder()) [[unlikely]] {
709 return false;
710 }
Steven Moreland5553ac42020-11-11 02:14:45 +0000711
Steven Moreland32150282021-11-12 22:54:53 +0000712 if constexpr (!kEnableKernelIpc) {
713 LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
714 return false;
715 }
716
Steven Moreland5553ac42020-11-11 02:14:45 +0000717 ALOGV("onIncStrongAttempted BpBinder %p handle %d\n", this, binderHandle());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800718 IPCThreadState* ipc = IPCThreadState::self();
Steven Moreland5553ac42020-11-11 02:14:45 +0000719 return ipc ? ipc->attemptIncStrongHandle(binderHandle()) == NO_ERROR : false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800720}
721
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700722uint32_t BpBinder::getBinderProxyCount(uint32_t uid)
723{
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700724 RpcMutexUniqueLock _l(sTrackingLock);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700725 auto it = sTrackingMap.find(uid);
726 if (it != sTrackingMap.end()) {
727 return it->second & COUNTING_VALUE_MASK;
728 }
729 return 0;
730}
731
Jing Ji4c4ac062023-10-07 15:20:23 -0700732uint32_t BpBinder::getBinderProxyCount()
733{
734 return sBinderProxyCount.load();
735}
736
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700737void BpBinder::getCountByUid(Vector<uint32_t>& uids, Vector<uint32_t>& counts)
738{
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700739 RpcMutexUniqueLock _l(sTrackingLock);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700740 uids.setCapacity(sTrackingMap.size());
741 counts.setCapacity(sTrackingMap.size());
742 for (const auto& it : sTrackingMap) {
743 uids.push_back(it.first);
744 counts.push_back(it.second & COUNTING_VALUE_MASK);
745 }
746}
747
748void BpBinder::enableCountByUid() { sCountByUidEnabled.store(true); }
749void BpBinder::disableCountByUid() { sCountByUidEnabled.store(false); }
750void BpBinder::setCountByUidEnabled(bool enable) { sCountByUidEnabled.store(enable); }
751
Jing Jibdbe29a2023-10-03 00:03:28 -0700752void BpBinder::setBinderProxyCountEventCallback(binder_proxy_limit_callback cbl,
753 binder_proxy_warning_callback cbw) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700754 RpcMutexUniqueLock _l(sTrackingLock);
Jing Jibdbe29a2023-10-03 00:03:28 -0700755 sLimitCallback = std::move(cbl);
756 sWarningCallback = std::move(cbw);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700757}
758
Jing Jibdbe29a2023-10-03 00:03:28 -0700759void BpBinder::setBinderProxyCountWatermarks(int high, int low, int warning) {
Tomasz Wasilczyk66ee1922023-10-26 14:53:49 -0700760 RpcMutexUniqueLock _l(sTrackingLock);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700761 sBinderProxyCountHighWatermark = high;
762 sBinderProxyCountLowWatermark = low;
Jing Jibdbe29a2023-10-03 00:03:28 -0700763 sBinderProxyCountWarningWatermark = warning;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700764}
765
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800766// ---------------------------------------------------------------------------
767
Steven Moreland61ff8492019-09-26 16:05:45 -0700768} // namespace android