Class RelocationState


  • public class RelocationState
    extends java.lang.Object
    This class maintains the running state while applying relocations.

    relocAddress Holds an address within the section where the relocations are to be performed. The initial value is the base address of the section to be relocated.

    importIndex Holds a symbol index, which is used to access an imported symbol's address. This address can then be used for relocations. The initial value is 0.

    sectionC Holds the memory address of an instantiated section within the PEF container, this variable is used by relocation instructions that relocate section addresses. The initial value is the memory address of section 0 (if that section is present and instantiated), otherwise it is 0.

    sectionD Holds the memory address of an instantiated section within the PEF container, this variable is used by relocation instructions that relocate section addresses. The initial value is the memory address of section 1 (if that section is present and instantiated), otherwise it is 0.

    • Constructor Detail

      • RelocationState

        public RelocationState​(ContainerHeader header,
                               LoaderRelocationHeader relocationHeader,
                               Program program,
                               ImportStateCache importState)
        Constructs a new relocation state
        Parameters:
        header - the PEF container header
        relocationHeader - the specific relocation header for this state
        program - the program being relocated
        sectionMap - the map of section headers to memory blocks
    • Method Detail

      • dispose

        public void dispose()
      • incrementImportIndex

        public void incrementImportIndex()
        Increments the import index by one.
      • incrementRelocationAddress

        public void incrementRelocationAddress​(int addend)
        Increments the relocation address by the given addend
        Parameters:
        addend - the amount to increment the relocation address
      • setRelocationAddress

        public void setRelocationAddress​(Address relocationAddress)
        Sets the relocation address.
        Parameters:
        relocationAddress - the new relocation address
      • setSectionC

        public void setSectionC​(Address sectionC)
        Set the sectionC variable to given address.
        Parameters:
        sectionC - the new sectionC address
      • setSectionD

        public void setSectionD​(Address sectionD)
        Set the sectionD variable to given address.
        Parameters:
        sectionD - the new sectionD address
      • getImportIndex

        public int getImportIndex()
        Returns the current import index.
        Returns:
        the current import index
      • setImportIndex

        public void setImportIndex​(int importIndex)
        Sets the import index.
        Parameters:
        importIndex - the new import index value
      • getRelocationAddress

        public Address getRelocationAddress()
        Returns the current relocation address.
        Returns:
        the current relocation address
      • getSectionC

        public Address getSectionC()
        Returns the current sectionC address.
        Returns:
        the current sectionC address
      • getSectionD

        public Address getSectionD()
        Returns the current sectionD address.
        Returns:
        the current sectionD address
      • fixupMemory

        public void fixupMemory​(Address address,
                                Address fixupAddress,
                                MessageLog log)
        Adds the fixup address to the contents stored at address, then creates a pointer at address.
        Parameters:
        address - the address to fixup
        fixupAddress - the value to use in fixup
        log - message log for recording errors
      • relocateMemoryAt

        public void relocateMemoryAt​(Address address,
                                     int addend,
                                     MessageLog log)
        Increments the integer in memory at the specified address
        Parameters:
        program - the program
        address - the address to increment
        addend - the value to add
        log - a message log
      • getSectionToBeRelocated

        public Address getSectionToBeRelocated()
        Returns the base address of the section to be relocated.
        Returns:
        the base address of the section to be relocated