blob: 212bffaf9f2dab65f626cc77a6dda9b9d3dfe92c [file] [log] [blame]
Mathias Agopian7922fa22009-05-18 15:08:03 -07001/*
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
Steven Morelandc4dd2102017-02-23 13:57:21 -080017#define LOG_TAG "hw-IPCThreadState"
Jason Parks2b17f142009-11-03 12:14:38 -080018
Martijn Coenen4080edc2016-05-04 14:17:02 +020019#include <hwbinder/IPCThreadState.h>
Mathias Agopian7922fa22009-05-18 15:08:03 -070020
Martijn Coenen4080edc2016-05-04 14:17:02 +020021#include <hwbinder/Binder.h>
Yifan Hong1e118d22017-01-12 14:42:28 -080022#include <hwbinder/BpHwBinder.h>
Martijn Coenen4080edc2016-05-04 14:17:02 +020023#include <hwbinder/TextOutput.h>
Chia-I Wu0e72fd52016-10-06 14:20:41 +080024#include <hwbinder/binder_kernel.h>
Mathias Agopian4ea13dc2013-05-06 20:20:50 -070025
Mathias Agopian7922fa22009-05-18 15:08:03 -070026#include <utils/Log.h>
Colin Crossb1dc6542016-04-15 14:29:55 -070027#include <utils/SystemClock.h>
Mathias Agopian7922fa22009-05-18 15:08:03 -070028#include <utils/threads.h>
29
30#include <private/binder/binder_module.h>
Martijn Coenene01f4f22016-05-12 12:33:28 +020031#include <hwbinder/Static.h>
Mathias Agopian7922fa22009-05-18 15:08:03 -070032
Mathias Agopian7922fa22009-05-18 15:08:03 -070033#include <errno.h>
Colin Crossb1dc6542016-04-15 14:29:55 -070034#include <inttypes.h>
Mathias Agopian7922fa22009-05-18 15:08:03 -070035#include <pthread.h>
36#include <sched.h>
Yabin Cuibbef2ba2015-01-26 19:45:47 -080037#include <signal.h>
38#include <stdio.h>
39#include <sys/ioctl.h>
Mathias Agopian7922fa22009-05-18 15:08:03 -070040#include <sys/resource.h>
Yabin Cuibbef2ba2015-01-26 19:45:47 -080041#include <unistd.h>
Mathias Agopian7922fa22009-05-18 15:08:03 -070042
43#if LOG_NDEBUG
44
45#define IF_LOG_TRANSACTIONS() if (false)
46#define IF_LOG_COMMANDS() if (false)
Yifan Hongdde40f32017-01-12 14:22:45 -080047#define LOG_REMOTEREFS(...)
Mathias Agopian7922fa22009-05-18 15:08:03 -070048#define IF_LOG_REMOTEREFS() if (false)
Yifan Hongdde40f32017-01-12 14:22:45 -080049#define LOG_THREADPOOL(...)
50#define LOG_ONEWAY(...)
Mathias Agopian7922fa22009-05-18 15:08:03 -070051
52#else
53
Steve Block5854b912011-10-12 17:27:03 +010054#define IF_LOG_TRANSACTIONS() IF_ALOG(LOG_VERBOSE, "transact")
55#define IF_LOG_COMMANDS() IF_ALOG(LOG_VERBOSE, "ipc")
56#define LOG_REMOTEREFS(...) ALOG(LOG_DEBUG, "remoterefs", __VA_ARGS__)
57#define IF_LOG_REMOTEREFS() IF_ALOG(LOG_DEBUG, "remoterefs")
58#define LOG_THREADPOOL(...) ALOG(LOG_DEBUG, "threadpool", __VA_ARGS__)
59#define LOG_ONEWAY(...) ALOG(LOG_DEBUG, "ipc", __VA_ARGS__)
Mathias Agopian7922fa22009-05-18 15:08:03 -070060
61#endif
62
63// ---------------------------------------------------------------------------
64
65namespace android {
Martijn Coenenf75a23d2016-08-01 11:55:17 +020066namespace hardware {
Mathias Agopian7922fa22009-05-18 15:08:03 -070067
Chih-Hung Hsieh30dcad72014-10-24 14:10:09 -070068// Static const and functions will be optimized out if not used,
69// when LOG_NDEBUG and references in IF_LOG_COMMANDS() are optimized out.
Mathias Agopian7922fa22009-05-18 15:08:03 -070070static const char *kReturnStrings[] = {
Andy McFadden457d51f2011-08-31 07:43:40 -070071 "BR_ERROR",
Mathias Agopian7922fa22009-05-18 15:08:03 -070072 "BR_OK",
Mathias Agopian7922fa22009-05-18 15:08:03 -070073 "BR_TRANSACTION",
74 "BR_REPLY",
75 "BR_ACQUIRE_RESULT",
76 "BR_DEAD_REPLY",
77 "BR_TRANSACTION_COMPLETE",
78 "BR_INCREFS",
79 "BR_ACQUIRE",
80 "BR_RELEASE",
81 "BR_DECREFS",
82 "BR_ATTEMPT_ACQUIRE",
Mathias Agopian7922fa22009-05-18 15:08:03 -070083 "BR_NOOP",
84 "BR_SPAWN_LOOPER",
85 "BR_FINISHED",
86 "BR_DEAD_BINDER",
Andy McFadden457d51f2011-08-31 07:43:40 -070087 "BR_CLEAR_DEATH_NOTIFICATION_DONE",
88 "BR_FAILED_REPLY"
Mathias Agopian7922fa22009-05-18 15:08:03 -070089};
90
91static const char *kCommandStrings[] = {
Mathias Agopian7922fa22009-05-18 15:08:03 -070092 "BC_TRANSACTION",
93 "BC_REPLY",
94 "BC_ACQUIRE_RESULT",
95 "BC_FREE_BUFFER",
Mathias Agopian7922fa22009-05-18 15:08:03 -070096 "BC_INCREFS",
97 "BC_ACQUIRE",
98 "BC_RELEASE",
99 "BC_DECREFS",
100 "BC_INCREFS_DONE",
101 "BC_ACQUIRE_DONE",
102 "BC_ATTEMPT_ACQUIRE",
Mathias Agopian7922fa22009-05-18 15:08:03 -0700103 "BC_REGISTER_LOOPER",
104 "BC_ENTER_LOOPER",
105 "BC_EXIT_LOOPER",
Mathias Agopian7922fa22009-05-18 15:08:03 -0700106 "BC_REQUEST_DEATH_NOTIFICATION",
107 "BC_CLEAR_DEATH_NOTIFICATION",
108 "BC_DEAD_BINDER_DONE"
Mathias Agopian7922fa22009-05-18 15:08:03 -0700109};
110
111static const char* getReturnString(size_t idx)
112{
113 if (idx < sizeof(kReturnStrings) / sizeof(kReturnStrings[0]))
114 return kReturnStrings[idx];
115 else
116 return "unknown";
117}
118
Mathias Agopian7922fa22009-05-18 15:08:03 -0700119static const void* printBinderTransactionData(TextOutput& out, const void* data)
120{
121 const binder_transaction_data* btd =
122 (const binder_transaction_data*)data;
Andy McFadden457d51f2011-08-31 07:43:40 -0700123 if (btd->target.handle < 1024) {
124 /* want to print descriptors in decimal; guess based on value */
125 out << "target.desc=" << btd->target.handle;
126 } else {
127 out << "target.ptr=" << btd->target.ptr;
128 }
129 out << " (cookie " << btd->cookie << ")" << endl
Chih-Hung Hsieh30dcad72014-10-24 14:10:09 -0700130 << "code=" << TypeCode(btd->code) << ", flags=" << (void*)(long)btd->flags << endl
Mathias Agopian7922fa22009-05-18 15:08:03 -0700131 << "data=" << btd->data.ptr.buffer << " (" << (void*)btd->data_size
132 << " bytes)" << endl
133 << "offsets=" << btd->data.ptr.offsets << " (" << (void*)btd->offsets_size
Andy McFadden457d51f2011-08-31 07:43:40 -0700134 << " bytes)";
Mathias Agopian7922fa22009-05-18 15:08:03 -0700135 return btd+1;
136}
137
138static const void* printReturnCommand(TextOutput& out, const void* _cmd)
139{
Andy McFadden457d51f2011-08-31 07:43:40 -0700140 static const size_t N = sizeof(kReturnStrings)/sizeof(kReturnStrings[0]);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700141 const int32_t* cmd = (const int32_t*)_cmd;
Bernhard Rosenkränzerb184ed02014-11-25 21:55:33 +0100142 uint32_t code = (uint32_t)*cmd++;
Andy McFadden457d51f2011-08-31 07:43:40 -0700143 size_t cmdIndex = code & 0xff;
Bernhard Rosenkränzerb184ed02014-11-25 21:55:33 +0100144 if (code == BR_ERROR) {
Chih-Hung Hsieh30dcad72014-10-24 14:10:09 -0700145 out << "BR_ERROR: " << (void*)(long)(*cmd++) << endl;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700146 return cmd;
Andy McFadden457d51f2011-08-31 07:43:40 -0700147 } else if (cmdIndex >= N) {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700148 out << "Unknown reply: " << code << endl;
149 return cmd;
150 }
Andy McFadden457d51f2011-08-31 07:43:40 -0700151 out << kReturnStrings[cmdIndex];
Yifan Hongdde40f32017-01-12 14:22:45 -0800152
Mathias Agopian7922fa22009-05-18 15:08:03 -0700153 switch (code) {
154 case BR_TRANSACTION:
155 case BR_REPLY: {
156 out << ": " << indent;
157 cmd = (const int32_t *)printBinderTransactionData(out, cmd);
158 out << dedent;
159 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800160
Mathias Agopian7922fa22009-05-18 15:08:03 -0700161 case BR_ACQUIRE_RESULT: {
162 const int32_t res = *cmd++;
163 out << ": " << res << (res ? " (SUCCESS)" : " (FAILURE)");
164 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800165
Mathias Agopian7922fa22009-05-18 15:08:03 -0700166 case BR_INCREFS:
167 case BR_ACQUIRE:
168 case BR_RELEASE:
169 case BR_DECREFS: {
170 const int32_t b = *cmd++;
171 const int32_t c = *cmd++;
Chih-Hung Hsieh30dcad72014-10-24 14:10:09 -0700172 out << ": target=" << (void*)(long)b << " (cookie " << (void*)(long)c << ")";
Mathias Agopian7922fa22009-05-18 15:08:03 -0700173 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800174
Mathias Agopian7922fa22009-05-18 15:08:03 -0700175 case BR_ATTEMPT_ACQUIRE: {
176 const int32_t p = *cmd++;
177 const int32_t b = *cmd++;
178 const int32_t c = *cmd++;
Chih-Hung Hsieh30dcad72014-10-24 14:10:09 -0700179 out << ": target=" << (void*)(long)b << " (cookie " << (void*)(long)c
Mathias Agopian7922fa22009-05-18 15:08:03 -0700180 << "), pri=" << p;
181 } break;
182
183 case BR_DEAD_BINDER:
184 case BR_CLEAR_DEATH_NOTIFICATION_DONE: {
185 const int32_t c = *cmd++;
Chih-Hung Hsieh30dcad72014-10-24 14:10:09 -0700186 out << ": death cookie " << (void*)(long)c;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700187 } break;
Andy McFadden457d51f2011-08-31 07:43:40 -0700188
189 default:
190 // no details to show for: BR_OK, BR_DEAD_REPLY,
191 // BR_TRANSACTION_COMPLETE, BR_FINISHED
192 break;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700193 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800194
Mathias Agopian7922fa22009-05-18 15:08:03 -0700195 out << endl;
196 return cmd;
197}
198
199static const void* printCommand(TextOutput& out, const void* _cmd)
200{
Andy McFadden457d51f2011-08-31 07:43:40 -0700201 static const size_t N = sizeof(kCommandStrings)/sizeof(kCommandStrings[0]);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700202 const int32_t* cmd = (const int32_t*)_cmd;
Bernhard Rosenkränzerb184ed02014-11-25 21:55:33 +0100203 uint32_t code = (uint32_t)*cmd++;
Andy McFadden457d51f2011-08-31 07:43:40 -0700204 size_t cmdIndex = code & 0xff;
205
206 if (cmdIndex >= N) {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700207 out << "Unknown command: " << code << endl;
208 return cmd;
209 }
Andy McFadden457d51f2011-08-31 07:43:40 -0700210 out << kCommandStrings[cmdIndex];
211
Mathias Agopian7922fa22009-05-18 15:08:03 -0700212 switch (code) {
213 case BC_TRANSACTION:
214 case BC_REPLY: {
215 out << ": " << indent;
216 cmd = (const int32_t *)printBinderTransactionData(out, cmd);
217 out << dedent;
218 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800219
Mathias Agopian7922fa22009-05-18 15:08:03 -0700220 case BC_ACQUIRE_RESULT: {
221 const int32_t res = *cmd++;
222 out << ": " << res << (res ? " (SUCCESS)" : " (FAILURE)");
223 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800224
Mathias Agopian7922fa22009-05-18 15:08:03 -0700225 case BC_FREE_BUFFER: {
226 const int32_t buf = *cmd++;
Chih-Hung Hsieh30dcad72014-10-24 14:10:09 -0700227 out << ": buffer=" << (void*)(long)buf;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700228 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800229
Mathias Agopian7922fa22009-05-18 15:08:03 -0700230 case BC_INCREFS:
231 case BC_ACQUIRE:
232 case BC_RELEASE:
233 case BC_DECREFS: {
234 const int32_t d = *cmd++;
Andy McFadden457d51f2011-08-31 07:43:40 -0700235 out << ": desc=" << d;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700236 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800237
Mathias Agopian7922fa22009-05-18 15:08:03 -0700238 case BC_INCREFS_DONE:
239 case BC_ACQUIRE_DONE: {
240 const int32_t b = *cmd++;
241 const int32_t c = *cmd++;
Chih-Hung Hsieh30dcad72014-10-24 14:10:09 -0700242 out << ": target=" << (void*)(long)b << " (cookie " << (void*)(long)c << ")";
Mathias Agopian7922fa22009-05-18 15:08:03 -0700243 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800244
Mathias Agopian7922fa22009-05-18 15:08:03 -0700245 case BC_ATTEMPT_ACQUIRE: {
246 const int32_t p = *cmd++;
247 const int32_t d = *cmd++;
Andy McFadden457d51f2011-08-31 07:43:40 -0700248 out << ": desc=" << d << ", pri=" << p;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700249 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800250
Mathias Agopian7922fa22009-05-18 15:08:03 -0700251 case BC_REQUEST_DEATH_NOTIFICATION:
252 case BC_CLEAR_DEATH_NOTIFICATION: {
253 const int32_t h = *cmd++;
254 const int32_t c = *cmd++;
Chih-Hung Hsieh30dcad72014-10-24 14:10:09 -0700255 out << ": handle=" << h << " (death cookie " << (void*)(long)c << ")";
Mathias Agopian7922fa22009-05-18 15:08:03 -0700256 } break;
257
258 case BC_DEAD_BINDER_DONE: {
259 const int32_t c = *cmd++;
Chih-Hung Hsieh30dcad72014-10-24 14:10:09 -0700260 out << ": death cookie " << (void*)(long)c;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700261 } break;
Andy McFadden457d51f2011-08-31 07:43:40 -0700262
263 default:
264 // no details to show for: BC_REGISTER_LOOPER, BC_ENTER_LOOPER,
265 // BC_EXIT_LOOPER
266 break;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700267 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800268
Mathias Agopian7922fa22009-05-18 15:08:03 -0700269 out << endl;
270 return cmd;
271}
Mathias Agopian7922fa22009-05-18 15:08:03 -0700272
273static pthread_mutex_t gTLSMutex = PTHREAD_MUTEX_INITIALIZER;
274static bool gHaveTLS = false;
275static pthread_key_t gTLS = 0;
276static bool gShutdown = false;
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800277static bool gDisableBackgroundScheduling = false;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700278
279IPCThreadState* IPCThreadState::self()
280{
281 if (gHaveTLS) {
282restart:
283 const pthread_key_t k = gTLS;
284 IPCThreadState* st = (IPCThreadState*)pthread_getspecific(k);
285 if (st) return st;
286 return new IPCThreadState;
287 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800288
Andreas Gampe1d5dc2b2016-02-01 13:21:56 -0800289 if (gShutdown) {
290 ALOGW("Calling IPCThreadState::self() during shutdown is dangerous, expect a crash.\n");
291 return NULL;
292 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800293
Mathias Agopian7922fa22009-05-18 15:08:03 -0700294 pthread_mutex_lock(&gTLSMutex);
295 if (!gHaveTLS) {
Andreas Gampe1d5dc2b2016-02-01 13:21:56 -0800296 int key_create_value = pthread_key_create(&gTLS, threadDestructor);
297 if (key_create_value != 0) {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700298 pthread_mutex_unlock(&gTLSMutex);
Andreas Gampe1d5dc2b2016-02-01 13:21:56 -0800299 ALOGW("IPCThreadState::self() unable to create TLS key, expect a crash: %s\n",
300 strerror(key_create_value));
Mathias Agopian7922fa22009-05-18 15:08:03 -0700301 return NULL;
302 }
303 gHaveTLS = true;
304 }
305 pthread_mutex_unlock(&gTLSMutex);
306 goto restart;
307}
308
Brad Fitzpatrick77949942010-12-13 16:52:35 -0800309IPCThreadState* IPCThreadState::selfOrNull()
310{
311 if (gHaveTLS) {
312 const pthread_key_t k = gTLS;
313 IPCThreadState* st = (IPCThreadState*)pthread_getspecific(k);
314 return st;
315 }
316 return NULL;
317}
318
Mathias Agopian7922fa22009-05-18 15:08:03 -0700319void IPCThreadState::shutdown()
320{
321 gShutdown = true;
Yifan Hongdde40f32017-01-12 14:22:45 -0800322
Mathias Agopian7922fa22009-05-18 15:08:03 -0700323 if (gHaveTLS) {
324 // XXX Need to wait for all thread pool threads to exit!
325 IPCThreadState* st = (IPCThreadState*)pthread_getspecific(gTLS);
326 if (st) {
327 delete st;
328 pthread_setspecific(gTLS, NULL);
329 }
zhongjie8e8a0252016-03-09 15:05:04 +0800330 pthread_key_delete(gTLS);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700331 gHaveTLS = false;
332 }
333}
334
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800335void IPCThreadState::disableBackgroundScheduling(bool disable)
336{
337 gDisableBackgroundScheduling = disable;
338}
339
Mathias Agopian7922fa22009-05-18 15:08:03 -0700340sp<ProcessState> IPCThreadState::process()
341{
342 return mProcess;
343}
344
345status_t IPCThreadState::clearLastError()
346{
347 const status_t err = mLastError;
348 mLastError = NO_ERROR;
349 return err;
350}
351
Dan Stozae8da8a42014-11-26 12:23:23 -0800352pid_t IPCThreadState::getCallingPid() const
Mathias Agopian7922fa22009-05-18 15:08:03 -0700353{
354 return mCallingPid;
355}
356
Dan Stozae8da8a42014-11-26 12:23:23 -0800357uid_t IPCThreadState::getCallingUid() const
Mathias Agopian7922fa22009-05-18 15:08:03 -0700358{
359 return mCallingUid;
360}
361
362int64_t IPCThreadState::clearCallingIdentity()
363{
364 int64_t token = ((int64_t)mCallingUid<<32) | mCallingPid;
365 clearCaller();
366 return token;
367}
368
Brad Fitzpatrick94c36342010-06-18 13:07:53 -0700369void IPCThreadState::setStrictModePolicy(int32_t policy)
370{
371 mStrictModePolicy = policy;
372}
373
Brad Fitzpatrick3f4ef592010-07-07 16:06:39 -0700374int32_t IPCThreadState::getStrictModePolicy() const
375{
Brad Fitzpatrick94c36342010-06-18 13:07:53 -0700376 return mStrictModePolicy;
377}
378
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -0700379void IPCThreadState::setLastTransactionBinderFlags(int32_t flags)
380{
381 mLastTransactionBinderFlags = flags;
382}
383
384int32_t IPCThreadState::getLastTransactionBinderFlags() const
385{
386 return mLastTransactionBinderFlags;
387}
388
Mathias Agopian7922fa22009-05-18 15:08:03 -0700389void IPCThreadState::restoreCallingIdentity(int64_t token)
390{
391 mCallingUid = (int)(token>>32);
392 mCallingPid = (int)token;
393}
394
395void IPCThreadState::clearCaller()
396{
Marco Nelissenb4f35d02009-07-17 07:59:17 -0700397 mCallingPid = getpid();
398 mCallingUid = getuid();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700399}
400
401void IPCThreadState::flushCommands()
402{
403 if (mProcess->mDriverFD <= 0)
404 return;
405 talkWithDriver(false);
406}
407
Wale Ogunwale2e604f02015-04-13 16:16:10 -0700408void IPCThreadState::blockUntilThreadAvailable()
409{
410 pthread_mutex_lock(&mProcess->mThreadCountLock);
411 while (mProcess->mExecutingThreadsCount >= mProcess->mMaxThreads) {
Wale Ogunwale319900a2015-04-21 12:29:50 -0700412 ALOGW("Waiting for thread to be free. mExecutingThreadsCount=%lu mMaxThreads=%lu\n",
413 static_cast<unsigned long>(mProcess->mExecutingThreadsCount),
414 static_cast<unsigned long>(mProcess->mMaxThreads));
Wale Ogunwale2e604f02015-04-13 16:16:10 -0700415 pthread_cond_wait(&mProcess->mThreadCountDecrement, &mProcess->mThreadCountLock);
416 }
417 pthread_mutex_unlock(&mProcess->mThreadCountLock);
418}
419
Todd Poynor0646cb02013-06-25 19:12:18 -0700420status_t IPCThreadState::getAndExecuteCommand()
421{
422 status_t result;
423 int32_t cmd;
424
425 result = talkWithDriver();
426 if (result >= NO_ERROR) {
427 size_t IN = mIn.dataAvail();
428 if (IN < sizeof(int32_t)) return result;
429 cmd = mIn.readInt32();
430 IF_LOG_COMMANDS() {
431 alog << "Processing top-level Command: "
432 << getReturnString(cmd) << endl;
433 }
434
Wale Ogunwale2e604f02015-04-13 16:16:10 -0700435 pthread_mutex_lock(&mProcess->mThreadCountLock);
436 mProcess->mExecutingThreadsCount++;
Colin Crossb1dc6542016-04-15 14:29:55 -0700437 if (mProcess->mExecutingThreadsCount >= mProcess->mMaxThreads &&
Martijn Coenen0ce07ce2017-07-14 15:37:25 +0200438 mProcess->mMaxThreads > 1 && mProcess->mStarvationStartTimeMs == 0) {
Colin Crossb1dc6542016-04-15 14:29:55 -0700439 mProcess->mStarvationStartTimeMs = uptimeMillis();
440 }
Wale Ogunwale2e604f02015-04-13 16:16:10 -0700441 pthread_mutex_unlock(&mProcess->mThreadCountLock);
442
Todd Poynor0646cb02013-06-25 19:12:18 -0700443 result = executeCommand(cmd);
444
Wale Ogunwale2e604f02015-04-13 16:16:10 -0700445 pthread_mutex_lock(&mProcess->mThreadCountLock);
446 mProcess->mExecutingThreadsCount--;
Martijn Coenen0ce07ce2017-07-14 15:37:25 +0200447 if (mProcess->mExecutingThreadsCount < mProcess->mMaxThreads && mProcess->mMaxThreads > 1 &&
448 mProcess->mStarvationStartTimeMs != 0) {
Colin Crossb1dc6542016-04-15 14:29:55 -0700449 int64_t starvationTimeMs = uptimeMillis() - mProcess->mStarvationStartTimeMs;
450 if (starvationTimeMs > 100) {
Martijn Coenen0ce07ce2017-07-14 15:37:25 +0200451 ALOGW("All binder threads in pool (%zu threads) busy for %" PRId64 " ms",
Colin Crossb1dc6542016-04-15 14:29:55 -0700452 mProcess->mMaxThreads, starvationTimeMs);
453 }
454 mProcess->mStarvationStartTimeMs = 0;
455 }
Wale Ogunwale2e604f02015-04-13 16:16:10 -0700456 pthread_cond_broadcast(&mProcess->mThreadCountDecrement);
457 pthread_mutex_unlock(&mProcess->mThreadCountLock);
Todd Poynor0646cb02013-06-25 19:12:18 -0700458 }
459
460 return result;
461}
462
463// When we've cleared the incoming command queue, process any pending derefs
464void IPCThreadState::processPendingDerefs()
465{
466 if (mIn.dataPosition() >= mIn.dataSize()) {
Martijn Coenenc9f105b2017-08-08 15:36:16 +0200467 /*
468 * The decWeak()/decStrong() calls may cause a destructor to run,
469 * which in turn could have initiated an outgoing transaction,
470 * which in turn could cause us to add to the pending refs
471 * vectors; so instead of simply iterating, loop until they're empty.
472 *
473 * We do this in an outer loop, because calling decStrong()
474 * may result in something being added to mPendingWeakDerefs,
475 * which could be delayed until the next incoming command
476 * from the driver if we don't process it now.
477 */
478 while (mPendingWeakDerefs.size() > 0 || mPendingStrongDerefs.size() > 0) {
479 while (mPendingWeakDerefs.size() > 0) {
480 RefBase::weakref_type* refs = mPendingWeakDerefs[0];
481 mPendingWeakDerefs.removeAt(0);
Todd Poynor0646cb02013-06-25 19:12:18 -0700482 refs->decWeak(mProcess.get());
483 }
Todd Poynor0646cb02013-06-25 19:12:18 -0700484
Martijn Coenenc9f105b2017-08-08 15:36:16 +0200485 if (mPendingStrongDerefs.size() > 0) {
486 // We don't use while() here because we don't want to re-order
487 // strong and weak decs at all; if this decStrong() causes both a
488 // decWeak() and a decStrong() to be queued, we want to process
489 // the decWeak() first.
490 BHwBinder* obj = mPendingStrongDerefs[0];
491 mPendingStrongDerefs.removeAt(0);
Todd Poynor0646cb02013-06-25 19:12:18 -0700492 obj->decStrong(mProcess.get());
493 }
Todd Poynor0646cb02013-06-25 19:12:18 -0700494 }
495 }
496}
497
Mathias Agopian7922fa22009-05-18 15:08:03 -0700498void IPCThreadState::joinThreadPool(bool isMain)
499{
500 LOG_THREADPOOL("**** THREAD %p (PID %d) IS JOINING THE THREAD POOL\n", (void*)pthread_self(), getpid());
501
502 mOut.writeInt32(isMain ? BC_ENTER_LOOPER : BC_REGISTER_LOOPER);
Yifan Hongdde40f32017-01-12 14:22:45 -0800503
Mathias Agopian7922fa22009-05-18 15:08:03 -0700504 status_t result;
505 do {
Todd Poynor0646cb02013-06-25 19:12:18 -0700506 processPendingDerefs();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700507 // now get the next command to be processed, waiting if necessary
Todd Poynor0646cb02013-06-25 19:12:18 -0700508 result = getAndExecuteCommand();
Jason Parks2b17f142009-11-03 12:14:38 -0800509
Todd Poynor0646cb02013-06-25 19:12:18 -0700510 if (result < NO_ERROR && result != TIMED_OUT && result != -ECONNREFUSED && result != -EBADF) {
511 ALOGE("getAndExecuteCommand(fd=%d) returned unexpected error %d, aborting",
Jeff Tinkeree711ec2013-06-11 11:30:21 -0700512 mProcess->mDriverFD, result);
513 abort();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700514 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800515
Mathias Agopian7922fa22009-05-18 15:08:03 -0700516 // Let this thread exit the thread pool if it is no longer
517 // needed and it is not the main process thread.
518 if(result == TIMED_OUT && !isMain) {
519 break;
520 }
521 } while (result != -ECONNREFUSED && result != -EBADF);
522
Wei Wang8a2e8ac2016-10-14 09:54:27 -0700523 LOG_THREADPOOL("**** THREAD %p (PID %d) IS LEAVING THE THREAD POOL err=%d\n",
524 (void*)pthread_self(), getpid(), result);
Yifan Hongdde40f32017-01-12 14:22:45 -0800525
Mathias Agopian7922fa22009-05-18 15:08:03 -0700526 mOut.writeInt32(BC_EXIT_LOOPER);
527 talkWithDriver(false);
528}
529
Todd Poynor0646cb02013-06-25 19:12:18 -0700530int IPCThreadState::setupPolling(int* fd)
531{
532 if (mProcess->mDriverFD <= 0) {
533 return -EBADF;
534 }
535
Martijn Coenen80b88ab2017-09-25 14:50:05 +0200536 // Tells the kernel to not spawn any additional binder threads,
537 // as that won't work with polling. Also, the caller is responsible
538 // for subsequently calling handlePolledCommands()
539 mProcess->setThreadPoolConfiguration(1, true /* callerWillJoin */);
540
Todd Poynor0646cb02013-06-25 19:12:18 -0700541 mOut.writeInt32(BC_ENTER_LOOPER);
542 *fd = mProcess->mDriverFD;
543 return 0;
544}
545
546status_t IPCThreadState::handlePolledCommands()
547{
548 status_t result;
549
550 do {
551 result = getAndExecuteCommand();
552 } while (mIn.dataPosition() < mIn.dataSize());
553
554 processPendingDerefs();
555 flushCommands();
556 return result;
557}
558
Colin Crossf0487982014-02-05 17:42:44 -0800559void IPCThreadState::stopProcess(bool /*immediate*/)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700560{
Steve Block93cf8542012-01-04 20:05:49 +0000561 //ALOGI("**** STOPPING PROCESS");
Mathias Agopian7922fa22009-05-18 15:08:03 -0700562 flushCommands();
563 int fd = mProcess->mDriverFD;
564 mProcess->mDriverFD = -1;
565 close(fd);
566 //kill(getpid(), SIGKILL);
567}
568
569status_t IPCThreadState::transact(int32_t handle,
570 uint32_t code, const Parcel& data,
571 Parcel* reply, uint32_t flags)
572{
Ganesh Mahendrance45b892017-10-11 18:05:13 +0800573 status_t err;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700574
575 flags |= TF_ACCEPT_FDS;
576
577 IF_LOG_TRANSACTIONS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700578 alog << "BC_TRANSACTION thr " << (void*)pthread_self() << " / hand "
579 << handle << " / code " << TypeCode(code) << ": "
580 << indent << data << dedent << endl;
581 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800582
Ganesh Mahendrance45b892017-10-11 18:05:13 +0800583 LOG_ONEWAY(">>>> SEND from pid %d uid %d %s", getpid(), getuid(),
584 (flags & TF_ONE_WAY) == 0 ? "READ REPLY" : "ONE WAY");
585 err = writeTransactionData(BC_TRANSACTION_SG, flags, handle, code, data, NULL);
Yifan Hongdde40f32017-01-12 14:22:45 -0800586
Mathias Agopian7922fa22009-05-18 15:08:03 -0700587 if (err != NO_ERROR) {
588 if (reply) reply->setError(err);
589 return (mLastError = err);
590 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800591
Mathias Agopian7922fa22009-05-18 15:08:03 -0700592 if ((flags & TF_ONE_WAY) == 0) {
Dianne Hackborn98878262010-09-24 11:16:23 -0700593 #if 0
594 if (code == 4) { // relayout
Steve Block93cf8542012-01-04 20:05:49 +0000595 ALOGI(">>>>>> CALLING transaction 4");
Dianne Hackborn98878262010-09-24 11:16:23 -0700596 } else {
Steve Block93cf8542012-01-04 20:05:49 +0000597 ALOGI(">>>>>> CALLING transaction %d", code);
Dianne Hackborn98878262010-09-24 11:16:23 -0700598 }
599 #endif
Mathias Agopian7922fa22009-05-18 15:08:03 -0700600 if (reply) {
601 err = waitForResponse(reply);
602 } else {
603 Parcel fakeReply;
604 err = waitForResponse(&fakeReply);
605 }
Dianne Hackborn98878262010-09-24 11:16:23 -0700606 #if 0
607 if (code == 4) { // relayout
Steve Block93cf8542012-01-04 20:05:49 +0000608 ALOGI("<<<<<< RETURNING transaction 4");
Dianne Hackborn98878262010-09-24 11:16:23 -0700609 } else {
Steve Block93cf8542012-01-04 20:05:49 +0000610 ALOGI("<<<<<< RETURNING transaction %d", code);
Dianne Hackborn98878262010-09-24 11:16:23 -0700611 }
612 #endif
Yifan Hongdde40f32017-01-12 14:22:45 -0800613
Mathias Agopian7922fa22009-05-18 15:08:03 -0700614 IF_LOG_TRANSACTIONS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700615 alog << "BR_REPLY thr " << (void*)pthread_self() << " / hand "
616 << handle << ": ";
617 if (reply) alog << indent << *reply << dedent << endl;
618 else alog << "(none requested)" << endl;
619 }
620 } else {
621 err = waitForResponse(NULL, NULL);
622 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800623
Mathias Agopian7922fa22009-05-18 15:08:03 -0700624 return err;
625}
626
627void IPCThreadState::incStrongHandle(int32_t handle)
628{
629 LOG_REMOTEREFS("IPCThreadState::incStrongHandle(%d)\n", handle);
630 mOut.writeInt32(BC_ACQUIRE);
631 mOut.writeInt32(handle);
632}
633
634void IPCThreadState::decStrongHandle(int32_t handle)
635{
636 LOG_REMOTEREFS("IPCThreadState::decStrongHandle(%d)\n", handle);
637 mOut.writeInt32(BC_RELEASE);
638 mOut.writeInt32(handle);
639}
640
641void IPCThreadState::incWeakHandle(int32_t handle)
642{
643 LOG_REMOTEREFS("IPCThreadState::incWeakHandle(%d)\n", handle);
644 mOut.writeInt32(BC_INCREFS);
645 mOut.writeInt32(handle);
646}
647
648void IPCThreadState::decWeakHandle(int32_t handle)
649{
650 LOG_REMOTEREFS("IPCThreadState::decWeakHandle(%d)\n", handle);
651 mOut.writeInt32(BC_DECREFS);
652 mOut.writeInt32(handle);
653}
654
655status_t IPCThreadState::attemptIncStrongHandle(int32_t handle)
656{
Arve Hjønnevåg304dcae2014-02-14 20:14:02 -0800657#if HAS_BC_ATTEMPT_ACQUIRE
Andy McFadden457d51f2011-08-31 07:43:40 -0700658 LOG_REMOTEREFS("IPCThreadState::attemptIncStrongHandle(%d)\n", handle);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700659 mOut.writeInt32(BC_ATTEMPT_ACQUIRE);
660 mOut.writeInt32(0); // xxx was thread priority
661 mOut.writeInt32(handle);
662 status_t result = UNKNOWN_ERROR;
Yifan Hongdde40f32017-01-12 14:22:45 -0800663
Mathias Agopian7922fa22009-05-18 15:08:03 -0700664 waitForResponse(NULL, &result);
Yifan Hongdde40f32017-01-12 14:22:45 -0800665
Mathias Agopian7922fa22009-05-18 15:08:03 -0700666#if LOG_REFCOUNTS
667 printf("IPCThreadState::attemptIncStrongHandle(%ld) = %s\n",
668 handle, result == NO_ERROR ? "SUCCESS" : "FAILURE");
669#endif
Yifan Hongdde40f32017-01-12 14:22:45 -0800670
Mathias Agopian7922fa22009-05-18 15:08:03 -0700671 return result;
Arve Hjønnevåg304dcae2014-02-14 20:14:02 -0800672#else
673 (void)handle;
674 ALOGE("%s(%d): Not supported\n", __func__, handle);
675 return INVALID_OPERATION;
676#endif
Mathias Agopian7922fa22009-05-18 15:08:03 -0700677}
678
679void IPCThreadState::expungeHandle(int32_t handle, IBinder* binder)
680{
681#if LOG_REFCOUNTS
682 printf("IPCThreadState::expungeHandle(%ld)\n", handle);
683#endif
Yunlian Jiang6b65ac32017-09-19 15:51:07 -0700684 self()->mProcess->expungeHandle(handle, binder); // NOLINT
Mathias Agopian7922fa22009-05-18 15:08:03 -0700685}
686
Yifan Hong1e118d22017-01-12 14:42:28 -0800687status_t IPCThreadState::requestDeathNotification(int32_t handle, BpHwBinder* proxy)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700688{
689 mOut.writeInt32(BC_REQUEST_DEATH_NOTIFICATION);
690 mOut.writeInt32((int32_t)handle);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +0000691 mOut.writePointer((uintptr_t)proxy);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700692 return NO_ERROR;
693}
694
Yifan Hong1e118d22017-01-12 14:42:28 -0800695status_t IPCThreadState::clearDeathNotification(int32_t handle, BpHwBinder* proxy)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700696{
697 mOut.writeInt32(BC_CLEAR_DEATH_NOTIFICATION);
698 mOut.writeInt32((int32_t)handle);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +0000699 mOut.writePointer((uintptr_t)proxy);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700700 return NO_ERROR;
701}
702
703IPCThreadState::IPCThreadState()
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -0700704 : mProcess(ProcessState::self()),
Elliott Hughes07cf48a2014-08-18 10:38:38 -0700705 mMyThreadId(gettid()),
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -0700706 mStrictModePolicy(0),
707 mLastTransactionBinderFlags(0)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700708{
709 pthread_setspecific(gTLS, this);
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800710 clearCaller();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700711 mIn.setDataCapacity(256);
712 mOut.setDataCapacity(256);
713}
714
715IPCThreadState::~IPCThreadState()
716{
717}
718
719status_t IPCThreadState::sendReply(const Parcel& reply, uint32_t flags)
720{
721 status_t err;
722 status_t statusBuffer;
Martijn Coenend39a1682016-06-03 21:27:28 +0200723 err = writeTransactionData(BC_REPLY_SG, flags, -1, 0, reply, &statusBuffer);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700724 if (err < NO_ERROR) return err;
Yifan Hongdde40f32017-01-12 14:22:45 -0800725
Mathias Agopian7922fa22009-05-18 15:08:03 -0700726 return waitForResponse(NULL, NULL);
727}
728
729status_t IPCThreadState::waitForResponse(Parcel *reply, status_t *acquireResult)
730{
Bernhard Rosenkränzerb184ed02014-11-25 21:55:33 +0100731 uint32_t cmd;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700732 int32_t err;
733
734 while (1) {
735 if ((err=talkWithDriver()) < NO_ERROR) break;
736 err = mIn.errorCheck();
737 if (err < NO_ERROR) break;
738 if (mIn.dataAvail() == 0) continue;
Yifan Hongdde40f32017-01-12 14:22:45 -0800739
Bernhard Rosenkränzerb184ed02014-11-25 21:55:33 +0100740 cmd = (uint32_t)mIn.readInt32();
Yifan Hongdde40f32017-01-12 14:22:45 -0800741
Mathias Agopian7922fa22009-05-18 15:08:03 -0700742 IF_LOG_COMMANDS() {
743 alog << "Processing waitForResponse Command: "
744 << getReturnString(cmd) << endl;
745 }
746
747 switch (cmd) {
748 case BR_TRANSACTION_COMPLETE:
749 if (!reply && !acquireResult) goto finish;
750 break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800751
Mathias Agopian7922fa22009-05-18 15:08:03 -0700752 case BR_DEAD_REPLY:
753 err = DEAD_OBJECT;
754 goto finish;
755
756 case BR_FAILED_REPLY:
757 err = FAILED_TRANSACTION;
758 goto finish;
Yifan Hongdde40f32017-01-12 14:22:45 -0800759
Mathias Agopian7922fa22009-05-18 15:08:03 -0700760 case BR_ACQUIRE_RESULT:
761 {
Steve Blockd0bfabc2012-01-09 18:35:44 +0000762 ALOG_ASSERT(acquireResult != NULL, "Unexpected brACQUIRE_RESULT");
Mathias Agopian7922fa22009-05-18 15:08:03 -0700763 const int32_t result = mIn.readInt32();
764 if (!acquireResult) continue;
765 *acquireResult = result ? NO_ERROR : INVALID_OPERATION;
766 }
767 goto finish;
Yifan Hongdde40f32017-01-12 14:22:45 -0800768
Mathias Agopian7922fa22009-05-18 15:08:03 -0700769 case BR_REPLY:
770 {
771 binder_transaction_data tr;
772 err = mIn.read(&tr, sizeof(tr));
Steve Blockd0bfabc2012-01-09 18:35:44 +0000773 ALOG_ASSERT(err == NO_ERROR, "Not enough command data for brREPLY");
Mathias Agopian7922fa22009-05-18 15:08:03 -0700774 if (err != NO_ERROR) goto finish;
775
776 if (reply) {
777 if ((tr.flags & TF_STATUS_CODE) == 0) {
778 reply->ipcSetDataReference(
779 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
780 tr.data_size,
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800781 reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
782 tr.offsets_size/sizeof(binder_size_t),
Mathias Agopian7922fa22009-05-18 15:08:03 -0700783 freeBuffer, this);
784 } else {
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800785 err = *reinterpret_cast<const status_t*>(tr.data.ptr.buffer);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700786 freeBuffer(NULL,
787 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
788 tr.data_size,
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800789 reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
790 tr.offsets_size/sizeof(binder_size_t), this);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700791 }
792 } else {
793 freeBuffer(NULL,
794 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
795 tr.data_size,
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800796 reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
797 tr.offsets_size/sizeof(binder_size_t), this);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700798 continue;
799 }
800 }
801 goto finish;
802
803 default:
804 err = executeCommand(cmd);
805 if (err != NO_ERROR) goto finish;
806 break;
807 }
808 }
809
810finish:
811 if (err != NO_ERROR) {
812 if (acquireResult) *acquireResult = err;
813 if (reply) reply->setError(err);
814 mLastError = err;
815 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800816
Mathias Agopian7922fa22009-05-18 15:08:03 -0700817 return err;
818}
819
820status_t IPCThreadState::talkWithDriver(bool doReceive)
821{
Johannes Carlsson597a3c72011-02-17 14:06:53 +0100822 if (mProcess->mDriverFD <= 0) {
823 return -EBADF;
824 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800825
Mathias Agopian7922fa22009-05-18 15:08:03 -0700826 binder_write_read bwr;
Yifan Hongdde40f32017-01-12 14:22:45 -0800827
Mathias Agopian7922fa22009-05-18 15:08:03 -0700828 // Is the read buffer empty?
829 const bool needRead = mIn.dataPosition() >= mIn.dataSize();
Yifan Hongdde40f32017-01-12 14:22:45 -0800830
Mathias Agopian7922fa22009-05-18 15:08:03 -0700831 // We don't want to write anything if we are still reading
832 // from data left in the input buffer and the caller
833 // has requested to read the next data.
834 const size_t outAvail = (!doReceive || needRead) ? mOut.dataSize() : 0;
Yifan Hongdde40f32017-01-12 14:22:45 -0800835
Mathias Agopian7922fa22009-05-18 15:08:03 -0700836 bwr.write_size = outAvail;
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800837 bwr.write_buffer = (uintptr_t)mOut.data();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700838
839 // This is what we'll read.
840 if (doReceive && needRead) {
841 bwr.read_size = mIn.dataCapacity();
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800842 bwr.read_buffer = (uintptr_t)mIn.data();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700843 } else {
844 bwr.read_size = 0;
Ben Cheng455a70a2011-12-01 17:11:32 -0800845 bwr.read_buffer = 0;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700846 }
Andy McFadden457d51f2011-08-31 07:43:40 -0700847
Mathias Agopian7922fa22009-05-18 15:08:03 -0700848 IF_LOG_COMMANDS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700849 if (outAvail != 0) {
850 alog << "Sending commands to driver: " << indent;
851 const void* cmds = (const void*)bwr.write_buffer;
852 const void* end = ((const uint8_t*)cmds)+bwr.write_size;
853 alog << HexDump(cmds, bwr.write_size) << endl;
854 while (cmds < end) cmds = printCommand(alog, cmds);
855 alog << dedent;
856 }
857 alog << "Size of receive buffer: " << bwr.read_size
858 << ", needRead: " << needRead << ", doReceive: " << doReceive << endl;
859 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800860
Mathias Agopian7922fa22009-05-18 15:08:03 -0700861 // Return immediately if there is nothing to do.
862 if ((bwr.write_size == 0) && (bwr.read_size == 0)) return NO_ERROR;
Andy McFadden457d51f2011-08-31 07:43:40 -0700863
Mathias Agopian7922fa22009-05-18 15:08:03 -0700864 bwr.write_consumed = 0;
865 bwr.read_consumed = 0;
866 status_t err;
867 do {
868 IF_LOG_COMMANDS() {
869 alog << "About to read/write, write size = " << mOut.dataSize() << endl;
870 }
Elliott Hughese5e70552015-08-12 15:27:47 -0700871#if defined(__ANDROID__)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700872 if (ioctl(mProcess->mDriverFD, BINDER_WRITE_READ, &bwr) >= 0)
873 err = NO_ERROR;
874 else
875 err = -errno;
876#else
877 err = INVALID_OPERATION;
878#endif
Johannes Carlsson597a3c72011-02-17 14:06:53 +0100879 if (mProcess->mDriverFD <= 0) {
880 err = -EBADF;
881 }
Mathias Agopian7922fa22009-05-18 15:08:03 -0700882 IF_LOG_COMMANDS() {
883 alog << "Finished read/write, write size = " << mOut.dataSize() << endl;
884 }
885 } while (err == -EINTR);
Andy McFadden457d51f2011-08-31 07:43:40 -0700886
Mathias Agopian7922fa22009-05-18 15:08:03 -0700887 IF_LOG_COMMANDS() {
Colin Crossf0487982014-02-05 17:42:44 -0800888 alog << "Our err: " << (void*)(intptr_t)err << ", write consumed: "
Mathias Agopian7922fa22009-05-18 15:08:03 -0700889 << bwr.write_consumed << " (of " << mOut.dataSize()
Todd Poynor0646cb02013-06-25 19:12:18 -0700890 << "), read consumed: " << bwr.read_consumed << endl;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700891 }
892
893 if (err >= NO_ERROR) {
894 if (bwr.write_consumed > 0) {
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800895 if (bwr.write_consumed < mOut.dataSize())
Mathias Agopian7922fa22009-05-18 15:08:03 -0700896 mOut.remove(0, bwr.write_consumed);
897 else
898 mOut.setDataSize(0);
899 }
900 if (bwr.read_consumed > 0) {
901 mIn.setDataSize(bwr.read_consumed);
902 mIn.setDataPosition(0);
903 }
904 IF_LOG_COMMANDS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700905 alog << "Remaining data size: " << mOut.dataSize() << endl;
906 alog << "Received commands from driver: " << indent;
907 const void* cmds = mIn.data();
908 const void* end = mIn.data() + mIn.dataSize();
909 alog << HexDump(cmds, mIn.dataSize()) << endl;
910 while (cmds < end) cmds = printReturnCommand(alog, cmds);
911 alog << dedent;
912 }
913 return NO_ERROR;
914 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800915
Mathias Agopian7922fa22009-05-18 15:08:03 -0700916 return err;
917}
918
919status_t IPCThreadState::writeTransactionData(int32_t cmd, uint32_t binderFlags,
920 int32_t handle, uint32_t code, const Parcel& data, status_t* statusBuffer)
921{
Martijn Coenenfd51ebb2016-07-05 17:00:39 +0200922 binder_transaction_data_sg tr_sg;
Christopher Ferris678434f2017-07-27 10:42:20 -0700923 /* Don't pass uninitialized stack data to a remote process */
924 tr_sg.transaction_data.target.ptr = 0;
925 tr_sg.transaction_data.target.handle = handle;
926 tr_sg.transaction_data.code = code;
927 tr_sg.transaction_data.flags = binderFlags;
928 tr_sg.transaction_data.cookie = 0;
929 tr_sg.transaction_data.sender_pid = 0;
930 tr_sg.transaction_data.sender_euid = 0;
Yifan Hongdde40f32017-01-12 14:22:45 -0800931
Mathias Agopian7922fa22009-05-18 15:08:03 -0700932 const status_t err = data.errorCheck();
933 if (err == NO_ERROR) {
Christopher Ferris678434f2017-07-27 10:42:20 -0700934 tr_sg.transaction_data.data_size = data.ipcDataSize();
935 tr_sg.transaction_data.data.ptr.buffer = data.ipcData();
936 tr_sg.transaction_data.offsets_size = data.ipcObjectsCount()*sizeof(binder_size_t);
937 tr_sg.transaction_data.data.ptr.offsets = data.ipcObjects();
Martijn Coenenfd51ebb2016-07-05 17:00:39 +0200938 tr_sg.buffers_size = data.ipcBufferSize();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700939 } else if (statusBuffer) {
Christopher Ferris678434f2017-07-27 10:42:20 -0700940 tr_sg.transaction_data.flags |= TF_STATUS_CODE;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700941 *statusBuffer = err;
Christopher Ferris678434f2017-07-27 10:42:20 -0700942 tr_sg.transaction_data.data_size = sizeof(status_t);
943 tr_sg.transaction_data.data.ptr.buffer = reinterpret_cast<uintptr_t>(statusBuffer);
944 tr_sg.transaction_data.offsets_size = 0;
945 tr_sg.transaction_data.data.ptr.offsets = 0;
Martijn Coenenfd51ebb2016-07-05 17:00:39 +0200946 tr_sg.buffers_size = 0;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700947 } else {
948 return (mLastError = err);
949 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800950
Mathias Agopian7922fa22009-05-18 15:08:03 -0700951 mOut.writeInt32(cmd);
Martijn Coenenfd51ebb2016-07-05 17:00:39 +0200952 mOut.write(&tr_sg, sizeof(tr_sg));
Yifan Hongdde40f32017-01-12 14:22:45 -0800953
Mathias Agopian7922fa22009-05-18 15:08:03 -0700954 return NO_ERROR;
955}
956
Yifan Hongdde40f32017-01-12 14:22:45 -0800957void IPCThreadState::setTheContextObject(sp<BHwBinder> obj)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700958{
Martijn Coenena660cbc2016-05-12 11:29:23 +0200959 mContextObject = obj;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700960}
961
962status_t IPCThreadState::executeCommand(int32_t cmd)
963{
Yifan Hongdde40f32017-01-12 14:22:45 -0800964 BHwBinder* obj;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700965 RefBase::weakref_type* refs;
966 status_t result = NO_ERROR;
Bernhard Rosenkränzerb184ed02014-11-25 21:55:33 +0100967 switch ((uint32_t)cmd) {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700968 case BR_ERROR:
969 result = mIn.readInt32();
970 break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800971
Mathias Agopian7922fa22009-05-18 15:08:03 -0700972 case BR_OK:
973 break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800974
Mathias Agopian7922fa22009-05-18 15:08:03 -0700975 case BR_ACQUIRE:
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +0000976 refs = (RefBase::weakref_type*)mIn.readPointer();
Yifan Hongdde40f32017-01-12 14:22:45 -0800977 obj = (BHwBinder*)mIn.readPointer();
Steve Blockd0bfabc2012-01-09 18:35:44 +0000978 ALOG_ASSERT(refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -0700979 "BR_ACQUIRE: object %p does not match cookie %p (expected %p)",
980 refs, obj, refs->refBase());
981 obj->incStrong(mProcess.get());
982 IF_LOG_REMOTEREFS() {
983 LOG_REMOTEREFS("BR_ACQUIRE from driver on %p", obj);
984 obj->printRefs();
985 }
986 mOut.writeInt32(BC_ACQUIRE_DONE);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +0000987 mOut.writePointer((uintptr_t)refs);
988 mOut.writePointer((uintptr_t)obj);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700989 break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800990
Mathias Agopian7922fa22009-05-18 15:08:03 -0700991 case BR_RELEASE:
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +0000992 refs = (RefBase::weakref_type*)mIn.readPointer();
Yifan Hongdde40f32017-01-12 14:22:45 -0800993 obj = (BHwBinder*)mIn.readPointer();
Steve Blockd0bfabc2012-01-09 18:35:44 +0000994 ALOG_ASSERT(refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -0700995 "BR_RELEASE: object %p does not match cookie %p (expected %p)",
996 refs, obj, refs->refBase());
997 IF_LOG_REMOTEREFS() {
998 LOG_REMOTEREFS("BR_RELEASE from driver on %p", obj);
999 obj->printRefs();
1000 }
1001 mPendingStrongDerefs.push(obj);
1002 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001003
Mathias Agopian7922fa22009-05-18 15:08:03 -07001004 case BR_INCREFS:
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001005 refs = (RefBase::weakref_type*)mIn.readPointer();
Yifan Hongdde40f32017-01-12 14:22:45 -08001006 obj = (BHwBinder*)mIn.readPointer();
Mathias Agopian7922fa22009-05-18 15:08:03 -07001007 refs->incWeak(mProcess.get());
1008 mOut.writeInt32(BC_INCREFS_DONE);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001009 mOut.writePointer((uintptr_t)refs);
1010 mOut.writePointer((uintptr_t)obj);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001011 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001012
Mathias Agopian7922fa22009-05-18 15:08:03 -07001013 case BR_DECREFS:
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001014 refs = (RefBase::weakref_type*)mIn.readPointer();
Yifan Hongdde40f32017-01-12 14:22:45 -08001015 obj = (BHwBinder*)mIn.readPointer();
Mathias Agopian7922fa22009-05-18 15:08:03 -07001016 // NOTE: This assertion is not valid, because the object may no
Yifan Hongdde40f32017-01-12 14:22:45 -08001017 // longer exist (thus the (BHwBinder*)cast above resulting in a different
Mathias Agopian7922fa22009-05-18 15:08:03 -07001018 // memory address).
Steve Blockd0bfabc2012-01-09 18:35:44 +00001019 //ALOG_ASSERT(refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -07001020 // "BR_DECREFS: object %p does not match cookie %p (expected %p)",
1021 // refs, obj, refs->refBase());
1022 mPendingWeakDerefs.push(refs);
1023 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001024
Mathias Agopian7922fa22009-05-18 15:08:03 -07001025 case BR_ATTEMPT_ACQUIRE:
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001026 refs = (RefBase::weakref_type*)mIn.readPointer();
Yifan Hongdde40f32017-01-12 14:22:45 -08001027 obj = (BHwBinder*)mIn.readPointer();
1028
Mathias Agopian7922fa22009-05-18 15:08:03 -07001029 {
1030 const bool success = refs->attemptIncStrong(mProcess.get());
Steve Blockd0bfabc2012-01-09 18:35:44 +00001031 ALOG_ASSERT(success && refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -07001032 "BR_ATTEMPT_ACQUIRE: object %p does not match cookie %p (expected %p)",
1033 refs, obj, refs->refBase());
Yifan Hongdde40f32017-01-12 14:22:45 -08001034
Mathias Agopian7922fa22009-05-18 15:08:03 -07001035 mOut.writeInt32(BC_ACQUIRE_RESULT);
1036 mOut.writeInt32((int32_t)success);
1037 }
1038 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001039
Mathias Agopian7922fa22009-05-18 15:08:03 -07001040 case BR_TRANSACTION:
1041 {
1042 binder_transaction_data tr;
1043 result = mIn.read(&tr, sizeof(tr));
Steve Blockd0bfabc2012-01-09 18:35:44 +00001044 ALOG_ASSERT(result == NO_ERROR,
Mathias Agopian7922fa22009-05-18 15:08:03 -07001045 "Not enough command data for brTRANSACTION");
1046 if (result != NO_ERROR) break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001047
Mathias Agopian7922fa22009-05-18 15:08:03 -07001048 Parcel buffer;
1049 buffer.ipcSetDataReference(
1050 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
1051 tr.data_size,
Arve Hjønnevåga5440702014-01-28 20:12:59 -08001052 reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
1053 tr.offsets_size/sizeof(binder_size_t), freeBuffer, this);
Yifan Hongdde40f32017-01-12 14:22:45 -08001054
Mathias Agopian7922fa22009-05-18 15:08:03 -07001055 const pid_t origPid = mCallingPid;
1056 const uid_t origUid = mCallingUid;
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001057 const int32_t origStrictModePolicy = mStrictModePolicy;
1058 const int32_t origTransactionBinderFlags = mLastTransactionBinderFlags;
1059
Mathias Agopian7922fa22009-05-18 15:08:03 -07001060 mCallingPid = tr.sender_pid;
1061 mCallingUid = tr.sender_euid;
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001062 mLastTransactionBinderFlags = tr.flags;
1063
Steve Block93cf8542012-01-04 20:05:49 +00001064 //ALOGI(">>>> TRANSACT from pid %d uid %d\n", mCallingPid, mCallingUid);
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001065
Mathias Agopian7922fa22009-05-18 15:08:03 -07001066 Parcel reply;
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001067 status_t error;
Martijn Coenen79c2f4d2016-05-20 10:55:59 +02001068 bool reply_sent = false;
Mathias Agopian7922fa22009-05-18 15:08:03 -07001069 IF_LOG_TRANSACTIONS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -07001070 alog << "BR_TRANSACTION thr " << (void*)pthread_self()
1071 << " / obj " << tr.target.ptr << " / code "
1072 << TypeCode(tr.code) << ": " << indent << buffer
1073 << dedent << endl
1074 << "Data addr = "
1075 << reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer)
1076 << ", offsets addr="
1077 << reinterpret_cast<const size_t*>(tr.data.ptr.offsets) << endl;
1078 }
Martijn Coenen79c2f4d2016-05-20 10:55:59 +02001079
1080 auto reply_callback = [&] (auto &replyParcel) {
1081 if (reply_sent) {
1082 // Reply was sent earlier, ignore it.
1083 ALOGE("Dropping binder reply, it was sent already.");
1084 return;
1085 }
1086 reply_sent = true;
1087 if ((tr.flags & TF_ONE_WAY) == 0) {
1088 replyParcel.setError(NO_ERROR);
1089 sendReply(replyParcel, 0);
1090 } else {
1091 ALOGE("Not sending reply in one-way transaction");
1092 }
1093 };
1094
Mathias Agopian7922fa22009-05-18 15:08:03 -07001095 if (tr.target.ptr) {
Dianne Hackborn839f7072016-03-21 10:36:54 -07001096 // We only have a weak reference on the target object, so we must first try to
1097 // safely acquire a strong reference before doing anything else with it.
1098 if (reinterpret_cast<RefBase::weakref_type*>(
1099 tr.target.ptr)->attemptIncStrong(this)) {
Yifan Hongdde40f32017-01-12 14:22:45 -08001100 error = reinterpret_cast<BHwBinder*>(tr.cookie)->transact(tr.code, buffer,
Martijn Coenen79c2f4d2016-05-20 10:55:59 +02001101 &reply, tr.flags, reply_callback);
Yifan Hongdde40f32017-01-12 14:22:45 -08001102 reinterpret_cast<BHwBinder*>(tr.cookie)->decStrong(this);
Dianne Hackborn839f7072016-03-21 10:36:54 -07001103 } else {
1104 error = UNKNOWN_TRANSACTION;
1105 }
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -07001106
Mathias Agopian7922fa22009-05-18 15:08:03 -07001107 } else {
Martijn Coenena660cbc2016-05-12 11:29:23 +02001108 error = mContextObject->transact(tr.code, buffer, &reply, tr.flags, reply_callback);
Martijn Coenen79c2f4d2016-05-20 10:55:59 +02001109 }
1110
1111 if ((tr.flags & TF_ONE_WAY) == 0) {
1112 if (!reply_sent) {
1113 // Should have been a reply but there wasn't, so there
1114 // must have been an error instead.
1115 reply.setError(error);
1116 sendReply(reply, 0);
1117 } else {
1118 if (error != NO_ERROR) {
1119 ALOGE("transact() returned error after sending reply.");
1120 } else {
1121 // Ok, reply sent and transact didn't return an error.
1122 }
1123 }
1124 } else {
1125 // One-way transaction, don't care about return value or reply.
Mathias Agopian7922fa22009-05-18 15:08:03 -07001126 }
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001127
Steve Block93cf8542012-01-04 20:05:49 +00001128 //ALOGI("<<<< TRANSACT from pid %d restore pid %d uid %d\n",
Mathias Agopian7922fa22009-05-18 15:08:03 -07001129 // mCallingPid, origPid, origUid);
Martijn Coenen79c2f4d2016-05-20 10:55:59 +02001130
Yifan Hongdde40f32017-01-12 14:22:45 -08001131
Mathias Agopian7922fa22009-05-18 15:08:03 -07001132 mCallingPid = origPid;
1133 mCallingUid = origUid;
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001134 mStrictModePolicy = origStrictModePolicy;
1135 mLastTransactionBinderFlags = origTransactionBinderFlags;
Christopher Tate7c4dfec2010-03-18 17:55:03 -07001136
Mathias Agopian7922fa22009-05-18 15:08:03 -07001137 IF_LOG_TRANSACTIONS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -07001138 alog << "BC_REPLY thr " << (void*)pthread_self() << " / obj "
1139 << tr.target.ptr << ": " << indent << reply << dedent << endl;
1140 }
Yifan Hongdde40f32017-01-12 14:22:45 -08001141
Mathias Agopian7922fa22009-05-18 15:08:03 -07001142 }
1143 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001144
Mathias Agopian7922fa22009-05-18 15:08:03 -07001145 case BR_DEAD_BINDER:
1146 {
Yifan Hong1e118d22017-01-12 14:42:28 -08001147 BpHwBinder *proxy = (BpHwBinder*)mIn.readPointer();
Mathias Agopian7922fa22009-05-18 15:08:03 -07001148 proxy->sendObituary();
1149 mOut.writeInt32(BC_DEAD_BINDER_DONE);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001150 mOut.writePointer((uintptr_t)proxy);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001151 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001152
Mathias Agopian7922fa22009-05-18 15:08:03 -07001153 case BR_CLEAR_DEATH_NOTIFICATION_DONE:
1154 {
Yifan Hong1e118d22017-01-12 14:42:28 -08001155 BpHwBinder *proxy = (BpHwBinder*)mIn.readPointer();
Mathias Agopian7922fa22009-05-18 15:08:03 -07001156 proxy->getWeakRefs()->decWeak(proxy);
1157 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001158
Mathias Agopian7922fa22009-05-18 15:08:03 -07001159 case BR_FINISHED:
1160 result = TIMED_OUT;
1161 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001162
Mathias Agopian7922fa22009-05-18 15:08:03 -07001163 case BR_NOOP:
1164 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001165
Mathias Agopian7922fa22009-05-18 15:08:03 -07001166 case BR_SPAWN_LOOPER:
1167 mProcess->spawnPooledThread(false);
1168 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001169
Mathias Agopian7922fa22009-05-18 15:08:03 -07001170 default:
1171 printf("*** BAD COMMAND %d received from Binder driver\n", cmd);
1172 result = UNKNOWN_ERROR;
1173 break;
1174 }
1175
1176 if (result != NO_ERROR) {
1177 mLastError = result;
1178 }
Yifan Hongdde40f32017-01-12 14:22:45 -08001179
Mathias Agopian7922fa22009-05-18 15:08:03 -07001180 return result;
1181}
1182
1183void IPCThreadState::threadDestructor(void *st)
1184{
Todd Poynor0646cb02013-06-25 19:12:18 -07001185 IPCThreadState* const self = static_cast<IPCThreadState*>(st);
1186 if (self) {
1187 self->flushCommands();
Elliott Hughese5e70552015-08-12 15:27:47 -07001188#if defined(__ANDROID__)
Johannes Carlsson597a3c72011-02-17 14:06:53 +01001189 if (self->mProcess->mDriverFD > 0) {
1190 ioctl(self->mProcess->mDriverFD, BINDER_THREAD_EXIT, 0);
1191 }
Mathias Agopian7922fa22009-05-18 15:08:03 -07001192#endif
Todd Poynor0646cb02013-06-25 19:12:18 -07001193 delete self;
1194 }
Mathias Agopian7922fa22009-05-18 15:08:03 -07001195}
1196
1197
Colin Crossf0487982014-02-05 17:42:44 -08001198void IPCThreadState::freeBuffer(Parcel* parcel, const uint8_t* data,
1199 size_t /*dataSize*/,
1200 const binder_size_t* /*objects*/,
1201 size_t /*objectsSize*/, void* /*cookie*/)
Mathias Agopian7922fa22009-05-18 15:08:03 -07001202{
Steve Block93cf8542012-01-04 20:05:49 +00001203 //ALOGI("Freeing parcel %p", &parcel);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001204 IF_LOG_COMMANDS() {
1205 alog << "Writing BC_FREE_BUFFER for " << data << endl;
1206 }
Steve Blockd0bfabc2012-01-09 18:35:44 +00001207 ALOG_ASSERT(data != NULL, "Called with NULL data");
Mathias Agopian7922fa22009-05-18 15:08:03 -07001208 if (parcel != NULL) parcel->closeFileDescriptors();
1209 IPCThreadState* state = self();
1210 state->mOut.writeInt32(BC_FREE_BUFFER);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001211 state->mOut.writePointer((uintptr_t)data);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001212}
1213
Martijn Coenenf75a23d2016-08-01 11:55:17 +02001214}; // namespace hardware
Mathias Agopian7922fa22009-05-18 15:08:03 -07001215}; // namespace android