summaryrefslogtreecommitdiff
path: root/view/sharedcache/core/SharedCache.cpp
diff options
context:
space:
mode:
authorkat <kat@vector35.com>2024-12-11 14:44:50 -0500
committerMark Rowe <mrowe@bdash.net.nz>2025-01-10 11:58:24 -0800
commit49bafa9cd9c0301235e806e0f868cf16cdaac405 (patch)
treebe8e4ed8f3fbc42429c2a983f21abfbab5a02944 /view/sharedcache/core/SharedCache.cpp
parentaa408cfdeaa3cd0c4319598223a4548b18731290 (diff)
[SharedCache] Avoid crashing the product whenever bugs occur in ser/deser, fix compilation issue on linux
Diffstat (limited to 'view/sharedcache/core/SharedCache.cpp')
-rw-r--r--view/sharedcache/core/SharedCache.cpp54
1 files changed, 32 insertions, 22 deletions
diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp
index b9150c31..33a4654d 100644
--- a/view/sharedcache/core/SharedCache.cpp
+++ b/view/sharedcache/core/SharedCache.cpp
@@ -314,7 +314,9 @@ void SharedCache::PerformInitialLoad()
}
if (primaryCacheHeader.objcOptsOffset && primaryCacheHeader.objcOptsSize) {
- MutableState().objcOptimizationDataRange = {primaryCacheHeader.objcOptsOffset, primaryCacheHeader.objcOptsSize};
+ uint64_t objcOptsOffset = primaryCacheHeader.objcOptsOffset;
+ uint64_t objcOptsSize = primaryCacheHeader.objcOptsSize;
+ MutableState().objcOptimizationDataRange = {objcOptsOffset, objcOptsSize};
}
switch (State().cacheFormat)
@@ -3309,30 +3311,38 @@ extern "C"
{
if (cache->object)
{
- auto vm = cache->object->GetVMMap(true);
- auto viewImageHeaders = cache->object->AllImageHeaders();
- *count = viewImageHeaders.size();
- BNDSCImage* images = (BNDSCImage*)malloc(sizeof(BNDSCImage) * viewImageHeaders.size());
- size_t i = 0;
- for (const auto& [baseAddress, header] : viewImageHeaders)
- {
- images[i].name = BNAllocString(header.installName.c_str());
- images[i].headerAddress = baseAddress;
- images[i].mappingCount = header.sections.size();
- images[i].mappings = (BNDSCImageMemoryMapping*)malloc(sizeof(BNDSCImageMemoryMapping) * header.sections.size());
- for (size_t j = 0; j < header.sections.size(); j++)
+ try {
+ auto vm = cache->object->GetVMMap(true);
+ auto viewImageHeaders = cache->object->AllImageHeaders();
+ *count = viewImageHeaders.size();
+ BNDSCImage* images = (BNDSCImage*)malloc(sizeof(BNDSCImage) * viewImageHeaders.size());
+ size_t i = 0;
+ for (const auto& [baseAddress, header] : viewImageHeaders)
{
- const auto sectionStart = header.sections[j].addr;
- images[i].mappings[j].rawViewOffset = header.sections[j].offset;
- images[i].mappings[j].vmAddress = sectionStart;
- images[i].mappings[j].size = header.sections[j].size;
- images[i].mappings[j].name = BNAllocString(header.sectionNames[j].c_str());
- images[i].mappings[j].filePath = BNAllocString(vm->MappingAtAddress(sectionStart).first.filePath.c_str());
- images[i].mappings[j].loaded = cache->object->IsMemoryMapped(sectionStart);
+ images[i].name = BNAllocString(header.installName.c_str());
+ images[i].headerAddress = baseAddress;
+ images[i].mappingCount = header.sections.size();
+ images[i].mappings = (BNDSCImageMemoryMapping*)malloc(sizeof(BNDSCImageMemoryMapping) * header.sections.size());
+ for (size_t j = 0; j < header.sections.size(); j++)
+ {
+ const auto sectionStart = header.sections[j].addr;
+ images[i].mappings[j].rawViewOffset = header.sections[j].offset;
+ images[i].mappings[j].vmAddress = sectionStart;
+ images[i].mappings[j].size = header.sections[j].size;
+ images[i].mappings[j].name = BNAllocString(header.sectionNames[j].c_str());
+ images[i].mappings[j].filePath = BNAllocString(vm->MappingAtAddress(sectionStart).first.filePath.c_str());
+ images[i].mappings[j].loaded = cache->object->IsMemoryMapped(sectionStart);
+ }
+ i++;
}
- i++;
+ return images;
+ }
+ catch (...)
+ {
+ LogError("SharedCache: Failed to load image listing. Likely caused by a ser/deserialization error or load failure");
+ *count = 0;
+ return nullptr;
}
- return images;
}
*count = 0;
return nullptr;