• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
      • X86isa
      • Axe
      • Execloader
        • Elf-reader
          • Elf64_sym
          • Elf32_sym
          • Elf-header
          • Elf-section-header
          • Elf64-segment-header
          • Elf32-segment-header
          • Elf_bits32
          • Elf_bits8
          • Elf_bits64
          • Elf_bits16
          • Section-info
          • Read-section-headers
            • Read-segment-headers-64
            • Read-segment-headers-32
            • Read-section-names
            • Elf64_sym-info
            • Elf32_sym-info
            • Read-elf-header
            • Parse-symtab-entries
            • Populate-elf-contents
            • Is-elf-content-p
            • Get-string-section-data
            • Get-section-info1
            • Set-elf-stobj-fields
            • Get-named-section-headers
            • Elf-read-mem-null-term
            • Get-section-info
            • Get-symtab-entries
            • Find-label-address-from-elf-symtab-info
            • Section-names
            • Populate-elf
            • Get-label-addresses
            • Elf-read-string-null-term
            • Get-label-address
            • Good-elf-p
            • Elf64_sym-equiv-under-mask
            • Elf64-segment-headers
            • Elf32_sym-equiv-under-mask
            • Elf32-segment-headers
            • Section-info-list
            • Elf64_sym-info-list
            • Elf32_sym-info-list
            • Elf-section-headers
            • Elf64_sym-debug
            • Elf32_sym-debug
          • Mach-o-reader
          • Merge-first-split-bytes
          • Split-bytes
          • Take-till-zero
          • Charlist->bytes
          • Merge-bytes
          • Bytes->charlist
          • String->bytes
          • Bytes->string
      • Math
      • Testing-utilities
    • Elf-reader

    Read-section-headers

    Read ELF section headers

    Signature
    (read-section-headers nsections w rest-of-the-file acc) 
      → 
    section-headers
    Arguments
    nsections — Guard (natp nsections).
    w — Guard (natp w).
    rest-of-the-file — Guard (byte-listp rest-of-the-file).
    acc — Guard (elf-section-headers-p acc).
    Returns
    section-headers — Type (elf-section-headers-p section-headers), given (elf-section-headers-p acc).

    Definitions and Theorems

    Function: read-section-headers

    (defun read-section-headers (nsections w rest-of-the-file acc)
     (declare (xargs :guard (and (natp nsections)
                                 (natp w)
                                 (byte-listp rest-of-the-file)
                                 (elf-section-headers-p acc))))
     (let ((__function__ 'read-section-headers))
      (declare (ignorable __function__))
      (if (zp nsections)
          (reverse acc)
       (b*
        (((unless (or (equal w 4) (equal w 8)))
          (prog2$
           (raise
            "Width of fields expected to be either 4 or 8, but it is ~x0 instead!"
            w)
           (reverse acc)))
         ((mv sh_name rest-of-the-file)
          (merge-first-split-bytes 4 rest-of-the-file))
         ((mv sh_type rest-of-the-file)
          (merge-first-split-bytes 4 rest-of-the-file))
         ((mv sh_flags rest-of-the-file)
          (merge-first-split-bytes w rest-of-the-file))
         ((mv sh_addr rest-of-the-file)
          (merge-first-split-bytes w rest-of-the-file))
         ((mv sh_offset rest-of-the-file)
          (merge-first-split-bytes w rest-of-the-file))
         ((mv sh_size rest-of-the-file)
          (merge-first-split-bytes w rest-of-the-file))
         ((mv sh_link rest-of-the-file)
          (merge-first-split-bytes 4 rest-of-the-file))
         ((mv sh_info rest-of-the-file)
          (merge-first-split-bytes 4 rest-of-the-file))
         ((mv sh_addralign rest-of-the-file)
          (merge-first-split-bytes w rest-of-the-file))
         ((mv sh_entsize rest-of-the-file)
          (merge-first-split-bytes w rest-of-the-file))
         (section (make-elf-section-header :name sh_name
                                           :type sh_type
                                           :flags sh_flags
                                           :addr sh_addr
                                           :offset sh_offset
                                           :size sh_size
                                           :link sh_link
                                           :info sh_info
                                           :addralign sh_addralign
                                           :entsize sh_entsize)))
        (read-section-headers (1- nsections)
                              w
                              rest-of-the-file (cons section acc))))))

    Theorem: elf-section-headers-p-of-read-section-headers

    (defthm elf-section-headers-p-of-read-section-headers
     (implies
       (elf-section-headers-p acc)
       (b*
         ((section-headers
               (read-section-headers nsections w rest-of-the-file acc)))
         (elf-section-headers-p section-headers)))
     :rule-classes :rewrite)