diff options
| -rw-r--r-- | libs/binder/Parcel.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index b3ae09b405..07d5c4bb2c 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -2239,8 +2239,30 @@ int Parcel::readParcelFileDescriptor() const int32_t hasComm = readInt32(); int fd = readFileDescriptor(); if (hasComm != 0) { - // skip - readFileDescriptor(); + // detach (owned by the binder driver) + int comm = readFileDescriptor(); + + // warning: this must be kept in sync with: + // frameworks/base/core/java/android/os/ParcelFileDescriptor.java + enum ParcelFileDescriptorStatus { + DETACHED = 2, + }; + +#if BYTE_ORDER == BIG_ENDIAN + const int32_t message = ParcelFileDescriptorStatus::DETACHED; +#endif +#if BYTE_ORDER == LITTLE_ENDIAN + const int32_t message = __builtin_bswap32(ParcelFileDescriptorStatus::DETACHED); +#endif + + ssize_t written = TEMP_FAILURE_RETRY( + ::write(comm, &message, sizeof(message))); + + if (written == -1 || written != sizeof(message)) { + ALOGW("Failed to detach ParcelFileDescriptor written: %zd err: %s", + written, strerror(errno)); + return BAD_TYPE; + } } return fd; } |