From 232d0b3721be5009bdbda017496ee9c205e39d23 Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Mon, 9 Oct 2023 17:37:16 +0000 Subject: Disable native_handle outside of Android Bug: 302723053 Test: mma Change-Id: Ia6d80574a3b137c7646b4a8a7575e03197fcb527 --- libs/binder/Android.bp | 16 ++++++++++++++++ libs/binder/Parcel.cpp | 4 ++++ libs/binder/include/binder/Parcel.h | 9 +++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp index 67e92ca1cb..620c23c1bb 100644 --- a/libs/binder/Android.bp +++ b/libs/binder/Android.bp @@ -374,6 +374,22 @@ cc_library_static { ], } +cc_library_static { + name: "libbinder_rpc_no_native_handle", + vendor_available: true, + defaults: [ + "libbinder_common_defaults", + "libbinder_android_defaults", + "libbinder_kernel_defaults", + ], + cflags: [ + "-DBINDER_DISABLE_NATIVE_HANDLE", + ], + visibility: [ + ":__subpackages__", + ], +} + cc_library_static { name: "libbinder_rpc_single_threaded", defaults: [ diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index a59b9284fc..17bdc455be 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -1436,6 +1436,7 @@ status_t Parcel::writeRawNullableParcelable(const Parcelable* parcelable) { return writeParcelable(*parcelable); } +#ifndef BINDER_DISABLE_NATIVE_HANDLE status_t Parcel::writeNativeHandle(const native_handle* handle) { if (!handle || handle->version != sizeof(native_handle)) @@ -1458,6 +1459,7 @@ status_t Parcel::writeNativeHandle(const native_handle* handle) err = write(handle->data + handle->numFds, sizeof(int)*handle->numInts); return err; } +#endif status_t Parcel::writeFileDescriptor(int fd, bool takeOwnership) { if (auto* rpcFields = maybeRpcFields()) { @@ -2239,6 +2241,7 @@ int32_t Parcel::readExceptionCode() const return status.exceptionCode(); } +#ifndef BINDER_DISABLE_NATIVE_HANDLE native_handle* Parcel::readNativeHandle() const { int numFds, numInts; @@ -2271,6 +2274,7 @@ native_handle* Parcel::readNativeHandle() const } return h; } +#endif int Parcel::readFileDescriptor() const { if (const auto* rpcFields = maybeRpcFields()) { diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h index b94267c360..98d12bb120 100644 --- a/libs/binder/include/binder/Parcel.h +++ b/libs/binder/include/binder/Parcel.h @@ -26,7 +26,9 @@ #include #include +#ifndef BINDER_DISABLE_NATIVE_HANDLE #include +#endif #include #include #include @@ -324,11 +326,13 @@ public: template status_t writeVectorSize(const std::unique_ptr>& val) __attribute__((deprecated("use std::optional version instead"))); +#ifndef BINDER_DISABLE_NATIVE_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); +#endif // Place a file descriptor into the parcel. The given fd must remain // valid for the lifetime of the parcel. @@ -559,13 +563,14 @@ public: // response headers rather than doing it by hand. int32_t readExceptionCode() const; +#ifndef BINDER_DISABLE_NATIVE_HANDLE // 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 + // must free the native_handle with native_handle_close() and // native_handle_delete(). native_handle* readNativeHandle() const; +#endif - // Retrieve a file descriptor from the parcel. This returns the raw fd // in the parcel, which you do not own -- use dup() to get your own copy. int readFileDescriptor() const; -- cgit v1.2.3-59-g8ed1b