Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b62b0564 authored by Joel Fernandes's avatar Joel Fernandes Committed by Joel Fernandes (Google)
Browse files

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: default avatarJoel Fernandes <joelaf@google.com>
parent fca547f4
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ void acquire_object(const sp<ProcessState>& proc,
            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 @@ static void release_object(const sp<ProcessState>& proc,
        }
        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 @@ status_t Parcel::readBlob(size_t len, ReadableBlob* outBlob) const
    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,