blob: 6e83faab7eecb994741bf3a3373b4b0880233986 [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
Jason Parks2b17f142009-11-03 12:14:38 -080017#define LOG_TAG "IPCThreadState"
18
Mathias Agopian16475702009-05-19 19:08:10 -070019#include <binder/IPCThreadState.h>
Mathias Agopian7922fa22009-05-18 15:08:03 -070020
Mathias Agopian16475702009-05-19 19:08:10 -070021#include <binder/Binder.h>
22#include <binder/BpBinder.h>
Glenn Kastencb5e2422012-03-16 07:15:23 -070023#include <cutils/sched_policy.h>
Mathias Agopian7922fa22009-05-18 15:08:03 -070024#include <utils/Debug.h>
25#include <utils/Log.h>
26#include <utils/TextOutput.h>
27#include <utils/threads.h>
28
29#include <private/binder/binder_module.h>
30#include <private/binder/Static.h>
31
32#include <sys/ioctl.h>
33#include <signal.h>
34#include <errno.h>
35#include <stdio.h>
36#include <unistd.h>
37
38#ifdef HAVE_PTHREADS
39#include <pthread.h>
40#include <sched.h>
41#include <sys/resource.h>
42#endif
43#ifdef HAVE_WIN32_THREADS
44#include <windows.h>
45#endif
46
47
48#if LOG_NDEBUG
49
50#define IF_LOG_TRANSACTIONS() if (false)
51#define IF_LOG_COMMANDS() if (false)
52#define LOG_REMOTEREFS(...)
53#define IF_LOG_REMOTEREFS() if (false)
54#define LOG_THREADPOOL(...)
55#define LOG_ONEWAY(...)
56
57#else
58
Steve Block5854b912011-10-12 17:27:03 +010059#define IF_LOG_TRANSACTIONS() IF_ALOG(LOG_VERBOSE, "transact")
60#define IF_LOG_COMMANDS() IF_ALOG(LOG_VERBOSE, "ipc")
61#define LOG_REMOTEREFS(...) ALOG(LOG_DEBUG, "remoterefs", __VA_ARGS__)
62#define IF_LOG_REMOTEREFS() IF_ALOG(LOG_DEBUG, "remoterefs")
63#define LOG_THREADPOOL(...) ALOG(LOG_DEBUG, "threadpool", __VA_ARGS__)
64#define LOG_ONEWAY(...) ALOG(LOG_DEBUG, "ipc", __VA_ARGS__)
Mathias Agopian7922fa22009-05-18 15:08:03 -070065
66#endif
67
68// ---------------------------------------------------------------------------
69
70namespace android {
71
72static const char* getReturnString(size_t idx);
73static const char* getCommandString(size_t idx);
74static const void* printReturnCommand(TextOutput& out, const void* _cmd);
75static const void* printCommand(TextOutput& out, const void* _cmd);
76
77// This will result in a missing symbol failure if the IF_LOG_COMMANDS()
78// conditionals don't get stripped... but that is probably what we want.
79#if !LOG_NDEBUG
80static const char *kReturnStrings[] = {
Andy McFadden457d51f2011-08-31 07:43:40 -070081 "BR_ERROR",
Mathias Agopian7922fa22009-05-18 15:08:03 -070082 "BR_OK",
Mathias Agopian7922fa22009-05-18 15:08:03 -070083 "BR_TRANSACTION",
84 "BR_REPLY",
85 "BR_ACQUIRE_RESULT",
86 "BR_DEAD_REPLY",
87 "BR_TRANSACTION_COMPLETE",
88 "BR_INCREFS",
89 "BR_ACQUIRE",
90 "BR_RELEASE",
91 "BR_DECREFS",
92 "BR_ATTEMPT_ACQUIRE",
Mathias Agopian7922fa22009-05-18 15:08:03 -070093 "BR_NOOP",
94 "BR_SPAWN_LOOPER",
95 "BR_FINISHED",
96 "BR_DEAD_BINDER",
Andy McFadden457d51f2011-08-31 07:43:40 -070097 "BR_CLEAR_DEATH_NOTIFICATION_DONE",
98 "BR_FAILED_REPLY"
Mathias Agopian7922fa22009-05-18 15:08:03 -070099};
100
101static const char *kCommandStrings[] = {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700102 "BC_TRANSACTION",
103 "BC_REPLY",
104 "BC_ACQUIRE_RESULT",
105 "BC_FREE_BUFFER",
Mathias Agopian7922fa22009-05-18 15:08:03 -0700106 "BC_INCREFS",
107 "BC_ACQUIRE",
108 "BC_RELEASE",
109 "BC_DECREFS",
110 "BC_INCREFS_DONE",
111 "BC_ACQUIRE_DONE",
112 "BC_ATTEMPT_ACQUIRE",
Mathias Agopian7922fa22009-05-18 15:08:03 -0700113 "BC_REGISTER_LOOPER",
114 "BC_ENTER_LOOPER",
115 "BC_EXIT_LOOPER",
Mathias Agopian7922fa22009-05-18 15:08:03 -0700116 "BC_REQUEST_DEATH_NOTIFICATION",
117 "BC_CLEAR_DEATH_NOTIFICATION",
118 "BC_DEAD_BINDER_DONE"
Mathias Agopian7922fa22009-05-18 15:08:03 -0700119};
120
121static const char* getReturnString(size_t idx)
122{
123 if (idx < sizeof(kReturnStrings) / sizeof(kReturnStrings[0]))
124 return kReturnStrings[idx];
125 else
126 return "unknown";
127}
128
129static const char* getCommandString(size_t idx)
130{
131 if (idx < sizeof(kCommandStrings) / sizeof(kCommandStrings[0]))
132 return kCommandStrings[idx];
133 else
134 return "unknown";
135}
136
137static const void* printBinderTransactionData(TextOutput& out, const void* data)
138{
139 const binder_transaction_data* btd =
140 (const binder_transaction_data*)data;
Andy McFadden457d51f2011-08-31 07:43:40 -0700141 if (btd->target.handle < 1024) {
142 /* want to print descriptors in decimal; guess based on value */
143 out << "target.desc=" << btd->target.handle;
144 } else {
145 out << "target.ptr=" << btd->target.ptr;
146 }
147 out << " (cookie " << btd->cookie << ")" << endl
Mathias Agopian7922fa22009-05-18 15:08:03 -0700148 << "code=" << TypeCode(btd->code) << ", flags=" << (void*)btd->flags << endl
149 << "data=" << btd->data.ptr.buffer << " (" << (void*)btd->data_size
150 << " bytes)" << endl
151 << "offsets=" << btd->data.ptr.offsets << " (" << (void*)btd->offsets_size
Andy McFadden457d51f2011-08-31 07:43:40 -0700152 << " bytes)";
Mathias Agopian7922fa22009-05-18 15:08:03 -0700153 return btd+1;
154}
155
156static const void* printReturnCommand(TextOutput& out, const void* _cmd)
157{
Andy McFadden457d51f2011-08-31 07:43:40 -0700158 static const size_t N = sizeof(kReturnStrings)/sizeof(kReturnStrings[0]);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700159 const int32_t* cmd = (const int32_t*)_cmd;
160 int32_t code = *cmd++;
Andy McFadden457d51f2011-08-31 07:43:40 -0700161 size_t cmdIndex = code & 0xff;
162 if (code == (int32_t) BR_ERROR) {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700163 out << "BR_ERROR: " << (void*)(*cmd++) << endl;
164 return cmd;
Andy McFadden457d51f2011-08-31 07:43:40 -0700165 } else if (cmdIndex >= N) {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700166 out << "Unknown reply: " << code << endl;
167 return cmd;
168 }
Andy McFadden457d51f2011-08-31 07:43:40 -0700169 out << kReturnStrings[cmdIndex];
Mathias Agopian7922fa22009-05-18 15:08:03 -0700170
Mathias Agopian7922fa22009-05-18 15:08:03 -0700171 switch (code) {
172 case BR_TRANSACTION:
173 case BR_REPLY: {
174 out << ": " << indent;
175 cmd = (const int32_t *)printBinderTransactionData(out, cmd);
176 out << dedent;
177 } break;
178
179 case BR_ACQUIRE_RESULT: {
180 const int32_t res = *cmd++;
181 out << ": " << res << (res ? " (SUCCESS)" : " (FAILURE)");
182 } break;
183
184 case BR_INCREFS:
185 case BR_ACQUIRE:
186 case BR_RELEASE:
187 case BR_DECREFS: {
188 const int32_t b = *cmd++;
189 const int32_t c = *cmd++;
190 out << ": target=" << (void*)b << " (cookie " << (void*)c << ")";
191 } break;
192
193 case BR_ATTEMPT_ACQUIRE: {
194 const int32_t p = *cmd++;
195 const int32_t b = *cmd++;
196 const int32_t c = *cmd++;
197 out << ": target=" << (void*)b << " (cookie " << (void*)c
198 << "), pri=" << p;
199 } break;
200
201 case BR_DEAD_BINDER:
202 case BR_CLEAR_DEATH_NOTIFICATION_DONE: {
203 const int32_t c = *cmd++;
204 out << ": death cookie " << (void*)c;
205 } break;
Andy McFadden457d51f2011-08-31 07:43:40 -0700206
207 default:
208 // no details to show for: BR_OK, BR_DEAD_REPLY,
209 // BR_TRANSACTION_COMPLETE, BR_FINISHED
210 break;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700211 }
212
213 out << endl;
214 return cmd;
215}
216
217static const void* printCommand(TextOutput& out, const void* _cmd)
218{
Andy McFadden457d51f2011-08-31 07:43:40 -0700219 static const size_t N = sizeof(kCommandStrings)/sizeof(kCommandStrings[0]);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700220 const int32_t* cmd = (const int32_t*)_cmd;
221 int32_t code = *cmd++;
Andy McFadden457d51f2011-08-31 07:43:40 -0700222 size_t cmdIndex = code & 0xff;
223
224 if (cmdIndex >= N) {
Mathias Agopian7922fa22009-05-18 15:08:03 -0700225 out << "Unknown command: " << code << endl;
226 return cmd;
227 }
Andy McFadden457d51f2011-08-31 07:43:40 -0700228 out << kCommandStrings[cmdIndex];
229
Mathias Agopian7922fa22009-05-18 15:08:03 -0700230 switch (code) {
231 case BC_TRANSACTION:
232 case BC_REPLY: {
233 out << ": " << indent;
234 cmd = (const int32_t *)printBinderTransactionData(out, cmd);
235 out << dedent;
236 } break;
237
238 case BC_ACQUIRE_RESULT: {
239 const int32_t res = *cmd++;
240 out << ": " << res << (res ? " (SUCCESS)" : " (FAILURE)");
241 } break;
242
243 case BC_FREE_BUFFER: {
244 const int32_t buf = *cmd++;
245 out << ": buffer=" << (void*)buf;
246 } break;
247
248 case BC_INCREFS:
249 case BC_ACQUIRE:
250 case BC_RELEASE:
251 case BC_DECREFS: {
252 const int32_t d = *cmd++;
Andy McFadden457d51f2011-08-31 07:43:40 -0700253 out << ": desc=" << d;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700254 } break;
255
256 case BC_INCREFS_DONE:
257 case BC_ACQUIRE_DONE: {
258 const int32_t b = *cmd++;
259 const int32_t c = *cmd++;
260 out << ": target=" << (void*)b << " (cookie " << (void*)c << ")";
261 } break;
262
263 case BC_ATTEMPT_ACQUIRE: {
264 const int32_t p = *cmd++;
265 const int32_t d = *cmd++;
Andy McFadden457d51f2011-08-31 07:43:40 -0700266 out << ": desc=" << d << ", pri=" << p;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700267 } break;
268
269 case BC_REQUEST_DEATH_NOTIFICATION:
270 case BC_CLEAR_DEATH_NOTIFICATION: {
271 const int32_t h = *cmd++;
272 const int32_t c = *cmd++;
273 out << ": handle=" << h << " (death cookie " << (void*)c << ")";
274 } break;
275
276 case BC_DEAD_BINDER_DONE: {
277 const int32_t c = *cmd++;
278 out << ": death cookie " << (void*)c;
279 } break;
Andy McFadden457d51f2011-08-31 07:43:40 -0700280
281 default:
282 // no details to show for: BC_REGISTER_LOOPER, BC_ENTER_LOOPER,
283 // BC_EXIT_LOOPER
284 break;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700285 }
286
287 out << endl;
288 return cmd;
289}
290#endif
291
292static pthread_mutex_t gTLSMutex = PTHREAD_MUTEX_INITIALIZER;
293static bool gHaveTLS = false;
294static pthread_key_t gTLS = 0;
295static bool gShutdown = false;
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800296static bool gDisableBackgroundScheduling = false;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700297
298IPCThreadState* IPCThreadState::self()
299{
300 if (gHaveTLS) {
301restart:
302 const pthread_key_t k = gTLS;
303 IPCThreadState* st = (IPCThreadState*)pthread_getspecific(k);
304 if (st) return st;
305 return new IPCThreadState;
306 }
307
308 if (gShutdown) return NULL;
309
310 pthread_mutex_lock(&gTLSMutex);
311 if (!gHaveTLS) {
312 if (pthread_key_create(&gTLS, threadDestructor) != 0) {
313 pthread_mutex_unlock(&gTLSMutex);
314 return NULL;
315 }
316 gHaveTLS = true;
317 }
318 pthread_mutex_unlock(&gTLSMutex);
319 goto restart;
320}
321
Brad Fitzpatrick77949942010-12-13 16:52:35 -0800322IPCThreadState* IPCThreadState::selfOrNull()
323{
324 if (gHaveTLS) {
325 const pthread_key_t k = gTLS;
326 IPCThreadState* st = (IPCThreadState*)pthread_getspecific(k);
327 return st;
328 }
329 return NULL;
330}
331
Mathias Agopian7922fa22009-05-18 15:08:03 -0700332void IPCThreadState::shutdown()
333{
334 gShutdown = true;
335
336 if (gHaveTLS) {
337 // XXX Need to wait for all thread pool threads to exit!
338 IPCThreadState* st = (IPCThreadState*)pthread_getspecific(gTLS);
339 if (st) {
340 delete st;
341 pthread_setspecific(gTLS, NULL);
342 }
343 gHaveTLS = false;
344 }
345}
346
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800347void IPCThreadState::disableBackgroundScheduling(bool disable)
348{
349 gDisableBackgroundScheduling = disable;
350}
351
Mathias Agopian7922fa22009-05-18 15:08:03 -0700352sp<ProcessState> IPCThreadState::process()
353{
354 return mProcess;
355}
356
357status_t IPCThreadState::clearLastError()
358{
359 const status_t err = mLastError;
360 mLastError = NO_ERROR;
361 return err;
362}
363
364int IPCThreadState::getCallingPid()
365{
366 return mCallingPid;
367}
368
369int IPCThreadState::getCallingUid()
370{
371 return mCallingUid;
372}
373
374int64_t IPCThreadState::clearCallingIdentity()
375{
376 int64_t token = ((int64_t)mCallingUid<<32) | mCallingPid;
377 clearCaller();
378 return token;
379}
380
Brad Fitzpatrick94c36342010-06-18 13:07:53 -0700381void IPCThreadState::setStrictModePolicy(int32_t policy)
382{
383 mStrictModePolicy = policy;
384}
385
Brad Fitzpatrick3f4ef592010-07-07 16:06:39 -0700386int32_t IPCThreadState::getStrictModePolicy() const
387{
Brad Fitzpatrick94c36342010-06-18 13:07:53 -0700388 return mStrictModePolicy;
389}
390
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -0700391void IPCThreadState::setLastTransactionBinderFlags(int32_t flags)
392{
393 mLastTransactionBinderFlags = flags;
394}
395
396int32_t IPCThreadState::getLastTransactionBinderFlags() const
397{
398 return mLastTransactionBinderFlags;
399}
400
Mathias Agopian7922fa22009-05-18 15:08:03 -0700401void IPCThreadState::restoreCallingIdentity(int64_t token)
402{
403 mCallingUid = (int)(token>>32);
404 mCallingPid = (int)token;
405}
406
407void IPCThreadState::clearCaller()
408{
Marco Nelissenb4f35d02009-07-17 07:59:17 -0700409 mCallingPid = getpid();
410 mCallingUid = getuid();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700411}
412
413void IPCThreadState::flushCommands()
414{
415 if (mProcess->mDriverFD <= 0)
416 return;
417 talkWithDriver(false);
418}
419
420void IPCThreadState::joinThreadPool(bool isMain)
421{
422 LOG_THREADPOOL("**** THREAD %p (PID %d) IS JOINING THE THREAD POOL\n", (void*)pthread_self(), getpid());
423
424 mOut.writeInt32(isMain ? BC_ENTER_LOOPER : BC_REGISTER_LOOPER);
425
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800426 // This thread may have been spawned by a thread that was in the background
Glenn Kastencb5e2422012-03-16 07:15:23 -0700427 // scheduling group, so first we will make sure it is in the foreground
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800428 // one to avoid performing an initial transaction in the background.
Glenn Kastencb5e2422012-03-16 07:15:23 -0700429 set_sched_policy(mMyThreadId, SP_FOREGROUND);
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800430
Mathias Agopian7922fa22009-05-18 15:08:03 -0700431 status_t result;
432 do {
433 int32_t cmd;
434
435 // When we've cleared the incoming command queue, process any pending derefs
436 if (mIn.dataPosition() >= mIn.dataSize()) {
437 size_t numPending = mPendingWeakDerefs.size();
438 if (numPending > 0) {
439 for (size_t i = 0; i < numPending; i++) {
440 RefBase::weakref_type* refs = mPendingWeakDerefs[i];
441 refs->decWeak(mProcess.get());
442 }
443 mPendingWeakDerefs.clear();
444 }
445
446 numPending = mPendingStrongDerefs.size();
447 if (numPending > 0) {
448 for (size_t i = 0; i < numPending; i++) {
449 BBinder* obj = mPendingStrongDerefs[i];
450 obj->decStrong(mProcess.get());
451 }
452 mPendingStrongDerefs.clear();
453 }
454 }
455
456 // now get the next command to be processed, waiting if necessary
457 result = talkWithDriver();
458 if (result >= NO_ERROR) {
459 size_t IN = mIn.dataAvail();
460 if (IN < sizeof(int32_t)) continue;
461 cmd = mIn.readInt32();
462 IF_LOG_COMMANDS() {
463 alog << "Processing top-level Command: "
464 << getReturnString(cmd) << endl;
465 }
Jason Parks2b17f142009-11-03 12:14:38 -0800466
Jason Parks2b17f142009-11-03 12:14:38 -0800467
Mathias Agopian7922fa22009-05-18 15:08:03 -0700468 result = executeCommand(cmd);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700469 }
470
Christopher Tate0d7c8be2009-11-08 14:29:02 -0800471 // After executing the command, ensure that the thread is returned to the
Glenn Kastencb5e2422012-03-16 07:15:23 -0700472 // foreground cgroup before rejoining the pool. The driver takes care of
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800473 // restoring the priority, but doesn't do anything with cgroups so we
474 // need to take care of that here in userspace. Note that we do make
475 // sure to go in the foreground after executing a transaction, but
476 // there are other callbacks into user code that could have changed
477 // our group so we want to make absolutely sure it is put back.
Glenn Kastencb5e2422012-03-16 07:15:23 -0700478 set_sched_policy(mMyThreadId, SP_FOREGROUND);
Christopher Tate0d7c8be2009-11-08 14:29:02 -0800479
Mathias Agopian7922fa22009-05-18 15:08:03 -0700480 // Let this thread exit the thread pool if it is no longer
481 // needed and it is not the main process thread.
482 if(result == TIMED_OUT && !isMain) {
483 break;
484 }
485 } while (result != -ECONNREFUSED && result != -EBADF);
486
487 LOG_THREADPOOL("**** THREAD %p (PID %d) IS LEAVING THE THREAD POOL err=%p\n",
488 (void*)pthread_self(), getpid(), (void*)result);
489
490 mOut.writeInt32(BC_EXIT_LOOPER);
491 talkWithDriver(false);
492}
493
494void IPCThreadState::stopProcess(bool immediate)
495{
Steve Block93cf8542012-01-04 20:05:49 +0000496 //ALOGI("**** STOPPING PROCESS");
Mathias Agopian7922fa22009-05-18 15:08:03 -0700497 flushCommands();
498 int fd = mProcess->mDriverFD;
499 mProcess->mDriverFD = -1;
500 close(fd);
501 //kill(getpid(), SIGKILL);
502}
503
504status_t IPCThreadState::transact(int32_t handle,
505 uint32_t code, const Parcel& data,
506 Parcel* reply, uint32_t flags)
507{
508 status_t err = data.errorCheck();
509
510 flags |= TF_ACCEPT_FDS;
511
512 IF_LOG_TRANSACTIONS() {
513 TextOutput::Bundle _b(alog);
514 alog << "BC_TRANSACTION thr " << (void*)pthread_self() << " / hand "
515 << handle << " / code " << TypeCode(code) << ": "
516 << indent << data << dedent << endl;
517 }
518
519 if (err == NO_ERROR) {
520 LOG_ONEWAY(">>>> SEND from pid %d uid %d %s", getpid(), getuid(),
521 (flags & TF_ONE_WAY) == 0 ? "READ REPLY" : "ONE WAY");
522 err = writeTransactionData(BC_TRANSACTION, flags, handle, code, data, NULL);
523 }
524
525 if (err != NO_ERROR) {
526 if (reply) reply->setError(err);
527 return (mLastError = err);
528 }
529
530 if ((flags & TF_ONE_WAY) == 0) {
Dianne Hackborn98878262010-09-24 11:16:23 -0700531 #if 0
532 if (code == 4) { // relayout
Steve Block93cf8542012-01-04 20:05:49 +0000533 ALOGI(">>>>>> CALLING transaction 4");
Dianne Hackborn98878262010-09-24 11:16:23 -0700534 } else {
Steve Block93cf8542012-01-04 20:05:49 +0000535 ALOGI(">>>>>> CALLING transaction %d", code);
Dianne Hackborn98878262010-09-24 11:16:23 -0700536 }
537 #endif
Mathias Agopian7922fa22009-05-18 15:08:03 -0700538 if (reply) {
539 err = waitForResponse(reply);
540 } else {
541 Parcel fakeReply;
542 err = waitForResponse(&fakeReply);
543 }
Dianne Hackborn98878262010-09-24 11:16:23 -0700544 #if 0
545 if (code == 4) { // relayout
Steve Block93cf8542012-01-04 20:05:49 +0000546 ALOGI("<<<<<< RETURNING transaction 4");
Dianne Hackborn98878262010-09-24 11:16:23 -0700547 } else {
Steve Block93cf8542012-01-04 20:05:49 +0000548 ALOGI("<<<<<< RETURNING transaction %d", code);
Dianne Hackborn98878262010-09-24 11:16:23 -0700549 }
550 #endif
Mathias Agopian7922fa22009-05-18 15:08:03 -0700551
552 IF_LOG_TRANSACTIONS() {
553 TextOutput::Bundle _b(alog);
554 alog << "BR_REPLY thr " << (void*)pthread_self() << " / hand "
555 << handle << ": ";
556 if (reply) alog << indent << *reply << dedent << endl;
557 else alog << "(none requested)" << endl;
558 }
559 } else {
560 err = waitForResponse(NULL, NULL);
561 }
562
563 return err;
564}
565
566void IPCThreadState::incStrongHandle(int32_t handle)
567{
568 LOG_REMOTEREFS("IPCThreadState::incStrongHandle(%d)\n", handle);
569 mOut.writeInt32(BC_ACQUIRE);
570 mOut.writeInt32(handle);
571}
572
573void IPCThreadState::decStrongHandle(int32_t handle)
574{
575 LOG_REMOTEREFS("IPCThreadState::decStrongHandle(%d)\n", handle);
576 mOut.writeInt32(BC_RELEASE);
577 mOut.writeInt32(handle);
578}
579
580void IPCThreadState::incWeakHandle(int32_t handle)
581{
582 LOG_REMOTEREFS("IPCThreadState::incWeakHandle(%d)\n", handle);
583 mOut.writeInt32(BC_INCREFS);
584 mOut.writeInt32(handle);
585}
586
587void IPCThreadState::decWeakHandle(int32_t handle)
588{
589 LOG_REMOTEREFS("IPCThreadState::decWeakHandle(%d)\n", handle);
590 mOut.writeInt32(BC_DECREFS);
591 mOut.writeInt32(handle);
592}
593
594status_t IPCThreadState::attemptIncStrongHandle(int32_t handle)
595{
Andy McFadden457d51f2011-08-31 07:43:40 -0700596 LOG_REMOTEREFS("IPCThreadState::attemptIncStrongHandle(%d)\n", handle);
Mathias Agopian7922fa22009-05-18 15:08:03 -0700597 mOut.writeInt32(BC_ATTEMPT_ACQUIRE);
598 mOut.writeInt32(0); // xxx was thread priority
599 mOut.writeInt32(handle);
600 status_t result = UNKNOWN_ERROR;
601
602 waitForResponse(NULL, &result);
603
604#if LOG_REFCOUNTS
605 printf("IPCThreadState::attemptIncStrongHandle(%ld) = %s\n",
606 handle, result == NO_ERROR ? "SUCCESS" : "FAILURE");
607#endif
608
609 return result;
610}
611
612void IPCThreadState::expungeHandle(int32_t handle, IBinder* binder)
613{
614#if LOG_REFCOUNTS
615 printf("IPCThreadState::expungeHandle(%ld)\n", handle);
616#endif
617 self()->mProcess->expungeHandle(handle, binder);
618}
619
620status_t IPCThreadState::requestDeathNotification(int32_t handle, BpBinder* proxy)
621{
622 mOut.writeInt32(BC_REQUEST_DEATH_NOTIFICATION);
623 mOut.writeInt32((int32_t)handle);
624 mOut.writeInt32((int32_t)proxy);
625 return NO_ERROR;
626}
627
628status_t IPCThreadState::clearDeathNotification(int32_t handle, BpBinder* proxy)
629{
630 mOut.writeInt32(BC_CLEAR_DEATH_NOTIFICATION);
631 mOut.writeInt32((int32_t)handle);
632 mOut.writeInt32((int32_t)proxy);
633 return NO_ERROR;
634}
635
636IPCThreadState::IPCThreadState()
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -0700637 : mProcess(ProcessState::self()),
638 mMyThreadId(androidGetTid()),
639 mStrictModePolicy(0),
640 mLastTransactionBinderFlags(0)
Mathias Agopian7922fa22009-05-18 15:08:03 -0700641{
642 pthread_setspecific(gTLS, this);
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -0800643 clearCaller();
Mathias Agopian7922fa22009-05-18 15:08:03 -0700644 mIn.setDataCapacity(256);
645 mOut.setDataCapacity(256);
646}
647
648IPCThreadState::~IPCThreadState()
649{
650}
651
652status_t IPCThreadState::sendReply(const Parcel& reply, uint32_t flags)
653{
654 status_t err;
655 status_t statusBuffer;
656 err = writeTransactionData(BC_REPLY, flags, -1, 0, reply, &statusBuffer);
657 if (err < NO_ERROR) return err;
658
659 return waitForResponse(NULL, NULL);
660}
661
662status_t IPCThreadState::waitForResponse(Parcel *reply, status_t *acquireResult)
663{
664 int32_t cmd;
665 int32_t err;
666
667 while (1) {
668 if ((err=talkWithDriver()) < NO_ERROR) break;
669 err = mIn.errorCheck();
670 if (err < NO_ERROR) break;
671 if (mIn.dataAvail() == 0) continue;
672
673 cmd = mIn.readInt32();
674
675 IF_LOG_COMMANDS() {
676 alog << "Processing waitForResponse Command: "
677 << getReturnString(cmd) << endl;
678 }
679
680 switch (cmd) {
681 case BR_TRANSACTION_COMPLETE:
682 if (!reply && !acquireResult) goto finish;
683 break;
684
685 case BR_DEAD_REPLY:
686 err = DEAD_OBJECT;
687 goto finish;
688
689 case BR_FAILED_REPLY:
690 err = FAILED_TRANSACTION;
691 goto finish;
692
693 case BR_ACQUIRE_RESULT:
694 {
Steve Blockd0bfabc2012-01-09 18:35:44 +0000695 ALOG_ASSERT(acquireResult != NULL, "Unexpected brACQUIRE_RESULT");
Mathias Agopian7922fa22009-05-18 15:08:03 -0700696 const int32_t result = mIn.readInt32();
697 if (!acquireResult) continue;
698 *acquireResult = result ? NO_ERROR : INVALID_OPERATION;
699 }
700 goto finish;
701
702 case BR_REPLY:
703 {
704 binder_transaction_data tr;
705 err = mIn.read(&tr, sizeof(tr));
Steve Blockd0bfabc2012-01-09 18:35:44 +0000706 ALOG_ASSERT(err == NO_ERROR, "Not enough command data for brREPLY");
Mathias Agopian7922fa22009-05-18 15:08:03 -0700707 if (err != NO_ERROR) goto finish;
708
709 if (reply) {
710 if ((tr.flags & TF_STATUS_CODE) == 0) {
711 reply->ipcSetDataReference(
712 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
713 tr.data_size,
714 reinterpret_cast<const size_t*>(tr.data.ptr.offsets),
715 tr.offsets_size/sizeof(size_t),
716 freeBuffer, this);
717 } else {
718 err = *static_cast<const status_t*>(tr.data.ptr.buffer);
719 freeBuffer(NULL,
720 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
721 tr.data_size,
722 reinterpret_cast<const size_t*>(tr.data.ptr.offsets),
723 tr.offsets_size/sizeof(size_t), this);
724 }
725 } else {
726 freeBuffer(NULL,
727 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
728 tr.data_size,
729 reinterpret_cast<const size_t*>(tr.data.ptr.offsets),
730 tr.offsets_size/sizeof(size_t), this);
731 continue;
732 }
733 }
734 goto finish;
735
736 default:
737 err = executeCommand(cmd);
738 if (err != NO_ERROR) goto finish;
739 break;
740 }
741 }
742
743finish:
744 if (err != NO_ERROR) {
745 if (acquireResult) *acquireResult = err;
746 if (reply) reply->setError(err);
747 mLastError = err;
748 }
749
750 return err;
751}
752
753status_t IPCThreadState::talkWithDriver(bool doReceive)
754{
Johannes Carlsson597a3c72011-02-17 14:06:53 +0100755 if (mProcess->mDriverFD <= 0) {
756 return -EBADF;
757 }
Mathias Agopian7922fa22009-05-18 15:08:03 -0700758
759 binder_write_read bwr;
760
761 // Is the read buffer empty?
762 const bool needRead = mIn.dataPosition() >= mIn.dataSize();
763
764 // We don't want to write anything if we are still reading
765 // from data left in the input buffer and the caller
766 // has requested to read the next data.
767 const size_t outAvail = (!doReceive || needRead) ? mOut.dataSize() : 0;
768
769 bwr.write_size = outAvail;
770 bwr.write_buffer = (long unsigned int)mOut.data();
771
772 // This is what we'll read.
773 if (doReceive && needRead) {
774 bwr.read_size = mIn.dataCapacity();
775 bwr.read_buffer = (long unsigned int)mIn.data();
776 } else {
777 bwr.read_size = 0;
Ben Cheng455a70a2011-12-01 17:11:32 -0800778 bwr.read_buffer = 0;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700779 }
Andy McFadden457d51f2011-08-31 07:43:40 -0700780
Mathias Agopian7922fa22009-05-18 15:08:03 -0700781 IF_LOG_COMMANDS() {
782 TextOutput::Bundle _b(alog);
783 if (outAvail != 0) {
784 alog << "Sending commands to driver: " << indent;
785 const void* cmds = (const void*)bwr.write_buffer;
786 const void* end = ((const uint8_t*)cmds)+bwr.write_size;
787 alog << HexDump(cmds, bwr.write_size) << endl;
788 while (cmds < end) cmds = printCommand(alog, cmds);
789 alog << dedent;
790 }
791 alog << "Size of receive buffer: " << bwr.read_size
792 << ", needRead: " << needRead << ", doReceive: " << doReceive << endl;
793 }
794
795 // Return immediately if there is nothing to do.
796 if ((bwr.write_size == 0) && (bwr.read_size == 0)) return NO_ERROR;
Andy McFadden457d51f2011-08-31 07:43:40 -0700797
Mathias Agopian7922fa22009-05-18 15:08:03 -0700798 bwr.write_consumed = 0;
799 bwr.read_consumed = 0;
800 status_t err;
801 do {
802 IF_LOG_COMMANDS() {
803 alog << "About to read/write, write size = " << mOut.dataSize() << endl;
804 }
805#if defined(HAVE_ANDROID_OS)
806 if (ioctl(mProcess->mDriverFD, BINDER_WRITE_READ, &bwr) >= 0)
807 err = NO_ERROR;
808 else
809 err = -errno;
810#else
811 err = INVALID_OPERATION;
812#endif
Johannes Carlsson597a3c72011-02-17 14:06:53 +0100813 if (mProcess->mDriverFD <= 0) {
814 err = -EBADF;
815 }
Mathias Agopian7922fa22009-05-18 15:08:03 -0700816 IF_LOG_COMMANDS() {
817 alog << "Finished read/write, write size = " << mOut.dataSize() << endl;
818 }
819 } while (err == -EINTR);
Andy McFadden457d51f2011-08-31 07:43:40 -0700820
Mathias Agopian7922fa22009-05-18 15:08:03 -0700821 IF_LOG_COMMANDS() {
822 alog << "Our err: " << (void*)err << ", write consumed: "
823 << bwr.write_consumed << " (of " << mOut.dataSize()
824 << "), read consumed: " << bwr.read_consumed << endl;
825 }
826
827 if (err >= NO_ERROR) {
828 if (bwr.write_consumed > 0) {
829 if (bwr.write_consumed < (ssize_t)mOut.dataSize())
830 mOut.remove(0, bwr.write_consumed);
831 else
832 mOut.setDataSize(0);
833 }
834 if (bwr.read_consumed > 0) {
835 mIn.setDataSize(bwr.read_consumed);
836 mIn.setDataPosition(0);
837 }
838 IF_LOG_COMMANDS() {
839 TextOutput::Bundle _b(alog);
840 alog << "Remaining data size: " << mOut.dataSize() << endl;
841 alog << "Received commands from driver: " << indent;
842 const void* cmds = mIn.data();
843 const void* end = mIn.data() + mIn.dataSize();
844 alog << HexDump(cmds, mIn.dataSize()) << endl;
845 while (cmds < end) cmds = printReturnCommand(alog, cmds);
846 alog << dedent;
847 }
848 return NO_ERROR;
849 }
850
851 return err;
852}
853
854status_t IPCThreadState::writeTransactionData(int32_t cmd, uint32_t binderFlags,
855 int32_t handle, uint32_t code, const Parcel& data, status_t* statusBuffer)
856{
857 binder_transaction_data tr;
858
859 tr.target.handle = handle;
860 tr.code = code;
861 tr.flags = binderFlags;
Evgeniy Stepanov68c8a652011-04-21 14:15:00 +0400862 tr.cookie = 0;
863 tr.sender_pid = 0;
864 tr.sender_euid = 0;
Mathias Agopian7922fa22009-05-18 15:08:03 -0700865
866 const status_t err = data.errorCheck();
867 if (err == NO_ERROR) {
868 tr.data_size = data.ipcDataSize();
869 tr.data.ptr.buffer = data.ipcData();
870 tr.offsets_size = data.ipcObjectsCount()*sizeof(size_t);
871 tr.data.ptr.offsets = data.ipcObjects();
872 } else if (statusBuffer) {
873 tr.flags |= TF_STATUS_CODE;
874 *statusBuffer = err;
875 tr.data_size = sizeof(status_t);
876 tr.data.ptr.buffer = statusBuffer;
877 tr.offsets_size = 0;
878 tr.data.ptr.offsets = NULL;
879 } else {
880 return (mLastError = err);
881 }
882
883 mOut.writeInt32(cmd);
884 mOut.write(&tr, sizeof(tr));
885
886 return NO_ERROR;
887}
888
889sp<BBinder> the_context_object;
890
891void setTheContextObject(sp<BBinder> obj)
892{
893 the_context_object = obj;
894}
895
896status_t IPCThreadState::executeCommand(int32_t cmd)
897{
898 BBinder* obj;
899 RefBase::weakref_type* refs;
900 status_t result = NO_ERROR;
901
902 switch (cmd) {
903 case BR_ERROR:
904 result = mIn.readInt32();
905 break;
906
907 case BR_OK:
908 break;
909
910 case BR_ACQUIRE:
911 refs = (RefBase::weakref_type*)mIn.readInt32();
912 obj = (BBinder*)mIn.readInt32();
Steve Blockd0bfabc2012-01-09 18:35:44 +0000913 ALOG_ASSERT(refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -0700914 "BR_ACQUIRE: object %p does not match cookie %p (expected %p)",
915 refs, obj, refs->refBase());
916 obj->incStrong(mProcess.get());
917 IF_LOG_REMOTEREFS() {
918 LOG_REMOTEREFS("BR_ACQUIRE from driver on %p", obj);
919 obj->printRefs();
920 }
921 mOut.writeInt32(BC_ACQUIRE_DONE);
922 mOut.writeInt32((int32_t)refs);
923 mOut.writeInt32((int32_t)obj);
924 break;
925
926 case BR_RELEASE:
927 refs = (RefBase::weakref_type*)mIn.readInt32();
928 obj = (BBinder*)mIn.readInt32();
Steve Blockd0bfabc2012-01-09 18:35:44 +0000929 ALOG_ASSERT(refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -0700930 "BR_RELEASE: object %p does not match cookie %p (expected %p)",
931 refs, obj, refs->refBase());
932 IF_LOG_REMOTEREFS() {
933 LOG_REMOTEREFS("BR_RELEASE from driver on %p", obj);
934 obj->printRefs();
935 }
936 mPendingStrongDerefs.push(obj);
937 break;
938
939 case BR_INCREFS:
940 refs = (RefBase::weakref_type*)mIn.readInt32();
941 obj = (BBinder*)mIn.readInt32();
942 refs->incWeak(mProcess.get());
943 mOut.writeInt32(BC_INCREFS_DONE);
944 mOut.writeInt32((int32_t)refs);
945 mOut.writeInt32((int32_t)obj);
946 break;
947
948 case BR_DECREFS:
949 refs = (RefBase::weakref_type*)mIn.readInt32();
950 obj = (BBinder*)mIn.readInt32();
951 // NOTE: This assertion is not valid, because the object may no
952 // longer exist (thus the (BBinder*)cast above resulting in a different
953 // memory address).
Steve Blockd0bfabc2012-01-09 18:35:44 +0000954 //ALOG_ASSERT(refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -0700955 // "BR_DECREFS: object %p does not match cookie %p (expected %p)",
956 // refs, obj, refs->refBase());
957 mPendingWeakDerefs.push(refs);
958 break;
959
960 case BR_ATTEMPT_ACQUIRE:
961 refs = (RefBase::weakref_type*)mIn.readInt32();
962 obj = (BBinder*)mIn.readInt32();
963
964 {
965 const bool success = refs->attemptIncStrong(mProcess.get());
Steve Blockd0bfabc2012-01-09 18:35:44 +0000966 ALOG_ASSERT(success && refs->refBase() == obj,
Mathias Agopian7922fa22009-05-18 15:08:03 -0700967 "BR_ATTEMPT_ACQUIRE: object %p does not match cookie %p (expected %p)",
968 refs, obj, refs->refBase());
969
970 mOut.writeInt32(BC_ACQUIRE_RESULT);
971 mOut.writeInt32((int32_t)success);
972 }
973 break;
974
975 case BR_TRANSACTION:
976 {
977 binder_transaction_data tr;
978 result = mIn.read(&tr, sizeof(tr));
Steve Blockd0bfabc2012-01-09 18:35:44 +0000979 ALOG_ASSERT(result == NO_ERROR,
Mathias Agopian7922fa22009-05-18 15:08:03 -0700980 "Not enough command data for brTRANSACTION");
981 if (result != NO_ERROR) break;
982
983 Parcel buffer;
984 buffer.ipcSetDataReference(
985 reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
986 tr.data_size,
987 reinterpret_cast<const size_t*>(tr.data.ptr.offsets),
988 tr.offsets_size/sizeof(size_t), freeBuffer, this);
989
990 const pid_t origPid = mCallingPid;
991 const uid_t origUid = mCallingUid;
992
993 mCallingPid = tr.sender_pid;
994 mCallingUid = tr.sender_euid;
995
Christopher Tate7c4dfec2010-03-18 17:55:03 -0700996 int curPrio = getpriority(PRIO_PROCESS, mMyThreadId);
997 if (gDisableBackgroundScheduling) {
998 if (curPrio > ANDROID_PRIORITY_NORMAL) {
999 // We have inherited a reduced priority from the caller, but do not
1000 // want to run in that state in this process. The driver set our
1001 // priority already (though not our scheduling class), so bounce
1002 // it back to the default before invoking the transaction.
1003 setpriority(PRIO_PROCESS, mMyThreadId, ANDROID_PRIORITY_NORMAL);
1004 }
1005 } else {
1006 if (curPrio >= ANDROID_PRIORITY_BACKGROUND) {
1007 // We want to use the inherited priority from the caller.
1008 // Ensure this thread is in the background scheduling class,
1009 // since the driver won't modify scheduling classes for us.
1010 // The scheduling group is reset to default by the caller
1011 // once this method returns after the transaction is complete.
Glenn Kastencb5e2422012-03-16 07:15:23 -07001012 set_sched_policy(mMyThreadId, SP_BACKGROUND);
Christopher Tate7c4dfec2010-03-18 17:55:03 -07001013 }
Dianne Hackborn5f4d7e82009-12-07 17:59:37 -08001014 }
Christopher Tate7c4dfec2010-03-18 17:55:03 -07001015
Steve Block93cf8542012-01-04 20:05:49 +00001016 //ALOGI(">>>> TRANSACT from pid %d uid %d\n", mCallingPid, mCallingUid);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001017
1018 Parcel reply;
1019 IF_LOG_TRANSACTIONS() {
1020 TextOutput::Bundle _b(alog);
1021 alog << "BR_TRANSACTION thr " << (void*)pthread_self()
1022 << " / obj " << tr.target.ptr << " / code "
1023 << TypeCode(tr.code) << ": " << indent << buffer
1024 << dedent << endl
1025 << "Data addr = "
1026 << reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer)
1027 << ", offsets addr="
1028 << reinterpret_cast<const size_t*>(tr.data.ptr.offsets) << endl;
1029 }
1030 if (tr.target.ptr) {
1031 sp<BBinder> b((BBinder*)tr.cookie);
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -07001032 const status_t error = b->transact(tr.code, buffer, &reply, tr.flags);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001033 if (error < NO_ERROR) reply.setError(error);
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -07001034
Mathias Agopian7922fa22009-05-18 15:08:03 -07001035 } else {
Brad Fitzpatrick24f8bca2010-08-30 16:01:16 -07001036 const status_t error = the_context_object->transact(tr.code, buffer, &reply, tr.flags);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001037 if (error < NO_ERROR) reply.setError(error);
1038 }
1039
Steve Block93cf8542012-01-04 20:05:49 +00001040 //ALOGI("<<<< TRANSACT from pid %d restore pid %d uid %d\n",
Mathias Agopian7922fa22009-05-18 15:08:03 -07001041 // mCallingPid, origPid, origUid);
1042
1043 if ((tr.flags & TF_ONE_WAY) == 0) {
1044 LOG_ONEWAY("Sending reply to %d!", mCallingPid);
1045 sendReply(reply, 0);
1046 } else {
1047 LOG_ONEWAY("NOT sending reply to %d!", mCallingPid);
1048 }
1049
1050 mCallingPid = origPid;
1051 mCallingUid = origUid;
Christopher Tate7c4dfec2010-03-18 17:55:03 -07001052
Mathias Agopian7922fa22009-05-18 15:08:03 -07001053 IF_LOG_TRANSACTIONS() {
1054 TextOutput::Bundle _b(alog);
1055 alog << "BC_REPLY thr " << (void*)pthread_self() << " / obj "
1056 << tr.target.ptr << ": " << indent << reply << dedent << endl;
1057 }
1058
1059 }
1060 break;
1061
1062 case BR_DEAD_BINDER:
1063 {
1064 BpBinder *proxy = (BpBinder*)mIn.readInt32();
1065 proxy->sendObituary();
1066 mOut.writeInt32(BC_DEAD_BINDER_DONE);
1067 mOut.writeInt32((int32_t)proxy);
1068 } break;
1069
1070 case BR_CLEAR_DEATH_NOTIFICATION_DONE:
1071 {
1072 BpBinder *proxy = (BpBinder*)mIn.readInt32();
1073 proxy->getWeakRefs()->decWeak(proxy);
1074 } break;
1075
1076 case BR_FINISHED:
1077 result = TIMED_OUT;
1078 break;
1079
1080 case BR_NOOP:
1081 break;
1082
1083 case BR_SPAWN_LOOPER:
1084 mProcess->spawnPooledThread(false);
1085 break;
1086
1087 default:
1088 printf("*** BAD COMMAND %d received from Binder driver\n", cmd);
1089 result = UNKNOWN_ERROR;
1090 break;
1091 }
1092
1093 if (result != NO_ERROR) {
1094 mLastError = result;
1095 }
1096
1097 return result;
1098}
1099
1100void IPCThreadState::threadDestructor(void *st)
1101{
1102 IPCThreadState* const self = static_cast<IPCThreadState*>(st);
1103 if (self) {
1104 self->flushCommands();
1105#if defined(HAVE_ANDROID_OS)
Johannes Carlsson597a3c72011-02-17 14:06:53 +01001106 if (self->mProcess->mDriverFD > 0) {
1107 ioctl(self->mProcess->mDriverFD, BINDER_THREAD_EXIT, 0);
1108 }
Mathias Agopian7922fa22009-05-18 15:08:03 -07001109#endif
1110 delete self;
1111 }
1112}
1113
1114
1115void IPCThreadState::freeBuffer(Parcel* parcel, const uint8_t* data, size_t dataSize,
1116 const size_t* objects, size_t objectsSize,
1117 void* cookie)
1118{
Steve Block93cf8542012-01-04 20:05:49 +00001119 //ALOGI("Freeing parcel %p", &parcel);
Mathias Agopian7922fa22009-05-18 15:08:03 -07001120 IF_LOG_COMMANDS() {
1121 alog << "Writing BC_FREE_BUFFER for " << data << endl;
1122 }
Steve Blockd0bfabc2012-01-09 18:35:44 +00001123 ALOG_ASSERT(data != NULL, "Called with NULL data");
Mathias Agopian7922fa22009-05-18 15:08:03 -07001124 if (parcel != NULL) parcel->closeFileDescriptors();
1125 IPCThreadState* state = self();
1126 state->mOut.writeInt32(BC_FREE_BUFFER);
1127 state->mOut.writeInt32((int32_t)data);
1128}
1129
1130}; // namespace android