Loading include/utils/Parcel.h +10 −8 Original line number Diff line number Diff line Loading @@ -80,8 +80,11 @@ public: status_t writeStrongBinder(const sp<IBinder>& val); status_t writeWeakBinder(const wp<IBinder>& val); // doesn't take ownership of the native_handle status_t writeNativeHandle(const native_handle& handle); // Place a native_handle into the parcel (the native_handle's file- // descriptors are dup'ed, so it is safe to delete the native_handle // when this function returns). // Doesn't take ownership of the native_handle. status_t writeNativeHandle(const native_handle* handle); // Place a file descriptor into the parcel. The given fd must remain // valid for the lifetime of the parcel. Loading Loading @@ -114,12 +117,11 @@ public: wp<IBinder> readWeakBinder() const; // if alloc is NULL, native_handle is allocated with malloc(), otherwise // alloc is used. If the function fails, the effects of alloc() must be // reverted by the caller. native_handle* readNativeHandle( native_handle* (*alloc)(void* cookie, int numFds, int ints), void* cookie) const; // Retrieve native_handle from the parcel. This returns a copy of the // parcel's native_handle (the caller takes ownership). The caller // must free the native_handle with native_handle_close() and // native_handle_delete(). native_handle* readNativeHandle() const; // Retrieve a file descriptor from the parcel. This returns the raw fd Loading libs/ui/Overlay.cpp +4 −8 Original line number Diff line number Diff line Loading @@ -129,12 +129,8 @@ OverlayRef::OverlayRef(overlay_handle_t handle, const sp<IOverlay>& channel, OverlayRef::~OverlayRef() { if (mOwnHandle) { /* FIXME: handles should be promoted to "real" API and be handled by * the framework */ for (int i=0 ; i<mOverlayHandle->numFds ; i++) { close(mOverlayHandle->data[i]); } free((void*)mOverlayHandle); native_handle_close(mOverlayHandle); native_handle_delete(const_cast<native_handle*>(mOverlayHandle)); } } Loading @@ -147,7 +143,7 @@ sp<OverlayRef> OverlayRef::readFromParcel(const Parcel& data) { uint32_t f = data.readInt32(); uint32_t ws = data.readInt32(); uint32_t hs = data.readInt32(); native_handle* handle = data.readNativeHandle(NULL, NULL); native_handle* handle = data.readNativeHandle(); result = new OverlayRef(); result->mOverlayHandle = handle; Loading @@ -169,7 +165,7 @@ status_t OverlayRef::writeToParcel(Parcel* reply, const sp<OverlayRef>& o) { reply->writeInt32(o->mFormat); reply->writeInt32(o->mWidthStride); reply->writeInt32(o->mHeightStride); reply->writeNativeHandle(*(o->mOverlayHandle)); reply->writeNativeHandle(o->mOverlayHandle); } else { reply->writeStrongBinder(NULL); } Loading libs/utils/Parcel.cpp +11 −29 Original line number Diff line number Diff line Loading @@ -650,28 +650,26 @@ status_t Parcel::writeWeakBinder(const wp<IBinder>& val) return flatten_binder(ProcessState::self(), val, this); } status_t Parcel::writeNativeHandle(const native_handle& handle) status_t Parcel::writeNativeHandle(const native_handle* handle) { if (handle.version != sizeof(native_handle)) if (handle->version != sizeof(native_handle)) return BAD_TYPE; status_t err; err = writeInt32(handle.numFds); err = writeInt32(handle->numFds); if (err != NO_ERROR) return err; err = writeInt32(handle.numInts); err = writeInt32(handle->numInts); if (err != NO_ERROR) return err; for (int i=0 ; err==NO_ERROR && i<handle.numFds ; i++) err = writeDupFileDescriptor(handle.data[i]); for (int i=0 ; err==NO_ERROR && i<handle->numFds ; i++) err = writeDupFileDescriptor(handle->data[i]); if (err != NO_ERROR) { LOGD("write native handle, write dup fd failed"); return err; } err = write(handle.data + handle.numFds, sizeof(int)*handle.numInts); err = write(handle->data + handle->numFds, sizeof(int)*handle->numInts); return err; } Loading Loading @@ -928,7 +926,7 @@ wp<IBinder> Parcel::readWeakBinder() const } native_handle* Parcel::readNativeHandle(native_handle* (*alloc)(void*, int, int), void* cookie) const native_handle* Parcel::readNativeHandle() const { int numFds, numInts; status_t err; Loading @@ -937,31 +935,15 @@ native_handle* Parcel::readNativeHandle(native_handle* (*alloc)(void*, int, int) err = readInt32(&numInts); if (err != NO_ERROR) return 0; native_handle* h; if (alloc == 0) { size_t size = sizeof(native_handle) + sizeof(int)*(numFds + numInts); h = (native_handle*)malloc(size); h->version = sizeof(native_handle); h->numFds = numFds; h->numInts = numInts; } else { h = alloc(cookie, numFds, numInts); if (h->version != sizeof(native_handle)) { return 0; } } native_handle* h = native_handle_create(numFds, numInts); for (int i=0 ; err==NO_ERROR && i<numFds ; i++) { h->data[i] = dup(readFileDescriptor()); if (h->data[i] < 0) err = BAD_VALUE; } err = read(h->data + numFds, sizeof(int)*numInts); if (err != NO_ERROR) { if (alloc == 0) { free(h); } native_handle_close(h); native_handle_delete(h); h = 0; } return h; Loading Loading
include/utils/Parcel.h +10 −8 Original line number Diff line number Diff line Loading @@ -80,8 +80,11 @@ public: status_t writeStrongBinder(const sp<IBinder>& val); status_t writeWeakBinder(const wp<IBinder>& val); // doesn't take ownership of the native_handle status_t writeNativeHandle(const native_handle& handle); // Place a native_handle into the parcel (the native_handle's file- // descriptors are dup'ed, so it is safe to delete the native_handle // when this function returns). // Doesn't take ownership of the native_handle. status_t writeNativeHandle(const native_handle* handle); // Place a file descriptor into the parcel. The given fd must remain // valid for the lifetime of the parcel. Loading Loading @@ -114,12 +117,11 @@ public: wp<IBinder> readWeakBinder() const; // if alloc is NULL, native_handle is allocated with malloc(), otherwise // alloc is used. If the function fails, the effects of alloc() must be // reverted by the caller. native_handle* readNativeHandle( native_handle* (*alloc)(void* cookie, int numFds, int ints), void* cookie) const; // Retrieve native_handle from the parcel. This returns a copy of the // parcel's native_handle (the caller takes ownership). The caller // must free the native_handle with native_handle_close() and // native_handle_delete(). native_handle* readNativeHandle() const; // Retrieve a file descriptor from the parcel. This returns the raw fd Loading
libs/ui/Overlay.cpp +4 −8 Original line number Diff line number Diff line Loading @@ -129,12 +129,8 @@ OverlayRef::OverlayRef(overlay_handle_t handle, const sp<IOverlay>& channel, OverlayRef::~OverlayRef() { if (mOwnHandle) { /* FIXME: handles should be promoted to "real" API and be handled by * the framework */ for (int i=0 ; i<mOverlayHandle->numFds ; i++) { close(mOverlayHandle->data[i]); } free((void*)mOverlayHandle); native_handle_close(mOverlayHandle); native_handle_delete(const_cast<native_handle*>(mOverlayHandle)); } } Loading @@ -147,7 +143,7 @@ sp<OverlayRef> OverlayRef::readFromParcel(const Parcel& data) { uint32_t f = data.readInt32(); uint32_t ws = data.readInt32(); uint32_t hs = data.readInt32(); native_handle* handle = data.readNativeHandle(NULL, NULL); native_handle* handle = data.readNativeHandle(); result = new OverlayRef(); result->mOverlayHandle = handle; Loading @@ -169,7 +165,7 @@ status_t OverlayRef::writeToParcel(Parcel* reply, const sp<OverlayRef>& o) { reply->writeInt32(o->mFormat); reply->writeInt32(o->mWidthStride); reply->writeInt32(o->mHeightStride); reply->writeNativeHandle(*(o->mOverlayHandle)); reply->writeNativeHandle(o->mOverlayHandle); } else { reply->writeStrongBinder(NULL); } Loading
libs/utils/Parcel.cpp +11 −29 Original line number Diff line number Diff line Loading @@ -650,28 +650,26 @@ status_t Parcel::writeWeakBinder(const wp<IBinder>& val) return flatten_binder(ProcessState::self(), val, this); } status_t Parcel::writeNativeHandle(const native_handle& handle) status_t Parcel::writeNativeHandle(const native_handle* handle) { if (handle.version != sizeof(native_handle)) if (handle->version != sizeof(native_handle)) return BAD_TYPE; status_t err; err = writeInt32(handle.numFds); err = writeInt32(handle->numFds); if (err != NO_ERROR) return err; err = writeInt32(handle.numInts); err = writeInt32(handle->numInts); if (err != NO_ERROR) return err; for (int i=0 ; err==NO_ERROR && i<handle.numFds ; i++) err = writeDupFileDescriptor(handle.data[i]); for (int i=0 ; err==NO_ERROR && i<handle->numFds ; i++) err = writeDupFileDescriptor(handle->data[i]); if (err != NO_ERROR) { LOGD("write native handle, write dup fd failed"); return err; } err = write(handle.data + handle.numFds, sizeof(int)*handle.numInts); err = write(handle->data + handle->numFds, sizeof(int)*handle->numInts); return err; } Loading Loading @@ -928,7 +926,7 @@ wp<IBinder> Parcel::readWeakBinder() const } native_handle* Parcel::readNativeHandle(native_handle* (*alloc)(void*, int, int), void* cookie) const native_handle* Parcel::readNativeHandle() const { int numFds, numInts; status_t err; Loading @@ -937,31 +935,15 @@ native_handle* Parcel::readNativeHandle(native_handle* (*alloc)(void*, int, int) err = readInt32(&numInts); if (err != NO_ERROR) return 0; native_handle* h; if (alloc == 0) { size_t size = sizeof(native_handle) + sizeof(int)*(numFds + numInts); h = (native_handle*)malloc(size); h->version = sizeof(native_handle); h->numFds = numFds; h->numInts = numInts; } else { h = alloc(cookie, numFds, numInts); if (h->version != sizeof(native_handle)) { return 0; } } native_handle* h = native_handle_create(numFds, numInts); for (int i=0 ; err==NO_ERROR && i<numFds ; i++) { h->data[i] = dup(readFileDescriptor()); if (h->data[i] < 0) err = BAD_VALUE; } err = read(h->data + numFds, sizeof(int)*numInts); if (err != NO_ERROR) { if (alloc == 0) { free(h); } native_handle_close(h); native_handle_delete(h); h = 0; } return h; Loading