summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tomasz Wasilczyk <twasilczyk@google.com> 2023-10-09 17:42:37 +0000
committer Tomasz Wasilczyk <twasilczyk@google.com> 2023-10-19 00:26:29 +0000
commitbca8f94b73f48080e1d4fa8bc1a9a9efabf9f629 (patch)
treec851244fdeeb12d2cae08d8e382869e9ccec63a8
parent3f4c4957a69f60df33fffb56a07edcfe523a13d4 (diff)
Disable Blob outside of Android
Bug: 302723053 Test: mma Change-Id: I2abc138831da28783b26efe75ee6f4583e263692
-rw-r--r--libs/binder/Android.bp16
-rw-r--r--libs/binder/Parcel.cpp17
2 files changed, 33 insertions, 0 deletions
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index fd2b27f839..67e92ca1cb 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -359,6 +359,22 @@ cc_library_static {
}
cc_library_static {
+ name: "libbinder_rpc_no_blob",
+ vendor_available: true,
+ defaults: [
+ "libbinder_common_defaults",
+ "libbinder_android_defaults",
+ "libbinder_kernel_defaults",
+ ],
+ cflags: [
+ "-DBINDER_DISABLE_BLOB",
+ ],
+ visibility: [
+ ":__subpackages__",
+ ],
+}
+
+cc_library_static {
name: "libbinder_rpc_single_threaded",
defaults: [
"libbinder_common_defaults",
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 16944a6221..a59b9284fc 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -40,7 +40,9 @@
#include <binder/TextOutput.h>
#include <android-base/scopeguard.h>
+#ifndef BINDER_DISABLE_BLOB
#include <cutils/ashmem.h>
+#endif
#include <utils/Flattenable.h>
#include <utils/Log.h>
#include <utils/String16.h>
@@ -1548,6 +1550,12 @@ status_t Parcel::writeUniqueFileDescriptor(const base::unique_fd& fd) {
status_t Parcel::writeBlob(size_t len, bool mutableCopy, WritableBlob* outBlob)
{
+#ifdef BINDER_DISABLE_BLOB
+ (void)len;
+ (void)mutableCopy;
+ (void)outBlob;
+ return INVALID_OPERATION;
+#else
if (len > INT32_MAX) {
// don't accept size_t values which may have come from an
// inadvertent conversion from a negative int.
@@ -1599,6 +1607,7 @@ status_t Parcel::writeBlob(size_t len, bool mutableCopy, WritableBlob* outBlob)
}
::close(fd);
return status;
+#endif
}
status_t Parcel::writeDupImmutableBlobFileDescriptor(int fd)
@@ -2382,6 +2391,11 @@ status_t Parcel::readUniqueParcelFileDescriptor(base::unique_fd* val) const
status_t Parcel::readBlob(size_t len, ReadableBlob* outBlob) const
{
+#ifdef BINDER_DISABLE_BLOB
+ (void)len;
+ (void)outBlob;
+ return INVALID_OPERATION;
+#else
int32_t blobType;
status_t status = readInt32(&blobType);
if (status) return status;
@@ -2415,6 +2429,7 @@ status_t Parcel::readBlob(size_t len, ReadableBlob* outBlob) const
outBlob->init(fd, ptr, len, isMutable);
return NO_ERROR;
+#endif
}
status_t Parcel::read(FlattenableHelperInterface& val) const
@@ -3158,6 +3173,7 @@ size_t Parcel::getOpenAshmemSize() const
}
size_t openAshmemSize = 0;
+#ifndef BINDER_DISABLE_BLOB
for (size_t i = 0; i < kernelFields->mObjectsSize; i++) {
const flat_binder_object* flat =
reinterpret_cast<const flat_binder_object*>(mData + kernelFields->mObjects[i]);
@@ -3172,6 +3188,7 @@ size_t Parcel::getOpenAshmemSize() const
}
}
}
+#endif
return openAshmemSize;
}
#endif // BINDER_WITH_KERNEL_IPC