key = $key; $this->name = $name; $this->type = $type; $this->addressRange = is_numeric($startAddress) && is_numeric($size) ? new AddressRange( $startAddress, $startAddress + ($size / ($addressSpaceUnitSize ?? 1)) - 1 ) : null; $this->addressSpaceUnitSize = $addressSpaceUnitSize; $this->pageSize = $pageSize; $this->access = $access; $this->sections = $sections; $this->executable = $executable; } public function size(): ?int { return $this->addressRange instanceof AddressRange ? $this->addressRange->size() * ($this->addressSpaceUnitSize ?? 1) : null; } public function getSection(string $sectionId): ?MemorySegmentSection { foreach ($this->sections as $section) { if ($section->key !== $sectionId) { continue; } return $section; } return null; } public function getInnermostSectionContainingAddressRange(AddressRange $range) : ?MemorySegmentSection { foreach ($this->sections as $section) { if ($section->containsAddressRange($range)) { return $section->getInnermostSubSectionContainingAddressRange($range); } } return null; } public function contains(MemorySegment $other): bool { return $this->addressRange instanceof AddressRange && $this->addressRange->contains($other->addressRange); } public function intersectsWith(MemorySegment $other): bool { return $this->addressRange instanceof AddressRange && $other->addressRange instanceof AddressRange && $this->addressRange->intersectsWith($other->addressRange) ; } public function totalSectionSize(): int { return array_sum( array_map( fn (MemorySegmentSection $section): int => (int) $section->size(), $this->sections ) ); } }