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

Commit 4fbece52 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Revert "Use MappedFile for mmap-related operations in CursorWindow""...

Merge "Revert "Use MappedFile for mmap-related operations in CursorWindow"" into main am: e7d08b0b am: f7e31cdd

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3308541



Change-Id: Idacf66f0b102bf3c5d898fc3498fa3f332bf5356
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 691af85c f7e31cdd
Loading
Loading
Loading
Loading
+8 −13
Original line number Diff line number Diff line
@@ -18,12 +18,11 @@

#include <androidfw/CursorWindow.h>

#include <sys/mman.h>

#include "android-base/logging.h"
#include "android-base/mapped_file.h"
#include "cutils/ashmem.h"

using android::base::MappedFile;

namespace android {

/**
@@ -40,7 +39,7 @@ CursorWindow::CursorWindow() {

CursorWindow::~CursorWindow() {
    if (mAshmemFd != -1) {
        mMappedFile.reset();
        ::munmap(mData, mSize);
        ::close(mAshmemFd);
    } else {
        free(mData);
@@ -76,7 +75,6 @@ fail_silent:
status_t CursorWindow::maybeInflate() {
    int ashmemFd = 0;
    void* newData = nullptr;
    std::unique_ptr<MappedFile> mappedFile;

    // Bail early when we can't expand any further
    if (mReadOnly || mSize == mInflatedSize) {
@@ -97,12 +95,11 @@ status_t CursorWindow::maybeInflate() {
        goto fail_silent;
    }

    mappedFile = MappedFile::FromFd(ashmemFd, 0, mInflatedSize, PROT_READ | PROT_WRITE);
    if (mappedFile == nullptr) {
    newData = ::mmap(nullptr, mInflatedSize, PROT_READ | PROT_WRITE, MAP_SHARED, ashmemFd, 0);
    if (newData == MAP_FAILED) {
        PLOG(ERROR) << "Failed mmap";
        goto fail_silent;
    }
    newData = mappedFile->data();

    if (ashmem_set_prot_region(ashmemFd, PROT_READ) < 0) {
        PLOG(ERROR) << "Failed ashmem_set_prot_region";
@@ -123,7 +120,6 @@ status_t CursorWindow::maybeInflate() {
        mData = newData;
        mSize = mInflatedSize;
        mSlotsOffset = newSlotsOffset;
        mMappedFile = std::move(mappedFile);

        updateSlotsData();
    }
@@ -134,7 +130,7 @@ status_t CursorWindow::maybeInflate() {
fail:
    LOG(ERROR) << "Failed maybeInflate";
fail_silent:
    mappedFile.reset();
    ::munmap(newData, mInflatedSize);
    ::close(ashmemFd);
    return UNKNOWN_ERROR;
}
@@ -171,12 +167,11 @@ status_t CursorWindow::createFromParcel(Parcel* parcel, CursorWindow** outWindow
            goto fail_silent;
        }

        window->mMappedFile = MappedFile::FromFd(window->mAshmemFd, 0, window->mSize, PROT_READ);
        if (window->mMappedFile == nullptr) {
        window->mData = ::mmap(nullptr, window->mSize, PROT_READ, MAP_SHARED, window->mAshmemFd, 0);
        if (window->mData == MAP_FAILED) {
            PLOG(ERROR) << "Failed mmap";
            goto fail_silent;
        }
        window->mData = window->mMappedFile->data();
    } else {
        window->mAshmemFd = -1;

+0 −4
Original line number Diff line number Diff line
@@ -26,8 +26,6 @@
#include "binder/Parcel.h"
#include "utils/String8.h"

#include "android-base/mapped_file.h"

#define LOG_WINDOW(...)

namespace android {
@@ -151,8 +149,6 @@ private:
    String8 mName;
    int mAshmemFd = -1;
    void* mData = nullptr;
    std::unique_ptr<android::base::MappedFile> mMappedFile;

    /**
     * Pointer to the first FieldSlot, used to optimize the extremely
     * hot code path of getFieldSlot().