Package ghidra.program.model.address
Interface AddressSpace
-
- All Superinterfaces:
java.lang.Comparable<AddressSpace>
- All Known Implementing Classes:
GenericAddressSpace
,OverlayAddressSpace
,ProtectedAddressSpace
,SegmentedAddressSpace
public interface AddressSpace extends java.lang.Comparable<AddressSpace>
The AddressSpace class is used to represent a unique context for addresses. Programs can have multiple address spaces and address 0 in one space is not the same as address 0 in another space.
-
-
Field Summary
Fields Modifier and Type Field Description static AddressSpace
DEFAULT_REGISTER_SPACE
A language may only define a single REGISTER space.static AddressSpace
EXTERNAL_SPACE
TheEXTERNAL_SPACE
is used to contain all external locations (i.e., data and functions) defined within a given library namespace.static AddressSpace
HASH_SPACE
TheHASH_SPACE
provides a 60-bit space for encoding of unique hashcodes.static int
ID_SIZE_MASK
static int
ID_SIZE_SHIFT
static int
ID_TYPE_MASK
static int
ID_UNIQUE_SHIFT
static AddressSpace
OTHER_SPACE
TheOTHER_SPACE
is used to store data from the original program file that doesn't get loaded into the final memory image and for user-defined spaces.static int
TYPE_CODE
static int
TYPE_CONSTANT
static int
TYPE_DELETED
static int
TYPE_EXTERNAL
static int
TYPE_IPTR_CONSTANT
static int
TYPE_IPTR_INTERNAL
static int
TYPE_IPTR_SPACEBASE
static int
TYPE_JOIN
static int
TYPE_NONE
static int
TYPE_OTHER
static int
TYPE_RAM
static int
TYPE_REGISTER
static int
TYPE_STACK
static int
TYPE_SYMBOL
static int
TYPE_UNIQUE
static int
TYPE_UNKNOWN
static int
TYPE_VARIABLE
static AddressSpace
VARIABLE_SPACE
TheVARIABLE_SPACE
is used to contain all variables and parameters defined within a given namespace (i.e., function).
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Address
add(Address addr, long displacement)
Creates a new address (possibly in a new space) by adding the given displacement from the given address.Address
addNoWrap(Address addr, long displacement)
Creates a new address by adding displacement to the given address.Address
addNoWrap(GenericAddress addr, java.math.BigInteger displacement)
Creates a new address by adding displacement to the given address.Address
addWrap(Address addr, long displacement)
Creates a new address by adding displacement to the given address.Address
addWrapSpace(Address addr, long displacement)
Creates a new address by adding the displacement to the given address.Address
getAddress(long byteOffset)
Returns a new address in this space with the given byte offset.Address
getAddress(long offset, boolean isAddressableWordOffset)
Returns a new address in this space with the given offset.Address
getAddress(java.lang.String addrString)
Parses the String into an address.Address
getAddress(java.lang.String addrString, boolean caseSensitive)
Parses the String into an address.int
getAddressableUnitSize()
Returns the number of data bytes which correspond to each addressable location within this space (i.e., word-size in bytes).long
getAddressableWordOffset(long byteOffset)
Get the addressable memory word offset which corresponds to the specified memory byte offset.Address
getAddressInThisSpaceOnly(long byteOffset)
Get a byte address from this address space.int
getBaseSpaceID()
Get the ID for this spaceAddress
getMaxAddress()
Get the max address allowed for this AddressSpace.Address
getMinAddress()
Get the min address allowed for this AddressSpacejava.lang.String
getName()
Returns the name of this address space.Address
getOverlayAddress(Address addr)
Get an address that is relative to this address space.AddressSpace
getPhysicalSpace()
Returns the physical space associated with an address space.int
getPointerSize()
Returns the absolute size of a pointer into this space (in bytes).int
getSize()
Returns the number of bits that are used to form the address.Address
getTruncatedAddress(long offset, boolean isAddressableWordOffset)
Returns a new address in this space with the given offset.int
getType()
Returns the type of this address spaceint
getUnique()
Returns the unique index for this address spaceint
getUniqueSpaceID()
boolean
hasMappedRegisters()
Returns true if this space has registers that are mapped into it.boolean
hasSignedOffset()
Returns true if space uses signed offsetboolean
isConstantSpace()
Returns true if this space in the constant spaceboolean
isExternalSpace()
Returns true if this space in the EXTERNAL_SPACEboolean
isHashSpace()
Returns true if this space represents a location in the HASH space.boolean
isLoadedMemorySpace()
Returns true if this space represents represents a Loaded Memory region (e.g., processor RAM).boolean
isMemorySpace()
Returns true if this space represents a memory address.boolean
isNonLoadedMemorySpace()
Returns true if this space represents represents a Non-Loaded storage region for retaining non-loaded file data (e.g., OTHER)boolean
isOverlaySpace()
Returns true if this addressSpace is an OverlayAddressSpaceboolean
isRegisterSpace()
Returns true if this space represents a register locationboolean
isStackSpace()
Returns true if this space represents a stack locationboolean
isSuccessor(Address addr1, Address addr2)
Tests whether addr2 immediately follows addr1.boolean
isUniqueSpace()
Returns true if this space in the unique spaceboolean
isValidRange(long byteOffset, long length)
Check the specified address range for validity within this space.boolean
isVariableSpace()
Returns true if this space represents a variable locationlong
makeValidOffset(long offset)
Tests if the offset if valid.boolean
showSpaceName()
Returns true if the address should display its addressSpace name.Address
subtract(Address addr, long displacement)
Creates a new address (possibly in a new space) by subtracting the given displacement from the given address.long
subtract(Address addr1, Address addr2)
Calculates the displacement between addr1 and addr2 (addr1 - addr2)Address
subtractNoWrap(Address addr, long displacement)
Creates a new address by subtracting displacement from addr's offset.Address
subtractWrap(Address addr, long displacement)
Creates a new address by subtracting displacement from addr's offset.Address
subtractWrapSpace(Address addr, long displacement)
Creates a new address by subtracting the displacement from the given address.long
truncateAddressableWordOffset(long wordOffset)
Truncate the specified addressable unit/word offset within this space to produce a valid offset.long
truncateOffset(long byteOffset)
Truncate the specified byte offset within this space to produce a valid offset.
-
-
-
Field Detail
-
TYPE_CONSTANT
static final int TYPE_CONSTANT
- See Also:
- Constant Field Values
-
TYPE_RAM
static final int TYPE_RAM
- See Also:
- Constant Field Values
-
TYPE_CODE
static final int TYPE_CODE
- See Also:
- Constant Field Values
-
TYPE_UNIQUE
static final int TYPE_UNIQUE
- See Also:
- Constant Field Values
-
TYPE_REGISTER
static final int TYPE_REGISTER
- See Also:
- Constant Field Values
-
TYPE_STACK
static final int TYPE_STACK
- See Also:
- Constant Field Values
-
TYPE_JOIN
static final int TYPE_JOIN
- See Also:
- Constant Field Values
-
TYPE_OTHER
static final int TYPE_OTHER
- See Also:
- Constant Field Values
-
TYPE_SYMBOL
static final int TYPE_SYMBOL
- See Also:
- Constant Field Values
-
TYPE_EXTERNAL
static final int TYPE_EXTERNAL
- See Also:
- Constant Field Values
-
TYPE_VARIABLE
static final int TYPE_VARIABLE
- See Also:
- Constant Field Values
-
TYPE_DELETED
static final int TYPE_DELETED
- See Also:
- Constant Field Values
-
TYPE_UNKNOWN
static final int TYPE_UNKNOWN
- See Also:
- Constant Field Values
-
TYPE_NONE
static final int TYPE_NONE
- See Also:
- Constant Field Values
-
TYPE_IPTR_CONSTANT
static final int TYPE_IPTR_CONSTANT
- See Also:
TYPE_CONSTANT
, Constant Field Values
-
TYPE_IPTR_INTERNAL
static final int TYPE_IPTR_INTERNAL
- See Also:
TYPE_UNIQUE
, Constant Field Values
-
TYPE_IPTR_SPACEBASE
static final int TYPE_IPTR_SPACEBASE
- See Also:
TYPE_STACK
, Constant Field Values
-
ID_SIZE_MASK
static final int ID_SIZE_MASK
- See Also:
- Constant Field Values
-
ID_SIZE_SHIFT
static final int ID_SIZE_SHIFT
- See Also:
- Constant Field Values
-
ID_TYPE_MASK
static final int ID_TYPE_MASK
- See Also:
- Constant Field Values
-
ID_UNIQUE_SHIFT
static final int ID_UNIQUE_SHIFT
- See Also:
- Constant Field Values
-
OTHER_SPACE
static final AddressSpace OTHER_SPACE
TheOTHER_SPACE
is used to store data from the original program file that doesn't get loaded into the final memory image and for user-defined spaces.
-
EXTERNAL_SPACE
static final AddressSpace EXTERNAL_SPACE
TheEXTERNAL_SPACE
is used to contain all external locations (i.e., data and functions) defined within a given library namespace. All external locations within a program are given a unique offset within the EXTERNAL space.
-
VARIABLE_SPACE
static final AddressSpace VARIABLE_SPACE
TheVARIABLE_SPACE
is used to contain all variables and parameters defined within a given namespace (i.e., function). All variables within a program are given a unique offset within the VARIABLE space.
-
HASH_SPACE
static final AddressSpace HASH_SPACE
TheHASH_SPACE
provides a 60-bit space for encoding of unique hashcodes.
-
DEFAULT_REGISTER_SPACE
static final AddressSpace DEFAULT_REGISTER_SPACE
A language may only define a single REGISTER space. If one is not defined, this DEFAULT_REGISTER_SPACE definition will be used.
-
-
Method Detail
-
getName
java.lang.String getName()
Returns the name of this address space.
-
getBaseSpaceID
int getBaseSpaceID()
Get the ID for this space- Returns:
- space ID
-
getUniqueSpaceID
int getUniqueSpaceID()
-
getSize
int getSize()
Returns the number of bits that are used to form the address. Thus the maximum offset for this address space will be 2^size-1.
-
getAddressableUnitSize
int getAddressableUnitSize()
Returns the number of data bytes which correspond to each addressable location within this space (i.e., word-size in bytes). NOTE: When transforming a byte-offset to an addressable word offset the methodgetAddressableWordOffset(long)
should be used instead of simple division. When transforming an addressable word-offset to a byte-offset simple multiplication may be used. Neither of these transformations perform address space bounds checking.byteOffset = wordOffset * addressUnitSize wordOffset = getAddressableWordOffset(byteOffset)
-
getAddressableWordOffset
long getAddressableWordOffset(long byteOffset)
Get the addressable memory word offset which corresponds to the specified memory byte offset. This method handles some of the issues of unsigned math when stuck using Java's signed long primitives. No space bounds checking is performed.- Parameters:
byteOffset
- memory byte offset- Returns:
- addressable memory word offset
-
getPointerSize
int getPointerSize()
Returns the absolute size of a pointer into this space (in bytes).
-
getType
int getType()
Returns the type of this address space
-
getUnique
int getUnique()
Returns the unique index for this address space
-
getAddress
Address getAddress(java.lang.String addrString) throws AddressFormatException
Parses the String into an address.- Parameters:
addrString
- the string to parse as an address.- Returns:
- an address if the string parsed successfully or null if the AddressSpace specified in the addrString is not this space.
- Throws:
AddressFormatException
- if the string cannot be parsed or the parsed offset is larger than the size for this space.
-
getAddress
Address getAddress(java.lang.String addrString, boolean caseSensitive) throws AddressFormatException
Parses the String into an address.- Parameters:
addrString
- the string to parse as an address.caseSensitive
- specifies if addressSpace names must match case.- Returns:
- an address if the string parsed successfully or null if the AddressSpace specified in the addrString is not this space.
- Throws:
AddressFormatException
- if the string cannot be parsed or the parsed offset is larger than the size for this space.
-
getAddress
Address getAddress(long byteOffset) throws AddressOutOfBoundsException
Returns a new address in this space with the given byte offset. NOTE: This method is the same as invoking getAddress(long byteOffset, false).- Parameters:
byteOffset
- the byte offset for the new address.- Returns:
- address with given byte offset
- Throws:
AddressOutOfBoundsException
- if the offset is less than 0 or greater than the max offset allowed for this space.
-
getAddress
Address getAddress(long offset, boolean isAddressableWordOffset) throws AddressOutOfBoundsException
Returns a new address in this space with the given offset. NOTE: for those spaces with an addressable unit size other than 1, the address returned may not correspond to an addressable unit/word boundary if a byte-offset is specified.- Parameters:
offset
- the offset for the new address.isAddressableWordOffset
- if true the specified offset is an addressable unit/word offset, otherwise offset is a byte offset. SeegetAddressableUnitSize()
to understand the distinction (i.e., wordOffset = byteOffset * addressableUnitSize).- Returns:
- address with given offset
- Throws:
AddressOutOfBoundsException
- if the offset is less than 0 or greater than the max offset allowed for this space.
-
getTruncatedAddress
Address getTruncatedAddress(long offset, boolean isAddressableWordOffset)
Returns a new address in this space with the given offset. The specified offset will be truncated within the space and will not throw an exception. NOTE: for those spaces with an addressable unit size other than 1, the address returned may not correspond to a word boundary (addressable unit) if a byte-offset is specified.- Parameters:
offset
- the offset for the new address.isAddressableWordOffset
- if true the specified offset is an addressable unit/word offset, otherwise offset is a byte offset. SeegetAddressableUnitSize()
to understand the distinction (i.e., wordOffset = byteOffset * addressableUnitSize).- Returns:
- address with given byte offset truncated to the physical space size
-
getAddressInThisSpaceOnly
Address getAddressInThisSpaceOnly(long byteOffset) throws AddressOutOfBoundsException
Get a byte address from this address space. Don't allow overlay spaces to remap the address into a base space when the address is not contained in the bounds of the overlay region.- Parameters:
byteOffset
- the byte offset for the new address.- Returns:
- an address if the offset is valid.
- Throws:
AddressOutOfBoundsException
- if the offset is less than 0 or greater than the max offset allowed for this space.
-
truncateOffset
long truncateOffset(long byteOffset)
Truncate the specified byte offset within this space to produce a valid offset.- Parameters:
byteOffset
- any byte offset- Returns:
- truncated byte offset
-
truncateAddressableWordOffset
long truncateAddressableWordOffset(long wordOffset)
Truncate the specified addressable unit/word offset within this space to produce a valid offset.- Parameters:
wordOffset
- any addressable unit/word offset- Returns:
- truncated word offset
-
getOverlayAddress
Address getOverlayAddress(Address addr)
Get an address that is relative to this address space. If this is an overlay space and the address falls within this space, return an address based in this space.- Parameters:
addr
- address possibly falling within this overlay space.- Returns:
- an address relative to this overlay
-
subtract
long subtract(Address addr1, Address addr2)
Calculates the displacement between addr1 and addr2 (addr1 - addr2)- Parameters:
addr1
- the address to subtract from.addr2
- the address to subtract.- Returns:
- the difference. (
addr1.offset - addr2.offset
). - Throws:
java.lang.IllegalArgumentException
- if the two addresses are not in the same address space.
-
subtractWrap
Address subtractWrap(Address addr, long displacement)
Creates a new address by subtracting displacement from addr's offset.- Parameters:
addr
- the original address. The new address will wrap in a manner that depends on the address space. For a generic address space this will wrap at the extents of the address space. For a segmented address space it will wrap at the extents of the segment.displacement
- the displacement to subtract.- Returns:
- a new address created by subtracting the displacement from addr.offset.
-
subtractWrapSpace
Address subtractWrapSpace(Address addr, long displacement)
Creates a new address by subtracting the displacement from the given address. If the offset is greater than the max offset of the address space, the high order bits are masked off, making the address wrap. For non-segmented addresses this will be the same as subtractWrap(). For segmented addresses, the address will wrap when the 20 bit (oxfffff) offset is exceeded, as opposed to when the segment offset is exceeded.- Parameters:
addr
- the address to subtract the displacement from.displacement
- the displacement to subtract.- Returns:
- The new Address formed by subtracting the displacement from the specified address.
-
subtractNoWrap
Address subtractNoWrap(Address addr, long displacement) throws AddressOverflowException
Creates a new address by subtracting displacement from addr's offset. The new offset will NOT wrap!- Parameters:
addr
- the original addressdisplacement
- the displacement to subtract.- Returns:
- The new address created by subtracting displacement from addr.offset.
- Throws:
AddressOverflowException
- if the subtraction would cause a wrap,
-
subtract
Address subtract(Address addr, long displacement)
Creates a new address (possibly in a new space) by subtracting the given displacement from the given address.- Parameters:
addr
- original address being subtracted fromdisplacement
- amount to subtract- Returns:
- the new address
- Throws:
AddressOutOfBoundsException
- if the result does not correspond to any address.
-
addWrap
Address addWrap(Address addr, long displacement)
Creates a new address by adding displacement to the given address. The resulting address may wrap. The new address will wrap in a manner that depends on the address space. For a generic address space this will wrap at the extents of the address space. For a segmented address space it will wrap at the extents of the segment.- Parameters:
addr
- the original address.displacement
- the displacement to add.- Returns:
- the new address created by adding displacement to addr.offset.
-
addWrapSpace
Address addWrapSpace(Address addr, long displacement)
Creates a new address by adding the displacement to the given address. If the offset is greater than the max offset of the address space, the high order bits are masked off, making the address wrap. For non-segmented addresses this will be the same as addWrap(). For segmented addresses, the address will wrap when the 20 bit (oxfffff) offset is exceeded, as opposed to when the segment offset is exceeded.- Parameters:
addr
- the address to add the displacement to.displacement
- the displacement to add.- Returns:
- The new Address formed by adding the displacement to the specified addresst.
-
addNoWrap
Address addNoWrap(Address addr, long displacement) throws AddressOverflowException
Creates a new address by adding displacement to the given address. The new address will NOT wrap!- Parameters:
addr
- the original address.displacement
- the displacement to add.- Returns:
- The new address created by adding displacement to addr.offset.
- Throws:
AddressOverflowException
- if the addition would cause a wrap,
-
addNoWrap
Address addNoWrap(GenericAddress addr, java.math.BigInteger displacement) throws AddressOverflowException
Creates a new address by adding displacement to the given address. The new address will NOT wrap!- Parameters:
addr
- the original address.displacement
- the displacement to add.- Returns:
- The new address created by adding displacement to addr.offset.
- Throws:
AddressOverflowException
- if the addition would cause a wrap,
-
add
Address add(Address addr, long displacement) throws AddressOutOfBoundsException
Creates a new address (possibly in a new space) by adding the given displacement from the given address.- Parameters:
addr
- original address being subtracted fromdisplacement
- amount to subtract- Returns:
- the new address
- Throws:
AddressOutOfBoundsException
- if the result does not correspond to any address.
-
isValidRange
boolean isValidRange(long byteOffset, long length)
Check the specified address range for validity within this space. Segmented spaces will restrict a range to a single segment.- Parameters:
byteOffset
-length
-- Returns:
- true if range is valid for this space
-
isSuccessor
boolean isSuccessor(Address addr1, Address addr2)
Tests whether addr2 immediately follows addr1.- Parameters:
addr1
- the first address.addr2
- the second address.
-
getMaxAddress
Address getMaxAddress()
Get the max address allowed for this AddressSpace.
-
getMinAddress
Address getMinAddress()
Get the min address allowed for this AddressSpace
-
getPhysicalSpace
AddressSpace getPhysicalSpace()
Returns the physical space associated with an address space. There is always exactly one physical space associated with an address space (it may be its own physical space).- Returns:
- the associated physical space.
-
makeValidOffset
long makeValidOffset(long offset) throws AddressOutOfBoundsException
Tests if the offset if valid. If the space is signed, then it sign extends the offset.- Parameters:
offset
- the offset to test and/or sign extend- Returns:
- the valid positive offset or appropriate sign extended offset.
- Throws:
AddressOutOfBoundsException
- if offset is invalid
-
isMemorySpace
boolean isMemorySpace()
Returns true if this space represents a memory address. NOTE: It is important to make the distinction between Loaded and Non-Loaded memory addresses. Program importers may create memory blocks associated with Non-Loaded file content which are not associated with processor defined memory regions. While Loaded file content is placed into memory blocks which are associated with specific memory address spaces defined by the processor language specification.- See Also:
isLoadedMemorySpace()
,isNonLoadedMemorySpace()
-
isLoadedMemorySpace
boolean isLoadedMemorySpace()
Returns true if this space represents represents a Loaded Memory region (e.g., processor RAM).
-
isNonLoadedMemorySpace
boolean isNonLoadedMemorySpace()
Returns true if this space represents represents a Non-Loaded storage region for retaining non-loaded file data (e.g., OTHER)
-
isRegisterSpace
boolean isRegisterSpace()
Returns true if this space represents a register location
-
isVariableSpace
boolean isVariableSpace()
Returns true if this space represents a variable location
-
isStackSpace
boolean isStackSpace()
Returns true if this space represents a stack location
-
isHashSpace
boolean isHashSpace()
Returns true if this space represents a location in the HASH space.
-
isExternalSpace
boolean isExternalSpace()
Returns true if this space in the EXTERNAL_SPACE
-
isUniqueSpace
boolean isUniqueSpace()
Returns true if this space in the unique space
-
isConstantSpace
boolean isConstantSpace()
Returns true if this space in the constant space
-
hasMappedRegisters
boolean hasMappedRegisters()
Returns true if this space has registers that are mapped into it. This means that registers could actually have pointers to them.- Returns:
- true if this space has any registers mapped in it.
-
showSpaceName
boolean showSpaceName()
Returns true if the address should display its addressSpace name.
-
isOverlaySpace
boolean isOverlaySpace()
Returns true if this addressSpace is an OverlayAddressSpace
-
hasSignedOffset
boolean hasSignedOffset()
Returns true if space uses signed offset
-
-