2 * Copyright (C) 2005 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "Parcel"
18 //#define LOG_NDEBUG 0
27 #include <sys/types.h>
30 #include <binder/Binder.h>
31 #include <binder/BpBinder.h>
32 #include <binder/IPCThreadState.h>
33 #include <binder/Parcel.h>
34 #include <binder/ProcessState.h>
35 #include <binder/TextOutput.h>
37 #include <cutils/ashmem.h>
38 #include <utils/Debug.h>
39 #include <utils/Flattenable.h>
40 #include <utils/Log.h>
41 #include <utils/misc.h>
42 #include <utils/String8.h>
43 #include <utils/String16.h>
45 #include <private/binder/binder_module.h>
46 #include <private/binder/Static.h>
49 #define INT32_MAX ((int32_t)(2147483647))
53 //#define LOG_REFS(...) ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)
54 #define LOG_ALLOC(...)
55 //#define LOG_ALLOC(...) ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)
57 // ---------------------------------------------------------------------------
59 // This macro should never be used at runtime, as a too large value
60 // of s could cause an integer overflow. Instead, you should always
61 // use the wrapper function pad_size()
62 #define PAD_SIZE_UNSAFE(s) (((s)+3)&~3)
64 static size_t pad_size(size_t s) {
65 if (s > (SIZE_T_MAX - 3)) {
68 return PAD_SIZE_UNSAFE(s);
71 // Note: must be kept in sync with android/os/StrictMode.java's PENALTY_GATHER
72 #define STRICT_MODE_PENALTY_GATHER (0x40 << 16)
74 // Note: must be kept in sync with android/os/Parcel.java's EX_HAS_REPLY_HEADER
75 #define EX_HAS_REPLY_HEADER -128
77 // XXX This can be made public if we want to provide
78 // support for typed data.
79 struct small_flat_data
87 static pthread_mutex_t gParcelGlobalAllocSizeLock = PTHREAD_MUTEX_INITIALIZER;
88 static size_t gParcelGlobalAllocSize = 0;
89 static size_t gParcelGlobalAllocCount = 0;
91 // Maximum size of a blob to transfer in-place.
92 static const size_t BLOB_INPLACE_LIMIT = 16 * 1024;
96 BLOB_ASHMEM_IMMUTABLE = 1,
97 BLOB_ASHMEM_MUTABLE = 2,
100 void acquire_object(const sp<ProcessState>& proc,
101 const flat_binder_object& obj, const void* who, size_t* outAshmemSize)
104 case BINDER_TYPE_BINDER:
106 LOG_REFS("Parcel %p acquiring reference on local %p", who, obj.cookie);
107 reinterpret_cast<IBinder*>(obj.cookie)->incStrong(who);
110 case BINDER_TYPE_WEAK_BINDER:
112 reinterpret_cast<RefBase::weakref_type*>(obj.binder)->incWeak(who);
114 case BINDER_TYPE_HANDLE: {
115 const sp<IBinder> b = proc->getStrongProxyForHandle(obj.handle);
117 LOG_REFS("Parcel %p acquiring reference on remote %p", who, b.get());
122 case BINDER_TYPE_WEAK_HANDLE: {
123 const wp<IBinder> b = proc->getWeakProxyForHandle(obj.handle);
124 if (b != NULL) b.get_refs()->incWeak(who);
127 case BINDER_TYPE_FD: {
128 if ((obj.cookie != 0) && (outAshmemSize != NULL)) {
130 int ret = fstat(obj.handle, &st);
131 if (!ret && S_ISCHR(st.st_mode)) {
132 // If we own an ashmem fd, keep track of how much memory it refers to.
133 int size = ashmem_get_size_region(obj.handle);
135 *outAshmemSize += size;
143 ALOGD("Invalid object type 0x%08x", obj.type);
146 void acquire_object(const sp<ProcessState>& proc,
147 const flat_binder_object& obj, const void* who)
149 acquire_object(proc, obj, who, NULL);
152 static void release_object(const sp<ProcessState>& proc,
153 const flat_binder_object& obj, const void* who, size_t* outAshmemSize)
156 case BINDER_TYPE_BINDER:
158 LOG_REFS("Parcel %p releasing reference on local %p", who, obj.cookie);
159 reinterpret_cast<IBinder*>(obj.cookie)->decStrong(who);
162 case BINDER_TYPE_WEAK_BINDER:
164 reinterpret_cast<RefBase::weakref_type*>(obj.binder)->decWeak(who);
166 case BINDER_TYPE_HANDLE: {
167 const sp<IBinder> b = proc->getStrongProxyForHandle(obj.handle);
169 LOG_REFS("Parcel %p releasing reference on remote %p", who, b.get());
174 case BINDER_TYPE_WEAK_HANDLE: {
175 const wp<IBinder> b = proc->getWeakProxyForHandle(obj.handle);
176 if (b != NULL) b.get_refs()->decWeak(who);
179 case BINDER_TYPE_FD: {
180 if (obj.cookie != 0) { // owned
181 if (outAshmemSize != NULL) {
183 int ret = fstat(obj.handle, &st);
184 if (!ret && S_ISCHR(st.st_mode)) {
185 int size = ashmem_get_size_region(obj.handle);
187 *outAshmemSize -= size;
198 ALOGE("Invalid object type 0x%08x", obj.type);
201 void release_object(const sp<ProcessState>& proc,
202 const flat_binder_object& obj, const void* who)
204 release_object(proc, obj, who, NULL);
207 inline static status_t finish_flatten_binder(
208 const sp<IBinder>& /*binder*/, const flat_binder_object& flat, Parcel* out)
210 return out->writeObject(flat, false);
213 status_t flatten_binder(const sp<ProcessState>& /*proc*/,
214 const sp<IBinder>& binder, Parcel* out)
216 flat_binder_object obj;
218 obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
219 if (binder != NULL) {
220 IBinder *local = binder->localBinder();
222 BpBinder *proxy = binder->remoteBinder();
226 const int32_t handle = proxy ? proxy->handle() : 0;
227 obj.type = BINDER_TYPE_HANDLE;
228 obj.binder = 0; /* Don't pass uninitialized stack data to a remote process */
232 obj.type = BINDER_TYPE_BINDER;
233 obj.binder = reinterpret_cast<uintptr_t>(local->getWeakRefs());
234 obj.cookie = reinterpret_cast<uintptr_t>(local);
237 obj.type = BINDER_TYPE_BINDER;
242 return finish_flatten_binder(binder, obj, out);
245 status_t flatten_binder(const sp<ProcessState>& /*proc*/,
246 const wp<IBinder>& binder, Parcel* out)
248 flat_binder_object obj;
250 obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
251 if (binder != NULL) {
252 sp<IBinder> real = binder.promote();
254 IBinder *local = real->localBinder();
256 BpBinder *proxy = real->remoteBinder();
260 const int32_t handle = proxy ? proxy->handle() : 0;
261 obj.type = BINDER_TYPE_WEAK_HANDLE;
262 obj.binder = 0; /* Don't pass uninitialized stack data to a remote process */
266 obj.type = BINDER_TYPE_WEAK_BINDER;
267 obj.binder = reinterpret_cast<uintptr_t>(binder.get_refs());
268 obj.cookie = reinterpret_cast<uintptr_t>(binder.unsafe_get());
270 return finish_flatten_binder(real, obj, out);
273 // XXX How to deal? In order to flatten the given binder,
274 // we need to probe it for information, which requires a primary
275 // reference... but we don't have one.
277 // The OpenBinder implementation uses a dynamic_cast<> here,
278 // but we can't do that with the different reference counting
279 // implementation we are using.
280 ALOGE("Unable to unflatten Binder weak reference!");
281 obj.type = BINDER_TYPE_BINDER;
284 return finish_flatten_binder(NULL, obj, out);
287 obj.type = BINDER_TYPE_BINDER;
290 return finish_flatten_binder(NULL, obj, out);
294 inline static status_t finish_unflatten_binder(
295 BpBinder* /*proxy*/, const flat_binder_object& /*flat*/,
296 const Parcel& /*in*/)
301 status_t unflatten_binder(const sp<ProcessState>& proc,
302 const Parcel& in, sp<IBinder>* out)
304 const flat_binder_object* flat = in.readObject(false);
307 switch (flat->type) {
308 case BINDER_TYPE_BINDER:
309 *out = reinterpret_cast<IBinder*>(flat->cookie);
310 return finish_unflatten_binder(NULL, *flat, in);
311 case BINDER_TYPE_HANDLE:
312 *out = proc->getStrongProxyForHandle(flat->handle);
313 return finish_unflatten_binder(
314 static_cast<BpBinder*>(out->get()), *flat, in);
320 status_t unflatten_binder(const sp<ProcessState>& proc,
321 const Parcel& in, wp<IBinder>* out)
323 const flat_binder_object* flat = in.readObject(false);
326 switch (flat->type) {
327 case BINDER_TYPE_BINDER:
328 *out = reinterpret_cast<IBinder*>(flat->cookie);
329 return finish_unflatten_binder(NULL, *flat, in);
330 case BINDER_TYPE_WEAK_BINDER:
331 if (flat->binder != 0) {
332 out->set_object_and_refs(
333 reinterpret_cast<IBinder*>(flat->cookie),
334 reinterpret_cast<RefBase::weakref_type*>(flat->binder));
338 return finish_unflatten_binder(NULL, *flat, in);
339 case BINDER_TYPE_HANDLE:
340 case BINDER_TYPE_WEAK_HANDLE:
341 *out = proc->getWeakProxyForHandle(flat->handle);
342 return finish_unflatten_binder(
343 static_cast<BpBinder*>(out->unsafe_get()), *flat, in);
349 // ---------------------------------------------------------------------------
353 LOG_ALLOC("Parcel %p: constructing", this);
360 LOG_ALLOC("Parcel %p: destroyed", this);
363 size_t Parcel::getGlobalAllocSize() {
364 pthread_mutex_lock(&gParcelGlobalAllocSizeLock);
365 size_t size = gParcelGlobalAllocSize;
366 pthread_mutex_unlock(&gParcelGlobalAllocSizeLock);
370 size_t Parcel::getGlobalAllocCount() {
371 pthread_mutex_lock(&gParcelGlobalAllocSizeLock);
372 size_t count = gParcelGlobalAllocCount;
373 pthread_mutex_unlock(&gParcelGlobalAllocSizeLock);
377 const uint8_t* Parcel::data() const
382 size_t Parcel::dataSize() const
384 return (mDataSize > mDataPos ? mDataSize : mDataPos);
387 size_t Parcel::dataAvail() const
389 // TODO: decide what to do about the possibility that this can
390 // report an available-data size that exceeds a Java int's max
391 // positive value, causing havoc. Fortunately this will only
392 // happen if someone constructs a Parcel containing more than two
393 // gigabytes of data, which on typical phone hardware is simply
395 return dataSize() - dataPosition();
398 size_t Parcel::dataPosition() const
403 size_t Parcel::dataCapacity() const
405 return mDataCapacity;
408 status_t Parcel::setDataSize(size_t size)
410 if (size > INT32_MAX) {
411 // don't accept size_t values which may have come from an
412 // inadvertent conversion from a negative int.
417 err = continueWrite(size);
418 if (err == NO_ERROR) {
420 ALOGV("setDataSize Setting data size of %p to %zu", this, mDataSize);
425 void Parcel::setDataPosition(size_t pos) const
427 if (pos > INT32_MAX) {
428 // don't accept size_t values which may have come from an
429 // inadvertent conversion from a negative int.
437 status_t Parcel::setDataCapacity(size_t size)
439 if (size > INT32_MAX) {
440 // don't accept size_t values which may have come from an
441 // inadvertent conversion from a negative int.
445 if (size > mDataCapacity) return continueWrite(size);
449 status_t Parcel::setData(const uint8_t* buffer, size_t len)
451 if (len > INT32_MAX) {
452 // don't accept size_t values which may have come from an
453 // inadvertent conversion from a negative int.
457 status_t err = restartWrite(len);
458 if (err == NO_ERROR) {
459 memcpy(const_cast<uint8_t*>(data()), buffer, len);
466 status_t Parcel::appendFrom(const Parcel *parcel, size_t offset, size_t len)
468 const sp<ProcessState> proc(ProcessState::self());
470 const uint8_t *data = parcel->mData;
471 const binder_size_t *objects = parcel->mObjects;
472 size_t size = parcel->mObjectsSize;
473 int startPos = mDataPos;
474 int firstIndex = -1, lastIndex = -2;
480 if (len > INT32_MAX) {
481 // don't accept size_t values which may have come from an
482 // inadvertent conversion from a negative int.
486 // range checks against the source parcel size
487 if ((offset > parcel->mDataSize)
488 || (len > parcel->mDataSize)
489 || (offset + len > parcel->mDataSize)) {
493 // Count objects in range
494 for (int i = 0; i < (int) size; i++) {
495 size_t off = objects[i];
496 if ((off >= offset) && (off + sizeof(flat_binder_object) <= offset + len)) {
497 if (firstIndex == -1) {
503 int numObjects = lastIndex - firstIndex + 1;
505 if ((mDataSize+len) > mDataCapacity) {
508 if (err != NO_ERROR) {
514 memcpy(mData + mDataPos, data + offset, len);
520 if (numObjects > 0) {
522 if (mObjectsCapacity < mObjectsSize + numObjects) {
523 size_t newSize = ((mObjectsSize + numObjects)*3)/2;
524 if (newSize*sizeof(binder_size_t) < mObjectsSize) return NO_MEMORY; // overflow
525 binder_size_t *objects =
526 (binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t));
527 if (objects == (binder_size_t*)0) {
531 mObjectsCapacity = newSize;
534 // append and acquire objects
535 int idx = mObjectsSize;
536 for (int i = firstIndex; i <= lastIndex; i++) {
537 size_t off = objects[i] - offset + startPos;
538 mObjects[idx++] = off;
541 flat_binder_object* flat
542 = reinterpret_cast<flat_binder_object*>(mData + off);
543 acquire_object(proc, *flat, this, &mOpenAshmemSize);
545 if (flat->type == BINDER_TYPE_FD) {
546 // If this is a file descriptor, we need to dup it so the
547 // new Parcel now owns its own fd, and can declare that we
548 // officially know we have fds.
549 flat->handle = dup(flat->handle);
551 mHasFds = mFdsKnown = true;
553 err = FDS_NOT_ALLOWED;
562 bool Parcel::allowFds() const
567 bool Parcel::pushAllowFds(bool allowFds)
569 const bool origValue = mAllowFds;
576 void Parcel::restoreAllowFds(bool lastValue)
578 mAllowFds = lastValue;
581 bool Parcel::hasFileDescriptors() const
589 // Write RPC headers. (previously just the interface token)
590 status_t Parcel::writeInterfaceToken(const String16& interface)
592 writeInt32(IPCThreadState::self()->getStrictModePolicy() |
593 STRICT_MODE_PENALTY_GATHER);
594 // currently the interface identification token is just its name as a string
595 return writeString16(interface);
598 bool Parcel::checkInterface(IBinder* binder) const
600 return enforceInterface(binder->getInterfaceDescriptor());
603 bool Parcel::enforceInterface(const String16& interface,
604 IPCThreadState* threadState) const
606 int32_t strictPolicy = readInt32();
607 if (threadState == NULL) {
608 threadState = IPCThreadState::self();
610 if ((threadState->getLastTransactionBinderFlags() &
611 IBinder::FLAG_ONEWAY) != 0) {
612 // For one-way calls, the callee is running entirely
613 // disconnected from the caller, so disable StrictMode entirely.
614 // Not only does disk/network usage not impact the caller, but
615 // there's no way to commuicate back any violations anyway.
616 threadState->setStrictModePolicy(0);
618 threadState->setStrictModePolicy(strictPolicy);
620 const String16 str(readString16());
621 if (str == interface) {
624 ALOGW("**** enforceInterface() expected '%s' but read '%s'",
625 String8(interface).string(), String8(str).string());
630 const binder_size_t* Parcel::objects() const
635 size_t Parcel::objectsCount() const
640 status_t Parcel::errorCheck() const
645 void Parcel::setError(status_t err)
650 status_t Parcel::finishWrite(size_t len)
652 if (len > INT32_MAX) {
653 // don't accept size_t values which may have come from an
654 // inadvertent conversion from a negative int.
658 //printf("Finish write of %d\n", len);
660 ALOGV("finishWrite Setting data pos of %p to %zu", this, mDataPos);
661 if (mDataPos > mDataSize) {
662 mDataSize = mDataPos;
663 ALOGV("finishWrite Setting data size of %p to %zu", this, mDataSize);
665 //printf("New pos=%d, size=%d\n", mDataPos, mDataSize);
669 status_t Parcel::writeUnpadded(const void* data, size_t len)
671 if (len > INT32_MAX) {
672 // don't accept size_t values which may have come from an
673 // inadvertent conversion from a negative int.
677 size_t end = mDataPos + len;
678 if (end < mDataPos) {
683 if (end <= mDataCapacity) {
685 memcpy(mData+mDataPos, data, len);
686 return finishWrite(len);
689 status_t err = growData(len);
690 if (err == NO_ERROR) goto restart_write;
694 status_t Parcel::write(const void* data, size_t len)
696 if (len > INT32_MAX) {
697 // don't accept size_t values which may have come from an
698 // inadvertent conversion from a negative int.
702 void* const d = writeInplace(len);
704 memcpy(d, data, len);
710 void* Parcel::writeInplace(size_t len)
712 if (len > INT32_MAX) {
713 // don't accept size_t values which may have come from an
714 // inadvertent conversion from a negative int.
718 const size_t padded = pad_size(len);
720 // sanity check for integer overflow
721 if (mDataPos+padded < mDataPos) {
725 if ((mDataPos+padded) <= mDataCapacity) {
727 //printf("Writing %ld bytes, padded to %ld\n", len, padded);
728 uint8_t* const data = mData+mDataPos;
730 // Need to pad at end?
732 #if BYTE_ORDER == BIG_ENDIAN
733 static const uint32_t mask[4] = {
734 0x00000000, 0xffffff00, 0xffff0000, 0xff000000
737 #if BYTE_ORDER == LITTLE_ENDIAN
738 static const uint32_t mask[4] = {
739 0x00000000, 0x00ffffff, 0x0000ffff, 0x000000ff
742 //printf("Applying pad mask: %p to %p\n", (void*)mask[padded-len],
743 // *reinterpret_cast<void**>(data+padded-4));
744 *reinterpret_cast<uint32_t*>(data+padded-4) &= mask[padded-len];
751 status_t err = growData(padded);
752 if (err == NO_ERROR) goto restart_write;
756 status_t Parcel::writeInt32(int32_t val)
758 return writeAligned(val);
761 status_t Parcel::writeUint32(uint32_t val)
763 return writeAligned(val);
766 status_t Parcel::writeInt32Array(size_t len, const int32_t *val) {
767 if (len > INT32_MAX) {
768 // don't accept size_t values which may have come from an
769 // inadvertent conversion from a negative int.
774 return writeInt32(-1);
776 status_t ret = writeInt32(static_cast<uint32_t>(len));
777 if (ret == NO_ERROR) {
778 ret = write(val, len * sizeof(*val));
782 status_t Parcel::writeByteArray(size_t len, const uint8_t *val) {
783 if (len > INT32_MAX) {
784 // don't accept size_t values which may have come from an
785 // inadvertent conversion from a negative int.
790 return writeInt32(-1);
792 status_t ret = writeInt32(static_cast<uint32_t>(len));
793 if (ret == NO_ERROR) {
794 ret = write(val, len * sizeof(*val));
799 status_t Parcel::writeInt64(int64_t val)
801 return writeAligned(val);
804 status_t Parcel::writeUint64(uint64_t val)
806 return writeAligned(val);
809 status_t Parcel::writePointer(uintptr_t val)
811 return writeAligned<binder_uintptr_t>(val);
814 status_t Parcel::writeFloat(float val)
816 return writeAligned(val);
819 #if defined(__mips__) && defined(__mips_hard_float)
821 status_t Parcel::writeDouble(double val)
825 unsigned long long ll;
828 return writeAligned(u.ll);
833 status_t Parcel::writeDouble(double val)
835 return writeAligned(val);
840 status_t Parcel::writeCString(const char* str)
842 return write(str, strlen(str)+1);
845 status_t Parcel::writeString8(const String8& str)
847 status_t err = writeInt32(str.bytes());
848 // only write string if its length is more than zero characters,
849 // as readString8 will only read if the length field is non-zero.
850 // this is slightly different from how writeString16 works.
851 if (str.bytes() > 0 && err == NO_ERROR) {
852 err = write(str.string(), str.bytes()+1);
857 status_t Parcel::writeString16(const String16& str)
859 return writeString16(str.string(), str.size());
862 status_t Parcel::writeString16(const char16_t* str, size_t len)
864 if (str == NULL) return writeInt32(-1);
866 status_t err = writeInt32(len);
867 if (err == NO_ERROR) {
868 len *= sizeof(char16_t);
869 uint8_t* data = (uint8_t*)writeInplace(len+sizeof(char16_t));
871 memcpy(data, str, len);
872 *reinterpret_cast<char16_t*>(data+len) = 0;
880 status_t Parcel::writeStrongBinder(const sp<IBinder>& val)
882 return flatten_binder(ProcessState::self(), val, this);
885 status_t Parcel::writeWeakBinder(const wp<IBinder>& val)
887 return flatten_binder(ProcessState::self(), val, this);
890 status_t Parcel::writeNativeHandle(const native_handle* handle)
892 if (!handle || handle->version != sizeof(native_handle))
896 err = writeInt32(handle->numFds);
897 if (err != NO_ERROR) return err;
899 err = writeInt32(handle->numInts);
900 if (err != NO_ERROR) return err;
902 for (int i=0 ; err==NO_ERROR && i<handle->numFds ; i++)
903 err = writeDupFileDescriptor(handle->data[i]);
905 if (err != NO_ERROR) {
906 ALOGD("write native handle, write dup fd failed");
909 err = write(handle->data + handle->numFds, sizeof(int)*handle->numInts);
913 status_t Parcel::writeFileDescriptor(int fd, bool takeOwnership)
915 flat_binder_object obj;
916 obj.type = BINDER_TYPE_FD;
917 obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
918 obj.binder = 0; /* Don't pass uninitialized stack data to a remote process */
920 obj.cookie = takeOwnership ? 1 : 0;
921 return writeObject(obj, true);
924 status_t Parcel::writeDupFileDescriptor(int fd)
930 status_t err = writeFileDescriptor(dupFd, true /*takeOwnership*/);
937 status_t Parcel::writeBlob(size_t len, bool mutableCopy, WritableBlob* outBlob)
939 if (len > INT32_MAX) {
940 // don't accept size_t values which may have come from an
941 // inadvertent conversion from a negative int.
946 if (!mAllowFds || len <= BLOB_INPLACE_LIMIT) {
947 ALOGV("writeBlob: write in place");
948 status = writeInt32(BLOB_INPLACE);
949 if (status) return status;
951 void* ptr = writeInplace(len);
952 if (!ptr) return NO_MEMORY;
954 outBlob->init(-1, ptr, len, false);
958 ALOGV("writeBlob: write to ashmem");
959 int fd = ashmem_create_region("Parcel Blob", len);
960 if (fd < 0) return NO_MEMORY;
962 int result = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE);
966 void* ptr = ::mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
967 if (ptr == MAP_FAILED) {
971 result = ashmem_set_prot_region(fd, PROT_READ);
976 status = writeInt32(mutableCopy ? BLOB_ASHMEM_MUTABLE : BLOB_ASHMEM_IMMUTABLE);
978 status = writeFileDescriptor(fd, true /*takeOwnership*/);
980 outBlob->init(fd, ptr, len, mutableCopy);
992 status_t Parcel::writeDupImmutableBlobFileDescriptor(int fd)
994 // Must match up with what's done in writeBlob.
995 if (!mAllowFds) return FDS_NOT_ALLOWED;
996 status_t status = writeInt32(BLOB_ASHMEM_IMMUTABLE);
997 if (status) return status;
998 return writeDupFileDescriptor(fd);
1001 status_t Parcel::write(const FlattenableHelperInterface& val)
1006 const size_t len = val.getFlattenedSize();
1007 const size_t fd_count = val.getFdCount();
1009 if ((len > INT32_MAX) || (fd_count > INT32_MAX)) {
1010 // don't accept size_t values which may have come from an
1011 // inadvertent conversion from a negative int.
1015 err = this->writeInt32(len);
1016 if (err) return err;
1018 err = this->writeInt32(fd_count);
1019 if (err) return err;
1022 void* const buf = this->writeInplace(pad_size(len));
1028 fds = new int[fd_count];
1031 err = val.flatten(buf, len, fds, fd_count);
1032 for (size_t i=0 ; i<fd_count && err==NO_ERROR ; i++) {
1033 err = this->writeDupFileDescriptor( fds[i] );
1043 status_t Parcel::writeObject(const flat_binder_object& val, bool nullMetaData)
1045 const bool enoughData = (mDataPos+sizeof(val)) <= mDataCapacity;
1046 const bool enoughObjects = mObjectsSize < mObjectsCapacity;
1047 if (enoughData && enoughObjects) {
1049 *reinterpret_cast<flat_binder_object*>(mData+mDataPos) = val;
1051 // remember if it's a file descriptor
1052 if (val.type == BINDER_TYPE_FD) {
1054 // fail before modifying our object index
1055 return FDS_NOT_ALLOWED;
1057 mHasFds = mFdsKnown = true;
1060 // Need to write meta-data?
1061 if (nullMetaData || val.binder != 0) {
1062 mObjects[mObjectsSize] = mDataPos;
1063 acquire_object(ProcessState::self(), val, this, &mOpenAshmemSize);
1067 return finishWrite(sizeof(flat_binder_object));
1071 const status_t err = growData(sizeof(val));
1072 if (err != NO_ERROR) return err;
1074 if (!enoughObjects) {
1075 size_t newSize = ((mObjectsSize+2)*3)/2;
1076 if (newSize*sizeof(binder_size_t) < mObjectsSize) return NO_MEMORY; // overflow
1077 binder_size_t* objects = (binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t));
1078 if (objects == NULL) return NO_MEMORY;
1080 mObjectsCapacity = newSize;
1086 status_t Parcel::writeNoException()
1088 return writeInt32(0);
1091 void Parcel::remove(size_t /*start*/, size_t /*amt*/)
1093 LOG_ALWAYS_FATAL("Parcel::remove() not yet implemented!");
1096 status_t Parcel::read(void* outData, size_t len) const
1098 if (len > INT32_MAX) {
1099 // don't accept size_t values which may have come from an
1100 // inadvertent conversion from a negative int.
1104 if ((mDataPos+pad_size(len)) >= mDataPos && (mDataPos+pad_size(len)) <= mDataSize
1105 && len <= pad_size(len)) {
1106 memcpy(outData, mData+mDataPos, len);
1107 mDataPos += pad_size(len);
1108 ALOGV("read Setting data pos of %p to %zu", this, mDataPos);
1111 return NOT_ENOUGH_DATA;
1114 const void* Parcel::readInplace(size_t len) const
1116 if (len > INT32_MAX) {
1117 // don't accept size_t values which may have come from an
1118 // inadvertent conversion from a negative int.
1122 if ((mDataPos+pad_size(len)) >= mDataPos && (mDataPos+pad_size(len)) <= mDataSize
1123 && len <= pad_size(len)) {
1124 const void* data = mData+mDataPos;
1125 mDataPos += pad_size(len);
1126 ALOGV("readInplace Setting data pos of %p to %zu", this, mDataPos);
1133 status_t Parcel::readAligned(T *pArg) const {
1134 COMPILE_TIME_ASSERT_FUNCTION_SCOPE(PAD_SIZE_UNSAFE(sizeof(T)) == sizeof(T));
1136 if ((mDataPos+sizeof(T)) <= mDataSize) {
1137 const void* data = mData+mDataPos;
1138 mDataPos += sizeof(T);
1139 *pArg = *reinterpret_cast<const T*>(data);
1142 return NOT_ENOUGH_DATA;
1147 T Parcel::readAligned() const {
1149 if (readAligned(&result) != NO_ERROR) {
1157 status_t Parcel::writeAligned(T val) {
1158 COMPILE_TIME_ASSERT_FUNCTION_SCOPE(PAD_SIZE_UNSAFE(sizeof(T)) == sizeof(T));
1160 if ((mDataPos+sizeof(val)) <= mDataCapacity) {
1162 *reinterpret_cast<T*>(mData+mDataPos) = val;
1163 return finishWrite(sizeof(val));
1166 status_t err = growData(sizeof(val));
1167 if (err == NO_ERROR) goto restart_write;
1171 status_t Parcel::readInt32(int32_t *pArg) const
1173 return readAligned(pArg);
1176 int32_t Parcel::readInt32() const
1178 return readAligned<int32_t>();
1181 status_t Parcel::readUint32(uint32_t *pArg) const
1183 return readAligned(pArg);
1186 uint32_t Parcel::readUint32() const
1188 return readAligned<uint32_t>();
1191 status_t Parcel::readInt64(int64_t *pArg) const
1193 return readAligned(pArg);
1197 int64_t Parcel::readInt64() const
1199 return readAligned<int64_t>();
1202 status_t Parcel::readUint64(uint64_t *pArg) const
1204 return readAligned(pArg);
1207 uint64_t Parcel::readUint64() const
1209 return readAligned<uint64_t>();
1212 status_t Parcel::readPointer(uintptr_t *pArg) const
1215 binder_uintptr_t ptr;
1216 ret = readAligned(&ptr);
1222 uintptr_t Parcel::readPointer() const
1224 return readAligned<binder_uintptr_t>();
1228 status_t Parcel::readFloat(float *pArg) const
1230 return readAligned(pArg);
1234 float Parcel::readFloat() const
1236 return readAligned<float>();
1239 #if defined(__mips__) && defined(__mips_hard_float)
1241 status_t Parcel::readDouble(double *pArg) const
1245 unsigned long long ll;
1249 status = readAligned(&u.ll);
1254 double Parcel::readDouble() const
1258 unsigned long long ll;
1260 u.ll = readAligned<unsigned long long>();
1266 status_t Parcel::readDouble(double *pArg) const
1268 return readAligned(pArg);
1271 double Parcel::readDouble() const
1273 return readAligned<double>();
1278 status_t Parcel::readIntPtr(intptr_t *pArg) const
1280 return readAligned(pArg);
1284 intptr_t Parcel::readIntPtr() const
1286 return readAligned<intptr_t>();
1290 const char* Parcel::readCString() const
1292 const size_t avail = mDataSize-mDataPos;
1294 const char* str = reinterpret_cast<const char*>(mData+mDataPos);
1295 // is the string's trailing NUL within the parcel's valid bounds?
1296 const char* eos = reinterpret_cast<const char*>(memchr(str, 0, avail));
1298 const size_t len = eos - str;
1299 mDataPos += pad_size(len+1);
1300 ALOGV("readCString Setting data pos of %p to %zu", this, mDataPos);
1307 String8 Parcel::readString8() const
1309 int32_t size = readInt32();
1310 // watch for potential int overflow adding 1 for trailing NUL
1311 if (size > 0 && size < INT32_MAX) {
1312 const char* str = (const char*)readInplace(size+1);
1313 if (str) return String8(str, size);
1318 String16 Parcel::readString16() const
1321 const char16_t* str = readString16Inplace(&len);
1322 if (str) return String16(str, len);
1323 ALOGE("Reading a NULL string not supported here.");
1327 const char16_t* Parcel::readString16Inplace(size_t* outLen) const
1329 int32_t size = readInt32();
1330 // watch for potential int overflow from size+1
1331 if (size >= 0 && size < INT32_MAX) {
1333 const char16_t* str = (const char16_t*)readInplace((size+1)*sizeof(char16_t));
1342 sp<IBinder> Parcel::readStrongBinder() const
1345 unflatten_binder(ProcessState::self(), *this, &val);
1349 wp<IBinder> Parcel::readWeakBinder() const
1352 unflatten_binder(ProcessState::self(), *this, &val);
1356 int32_t Parcel::readExceptionCode() const
1358 int32_t exception_code = readAligned<int32_t>();
1359 if (exception_code == EX_HAS_REPLY_HEADER) {
1360 int32_t header_start = dataPosition();
1361 int32_t header_size = readAligned<int32_t>();
1362 // Skip over fat responses headers. Not used (or propagated) in
1364 setDataPosition(header_start + header_size);
1365 // And fat response headers are currently only used when there are no
1366 // exceptions, so return no error:
1369 return exception_code;
1372 native_handle* Parcel::readNativeHandle() const
1374 int numFds, numInts;
1376 err = readInt32(&numFds);
1377 if (err != NO_ERROR) return 0;
1378 err = readInt32(&numInts);
1379 if (err != NO_ERROR) return 0;
1381 native_handle* h = native_handle_create(numFds, numInts);
1386 for (int i=0 ; err==NO_ERROR && i<numFds ; i++) {
1387 h->data[i] = dup(readFileDescriptor());
1388 if (h->data[i] < 0) {
1389 for (int j = 0; j < i; j++) {
1392 native_handle_delete(h);
1396 err = read(h->data + numFds, sizeof(int)*numInts);
1397 if (err != NO_ERROR) {
1398 native_handle_close(h);
1399 native_handle_delete(h);
1406 int Parcel::readFileDescriptor() const
1408 const flat_binder_object* flat = readObject(true);
1410 switch (flat->type) {
1411 case BINDER_TYPE_FD:
1412 //ALOGI("Returning file descriptor %ld from parcel %p", flat->handle, this);
1413 return flat->handle;
1419 status_t Parcel::readBlob(size_t len, ReadableBlob* outBlob) const
1422 status_t status = readInt32(&blobType);
1423 if (status) return status;
1425 if (blobType == BLOB_INPLACE) {
1426 ALOGV("readBlob: read in place");
1427 const void* ptr = readInplace(len);
1428 if (!ptr) return BAD_VALUE;
1430 outBlob->init(-1, const_cast<void*>(ptr), len, false);
1434 ALOGV("readBlob: read from ashmem");
1435 bool isMutable = (blobType == BLOB_ASHMEM_MUTABLE);
1436 int fd = readFileDescriptor();
1437 if (fd == int(BAD_TYPE)) return BAD_VALUE;
1439 void* ptr = ::mmap(NULL, len, isMutable ? PROT_READ | PROT_WRITE : PROT_READ,
1441 if (ptr == MAP_FAILED) return NO_MEMORY;
1443 outBlob->init(fd, ptr, len, isMutable);
1447 status_t Parcel::read(FlattenableHelperInterface& val) const
1450 const size_t len = this->readInt32();
1451 const size_t fd_count = this->readInt32();
1453 if (len > INT32_MAX) {
1454 // don't accept size_t values which may have come from an
1455 // inadvertent conversion from a negative int.
1460 void const* const buf = this->readInplace(pad_size(len));
1466 fds = new int[fd_count];
1469 status_t err = NO_ERROR;
1470 for (size_t i=0 ; i<fd_count && err==NO_ERROR ; i++) {
1471 fds[i] = dup(this->readFileDescriptor());
1474 ALOGE("dup() failed in Parcel::read, i is %zu, fds[i] is %d, fd_count is %zu, error: %s",
1475 i, fds[i], fd_count, strerror(errno));
1479 if (err == NO_ERROR) {
1480 err = val.unflatten(buf, len, fds, fd_count);
1489 const flat_binder_object* Parcel::readObject(bool nullMetaData) const
1491 const size_t DPOS = mDataPos;
1492 if ((DPOS+sizeof(flat_binder_object)) <= mDataSize) {
1493 const flat_binder_object* obj
1494 = reinterpret_cast<const flat_binder_object*>(mData+DPOS);
1495 mDataPos = DPOS + sizeof(flat_binder_object);
1496 if (!nullMetaData && (obj->cookie == 0 && obj->binder == 0)) {
1497 // When transferring a NULL object, we don't write it into
1498 // the object list, so we don't want to check for it when
1500 ALOGV("readObject Setting data pos of %p to %zu", this, mDataPos);
1504 // Ensure that this object is valid...
1505 binder_size_t* const OBJS = mObjects;
1506 const size_t N = mObjectsSize;
1507 size_t opos = mNextObjectHint;
1510 ALOGV("Parcel %p looking for obj at %zu, hint=%zu",
1513 // Start at the current hint position, looking for an object at
1514 // the current data position.
1516 while (opos < (N-1) && OBJS[opos] < DPOS) {
1522 if (OBJS[opos] == DPOS) {
1524 ALOGV("Parcel %p found obj %zu at index %zu with forward search",
1526 mNextObjectHint = opos+1;
1527 ALOGV("readObject Setting data pos of %p to %zu", this, mDataPos);
1531 // Look backwards for it...
1532 while (opos > 0 && OBJS[opos] > DPOS) {
1535 if (OBJS[opos] == DPOS) {
1537 ALOGV("Parcel %p found obj %zu at index %zu with backward search",
1539 mNextObjectHint = opos+1;
1540 ALOGV("readObject Setting data pos of %p to %zu", this, mDataPos);
1544 ALOGW("Attempt to read object from Parcel %p at offset %zu that is not in the object list",
1550 void Parcel::closeFileDescriptors()
1552 size_t i = mObjectsSize;
1554 //ALOGI("Closing file descriptors for %zu objects...", i);
1558 const flat_binder_object* flat
1559 = reinterpret_cast<flat_binder_object*>(mData+mObjects[i]);
1560 if (flat->type == BINDER_TYPE_FD) {
1561 //ALOGI("Closing fd: %ld", flat->handle);
1562 close(flat->handle);
1567 uintptr_t Parcel::ipcData() const
1569 return reinterpret_cast<uintptr_t>(mData);
1572 size_t Parcel::ipcDataSize() const
1574 return (mDataSize > mDataPos ? mDataSize : mDataPos);
1577 uintptr_t Parcel::ipcObjects() const
1579 return reinterpret_cast<uintptr_t>(mObjects);
1582 size_t Parcel::ipcObjectsCount() const
1584 return mObjectsSize;
1587 void Parcel::ipcSetDataReference(const uint8_t* data, size_t dataSize,
1588 const binder_size_t* objects, size_t objectsCount, release_func relFunc, void* relCookie)
1590 binder_size_t minOffset = 0;
1593 mData = const_cast<uint8_t*>(data);
1594 mDataSize = mDataCapacity = dataSize;
1595 //ALOGI("setDataReference Setting data size of %p to %lu (pid=%d)", this, mDataSize, getpid());
1597 ALOGV("setDataReference Setting data pos of %p to %zu", this, mDataPos);
1598 mObjects = const_cast<binder_size_t*>(objects);
1599 mObjectsSize = mObjectsCapacity = objectsCount;
1600 mNextObjectHint = 0;
1602 mOwnerCookie = relCookie;
1603 for (size_t i = 0; i < mObjectsSize; i++) {
1604 binder_size_t offset = mObjects[i];
1605 if (offset < minOffset) {
1606 ALOGE("%s: bad object offset %" PRIu64 " < %" PRIu64 "\n",
1607 __func__, (uint64_t)offset, (uint64_t)minOffset);
1611 minOffset = offset + sizeof(flat_binder_object);
1616 void Parcel::print(TextOutput& to, uint32_t /*flags*/) const
1620 if (errorCheck() != NO_ERROR) {
1621 const status_t err = errorCheck();
1622 to << "Error: " << (void*)(intptr_t)err << " \"" << strerror(-err) << "\"";
1623 } else if (dataSize() > 0) {
1624 const uint8_t* DATA = data();
1625 to << indent << HexDump(DATA, dataSize()) << dedent;
1626 const binder_size_t* OBJS = objects();
1627 const size_t N = objectsCount();
1628 for (size_t i=0; i<N; i++) {
1629 const flat_binder_object* flat
1630 = reinterpret_cast<const flat_binder_object*>(DATA+OBJS[i]);
1631 to << endl << "Object #" << i << " @ " << (void*)OBJS[i] << ": "
1632 << TypeCode(flat->type & 0x7f7f7f00)
1633 << " = " << flat->binder;
1642 void Parcel::releaseObjects()
1644 const sp<ProcessState> proc(ProcessState::self());
1645 size_t i = mObjectsSize;
1646 uint8_t* const data = mData;
1647 binder_size_t* const objects = mObjects;
1650 const flat_binder_object* flat
1651 = reinterpret_cast<flat_binder_object*>(data+objects[i]);
1652 release_object(proc, *flat, this, &mOpenAshmemSize);
1656 void Parcel::acquireObjects()
1658 const sp<ProcessState> proc(ProcessState::self());
1659 size_t i = mObjectsSize;
1660 uint8_t* const data = mData;
1661 binder_size_t* const objects = mObjects;
1664 const flat_binder_object* flat
1665 = reinterpret_cast<flat_binder_object*>(data+objects[i]);
1666 acquire_object(proc, *flat, this, &mOpenAshmemSize);
1670 void Parcel::freeData()
1676 void Parcel::freeDataNoInit()
1679 LOG_ALLOC("Parcel %p: freeing other owner data", this);
1680 //ALOGI("Freeing data ref of %p (pid=%d)", this, getpid());
1681 mOwner(this, mData, mDataSize, mObjects, mObjectsSize, mOwnerCookie);
1683 LOG_ALLOC("Parcel %p: freeing allocated data", this);
1686 LOG_ALLOC("Parcel %p: freeing with %zu capacity", this, mDataCapacity);
1687 pthread_mutex_lock(&gParcelGlobalAllocSizeLock);
1688 gParcelGlobalAllocSize -= mDataCapacity;
1689 gParcelGlobalAllocCount--;
1690 pthread_mutex_unlock(&gParcelGlobalAllocSizeLock);
1693 if (mObjects) free(mObjects);
1697 status_t Parcel::growData(size_t len)
1699 if (len > INT32_MAX) {
1700 // don't accept size_t values which may have come from an
1701 // inadvertent conversion from a negative int.
1705 size_t newSize = ((mDataSize+len)*3)/2;
1706 return (newSize <= mDataSize)
1707 ? (status_t) NO_MEMORY
1708 : continueWrite(newSize);
1711 status_t Parcel::restartWrite(size_t desired)
1713 if (desired > INT32_MAX) {
1714 // don't accept size_t values which may have come from an
1715 // inadvertent conversion from a negative int.
1721 return continueWrite(desired);
1724 uint8_t* data = (uint8_t*)realloc(mData, desired);
1725 if (!data && desired > mDataCapacity) {
1733 LOG_ALLOC("Parcel %p: restart from %zu to %zu capacity", this, mDataCapacity, desired);
1734 pthread_mutex_lock(&gParcelGlobalAllocSizeLock);
1735 gParcelGlobalAllocSize += desired;
1736 gParcelGlobalAllocSize -= mDataCapacity;
1737 pthread_mutex_unlock(&gParcelGlobalAllocSizeLock);
1739 mDataCapacity = desired;
1742 mDataSize = mDataPos = 0;
1743 ALOGV("restartWrite Setting data size of %p to %zu", this, mDataSize);
1744 ALOGV("restartWrite Setting data pos of %p to %zu", this, mDataPos);
1748 mObjectsSize = mObjectsCapacity = 0;
1749 mNextObjectHint = 0;
1757 status_t Parcel::continueWrite(size_t desired)
1759 if (desired > INT32_MAX) {
1760 // don't accept size_t values which may have come from an
1761 // inadvertent conversion from a negative int.
1765 // If shrinking, first adjust for any objects that appear
1766 // after the new data size.
1767 size_t objectsSize = mObjectsSize;
1768 if (desired < mDataSize) {
1772 while (objectsSize > 0) {
1773 if (mObjects[objectsSize-1] < desired)
1781 // If the size is going to zero, just release the owner's data.
1787 // If there is a different owner, we need to take
1789 uint8_t* data = (uint8_t*)malloc(desired);
1794 binder_size_t* objects = NULL;
1797 objects = (binder_size_t*)calloc(objectsSize, sizeof(binder_size_t));
1805 // Little hack to only acquire references on objects
1806 // we will be keeping.
1807 size_t oldObjectsSize = mObjectsSize;
1808 mObjectsSize = objectsSize;
1810 mObjectsSize = oldObjectsSize;
1814 memcpy(data, mData, mDataSize < desired ? mDataSize : desired);
1816 if (objects && mObjects) {
1817 memcpy(objects, mObjects, objectsSize*sizeof(binder_size_t));
1819 //ALOGI("Freeing data ref of %p (pid=%d)", this, getpid());
1820 mOwner(this, mData, mDataSize, mObjects, mObjectsSize, mOwnerCookie);
1823 LOG_ALLOC("Parcel %p: taking ownership of %zu capacity", this, desired);
1824 pthread_mutex_lock(&gParcelGlobalAllocSizeLock);
1825 gParcelGlobalAllocSize += desired;
1826 gParcelGlobalAllocCount++;
1827 pthread_mutex_unlock(&gParcelGlobalAllocSizeLock);
1831 mDataSize = (mDataSize < desired) ? mDataSize : desired;
1832 ALOGV("continueWrite Setting data size of %p to %zu", this, mDataSize);
1833 mDataCapacity = desired;
1834 mObjectsSize = mObjectsCapacity = objectsSize;
1835 mNextObjectHint = 0;
1838 if (objectsSize < mObjectsSize) {
1839 // Need to release refs on any objects we are dropping.
1840 const sp<ProcessState> proc(ProcessState::self());
1841 for (size_t i=objectsSize; i<mObjectsSize; i++) {
1842 const flat_binder_object* flat
1843 = reinterpret_cast<flat_binder_object*>(mData+mObjects[i]);
1844 if (flat->type == BINDER_TYPE_FD) {
1845 // will need to rescan because we may have lopped off the only FDs
1848 release_object(proc, *flat, this, &mOpenAshmemSize);
1850 binder_size_t* objects =
1851 (binder_size_t*)realloc(mObjects, objectsSize*sizeof(binder_size_t));
1855 mObjectsSize = objectsSize;
1856 mNextObjectHint = 0;
1859 // We own the data, so we can just do a realloc().
1860 if (desired > mDataCapacity) {
1861 uint8_t* data = (uint8_t*)realloc(mData, desired);
1863 LOG_ALLOC("Parcel %p: continue from %zu to %zu capacity", this, mDataCapacity,
1865 pthread_mutex_lock(&gParcelGlobalAllocSizeLock);
1866 gParcelGlobalAllocSize += desired;
1867 gParcelGlobalAllocSize -= mDataCapacity;
1868 pthread_mutex_unlock(&gParcelGlobalAllocSizeLock);
1870 mDataCapacity = desired;
1871 } else if (desired > mDataCapacity) {
1876 if (mDataSize > desired) {
1877 mDataSize = desired;
1878 ALOGV("continueWrite Setting data size of %p to %zu", this, mDataSize);
1880 if (mDataPos > desired) {
1882 ALOGV("continueWrite Setting data pos of %p to %zu", this, mDataPos);
1887 // This is the first data. Easy!
1888 uint8_t* data = (uint8_t*)malloc(desired);
1894 if(!(mDataCapacity == 0 && mObjects == NULL
1895 && mObjectsCapacity == 0)) {
1896 ALOGE("continueWrite: %zu/%p/%zu/%zu", mDataCapacity, mObjects, mObjectsCapacity, desired);
1899 LOG_ALLOC("Parcel %p: allocating with %zu capacity", this, desired);
1900 pthread_mutex_lock(&gParcelGlobalAllocSizeLock);
1901 gParcelGlobalAllocSize += desired;
1902 gParcelGlobalAllocCount++;
1903 pthread_mutex_unlock(&gParcelGlobalAllocSizeLock);
1906 mDataSize = mDataPos = 0;
1907 ALOGV("continueWrite Setting data size of %p to %zu", this, mDataSize);
1908 ALOGV("continueWrite Setting data pos of %p to %zu", this, mDataPos);
1909 mDataCapacity = desired;
1915 void Parcel::initState()
1917 LOG_ALLOC("Parcel %p: initState", this);
1923 ALOGV("initState Setting data size of %p to %zu", this, mDataSize);
1924 ALOGV("initState Setting data pos of %p to %zu", this, mDataPos);
1927 mObjectsCapacity = 0;
1928 mNextObjectHint = 0;
1933 mOpenAshmemSize = 0;
1936 void Parcel::scanForFds() const
1938 bool hasFds = false;
1939 for (size_t i=0; i<mObjectsSize; i++) {
1940 const flat_binder_object* flat
1941 = reinterpret_cast<const flat_binder_object*>(mData + mObjects[i]);
1942 if (flat->type == BINDER_TYPE_FD) {
1951 size_t Parcel::getBlobAshmemSize() const
1953 // This used to return the size of all blobs that were written to ashmem, now we're returning
1954 // the ashmem currently referenced by this Parcel, which should be equivalent.
1955 // TODO: Remove method once ABI can be changed.
1956 return mOpenAshmemSize;
1959 size_t Parcel::getOpenAshmemSize() const
1961 return mOpenAshmemSize;
1964 // --- Parcel::Blob ---
1966 Parcel::Blob::Blob() :
1967 mFd(-1), mData(NULL), mSize(0), mMutable(false) {
1970 Parcel::Blob::~Blob() {
1974 void Parcel::Blob::release() {
1975 if (mFd != -1 && mData) {
1976 ::munmap(mData, mSize);
1981 void Parcel::Blob::init(int fd, void* data, size_t size, bool isMutable) {
1985 mMutable = isMutable;
1988 void Parcel::Blob::clear() {
1995 }; // namespace android