blob: 2f27c2b139205f4a3d280427d7fdf14b613009c6 [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{
573 status_t err = data.errorCheck();
574
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
Mathias Agopian7922fa22009-05-18 15:08:03 -0700583 if (err == NO_ERROR) {
584 LOG_ONEWAY(">>>> SEND from pid %d uid %d %s", getpid(), getuid(),
585 (flags & TF_ONE_WAY) == 0 ? "READ REPLY" : "ONE WAY");
Martijn Coenend39a1682016-06-03 21:27:28 +0200586 err = writeTransactionData(BC_TRANSACTION_SG, flags, handle, code, data, NULL);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700587 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800588
Mathias Agopian7922fa22009-05-18 15:08:03 -0700589 if (err != NO_ERROR) {
590 if (reply) reply->setError(err);
591 return (mLastError = err);
592 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800593
Mathias Agopian7922fa22009-05-18 15:08:03 -0700594 if ((flags & TF_ONE_WAY) == 0) {
Dianne Hackborn98878262010-09-24 11:16:23 -0700595 #if 0
596 if (code == 4) { // relayout
Steve Block93cf8542012-01-04 20:05:49 +0000597 ALOGI(">>>>>> CALLING transaction 4");
Dianne Hackborn98878262010-09-24 11:16:23 -0700598 } else {
Steve Block93cf8542012-01-04 20:05:49 +0000599 ALOGI(">>>>>> CALLING transaction %d", code);
Dianne Hackborn98878262010-09-24 11:16:23 -0700600 }
601 #endif
Mathias Agopian7922fa22009-05-18 15:08:03 -0700602 if (reply) {
603 err = waitForResponse(reply);
604 } else {
605 Parcel fakeReply;
606 err = waitForResponse(&fakeReply);
607 }
Dianne Hackborn98878262010-09-24 11:16:23 -0700608 #if 0
609 if (code == 4) { // relayout
Steve Block93cf8542012-01-04 20:05:49 +0000610 ALOGI("<<<<<< RETURNING transaction 4");
Dianne Hackborn98878262010-09-24 11:16:23 -0700611 } else {
Steve Block93cf8542012-01-04 20:05:49 +0000612 ALOGI("<<<<<< RETURNING transaction %d", code);
Dianne Hackborn98878262010-09-24 11:16:23 -0700613 }
614 #endif
Yifan Hongdde40f32017-01-12 14:22:45 -0800615
Mathias Agopian7922fa22009-05-18 15:08:03 -0700616 IF_LOG_TRANSACTIONS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700617 alog << "BR_REPLY thr " << (void*)pthread_self() << " / hand "
618 << handle << ": ";
619 if (reply) alog << indent << *reply << dedent << endl;
620 else alog << "(none requested)" << endl;
621 }
622 } else {
623 err = waitForResponse(NULL, NULL);
624 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800625
Mathias Agopian7922fa22009-05-18 15:08:03 -0700626 return err;
627}
628
629void IPCThreadState::incStrongHandle(int32_t handle)
630{
631 LOG_REMOTEREFS("IPCThreadState::incStrongHandle(%d)\n", handle);
632 mOut.writeInt32(BC_ACQUIRE);
633 mOut.writeInt32(handle);
634}
635
636void IPCThreadState::decStrongHandle(int32_t handle)
637{
638 LOG_REMOTEREFS("IPCThreadState::decStrongHandle(%d)\n", handle);
639 mOut.writeInt32(BC_RELEASE);
640 mOut.writeInt32(handle);
641}
642
643void IPCThreadState::incWeakHandle(int32_t handle)
644{
645 LOG_REMOTEREFS("IPCThreadState::incWeakHandle(%d)\n", handle);
646 mOut.writeInt32(BC_INCREFS);
647 mOut.writeInt32(handle);
648}
649
650void IPCThreadState::decWeakHandle(int32_t handle)
651{
652 LOG_REMOTEREFS("IPCThreadState::decWeakHandle(%d)\n", handle);
653 mOut.writeInt32(BC_DECREFS);
654 mOut.writeInt32(handle);
655}
656
657status_t IPCThreadState::attemptIncStrongHandle(int32_t handle)
658{
Arve Hjønnevåg304dcae2014-02-14 20:14:02 -0800659#if HAS_BC_ATTEMPT_ACQUIRE
Andy McFadden457d51f2011-08-31 07:43:40 -0700660 LOG_REMOTEREFS("IPCThreadState::attemptIncStrongHandle(%d)\n", handle);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700661 mOut.writeInt32(BC_ATTEMPT_ACQUIRE);
662 mOut.writeInt32(0); // xxx was thread priority
663 mOut.writeInt32(handle);
664 status_t result = UNKNOWN_ERROR;
Yifan Hongdde40f32017-01-12 14:22:45 -0800665
Mathias Agopian7922fa22009-05-18 15:08:03 -0700666 waitForResponse(NULL, &result);
Yifan Hongdde40f32017-01-12 14:22:45 -0800667
Mathias Agopian7922fa22009-05-18 15:08:03 -0700668#if LOG_REFCOUNTS
669 printf("IPCThreadState::attemptIncStrongHandle(%ld) = %s\n",
670 handle, result == NO_ERROR ? "SUCCESS" : "FAILURE");
671#endif
Yifan Hongdde40f32017-01-12 14:22:45 -0800672
Mathias Agopian7922fa22009-05-18 15:08:03 -0700673 return result;
Arve Hjønnevåg304dcae2014-02-14 20:14:02 -0800674#else
675 (void)handle;
676 ALOGE("%s(%d): Not supported\n", __func__, handle);
677 return INVALID_OPERATION;
678#endif
Mathias Agopian7922fa22009-05-18 15:08:03 -0700679}
680
681void IPCThreadState::expungeHandle(int32_t handle, IBinder* binder)
682{
683#if LOG_REFCOUNTS
684 printf("IPCThreadState::expungeHandle(%ld)\n", handle);
685#endif
686 self()->mProcess->expungeHandle(handle, binder);
687}
688
Yifan Hong1e118d22017-01-12 14:42:28 -0800689status_t IPCThreadState::requestDeathNotification(int32_t handle, BpHwBinder* proxy)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700690{
691 mOut.writeInt32(BC_REQUEST_DEATH_NOTIFICATION);
692 mOut.writeInt32((int32_t)handle);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +0000693 mOut.writePointer((uintptr_t)proxy);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700694 return NO_ERROR;
695}
696
Yifan Hong1e118d22017-01-12 14:42:28 -0800697status_t IPCThreadState::clearDeathNotification(int32_t handle, BpHwBinder* proxy)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700698{
699 mOut.writeInt32(BC_CLEAR_DEATH_NOTIFICATION);
700 mOut.writeInt32((int32_t)handle);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +0000701 mOut.writePointer((uintptr_t)proxy);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700702 return NO_ERROR;
703}
704
705IPCThreadState::IPCThreadState()
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -0700706 : mProcess(ProcessState::self()),
Elliott Hughes07cf48a2014-08-18 10:38:38 -0700707 mMyThreadId(gettid()),
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -0700708 mStrictModePolicy(0),
709 mLastTransactionBinderFlags(0)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700710{
711 pthread_setspecific(gTLS, this);
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800712 clearCaller();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700713 mIn.setDataCapacity(256);
714 mOut.setDataCapacity(256);
715}
716
717IPCThreadState::~IPCThreadState()
718{
719}
720
721status_t IPCThreadState::sendReply(const Parcel& reply, uint32_t flags)
722{
723 status_t err;
724 status_t statusBuffer;
Martijn Coenend39a1682016-06-03 21:27:28 +0200725 err = writeTransactionData(BC_REPLY_SG, flags, -1, 0, reply, &statusBuffer);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700726 if (err < NO_ERROR) return err;
Yifan Hongdde40f32017-01-12 14:22:45 -0800727
Mathias Agopian7922fa22009-05-18 15:08:03 -0700728 return waitForResponse(NULL, NULL);
729}
730
731status_t IPCThreadState::waitForResponse(Parcel *reply, status_t *acquireResult)
732{
Bernhard Rosenkränzerb184ed02014-11-25 21:55:33 +0100733 uint32_t cmd;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700734 int32_t err;
735
736 while (1) {
737 if ((err=talkWithDriver()) < NO_ERROR) break;
738 err = mIn.errorCheck();
739 if (err < NO_ERROR) break;
740 if (mIn.dataAvail() == 0) continue;
Yifan Hongdde40f32017-01-12 14:22:45 -0800741
Bernhard Rosenkränzerb184ed02014-11-25 21:55:33 +0100742 cmd = (uint32_t)mIn.readInt32();
Yifan Hongdde40f32017-01-12 14:22:45 -0800743
Mathias Agopian7922fa22009-05-18 15:08:03 -0700744 IF_LOG_COMMANDS() {
745 alog << "Processing waitForResponse Command: "
746 << getReturnString(cmd) << endl;
747 }
748
749 switch (cmd) {
750 case BR_TRANSACTION_COMPLETE:
751 if (!reply && !acquireResult) goto finish;
752 break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800753
Mathias Agopian7922fa22009-05-18 15:08:03 -0700754 case BR_DEAD_REPLY:
755 err = DEAD_OBJECT;
756 goto finish;
757
758 case BR_FAILED_REPLY:
759 err = FAILED_TRANSACTION;
760 goto finish;
Yifan Hongdde40f32017-01-12 14:22:45 -0800761
Mathias Agopian7922fa22009-05-18 15:08:03 -0700762 case BR_ACQUIRE_RESULT:
763 {
Steve Blockd0bfabc2012-01-09 18:35:44 +0000764 ALOG_ASSERT(acquireResult != NULL, "Unexpected brACQUIRE_RESULT");
Mathias Agopian7922fa22009-05-18 15:08:03 -0700765 const int32_t result = mIn.readInt32();
766 if (!acquireResult) continue;
767 *acquireResult = result ? NO_ERROR : INVALID_OPERATION;
768 }
769 goto finish;
Yifan Hongdde40f32017-01-12 14:22:45 -0800770
Mathias Agopian7922fa22009-05-18 15:08:03 -0700771 case BR_REPLY:
772 {
773 binder_transaction_data tr;
774 err = mIn.read(&tr, sizeof(tr));
Steve Blockd0bfabc2012-01-09 18:35:44 +0000775 ALOG_ASSERT(err == NO_ERROR, "Not enough command data for brREPLY");
Mathias Agopian7922fa22009-05-18 15:08:03 -0700776 if (err != NO_ERROR) goto finish;
777
778 if (reply) {
779 if ((tr.flags & TF_STATUS_CODE) == 0) {
780 reply->ipcSetDataReference(
781 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
782 tr.data_size,
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800783 reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
784 tr.offsets_size/sizeof(binder_size_t),
Mathias Agopian7922fa22009-05-18 15:08:03 -0700785 freeBuffer, this);
786 } else {
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800787 err = *reinterpret_cast<const status_t*>(tr.data.ptr.buffer);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700788 freeBuffer(NULL,
789 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
790 tr.data_size,
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800791 reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
792 tr.offsets_size/sizeof(binder_size_t), this);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700793 }
794 } else {
795 freeBuffer(NULL,
796 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
797 tr.data_size,
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800798 reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
799 tr.offsets_size/sizeof(binder_size_t), this);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700800 continue;
801 }
802 }
803 goto finish;
804
805 default:
806 err = executeCommand(cmd);
807 if (err != NO_ERROR) goto finish;
808 break;
809 }
810 }
811
812finish:
813 if (err != NO_ERROR) {
814 if (acquireResult) *acquireResult = err;
815 if (reply) reply->setError(err);
816 mLastError = err;
817 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800818
Mathias Agopian7922fa22009-05-18 15:08:03 -0700819 return err;
820}
821
822status_t IPCThreadState::talkWithDriver(bool doReceive)
823{
Johannes Carlsson597a3c72011-02-17 14:06:53 +0100824 if (mProcess->mDriverFD <= 0) {
825 return -EBADF;
826 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800827
Mathias Agopian7922fa22009-05-18 15:08:03 -0700828 binder_write_read bwr;
Yifan Hongdde40f32017-01-12 14:22:45 -0800829
Mathias Agopian7922fa22009-05-18 15:08:03 -0700830 // Is the read buffer empty?
831 const bool needRead = mIn.dataPosition() >= mIn.dataSize();
Yifan Hongdde40f32017-01-12 14:22:45 -0800832
Mathias Agopian7922fa22009-05-18 15:08:03 -0700833 // We don't want to write anything if we are still reading
834 // from data left in the input buffer and the caller
835 // has requested to read the next data.
836 const size_t outAvail = (!doReceive || needRead) ? mOut.dataSize() : 0;
Yifan Hongdde40f32017-01-12 14:22:45 -0800837
Mathias Agopian7922fa22009-05-18 15:08:03 -0700838 bwr.write_size = outAvail;
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800839 bwr.write_buffer = (uintptr_t)mOut.data();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700840
841 // This is what we'll read.
842 if (doReceive && needRead) {
843 bwr.read_size = mIn.dataCapacity();
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800844 bwr.read_buffer = (uintptr_t)mIn.data();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700845 } else {
846 bwr.read_size = 0;
Ben Cheng455a70a2011-12-01 17:11:32 -0800847 bwr.read_buffer = 0;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700848 }
Andy McFadden457d51f2011-08-31 07:43:40 -0700849
Mathias Agopian7922fa22009-05-18 15:08:03 -0700850 IF_LOG_COMMANDS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700851 if (outAvail != 0) {
852 alog << "Sending commands to driver: " << indent;
853 const void* cmds = (const void*)bwr.write_buffer;
854 const void* end = ((const uint8_t*)cmds)+bwr.write_size;
855 alog << HexDump(cmds, bwr.write_size) << endl;
856 while (cmds < end) cmds = printCommand(alog, cmds);
857 alog << dedent;
858 }
859 alog << "Size of receive buffer: " << bwr.read_size
860 << ", needRead: " << needRead << ", doReceive: " << doReceive << endl;
861 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800862
Mathias Agopian7922fa22009-05-18 15:08:03 -0700863 // Return immediately if there is nothing to do.
864 if ((bwr.write_size == 0) && (bwr.read_size == 0)) return NO_ERROR;
Andy McFadden457d51f2011-08-31 07:43:40 -0700865
Mathias Agopian7922fa22009-05-18 15:08:03 -0700866 bwr.write_consumed = 0;
867 bwr.read_consumed = 0;
868 status_t err;
869 do {
870 IF_LOG_COMMANDS() {
871 alog << "About to read/write, write size = " << mOut.dataSize() << endl;
872 }
Elliott Hughese5e70552015-08-12 15:27:47 -0700873#if defined(__ANDROID__)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700874 if (ioctl(mProcess->mDriverFD, BINDER_WRITE_READ, &bwr) >= 0)
875 err = NO_ERROR;
876 else
877 err = -errno;
878#else
879 err = INVALID_OPERATION;
880#endif
Johannes Carlsson597a3c72011-02-17 14:06:53 +0100881 if (mProcess->mDriverFD <= 0) {
882 err = -EBADF;
883 }
Mathias Agopian7922fa22009-05-18 15:08:03 -0700884 IF_LOG_COMMANDS() {
885 alog << "Finished read/write, write size = " << mOut.dataSize() << endl;
886 }
887 } while (err == -EINTR);
Andy McFadden457d51f2011-08-31 07:43:40 -0700888
Mathias Agopian7922fa22009-05-18 15:08:03 -0700889 IF_LOG_COMMANDS() {
Colin Crossf0487982014-02-05 17:42:44 -0800890 alog << "Our err: " << (void*)(intptr_t)err << ", write consumed: "
Mathias Agopian7922fa22009-05-18 15:08:03 -0700891 << bwr.write_consumed << " (of " << mOut.dataSize()
Todd Poynor0646cb02013-06-25 19:12:18 -0700892 << "), read consumed: " << bwr.read_consumed << endl;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700893 }
894
895 if (err >= NO_ERROR) {
896 if (bwr.write_consumed > 0) {
Arve Hjønnevåga5440702014-01-28 20:12:59 -0800897 if (bwr.write_consumed < mOut.dataSize())
Mathias Agopian7922fa22009-05-18 15:08:03 -0700898 mOut.remove(0, bwr.write_consumed);
899 else
900 mOut.setDataSize(0);
901 }
902 if (bwr.read_consumed > 0) {
903 mIn.setDataSize(bwr.read_consumed);
904 mIn.setDataPosition(0);
905 }
906 IF_LOG_COMMANDS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700907 alog << "Remaining data size: " << mOut.dataSize() << endl;
908 alog << "Received commands from driver: " << indent;
909 const void* cmds = mIn.data();
910 const void* end = mIn.data() + mIn.dataSize();
911 alog << HexDump(cmds, mIn.dataSize()) << endl;
912 while (cmds < end) cmds = printReturnCommand(alog, cmds);
913 alog << dedent;
914 }
915 return NO_ERROR;
916 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800917
Mathias Agopian7922fa22009-05-18 15:08:03 -0700918 return err;
919}
920
921status_t IPCThreadState::writeTransactionData(int32_t cmd, uint32_t binderFlags,
922 int32_t handle, uint32_t code, const Parcel& data, status_t* statusBuffer)
923{
Martijn Coenenfd51ebb2016-07-05 17:00:39 +0200924 binder_transaction_data_sg tr_sg;
Christopher Ferris678434f2017-07-27 10:42:20 -0700925 /* Don't pass uninitialized stack data to a remote process */
926 tr_sg.transaction_data.target.ptr = 0;
927 tr_sg.transaction_data.target.handle = handle;
928 tr_sg.transaction_data.code = code;
929 tr_sg.transaction_data.flags = binderFlags;
930 tr_sg.transaction_data.cookie = 0;
931 tr_sg.transaction_data.sender_pid = 0;
932 tr_sg.transaction_data.sender_euid = 0;
Yifan Hongdde40f32017-01-12 14:22:45 -0800933
Mathias Agopian7922fa22009-05-18 15:08:03 -0700934 const status_t err = data.errorCheck();
935 if (err == NO_ERROR) {
Christopher Ferris678434f2017-07-27 10:42:20 -0700936 tr_sg.transaction_data.data_size = data.ipcDataSize();
937 tr_sg.transaction_data.data.ptr.buffer = data.ipcData();
938 tr_sg.transaction_data.offsets_size = data.ipcObjectsCount()*sizeof(binder_size_t);
939 tr_sg.transaction_data.data.ptr.offsets = data.ipcObjects();
Martijn Coenenfd51ebb2016-07-05 17:00:39 +0200940 tr_sg.buffers_size = data.ipcBufferSize();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700941 } else if (statusBuffer) {
Christopher Ferris678434f2017-07-27 10:42:20 -0700942 tr_sg.transaction_data.flags |= TF_STATUS_CODE;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700943 *statusBuffer = err;
Christopher Ferris678434f2017-07-27 10:42:20 -0700944 tr_sg.transaction_data.data_size = sizeof(status_t);
945 tr_sg.transaction_data.data.ptr.buffer = reinterpret_cast<uintptr_t>(statusBuffer);
946 tr_sg.transaction_data.offsets_size = 0;
947 tr_sg.transaction_data.data.ptr.offsets = 0;
Martijn Coenenfd51ebb2016-07-05 17:00:39 +0200948 tr_sg.buffers_size = 0;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700949 } else {
950 return (mLastError = err);
951 }
Yifan Hongdde40f32017-01-12 14:22:45 -0800952
Mathias Agopian7922fa22009-05-18 15:08:03 -0700953 mOut.writeInt32(cmd);
Martijn Coenenfd51ebb2016-07-05 17:00:39 +0200954 mOut.write(&tr_sg, sizeof(tr_sg));
Yifan Hongdde40f32017-01-12 14:22:45 -0800955
Mathias Agopian7922fa22009-05-18 15:08:03 -0700956 return NO_ERROR;
957}
958
Yifan Hongdde40f32017-01-12 14:22:45 -0800959void IPCThreadState::setTheContextObject(sp<BHwBinder> obj)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700960{
Martijn Coenena660cbc2016-05-12 11:29:23 +0200961 mContextObject = obj;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700962}
963
964status_t IPCThreadState::executeCommand(int32_t cmd)
965{
Yifan Hongdde40f32017-01-12 14:22:45 -0800966 BHwBinder* obj;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700967 RefBase::weakref_type* refs;
968 status_t result = NO_ERROR;
Bernhard Rosenkränzerb184ed02014-11-25 21:55:33 +0100969 switch ((uint32_t)cmd) {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700970 case BR_ERROR:
971 result = mIn.readInt32();
972 break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800973
Mathias Agopian7922fa22009-05-18 15:08:03 -0700974 case BR_OK:
975 break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800976
Mathias Agopian7922fa22009-05-18 15:08:03 -0700977 case BR_ACQUIRE:
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +0000978 refs = (RefBase::weakref_type*)mIn.readPointer();
Yifan Hongdde40f32017-01-12 14:22:45 -0800979 obj = (BHwBinder*)mIn.readPointer();
Steve Blockd0bfabc2012-01-09 18:35:44 +0000980 ALOG_ASSERT(refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -0700981 "BR_ACQUIRE: object %p does not match cookie %p (expected %p)",
982 refs, obj, refs->refBase());
983 obj->incStrong(mProcess.get());
984 IF_LOG_REMOTEREFS() {
985 LOG_REMOTEREFS("BR_ACQUIRE from driver on %p", obj);
986 obj->printRefs();
987 }
988 mOut.writeInt32(BC_ACQUIRE_DONE);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +0000989 mOut.writePointer((uintptr_t)refs);
990 mOut.writePointer((uintptr_t)obj);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700991 break;
Yifan Hongdde40f32017-01-12 14:22:45 -0800992
Mathias Agopian7922fa22009-05-18 15:08:03 -0700993 case BR_RELEASE:
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +0000994 refs = (RefBase::weakref_type*)mIn.readPointer();
Yifan Hongdde40f32017-01-12 14:22:45 -0800995 obj = (BHwBinder*)mIn.readPointer();
Steve Blockd0bfabc2012-01-09 18:35:44 +0000996 ALOG_ASSERT(refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -0700997 "BR_RELEASE: object %p does not match cookie %p (expected %p)",
998 refs, obj, refs->refBase());
999 IF_LOG_REMOTEREFS() {
1000 LOG_REMOTEREFS("BR_RELEASE from driver on %p", obj);
1001 obj->printRefs();
1002 }
1003 mPendingStrongDerefs.push(obj);
1004 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001005
Mathias Agopian7922fa22009-05-18 15:08:03 -07001006 case BR_INCREFS:
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001007 refs = (RefBase::weakref_type*)mIn.readPointer();
Yifan Hongdde40f32017-01-12 14:22:45 -08001008 obj = (BHwBinder*)mIn.readPointer();
Mathias Agopian7922fa22009-05-18 15:08:03 -07001009 refs->incWeak(mProcess.get());
1010 mOut.writeInt32(BC_INCREFS_DONE);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001011 mOut.writePointer((uintptr_t)refs);
1012 mOut.writePointer((uintptr_t)obj);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001013 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001014
Mathias Agopian7922fa22009-05-18 15:08:03 -07001015 case BR_DECREFS:
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001016 refs = (RefBase::weakref_type*)mIn.readPointer();
Yifan Hongdde40f32017-01-12 14:22:45 -08001017 obj = (BHwBinder*)mIn.readPointer();
Mathias Agopian7922fa22009-05-18 15:08:03 -07001018 // NOTE: This assertion is not valid, because the object may no
Yifan Hongdde40f32017-01-12 14:22:45 -08001019 // longer exist (thus the (BHwBinder*)cast above resulting in a different
Mathias Agopian7922fa22009-05-18 15:08:03 -07001020 // memory address).
Steve Blockd0bfabc2012-01-09 18:35:44 +00001021 //ALOG_ASSERT(refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -07001022 // "BR_DECREFS: object %p does not match cookie %p (expected %p)",
1023 // refs, obj, refs->refBase());
1024 mPendingWeakDerefs.push(refs);
1025 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001026
Mathias Agopian7922fa22009-05-18 15:08:03 -07001027 case BR_ATTEMPT_ACQUIRE:
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001028 refs = (RefBase::weakref_type*)mIn.readPointer();
Yifan Hongdde40f32017-01-12 14:22:45 -08001029 obj = (BHwBinder*)mIn.readPointer();
1030
Mathias Agopian7922fa22009-05-18 15:08:03 -07001031 {
1032 const bool success = refs->attemptIncStrong(mProcess.get());
Steve Blockd0bfabc2012-01-09 18:35:44 +00001033 ALOG_ASSERT(success && refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -07001034 "BR_ATTEMPT_ACQUIRE: object %p does not match cookie %p (expected %p)",
1035 refs, obj, refs->refBase());
Yifan Hongdde40f32017-01-12 14:22:45 -08001036
Mathias Agopian7922fa22009-05-18 15:08:03 -07001037 mOut.writeInt32(BC_ACQUIRE_RESULT);
1038 mOut.writeInt32((int32_t)success);
1039 }
1040 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001041
Mathias Agopian7922fa22009-05-18 15:08:03 -07001042 case BR_TRANSACTION:
1043 {
1044 binder_transaction_data tr;
1045 result = mIn.read(&tr, sizeof(tr));
Steve Blockd0bfabc2012-01-09 18:35:44 +00001046 ALOG_ASSERT(result == NO_ERROR,
Mathias Agopian7922fa22009-05-18 15:08:03 -07001047 "Not enough command data for brTRANSACTION");
1048 if (result != NO_ERROR) break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001049
Mathias Agopian7922fa22009-05-18 15:08:03 -07001050 Parcel buffer;
1051 buffer.ipcSetDataReference(
1052 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
1053 tr.data_size,
Arve Hjønnevåga5440702014-01-28 20:12:59 -08001054 reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
1055 tr.offsets_size/sizeof(binder_size_t), freeBuffer, this);
Yifan Hongdde40f32017-01-12 14:22:45 -08001056
Mathias Agopian7922fa22009-05-18 15:08:03 -07001057 const pid_t origPid = mCallingPid;
1058 const uid_t origUid = mCallingUid;
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001059 const int32_t origStrictModePolicy = mStrictModePolicy;
1060 const int32_t origTransactionBinderFlags = mLastTransactionBinderFlags;
1061
Mathias Agopian7922fa22009-05-18 15:08:03 -07001062 mCallingPid = tr.sender_pid;
1063 mCallingUid = tr.sender_euid;
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001064 mLastTransactionBinderFlags = tr.flags;
1065
Steve Block93cf8542012-01-04 20:05:49 +00001066 //ALOGI(">>>> TRANSACT from pid %d uid %d\n", mCallingPid, mCallingUid);
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001067
Mathias Agopian7922fa22009-05-18 15:08:03 -07001068 Parcel reply;
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001069 status_t error;
Martijn Coenen79c2f4d2016-05-20 10:55:59 +02001070 bool reply_sent = false;
Mathias Agopian7922fa22009-05-18 15:08:03 -07001071 IF_LOG_TRANSACTIONS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -07001072 alog << "BR_TRANSACTION thr " << (void*)pthread_self()
1073 << " / obj " << tr.target.ptr << " / code "
1074 << TypeCode(tr.code) << ": " << indent << buffer
1075 << dedent << endl
1076 << "Data addr = "
1077 << reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer)
1078 << ", offsets addr="
1079 << reinterpret_cast<const size_t*>(tr.data.ptr.offsets) << endl;
1080 }
Martijn Coenen79c2f4d2016-05-20 10:55:59 +02001081
1082 auto reply_callback = [&] (auto &replyParcel) {
1083 if (reply_sent) {
1084 // Reply was sent earlier, ignore it.
1085 ALOGE("Dropping binder reply, it was sent already.");
1086 return;
1087 }
1088 reply_sent = true;
1089 if ((tr.flags & TF_ONE_WAY) == 0) {
1090 replyParcel.setError(NO_ERROR);
1091 sendReply(replyParcel, 0);
1092 } else {
1093 ALOGE("Not sending reply in one-way transaction");
1094 }
1095 };
1096
Mathias Agopian7922fa22009-05-18 15:08:03 -07001097 if (tr.target.ptr) {
Dianne Hackborn839f7072016-03-21 10:36:54 -07001098 // We only have a weak reference on the target object, so we must first try to
1099 // safely acquire a strong reference before doing anything else with it.
1100 if (reinterpret_cast<RefBase::weakref_type*>(
1101 tr.target.ptr)->attemptIncStrong(this)) {
Yifan Hongdde40f32017-01-12 14:22:45 -08001102 error = reinterpret_cast<BHwBinder*>(tr.cookie)->transact(tr.code, buffer,
Martijn Coenen79c2f4d2016-05-20 10:55:59 +02001103 &reply, tr.flags, reply_callback);
Yifan Hongdde40f32017-01-12 14:22:45 -08001104 reinterpret_cast<BHwBinder*>(tr.cookie)->decStrong(this);
Dianne Hackborn839f7072016-03-21 10:36:54 -07001105 } else {
1106 error = UNKNOWN_TRANSACTION;
1107 }
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -07001108
Mathias Agopian7922fa22009-05-18 15:08:03 -07001109 } else {
Martijn Coenena660cbc2016-05-12 11:29:23 +02001110 error = mContextObject->transact(tr.code, buffer, &reply, tr.flags, reply_callback);
Martijn Coenen79c2f4d2016-05-20 10:55:59 +02001111 }
1112
1113 if ((tr.flags & TF_ONE_WAY) == 0) {
1114 if (!reply_sent) {
1115 // Should have been a reply but there wasn't, so there
1116 // must have been an error instead.
1117 reply.setError(error);
1118 sendReply(reply, 0);
1119 } else {
1120 if (error != NO_ERROR) {
1121 ALOGE("transact() returned error after sending reply.");
1122 } else {
1123 // Ok, reply sent and transact didn't return an error.
1124 }
1125 }
1126 } else {
1127 // One-way transaction, don't care about return value or reply.
Mathias Agopian7922fa22009-05-18 15:08:03 -07001128 }
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001129
Steve Block93cf8542012-01-04 20:05:49 +00001130 //ALOGI("<<<< TRANSACT from pid %d restore pid %d uid %d\n",
Mathias Agopian7922fa22009-05-18 15:08:03 -07001131 // mCallingPid, origPid, origUid);
Martijn Coenen79c2f4d2016-05-20 10:55:59 +02001132
Yifan Hongdde40f32017-01-12 14:22:45 -08001133
Mathias Agopian7922fa22009-05-18 15:08:03 -07001134 mCallingPid = origPid;
1135 mCallingUid = origUid;
Dianne Hackbornf99aec62014-09-30 11:30:03 -07001136 mStrictModePolicy = origStrictModePolicy;
1137 mLastTransactionBinderFlags = origTransactionBinderFlags;
Christopher Tate7c4dfec2010-03-18 17:55:03 -07001138
Mathias Agopian7922fa22009-05-18 15:08:03 -07001139 IF_LOG_TRANSACTIONS() {
Mathias Agopian7922fa22009-05-18 15:08:03 -07001140 alog << "BC_REPLY thr " << (void*)pthread_self() << " / obj "
1141 << tr.target.ptr << ": " << indent << reply << dedent << endl;
1142 }
Yifan Hongdde40f32017-01-12 14:22:45 -08001143
Mathias Agopian7922fa22009-05-18 15:08:03 -07001144 }
1145 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001146
Mathias Agopian7922fa22009-05-18 15:08:03 -07001147 case BR_DEAD_BINDER:
1148 {
Yifan Hong1e118d22017-01-12 14:42:28 -08001149 BpHwBinder *proxy = (BpHwBinder*)mIn.readPointer();
Mathias Agopian7922fa22009-05-18 15:08:03 -07001150 proxy->sendObituary();
1151 mOut.writeInt32(BC_DEAD_BINDER_DONE);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001152 mOut.writePointer((uintptr_t)proxy);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001153 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001154
Mathias Agopian7922fa22009-05-18 15:08:03 -07001155 case BR_CLEAR_DEATH_NOTIFICATION_DONE:
1156 {
Yifan Hong1e118d22017-01-12 14:42:28 -08001157 BpHwBinder *proxy = (BpHwBinder*)mIn.readPointer();
Mathias Agopian7922fa22009-05-18 15:08:03 -07001158 proxy->getWeakRefs()->decWeak(proxy);
1159 } break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001160
Mathias Agopian7922fa22009-05-18 15:08:03 -07001161 case BR_FINISHED:
1162 result = TIMED_OUT;
1163 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001164
Mathias Agopian7922fa22009-05-18 15:08:03 -07001165 case BR_NOOP:
1166 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001167
Mathias Agopian7922fa22009-05-18 15:08:03 -07001168 case BR_SPAWN_LOOPER:
1169 mProcess->spawnPooledThread(false);
1170 break;
Yifan Hongdde40f32017-01-12 14:22:45 -08001171
Mathias Agopian7922fa22009-05-18 15:08:03 -07001172 default:
1173 printf("*** BAD COMMAND %d received from Binder driver\n", cmd);
1174 result = UNKNOWN_ERROR;
1175 break;
1176 }
1177
1178 if (result != NO_ERROR) {
1179 mLastError = result;
1180 }
Yifan Hongdde40f32017-01-12 14:22:45 -08001181
Mathias Agopian7922fa22009-05-18 15:08:03 -07001182 return result;
1183}
1184
1185void IPCThreadState::threadDestructor(void *st)
1186{
Todd Poynor0646cb02013-06-25 19:12:18 -07001187 IPCThreadState* const self = static_cast<IPCThreadState*>(st);
1188 if (self) {
1189 self->flushCommands();
Elliott Hughese5e70552015-08-12 15:27:47 -07001190#if defined(__ANDROID__)
Johannes Carlsson597a3c72011-02-17 14:06:53 +01001191 if (self->mProcess->mDriverFD > 0) {
1192 ioctl(self->mProcess->mDriverFD, BINDER_THREAD_EXIT, 0);
1193 }
Mathias Agopian7922fa22009-05-18 15:08:03 -07001194#endif
Todd Poynor0646cb02013-06-25 19:12:18 -07001195 delete self;
1196 }
Mathias Agopian7922fa22009-05-18 15:08:03 -07001197}
1198
1199
Colin Crossf0487982014-02-05 17:42:44 -08001200void IPCThreadState::freeBuffer(Parcel* parcel, const uint8_t* data,
1201 size_t /*dataSize*/,
1202 const binder_size_t* /*objects*/,
1203 size_t /*objectsSize*/, void* /*cookie*/)
Mathias Agopian7922fa22009-05-18 15:08:03 -07001204{
Steve Block93cf8542012-01-04 20:05:49 +00001205 //ALOGI("Freeing parcel %p", &parcel);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001206 IF_LOG_COMMANDS() {
1207 alog << "Writing BC_FREE_BUFFER for " << data << endl;
1208 }
Steve Blockd0bfabc2012-01-09 18:35:44 +00001209 ALOG_ASSERT(data != NULL, "Called with NULL data");
Mathias Agopian7922fa22009-05-18 15:08:03 -07001210 if (parcel != NULL) parcel->closeFileDescriptors();
1211 IPCThreadState* state = self();
1212 state->mOut.writeInt32(BC_FREE_BUFFER);
Serban Constantinescu4ca5baf2013-11-05 16:53:55 +00001213 state->mOut.writePointer((uintptr_t)data);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001214}
1215
Martijn Coenenf75a23d2016-08-01 11:55:17 +02001216}; // namespace hardware
Mathias Agopian7922fa22009-05-18 15:08:03 -07001217}; // namespace android