• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
      • X86isa
        • Program-execution
        • Sdm-instruction-set-summary
        • Tlb
        • Running-linux
        • Introduction
        • Asmtest
        • X86isa-build-instructions
        • Publications
        • Contributors
        • Machine
          • X86isa-state
          • Syscalls
            • Syscalls-logic
              • Syscall-write-logic
              • Syscall-lseek-logic
              • Syscall-read-logic
              • Syscall-open-logic
              • Syscall-dup2-logic
              • Syscall-close-logic
              • Syscall-dup-logic
                • Syscall-write
                • Syscall-read
                • Syscall-open
                • Syscall-lseek
                • Syscall-close
                • Syscall-dup
                • Syscall-unlink
                • Syscall-truncate
                • Syscall-stat
                • Syscall-lstat
                • Syscall-link
                • Syscall-ftruncate
                • Syscall-fstat
                • Syscall-fcntl
                • Syscall-fadvise64
                • Syscall-dup2
                • Syscall-unlink-logic
                • Syscall-truncate-logic
                • Syscall-stat-logic
                • Syscall-lstat-logic
                • Syscall-link-logic
                • Syscall-ftruncate-logic
                • Syscall-fstat-logic
                • Syscall-fcntl-logic
                • Syscall-fadvise64-logic
                • Syscall-dup3-logic
                • Syscall-dup3
              • X86-syscall-args-and-return-value-marshalling
              • Syscall-numbers
              • Syscalls-exec
            • Cpuid
            • Linear-memory
            • Rflag-specifications
            • Characterizing-undefined-behavior
            • Top-level-memory
            • App-view
            • X86-decoder
            • Physical-memory
            • Decoding-and-spec-utils
            • Instructions
            • Register-readers-and-writers
            • X86-modes
            • Segmentation
            • Other-non-deterministic-computations
            • Environment
            • Paging
          • Implemented-opcodes
          • To-do
          • Proof-utilities
          • Peripherals
          • Model-validation
          • Modelcalls
          • Concrete-simulation-examples
          • Utils
          • Debugging-code-proofs
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Syscalls-logic

    Syscall-dup-logic

    Signature
    (syscall-dup-logic oldfd x86) → (mv * x86)

    From the dup(2) man page (Linux):

    int dup(int oldfd);

    dup() uses the lowest-numbered unused descriptor for the new descriptor.

    Definitions and Theorems

    Function: syscall-dup-logic

    (defun syscall-dup-logic (oldfd x86)
     (declare (xargs :stobjs (x86)))
     (declare (ignorable oldfd x86))
     (declare (xargs :guard (integerp oldfd)))
     (let ((__function__ 'syscall-dup-logic))
      (declare (ignorable __function__))
      (b*
       ((obj-fd-field (read-x86-file-des oldfd x86))
        ((when (not (file-descriptor-fieldp obj-fd-field)))
         (b*
          ((-
            (cw
             "~%Error: File Descriptor Field ill-formed. Maybe these books were ~
    not built with X86ISA_EXEC set to t? See :doc x86isa-build-instructions.~%~%"))
           (x86
            (!ms
             (list
              (rip x86)
              "File Descriptor Field ill-formed. Maybe these books were ~
    not built with X86ISA_EXEC set to t? See :doc x86isa-build-instructions."
              (ms x86))
             x86)))
          (mv -1 x86)))
        ((mv newfd x86) (pop-x86-oracle x86))
        ((when (not (integerp newfd)))
         (b*
           ((- (cw "~%Error: New file descriptor not an integer.~%~%"))
            (x86 (!ms (list (rip x86)
                            "New file descriptor not an integer"
                            newfd (ms x86))
                      x86)))
           (mv -1 x86))))
       (mv newfd x86))))