Loading...
common/ProcessAtlas.cpp dyld-1066.8 dyld-1042.1
--- dyld/dyld-1066.8/common/ProcessAtlas.cpp
+++ dyld/dyld-1042.1/common/ProcessAtlas.cpp
@@ -133,15 +133,6 @@
     data = data.last(data.size()-byteSize);
 }
 
-Bitmap::Bitmap(Bitmap&& other) {
-    swap(other);
-}
-
-Bitmap& Bitmap::operator=(Bitmap&& other) {
-    swap(other);
-    return *this;
-}
-
 void Bitmap::setBit(size_t bit) {
     contract(bit < _size);
     _bitmap.withUnsafe([&](std::byte* bitmap) {
@@ -591,11 +582,8 @@
         auto fileID = ldr->fileID(state->fileManager);
         if (fileID.inode() &&  fileID.device()) {
             _file = state->fileManager.fileRecordForFileID(ldr->fileID(state->fileManager));
-            if ( _file.volume().empty() ) {
-                _file = state->fileManager.fileRecordForPath(ephemeralAllocator, ldr->path());
-            }
         } else {
-            _file = state->fileManager.fileRecordForPath(ephemeralAllocator, ldr->path());
+            _file = state->fileManager.fileRecordForPath(ldr->path());
         }
     }
 #endif
@@ -624,32 +612,24 @@
     using std::swap;
 
     if (this == &other) { return; }
-    swap(_uuid,                 other._uuid);
-    swap(_ml,                   other._ml);
-    swap(_sharedCacheSlide,     other._sharedCacheSlide);
-    swap(_rebasedAddress,       other._rebasedAddress);
-    swap(_mapper,               other._mapper);
-    swap(_sharedCache,          other._sharedCache);
-    swap(_installname,          other._installname);
-    swap(_file,                 other._file);
-    swap(_uuidLoaded,           other._uuidLoaded);
-    swap(_installnameLoaded,    other._installnameLoaded);
-    swap(_mapperFailed,         other._mapperFailed);
+    std::swap(_uuid,                other._uuid);
+    std::swap(_ml,                  other._ml);
+    std::swap(_sharedCacheSlide,    other._sharedCacheSlide);
+    std::swap(_rebasedAddress,      other._rebasedAddress);
+    std::swap(_mapper,              other._mapper);
+    std::swap(_sharedCache,         other._sharedCache);
+    std::swap(_installname,         other._installname);
+    std::swap(_file,                other._file);
+    std::swap(_uuidLoaded,          other._uuidLoaded);
+    std::swap(_installnameLoaded,   other._installnameLoaded);
 }
 
 const MachOLoaded* Image::ml() const {
-    if (_mapperFailed) {
-        return nullptr;
-    }
+    void* slidML = (void*)rebasedAddress();
     if (!_ml) {
-        void* slidML = (void*)rebasedAddress();
         // Note, using 4k here as we might be an arm64e process inspecting an x86_64 image, which uses 4k pages
-        if (!_mapper && !_mapperFailed) {
+        if (!_mapper) {
             _mapper = Mapper::mapperForMachO(_transactionalAllocator, _file, _uuid, _rebasedAddress);
-        }
-        if (!_mapper) {
-            _mapperFailed = true;
-            return nullptr;
         }
         _ml = _mapper->map<MachOLoaded>(slidML, 4096);
         size_t size = _ml->sizeofcmds;
@@ -671,7 +651,7 @@
     if (!_uuidLoaded) {
         uuid_t fileUUID;
         const MachOLoaded* mh = ml();
-        if (mh && mh->hasMachOMagic()) {
+        if (mh->hasMachOMagic()) {
             if (mh->getUuid(fileUUID))
                 _uuid = UUID(fileUUID);
         }
@@ -687,9 +667,7 @@
 
 const char* Image::installname() const {
     if (!_installnameLoaded) {
-        if (ml()) {
-            _installname = ml()->installName();
-        }
+        _installname = ml()->installName();
         _installnameLoaded = true;
     }
     return _installname;
@@ -712,12 +690,10 @@
 }
 
 uint32_t Image::pointerSize() {
-    if (!ml()) { return 0; }
     return ml()->pointerSize();
 }
 
 bool Image::forEachSegment(void (^block)(const char* segmentName, uint64_t vmAddr, uint64_t vmSize, int perm)) {
-    if (!ml()) { return false; }
     __block uint64_t slide = (uint64_t)_rebasedAddress - ml()->preferredLoadAddress();
     ml()->forEachSegment(^(const MachOLoaded::SegmentInfo &info, bool &stop) {
         uint64_t vmAddr = 0x0;
@@ -736,7 +712,6 @@
 }
 
 bool Image::forEachSection(void (^block)(const char* segmentName, const char* sectionName, uint64_t vmAddr, uint64_t vmSize)) {
-    if (!ml()) { return false; }
     __block uint64_t slide = (uint64_t)_rebasedAddress - ml()->preferredLoadAddress();
     ml()->forEachSection(^(const MachOLoaded::SectionInfo &info, bool malformedSectionRange, bool &stop) {
         uint64_t sectAddr = 0x0;
@@ -751,7 +726,6 @@
 }
 
 bool Image::contentForSegment(const char* segmentName, void (^contentReader)(const void* content, uint64_t vmAddr, uint64_t vmSize)) {
-    if (!ml()) { return false; }
     __block bool result = false;
     __block uint64_t slide = (uint64_t)_rebasedAddress - ml()->preferredLoadAddress();
     ml()->forEachSegment(^(const MachOLoaded::SegmentInfo &info, bool &stop) {
@@ -957,7 +931,7 @@
                     continue;
 
                 // FIXME: The memory managemnt here is awful, fix with allocators
-                auto cacheFile = fileManager.fileRecordForPath(_ephemeralAllocator, cachePath);
+                auto cacheFile = fileManager.fileRecordForPath(cachePath);
                 auto cache = Atlas::SharedCache::createForFileRecord(_ephemeralAllocator, std::move(cacheFile));
                 if (cache) {
                     cache.withUnsafe([&](auto cachePtr){
@@ -1078,7 +1052,7 @@
             return nullptr;
     }
     // TODO: Create Path extension helpers for FileRecord
-    auto localSymbolsCacheFile = _file.fileManager().fileRecordForPath(_ephemeralAllocator, localSymbolsCachePath);
+    auto localSymbolsCacheFile = _file.fileManager().fileRecordForPath(localSymbolsCachePath);
     auto [fileMapper, baseAddress] = Mapper::mapperForSharedCacheLocals(_ephemeralAllocator, localSymbolsCacheFile);
     if (!fileMapper) { return nullptr; }
     // Use placement new since operator new is not available
@@ -1269,7 +1243,7 @@
                     executablePath[len] = '\0';
                 }
                 SharedPtr<Mapper> mapper = nullptr;
-                auto file = _fileManager.fileRecordForPath(_transactionalAllocator, executablePath);
+                auto file = _fileManager.fileRecordForPath(executablePath);
                 uuid_t rawUUID;
                 mf->getUuid(rawUUID);
                 auto uuid = UUID(rawUUID);
@@ -1281,7 +1255,7 @@
                     executablePath[len] = '\0';
                 }
                 SharedPtr<Mapper> mapper = nullptr;
-                auto file = _fileManager.fileRecordForPath(_transactionalAllocator, executablePath);
+                auto file = _fileManager.fileRecordForPath(executablePath);
                 uuid_t rawUUID;
                 mf->getUuid(rawUUID);
                 auto uuid = UUID(rawUUID);
@@ -1603,7 +1577,7 @@
         if (!serializer.deserialize(data)) {
             // Deerialization failed, reset the snapshot and mark invalid
             _images.clear();
-            _bitmap             = nullptr;
+            _bitmap             = Bitmap();
             _sharedCache        = nullptr;
             _platform           = 0;
             _initialImageCount  = 0;
@@ -1626,7 +1600,7 @@
         if (processedCacheImages) { return; }
         processedCacheImages = true;
         for (auto i = 0; i < _sharedCache->imageCount(); ++i) {
-            if (!_bitmap->checkBit(i)) { continue; }
+            if (!_bitmap.checkBit(i)) { continue; }
             _sharedCache->withImageForIndex(i, ^(Image *image) {
                 block(image);
             });
@@ -1649,8 +1623,8 @@
         if (processedCacheImages) { return; }
         if (!_sharedCache) { return; }
         for (auto i = 0; i < _sharedCache->imageCount(); ++i) {
-            if (!_bitmap->checkBit(i)) { continue; }
-            if (other._sharedCache && other._bitmap->checkBit(i)) { continue; }
+            if (!_bitmap.checkBit(i)) { continue; }
+            if (other._sharedCache && other._bitmap.checkBit(i)) { continue; }
             _sharedCache->withImageForIndex(i, ^(Image *image) {
                 block(image);
             });
@@ -1692,7 +1666,7 @@
 void ProcessSnapshot::addImages(RuntimeState* state, const std::span<const Loader*>& loaders) {
     for (auto& ldr : loaders) {
         if (_sharedCache && ldr->dylibInDyldCache) {
-            _bitmap->setBit(ldr->ref.index);
+            _bitmap.setBit(ldr->ref.index);
         } else {
             _images.insert(_transactionalAllocator.makeUnique<Image>(state, _ephemeralAllocator, identityMapper(), ldr));
         }
@@ -1714,7 +1688,7 @@
 #if BUILDING_DYLD || BUILDING_UNIT_TESTS
 void ProcessSnapshot::addSharedCache(SharedCache&& sharedCache) {
     _sharedCache = _transactionalAllocator.makeUnique<SharedCache>(std::move(sharedCache));
-    _bitmap = _transactionalAllocator.makeUnique<Bitmap>(_transactionalAllocator, _sharedCache->imageCount());
+    _bitmap = Bitmap(_transactionalAllocator, _sharedCache->imageCount());
 }
 
 void ProcessSnapshot::addSharedCacheImage(const struct mach_header* mh) {
@@ -1727,7 +1701,7 @@
         return (other.loadAddress == ((uint64_t)mh-slide));
     });
     assert(i != images.end());
-    _bitmap->setBit(i-images.begin());
+    _bitmap.setBit(i-images.begin());
 }
 
 
@@ -1900,7 +1874,7 @@
     }
     if (flags & kMappedFileFlagsHasFilePath) {
         uint64_t pathOffset = readPVLEUInt64(data);
-        file = _fileManager.fileRecordForPath(_ephemeralAllocator, &_stringTableBuffer[(size_t)pathOffset]);
+        file = _fileManager.fileRecordForPath(&_stringTableBuffer[(size_t)pathOffset]);
     }
 }
 
@@ -1909,7 +1883,6 @@
     _genCount++;
     auto result = Vector<std::byte>(_ephemeralAllocator);
     // We need unique all the strings and UUIDs and place them in sorted tables
-    // FIXME: We should use vectors and sort them since it faster in pathological cases, but we need a non-allocating sort
     OrderedSet<const char*, lsl::ConstCharStarCompare>   stringSet(_ephemeralAllocator);
     OrderedSet<UUID>                                     volumeUUIDSet(_ephemeralAllocator);
     if (PAGE_SIZE == 16384) {
@@ -1932,7 +1905,7 @@
         if (file.persistent()) {
             volumeUUIDSet.insert(file.volume());
         } else if (auto filePath = file.getPath()) {
-            stringSet.insert(filePath);
+            stringSet.insert(file.getPath());
         } else {
             stringSet.insert("???");
         }
@@ -1975,7 +1948,7 @@
     if (_processFlags & kProcessFlagsHasSharedCache) {
         uint64_t address = _sharedCache->rebasedAddress()/((_processFlags & kProcessFlagsHas16kPages) ? 16384 : 4096);
         emitMappedFileInfo(address, _sharedCache->uuid(), _sharedCache->file(), result);
-        _bitmap->emit(result);
+        _bitmap.emit(result);
     }
 
     emitPVLEUInt64(_images.size(), result);
@@ -2054,7 +2027,7 @@
 
         _sharedCache = _transactionalAllocator.makeUnique<SharedCache>(_ephemeralAllocator, std::move(file), mapper,
                                                                        rebasedAddress, _processFlags & kProcessFlagsHasPrivateCache);
-        _bitmap = _transactionalAllocator.makeUnique<Bitmap>(_transactionalAllocator, i);
+        _bitmap = Bitmap(_transactionalAllocator, i);
     }
     auto imageCount = readPVLEUInt64(i);
     uint64_t lastAddress = 0;
@@ -2068,12 +2041,16 @@
         SharedPtr<Mapper> mapper = nullptr;
         if (_processSnapshot._useIdentityMapper) {
             mapper = _processSnapshot.identityMapper();
-        }
+        } else {
 #if BUILDING_DYLD || BUILDING_UNIT_TESTS
-        else {
             mapper = _transactionalAllocator.makeShared<Mapper>(_transactionalAllocator);
-        }
+#else
+            mapper = Mapper::mapperForMachO(_transactionalAllocator, file, uuid, (const void*)rebasedAddress);
 #endif
+        }
+        if (!mapper) {
+            return false;
+        }
         auto image = Image(_ephemeralAllocator, std::move(file), mapper, (const struct mach_header*)rebasedAddress, uuid);
         _images.insert(_transactionalAllocator.makeUnique<Image>(std::move(image)));
     }