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

Commit 266ad0c9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "EGL Multifile Blobcache: Make use of crc32_z algorithm instead of...

Merge "EGL Multifile Blobcache: Make use of crc32_z algorithm instead of crc32c" into main am: f81814b5 am: 52c39142

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3310712



Change-Id: Ia3af3e9f08f65362f8f57f751a80bd847d3c63b4
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 96742256 52c39142
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -135,6 +135,9 @@ cc_library_static {
        "EGL/MultifileBlobCache.cpp",
    ],
    export_include_dirs: ["EGL"],
    shared_libs: [
        "libz",
    ],
}

cc_library_shared {
@@ -169,6 +172,7 @@ cc_library_shared {
        "libutils",
        "libSurfaceFlingerProp",
        "libunwindstack",
        "libz",
    ],
    static_libs: [
        "libEGL_getProcAddress",
@@ -199,6 +203,7 @@ cc_test {
    ],
    shared_libs: [
        "libutils",
        "libz",
    ],
}

+7 −16
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@

#include <log/log.h>
#include <utils/Trace.h>
#include <zlib.h>

// Cache file header
static const char* cacheFileMagic = "EGL$";
@@ -34,20 +35,10 @@ static const size_t cacheFileHeaderSize = 8;

namespace android {

uint32_t crc32c(const uint8_t* buf, size_t len) {
    const uint32_t polyBits = 0x82F63B78;
    uint32_t r = 0;
    for (size_t i = 0; i < len; i++) {
        r ^= buf[i];
        for (int j = 0; j < 8; j++) {
            if (r & 1) {
                r = (r >> 1) ^ polyBits;
            } else {
                r >>= 1;
            }
        }
    }
    return r;
uint32_t GenerateCRC32(const uint8_t *data, size_t size)
{
    const unsigned long initialValue = crc32_z(0u, nullptr, 0u);
    return static_cast<uint32_t>(crc32_z(initialValue, data, size));
}

FileBlobCache::FileBlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize,
@@ -101,7 +92,7 @@ FileBlobCache::FileBlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxT
            return;
        }
        uint32_t* crc = reinterpret_cast<uint32_t*>(buf + 4);
        if (crc32c(buf + headerSize, cacheSize) != *crc) {
        if (GenerateCRC32(buf + headerSize, cacheSize) != *crc) {
            ALOGE("cache file failed CRC check");
            close(fd);
            return;
@@ -175,7 +166,7 @@ void FileBlobCache::writeToFile() {
        // Write the file magic and CRC
        memcpy(buf, cacheFileMagic, 4);
        uint32_t* crc = reinterpret_cast<uint32_t*>(buf + 4);
        *crc = crc32c(buf + headerSize, cacheSize);
        *crc = GenerateCRC32(buf + headerSize, cacheSize);

        if (write(fd, buf, fileSize) == -1) {
            ALOGE("error writing cache file: %s (%d)", strerror(errno),
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@

namespace android {

uint32_t crc32c(const uint8_t* buf, size_t len);
uint32_t GenerateCRC32(const uint8_t *data, size_t size);

class FileBlobCache : public BlobCache {
public:
+10 −11
Original line number Diff line number Diff line
@@ -214,8 +214,7 @@ MultifileBlobCache::MultifileBlobCache(size_t maxKeySize, size_t maxValueSize, s
                }

                // Ensure we have a good CRC
                if (header.crc !=
                    crc32c(mappedEntry + sizeof(MultifileHeader),
                if (header.crc != GenerateCRC32(mappedEntry + sizeof(MultifileHeader),
                                                fileSize - sizeof(MultifileHeader))) {
                    ALOGV("INIT: Entry %u failed CRC check! Removing.", entryHash);
                    if (remove(fullPath.c_str()) != 0) {
@@ -532,8 +531,8 @@ bool MultifileBlobCache::createStatus(const std::string& baseDir) {
            mBuildId.length() > PROP_VALUE_MAX ? PROP_VALUE_MAX : mBuildId.length());

    // Finally update the crc, using cacheVersion and everything the follows
    status.crc =
            crc32c(reinterpret_cast<uint8_t*>(&status) + offsetof(MultifileStatus, cacheVersion),
    status.crc = GenerateCRC32(
        reinterpret_cast<uint8_t *>(&status) + offsetof(MultifileStatus, cacheVersion),
        sizeof(status) - offsetof(MultifileStatus, cacheVersion));

    // Create the status file
@@ -599,8 +598,8 @@ bool MultifileBlobCache::checkStatus(const std::string& baseDir) {
    }

    // Ensure we have a good CRC
    if (status.crc !=
        crc32c(reinterpret_cast<uint8_t*>(&status) + offsetof(MultifileStatus, cacheVersion),
    if (status.crc != GenerateCRC32(reinterpret_cast<uint8_t *>(&status) +
                                        offsetof(MultifileStatus, cacheVersion),
                                    sizeof(status) - offsetof(MultifileStatus, cacheVersion))) {
        ALOGE("STATUS(CHECK): Cache status failed CRC check!");
        return false;
@@ -840,8 +839,8 @@ void MultifileBlobCache::processTask(DeferredTask& task) {

            // Add CRC check to the header (always do this last!)
            MultifileHeader* header = reinterpret_cast<MultifileHeader*>(buffer);
            header->crc =
                    crc32c(buffer + sizeof(MultifileHeader), bufferSize - sizeof(MultifileHeader));
            header->crc             = GenerateCRC32(buffer + sizeof(MultifileHeader),
                                                    bufferSize - sizeof(MultifileHeader));

            ssize_t result = write(fd, buffer, bufferSize);
            if (result != bufferSize) {
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@

namespace android {

constexpr uint32_t kMultifileBlobCacheVersion = 1;
constexpr uint32_t kMultifileBlobCacheVersion = 2;
constexpr char kMultifileBlobCacheStatusFile[] = "cache.status";

struct MultifileHeader {
Loading