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

Commit f23b2bda authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi Committed by Android (Google) Code Review
Browse files

Merge "[f/b] Replace MappedFile::FromFd with Create" into main

parents 7e27ae70 2202bf7f
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -671,9 +671,8 @@ static int createAshmemRegionWithData(JNIEnv* env, const void* data, size_t leng
        ALOGE("ashmem_create_region failed: %s", strerror(error));
    } else {
        if (length > 0) {
            std::unique_ptr<base::MappedFile> mappedFile =
                    base::MappedFile::FromFd(fd, 0, length, PROT_READ | PROT_WRITE);
            if (mappedFile == nullptr) {
            auto mappedFile = base::MappedFile::Create(fd, 0, length, PROT_READ | PROT_WRITE);
            if (!mappedFile) {
                error = errno;
                ALOGE("mmap failed: %s", strerror(error));
            } else {
+4 −3
Original line number Diff line number Diff line
@@ -70,12 +70,13 @@ static std::pair<const uint8_t*, size_t> mmapPatternFile(const std::string& loca
        return std::make_pair(nullptr, 0);
    }
#else
    std::unique_ptr<base::MappedFile> patternFile =
            base::MappedFile::FromFd(fd, 0, st.st_size, PROT_READ);
    auto patternFile = base::MappedFile::Create(fd, 0, st.st_size, PROT_READ);
    close(fd);
    if (patternFile == nullptr) {
    if (!patternFile) {
        return std::make_pair(nullptr, 0);
    }
    // Yes, this line leaks the allocated MappedFile object, because it needs to load the file
    // for the lifetime of the process and MappedFile doesn't have a way to "release" the mapping.
    auto* mappedPtr = new base::MappedFile(std::move(*patternFile));
    char* ptr = mappedPtr->data();
#endif
+5 −6
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ fail_silent:
status_t CursorWindow::maybeInflate() {
    int ashmemFd = 0;
    void* newData = nullptr;
    std::unique_ptr<MappedFile> newMappedFile = nullptr;
    std::optional<MappedFile> newMappedFile;

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

    newMappedFile = MappedFile::FromFd(ashmemFd, 0, mInflatedSize, PROT_READ | PROT_WRITE);
    if (newMappedFile == nullptr) {
    newMappedFile = MappedFile::Create(ashmemFd, 0, mInflatedSize, PROT_READ | PROT_WRITE);
    if (!newMappedFile) {
        PLOG(ERROR) << "Failed mmap";
        goto fail_silent;
    }
@@ -134,7 +134,6 @@ status_t CursorWindow::maybeInflate() {
fail:
    LOG(ERROR) << "Failed maybeInflate";
fail_silent:
    newMappedFile.reset();
    ::close(ashmemFd);
    return UNKNOWN_ERROR;
}
@@ -171,8 +170,8 @@ status_t CursorWindow::createFromParcel(Parcel* parcel, CursorWindow** outWindow
            PLOG(ERROR) << "Failed F_DUPFD_CLOEXEC";
            goto fail_silent;
        }
        window->mMappedFile = MappedFile::FromFd(tempFd, 0, window->mSize, PROT_READ);
        if (window->mMappedFile == nullptr) {
        window->mMappedFile = MappedFile::Create(tempFd, 0, window->mSize, PROT_READ);
        if (!window->mMappedFile) {
            ::close(tempFd);
            PLOG(ERROR) << "Failed mmap";
            goto fail_silent;
+1 −1
Original line number Diff line number Diff line
@@ -152,8 +152,8 @@ public:

private:
    String8 mName;
    std::optional<android::base::MappedFile> mMappedFile;
    int mAshmemFd = -1;
    std::unique_ptr<android::base::MappedFile> mMappedFile = nullptr;
    void* mData = nullptr;
    /**
     * Pointer to the first FieldSlot, used to optimize the extremely