binder: Remove ashmem validitiy checks
ashmem_get_size_region will return an error if the fd is invalid or is
not an ashmem_fd. There is no point in calling ashmem_valid and doing an
fstat. This patch avoids it since its of no use in the critical path.
Test: Run camera preview succesfully
VFS calls before change:
ffffff8ed17e263c vfs_getattr.cfi 1457
ffffff8ed2d09d48 vfs_getattr 1597
ffffff8ed2d2ccd4 vfs_read 2826
ffffff8ed17d6a34 vfs_read.cfi 2856
ffffff8ed17d6660 vfs_write.cfi 1753
ffffff8ed2d2d170 vfs_write 1840
VFS calls after change (showing reduction in getattr):
ffffff9625309d48 vfs_getattr 151
ffffff9623de263c vfs_getattr.cfi 151
ffffff962532ccd4 vfs_read 1301
ffffff9623dd6a34 vfs_read.cfi 1333
ffffff9623dd6660 vfs_write.cfi 1385
ffffff962532d170 vfs_write 1458
Bug: 111418894
Change-Id: I47038e0ed4cf564dfb63db8918c7f39d919b3634
Signed-off-by: Joel Fernandes <joelaf@google.com>
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 87c9842..d3351c8 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -129,7 +129,7 @@
return;
}
case BINDER_TYPE_FD: {
- if ((obj.cookie != 0) && (outAshmemSize != nullptr) && ashmem_valid(obj.handle)) {
+ if ((obj.cookie != 0) && (outAshmemSize != nullptr)) {
// If we own an ashmem fd, keep track of how much memory it refers to.
int size = ashmem_get_size_region(obj.handle);
if (size > 0) {
@@ -178,7 +178,7 @@
}
case BINDER_TYPE_FD: {
if (obj.cookie != 0) { // owned
- if ((outAshmemSize != nullptr) && ashmem_valid(obj.handle)) {
+ if ((outAshmemSize != nullptr)) {
int size = ashmem_get_size_region(obj.handle);
if (size > 0) {
*outAshmemSize -= size;
@@ -2307,13 +2307,9 @@
int fd = readFileDescriptor();
if (fd == int(BAD_TYPE)) return BAD_VALUE;
- if (!ashmem_valid(fd)) {
- ALOGE("invalid fd");
- return BAD_VALUE;
- }
int size = ashmem_get_size_region(fd);
if (size < 0 || size_t(size) < len) {
- ALOGE("request size %zu does not match fd size %d", len, size);
+ ALOGE("invalid fd or request size %zu does not match fd size %d", len, size);
return BAD_VALUE;
}
void* ptr = ::mmap(nullptr, len, isMutable ? PROT_READ | PROT_WRITE : PROT_READ,