Loading include/utils/BlobCache.h +6 −0 Original line number Original line Diff line number Diff line Loading @@ -185,6 +185,12 @@ private: // mNumEntries is number of cache entries following the header in the // mNumEntries is number of cache entries following the header in the // data. // data. size_t mNumEntries; size_t mNumEntries; // mBuildId is the build id of the device when the cache was created. // When an update to the build happens (via an OTA or other update) this // is used to invalidate the cache. int mBuildIdLength; char mBuildId[]; }; }; // An EntryHeader is the header for a serialized cache entry. No need to // An EntryHeader is the header for a serialized cache entry. No need to Loading libutils/Android.mk +3 −2 Original line number Original line Diff line number Diff line Loading @@ -16,7 +16,6 @@ LOCAL_PATH:= $(call my-dir) commonSources:= \ commonSources:= \ BasicHashtable.cpp \ BasicHashtable.cpp \ BlobCache.cpp \ CallStack.cpp \ CallStack.cpp \ FileMap.cpp \ FileMap.cpp \ JenkinsHash.cpp \ JenkinsHash.cpp \ Loading Loading @@ -74,6 +73,7 @@ include $(CLEAR_VARS) # we have the common sources, plus some device-specific stuff # we have the common sources, plus some device-specific stuff LOCAL_SRC_FILES:= \ LOCAL_SRC_FILES:= \ $(commonSources) \ $(commonSources) \ BlobCache.cpp \ Looper.cpp \ Looper.cpp \ Trace.cpp Trace.cpp Loading @@ -83,7 +83,8 @@ endif LOCAL_CFLAGS += -Werror LOCAL_CFLAGS += -Werror LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \ libcutils libcutils \ libc LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \ libbacktrace \ libbacktrace \ Loading libutils/BlobCache.cpp +14 −5 Original line number Original line Diff line number Diff line Loading @@ -25,13 +25,15 @@ #include <utils/Errors.h> #include <utils/Errors.h> #include <utils/Log.h> #include <utils/Log.h> #include <cutils/properties.h> namespace android { namespace android { // BlobCache::Header::mMagicNumber value // BlobCache::Header::mMagicNumber value static const uint32_t blobCacheMagic = ('_' << 24) + ('B' << 16) + ('b' << 8) + '$'; static const uint32_t blobCacheMagic = ('_' << 24) + ('B' << 16) + ('b' << 8) + '$'; // BlobCache::Header::mBlobCacheVersion value // BlobCache::Header::mBlobCacheVersion value static const uint32_t blobCacheVersion = 2; static const uint32_t blobCacheVersion = 3; // BlobCache::Header::mDeviceVersion value // BlobCache::Header::mDeviceVersion value static const uint32_t blobCacheDeviceVersion = 1; static const uint32_t blobCacheDeviceVersion = 1; Loading Loading @@ -165,7 +167,7 @@ static inline size_t align4(size_t size) { } } size_t BlobCache::getFlattenedSize() const { size_t BlobCache::getFlattenedSize() const { size_t size = align4(sizeof(Header)); size_t size = align4(sizeof(Header) + PROPERTY_VALUE_MAX); for (size_t i = 0; i < mCacheEntries.size(); i++) { for (size_t i = 0; i < mCacheEntries.size(); i++) { const CacheEntry& e(mCacheEntries[i]); const CacheEntry& e(mCacheEntries[i]); sp<Blob> keyBlob = e.getKey(); sp<Blob> keyBlob = e.getKey(); Loading @@ -187,10 +189,13 @@ status_t BlobCache::flatten(void* buffer, size_t size) const { header->mBlobCacheVersion = blobCacheVersion; header->mBlobCacheVersion = blobCacheVersion; header->mDeviceVersion = blobCacheDeviceVersion; header->mDeviceVersion = blobCacheDeviceVersion; header->mNumEntries = mCacheEntries.size(); header->mNumEntries = mCacheEntries.size(); char buildId[PROPERTY_VALUE_MAX]; header->mBuildIdLength = property_get("ro.build.id", buildId, ""); memcpy(header->mBuildId, buildId, header->mBuildIdLength); // Write cache entries // Write cache entries uint8_t* byteBuffer = reinterpret_cast<uint8_t*>(buffer); uint8_t* byteBuffer = reinterpret_cast<uint8_t*>(buffer); off_t byteOffset = align4(sizeof(Header)); off_t byteOffset = align4(sizeof(Header) + header->mBuildIdLength); for (size_t i = 0; i < mCacheEntries.size(); i++) { for (size_t i = 0; i < mCacheEntries.size(); i++) { const CacheEntry& e(mCacheEntries[i]); const CacheEntry& e(mCacheEntries[i]); sp<Blob> keyBlob = e.getKey(); sp<Blob> keyBlob = e.getKey(); Loading Loading @@ -239,15 +244,19 @@ status_t BlobCache::unflatten(void const* buffer, size_t size) { ALOGE("unflatten: bad magic number: %" PRIu32, header->mMagicNumber); ALOGE("unflatten: bad magic number: %" PRIu32, header->mMagicNumber); return BAD_VALUE; return BAD_VALUE; } } char buildId[PROPERTY_VALUE_MAX]; int len = property_get("ro.build.id", buildId, ""); if (header->mBlobCacheVersion != blobCacheVersion || if (header->mBlobCacheVersion != blobCacheVersion || header->mDeviceVersion != blobCacheDeviceVersion) { header->mDeviceVersion != blobCacheDeviceVersion || len != header->mBuildIdLength || strncmp(buildId, header->mBuildId, len)) { // We treat version mismatches as an empty cache. // We treat version mismatches as an empty cache. return OK; return OK; } } // Read cache entries // Read cache entries const uint8_t* byteBuffer = reinterpret_cast<const uint8_t*>(buffer); const uint8_t* byteBuffer = reinterpret_cast<const uint8_t*>(buffer); off_t byteOffset = align4(sizeof(Header)); off_t byteOffset = align4(sizeof(Header) + header->mBuildIdLength); size_t numEntries = header->mNumEntries; size_t numEntries = header->mNumEntries; for (size_t i = 0; i < numEntries; i++) { for (size_t i = 0; i < numEntries; i++) { if (byteOffset + sizeof(EntryHeader) > size) { if (byteOffset + sizeof(EntryHeader) > size) { Loading Loading
include/utils/BlobCache.h +6 −0 Original line number Original line Diff line number Diff line Loading @@ -185,6 +185,12 @@ private: // mNumEntries is number of cache entries following the header in the // mNumEntries is number of cache entries following the header in the // data. // data. size_t mNumEntries; size_t mNumEntries; // mBuildId is the build id of the device when the cache was created. // When an update to the build happens (via an OTA or other update) this // is used to invalidate the cache. int mBuildIdLength; char mBuildId[]; }; }; // An EntryHeader is the header for a serialized cache entry. No need to // An EntryHeader is the header for a serialized cache entry. No need to Loading
libutils/Android.mk +3 −2 Original line number Original line Diff line number Diff line Loading @@ -16,7 +16,6 @@ LOCAL_PATH:= $(call my-dir) commonSources:= \ commonSources:= \ BasicHashtable.cpp \ BasicHashtable.cpp \ BlobCache.cpp \ CallStack.cpp \ CallStack.cpp \ FileMap.cpp \ FileMap.cpp \ JenkinsHash.cpp \ JenkinsHash.cpp \ Loading Loading @@ -74,6 +73,7 @@ include $(CLEAR_VARS) # we have the common sources, plus some device-specific stuff # we have the common sources, plus some device-specific stuff LOCAL_SRC_FILES:= \ LOCAL_SRC_FILES:= \ $(commonSources) \ $(commonSources) \ BlobCache.cpp \ Looper.cpp \ Looper.cpp \ Trace.cpp Trace.cpp Loading @@ -83,7 +83,8 @@ endif LOCAL_CFLAGS += -Werror LOCAL_CFLAGS += -Werror LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \ libcutils libcutils \ libc LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \ libbacktrace \ libbacktrace \ Loading
libutils/BlobCache.cpp +14 −5 Original line number Original line Diff line number Diff line Loading @@ -25,13 +25,15 @@ #include <utils/Errors.h> #include <utils/Errors.h> #include <utils/Log.h> #include <utils/Log.h> #include <cutils/properties.h> namespace android { namespace android { // BlobCache::Header::mMagicNumber value // BlobCache::Header::mMagicNumber value static const uint32_t blobCacheMagic = ('_' << 24) + ('B' << 16) + ('b' << 8) + '$'; static const uint32_t blobCacheMagic = ('_' << 24) + ('B' << 16) + ('b' << 8) + '$'; // BlobCache::Header::mBlobCacheVersion value // BlobCache::Header::mBlobCacheVersion value static const uint32_t blobCacheVersion = 2; static const uint32_t blobCacheVersion = 3; // BlobCache::Header::mDeviceVersion value // BlobCache::Header::mDeviceVersion value static const uint32_t blobCacheDeviceVersion = 1; static const uint32_t blobCacheDeviceVersion = 1; Loading Loading @@ -165,7 +167,7 @@ static inline size_t align4(size_t size) { } } size_t BlobCache::getFlattenedSize() const { size_t BlobCache::getFlattenedSize() const { size_t size = align4(sizeof(Header)); size_t size = align4(sizeof(Header) + PROPERTY_VALUE_MAX); for (size_t i = 0; i < mCacheEntries.size(); i++) { for (size_t i = 0; i < mCacheEntries.size(); i++) { const CacheEntry& e(mCacheEntries[i]); const CacheEntry& e(mCacheEntries[i]); sp<Blob> keyBlob = e.getKey(); sp<Blob> keyBlob = e.getKey(); Loading @@ -187,10 +189,13 @@ status_t BlobCache::flatten(void* buffer, size_t size) const { header->mBlobCacheVersion = blobCacheVersion; header->mBlobCacheVersion = blobCacheVersion; header->mDeviceVersion = blobCacheDeviceVersion; header->mDeviceVersion = blobCacheDeviceVersion; header->mNumEntries = mCacheEntries.size(); header->mNumEntries = mCacheEntries.size(); char buildId[PROPERTY_VALUE_MAX]; header->mBuildIdLength = property_get("ro.build.id", buildId, ""); memcpy(header->mBuildId, buildId, header->mBuildIdLength); // Write cache entries // Write cache entries uint8_t* byteBuffer = reinterpret_cast<uint8_t*>(buffer); uint8_t* byteBuffer = reinterpret_cast<uint8_t*>(buffer); off_t byteOffset = align4(sizeof(Header)); off_t byteOffset = align4(sizeof(Header) + header->mBuildIdLength); for (size_t i = 0; i < mCacheEntries.size(); i++) { for (size_t i = 0; i < mCacheEntries.size(); i++) { const CacheEntry& e(mCacheEntries[i]); const CacheEntry& e(mCacheEntries[i]); sp<Blob> keyBlob = e.getKey(); sp<Blob> keyBlob = e.getKey(); Loading Loading @@ -239,15 +244,19 @@ status_t BlobCache::unflatten(void const* buffer, size_t size) { ALOGE("unflatten: bad magic number: %" PRIu32, header->mMagicNumber); ALOGE("unflatten: bad magic number: %" PRIu32, header->mMagicNumber); return BAD_VALUE; return BAD_VALUE; } } char buildId[PROPERTY_VALUE_MAX]; int len = property_get("ro.build.id", buildId, ""); if (header->mBlobCacheVersion != blobCacheVersion || if (header->mBlobCacheVersion != blobCacheVersion || header->mDeviceVersion != blobCacheDeviceVersion) { header->mDeviceVersion != blobCacheDeviceVersion || len != header->mBuildIdLength || strncmp(buildId, header->mBuildId, len)) { // We treat version mismatches as an empty cache. // We treat version mismatches as an empty cache. return OK; return OK; } } // Read cache entries // Read cache entries const uint8_t* byteBuffer = reinterpret_cast<const uint8_t*>(buffer); const uint8_t* byteBuffer = reinterpret_cast<const uint8_t*>(buffer); off_t byteOffset = align4(sizeof(Header)); off_t byteOffset = align4(sizeof(Header) + header->mBuildIdLength); size_t numEntries = header->mNumEntries; size_t numEntries = header->mNumEntries; for (size_t i = 0; i < numEntries; i++) { for (size_t i = 0; i < numEntries; i++) { if (byteOffset + sizeof(EntryHeader) > size) { if (byteOffset + sizeof(EntryHeader) > size) { Loading