macaw-base
Safe HaskellNone
LanguageHaskell2010

Data.Macaw.AbsDomain.AbsState

Contents

Synopsis

Documentation

data AbsBlockState (r :: Type -> Type) Source #

Processor/memory state after at beginning of a block.

Instances

Instances details
(ShowF r, MemWidth (RegAddrWidth r)) => Show (AbsBlockState r) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

(ShowF r, MemWidth (RegAddrWidth r)) => Pretty (AbsBlockState r) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Methods

pretty :: AbsBlockState r -> Doc ann

prettyList :: [AbsBlockState r] -> Doc ann

setAbsIP Source #

Arguments

:: forall (r :: Type -> Type). RegisterInfo r 
=> MemSegmentOff (RegAddrWidth r)

The address to set.

-> AbsBlockState r 
-> AbsBlockState r 

Update the block state to point to a specific IP address.

absRegState :: forall (r :: Type -> Type) f. Functor f => (RegState r (AbsValue (RegAddrWidth r)) -> f (RegState r (AbsValue (RegAddrWidth r)))) -> AbsBlockState r -> f (AbsBlockState r) Source #

absStackHasReturnAddr :: forall (r :: Type -> Type). AbsBlockState r -> Bool Source #

Returns true if return address is known to sit on stack.

data CallParams (r :: Type -> Type) Source #

Minimal information needed to update stack constraints after a call.

Constructors

CallParams 

Fields

  • postCallStackDelta :: Integer

    Amount stack should shift after call returns.

    On X86_64 this is 8 to reflect the pop of the return value.

  • stackGrowsDown :: !Bool

    Returns true if stack grows down

  • preserveReg :: forall (tp :: Type). r tp -> Bool

    Return true if a register value is preserved by a call.

    We assume stack pointer and instruction pointer are preserved, so the return value for these does not matter.

absEvalCall Source #

Arguments

:: RegisterInfo (ArchReg arch) 
=> CallParams (ArchReg arch)

Configuration

-> AbsProcessorState (ArchReg arch) ids

State before call

-> RegState (ArchReg arch) (Value arch ids) 
-> ArchSegmentOff arch

Address we are jumping to

-> AbsBlockState (ArchReg arch) 

This updates the registers after a call has been performed.

type AbsBlockStack (w :: Nat) = Map Int64 (StackEntry w) Source #

The AbsBlockStack describes offsets of the stack. Values that are not in the map may denote any values.

The stack grows down, so negative keys are in the stack frame.

fnStartAbsBlockState Source #

Arguments

:: forall (r :: Type -> Type). RegisterInfo r 
=> MemSegmentOff (RegAddrWidth r)

Start address of the block

-> MapF r (AbsValue (RegAddrWidth r))

Values to explicitly assign to registers (overriding default IP and SP values)

-> [(Int64, StackEntry (RegAddrWidth r))]

Stack entries to populate the abstract stack with (format: (offset, abstract stack entry))

-> AbsBlockState r 

This constructs the abstract state for the start of the function.

It populates the register state with abstract values from the provided map, along with defaults for the instruction pointer and stack pointer. The provided list provides abstract values to be placed on the stack.

NOTE: It does not place the return address as where that is stored is architecture-specific.

data StackEntry (w :: Nat) Source #

Constructors

StackEntry !(MemRepr tp) !(AbsValue w tp) 

Instances

Instances details
MemWidth w => Show (StackEntry w) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Eq (StackEntry w) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Methods

(==) :: StackEntry w -> StackEntry w -> Bool #

(/=) :: StackEntry w -> StackEntry w -> Bool #

type ArchAbsValue arch = AbsValue (ArchAddrWidth arch) Source #

The type of abstract values associated with a given architecture.

This is only a function of the address width.

data AbsValue (w :: Nat) (tp :: Type) Source #

The abstract information that is associated with values of a given type.

The first parameter is the width of pointers on the value. It is expected to be at most 64 bits.

Constructors

tp ~ BoolType => BoolConst !Bool

A Boolean constant

tp ~ BVType n => FinSet !(Set Integer)

Denotes that this value can take any one of the fixed set.

tp ~ BVType w => CodePointers !(Set (MemSegmentOff w)) !Bool

Represents that all values point to a bounded set of addresses in an executable segment or the constant zero. The set contains the possible addresses, and the Boolean indicates whether this set contains the address 0.

tp ~ BVType w => StackOffsetAbsVal !(MemAddr w) !Int64

Offset of stack from the beginning of the block at the given address.

To avoid conflating offsets that are relative to the begining of different blocks, we include the address of the block as the first argument.

tp ~ BVType w => SomeStackOffset !(MemAddr w)

An offset to the stack at some offset.

Note. We do nothing to guarantee that this is a legal stack offset.

To avoid conflating offsets that are relative to the begining of different blocks, we include the address of the block as the first argument.

tp ~ BVType n => StridedInterval !(StridedInterval n)

A strided interval

((n + 1) <= n', tp ~ BVType n') => SubValue !(NatRepr n) !(AbsValue w (BVType n))

A sub-value about which we know something about the low order bits.

e.g., when tp = BVType 16, and n = 8, and the abs value argument is av, we know that the lower 8-bits of the value are in av, but the upper bits may be arbitrary.

TopV

Any value

tp ~ BVType w => ReturnAddr

Denotes a return address in the body of a function.

Instances

Instances details
(MemWidth w, ShowF r) => PrettyRegValue r (AbsValue w) Source #

Print a list of Docs vertically separated.

Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Methods

ppValueEq :: forall (tp :: Type) ann. r tp -> AbsValue w tp -> Maybe (Doc ann) Source #

EqF (AbsValue w :: Type -> Type) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Methods

eqF :: forall (a :: Type). AbsValue w a -> AbsValue w a -> Bool

MemWidth w => Show (AbsValue w tp) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Methods

showsPrec :: Int -> AbsValue w tp -> ShowS #

show :: AbsValue w tp -> String #

showList :: [AbsValue w tp] -> ShowS #

Eq (AbsValue w tp) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Methods

(==) :: AbsValue w tp -> AbsValue w tp -> Bool #

(/=) :: AbsValue w tp -> AbsValue w tp -> Bool #

MemWidth w => AbsDomain (AbsValue w tp) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Methods

top :: AbsValue w tp Source #

leq :: AbsValue w tp -> AbsValue w tp -> Bool Source #

lub :: AbsValue w tp -> AbsValue w tp -> AbsValue w tp Source #

joinD :: AbsValue w tp -> AbsValue w tp -> Maybe (AbsValue w tp) Source #

MemWidth w => Pretty (AbsValue w tp) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Methods

pretty :: AbsValue w tp -> Doc ann

prettyList :: [AbsValue w tp] -> Doc ann

bvadd :: forall (w :: Natural) (u :: Nat). MemWidth w => NatRepr u -> AbsValue w (BVType u) -> AbsValue w (BVType u) -> AbsValue w (BVType u) Source #

emptyAbsValue :: forall (w :: Nat). AbsValue w (BVType w) Source #

Denotes that we do not know of any value that could be in set.

concreteCodeAddr :: forall (w :: Nat). MemSegmentOff w -> AbsValue w (BVType w) Source #

Construct a abstract value for a pointer to a code address.

joinAbsValue :: forall (w :: Natural) (tp :: Type). MemWidth w => AbsValue w tp -> AbsValue w tp -> Maybe (AbsValue w tp) Source #

Join the old and new states and return the updated state iff the result is larger than the old state. This also returns any addresses that are discarded during joining.

ppAbsValue :: forall (w :: Natural) (tp :: Type) ann. MemWidth w => AbsValue w tp -> Maybe (Doc ann) Source #

absTrue :: forall (w :: Nat). AbsValue w BoolType Source #

absFalse :: forall (w :: Nat). AbsValue w BoolType Source #

subValue :: forall (n :: Natural) (n' :: Natural) (w :: Nat). (n + 1) <= n' => NatRepr n -> AbsValue w (BVType n) -> AbsValue w (BVType n') Source #

Smart constructor for sub-values. This ensures that the subvalues are sorted on size.

concretize :: forall (w :: Natural) (tp :: Type). MemWidth w => AbsValue w tp -> Maybe (Set Integer) Source #

Returns a set of concrete integers that this value may be. This function will neither return the complete set or an known under-approximation.

asConcreteSingleton :: forall (w :: Natural) (tp :: Type). MemWidth w => AbsValue w tp -> Maybe Integer Source #

Returns single value, if the abstract value can only take on one value.

meet :: forall (w :: Natural) (tp :: Type). MemWidth w => AbsValue w tp -> AbsValue w tp -> AbsValue w tp Source #

absValueSize :: forall (w :: Nat) (tp :: Type). AbsValue w tp -> Maybe Integer Source #

codePointerSet :: forall (w :: Nat) (tp :: Type). AbsValue w tp -> Set (MemSegmentOff w) Source #

class Eq d => AbsDomain d where Source #

This represents an lattice order.

Elements are comparable for equality, have a partial order, a top element, and the ability to join to elements.

Minimal complete definition

top, (leq, lub | joinD)

Methods

top :: d Source #

The top element

leq :: d -> d -> Bool Source #

A partial ordering over d. forall x. x leq top

lub :: d -> d -> d Source #

Least upper bound (always defined, as we have top)

joinD :: d -> d -> Maybe d Source #

Join the old and new states and return the updated state iff the result is larger than the old state.

Instances

Instances details
MemWidth w => AbsDomain (AbsValue w tp) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Methods

top :: AbsValue w tp Source #

leq :: AbsValue w tp -> AbsValue w tp -> Bool Source #

lub :: AbsValue w tp -> AbsValue w tp -> AbsValue w tp Source #

joinD :: AbsValue w tp -> AbsValue w tp -> Maybe (AbsValue w tp) Source #

data AbsProcessorState (r :: Type -> Type) ids Source #

This stores the abstract state of the system which may be within a block.

Instances

Instances details
(ShowF r, MemWidth (RegAddrWidth r)) => Show (AbsProcessorState r ids) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

(ShowF r, MemWidth (RegAddrWidth r)) => Pretty (AbsProcessorState r ids) Source # 
Instance details

Defined in Data.Macaw.AbsDomain.AbsState

Methods

pretty :: AbsProcessorState r ids -> Doc ann

prettyList :: [AbsProcessorState r ids] -> Doc ann

absMem :: AbsProcessorState r ids -> Memory (RegAddrWidth r) Source #

Recognizer for code addresses.

curAbsStack :: forall (r :: Type -> Type) ids f. Functor f => (AbsBlockStack (RegAddrWidth r) -> f (AbsBlockStack (RegAddrWidth r))) -> AbsProcessorState r ids -> f (AbsProcessorState r ids) Source #

absInitialRegs :: forall (r :: Type -> Type) ids f. Functor f => (RegState r (AbsValue (RegAddrWidth r)) -> f (RegState r (AbsValue (RegAddrWidth r)))) -> AbsProcessorState r ids -> f (AbsProcessorState r ids) Source #

initAbsProcessorState Source #

Arguments

:: forall (r :: Type -> Type) ids. Memory (RegAddrWidth r)

Current state of memory in the processor.

Used for checking code segment status.

-> AbsBlockState r 
-> AbsProcessorState r ids 

Construct a abstate processor state for the start of block execution.

absAssignments :: forall (r :: Type -> Type) ids f. Functor f => (MapF (AssignId ids) (AbsValue (RegAddrWidth r)) -> f (MapF (AssignId ids) (AbsValue (RegAddrWidth r)))) -> AbsProcessorState r ids -> f (AbsProcessorState r ids) Source #

assignLens :: forall ids (tp :: Type) (w :: Nat). AssignId ids tp -> Lens' (MapF (AssignId ids) (AbsValue w)) (AbsValue w tp) Source #

A lens that allows one to lookup and update the value of an assignment in map from assignments to abstract values.

stridedInterval :: forall (n :: Nat) (w :: Nat). StridedInterval n -> AbsValue w (BVType n) Source #

Smart constructor for strided intervals which takes care of top

finalAbsBlockState Source #

Arguments

:: RegisterInfo (ArchReg a) 
=> AbsProcessorState (ArchReg a) ids 
-> RegState (ArchReg a) (Value a ids)

Final values for abstract processor state

-> AbsBlockState (ArchReg a) 

Return state for after value has run.

addMemWrite Source #

Arguments

:: forall arch ids (tp :: Type). (RegisterInfo (ArchReg arch), MemWidth (ArchAddrWidth arch), HasCallStack) 
=> AbsProcessorState (ArchReg arch) ids

Current processor state.

-> Value arch ids (BVType (ArchAddrWidth arch))

Address that we are writing to.

-> MemRepr tp

Information about how value should be represented in memory.

-> Value arch ids tp

Value to write to memory

-> AbsProcessorState (ArchReg arch) ids 

Update the processor state with a memory write.

addCondMemWrite Source #

Arguments

:: forall (r :: Type -> Type) arch ids (tp :: Type). (RegisterInfo r, MemWidth (RegAddrWidth r), HasCallStack, r ~ ArchReg arch) 
=> AbsProcessorState r ids

Current processor state.

-> Value arch ids BoolType

Condition that holds if write is performed.

-> Value arch ids (BVType (RegAddrWidth r))

Address that we are writing to.

-> MemRepr tp

Information about how value should be represented in memory.

-> Value arch ids tp

Value to write to memory

-> AbsProcessorState r ids 

Update the processor state with a potential memory write.

transferValue :: forall a ids (tp :: Type). (RegisterInfo (ArchReg a), HasCallStack) => AbsProcessorState (ArchReg a) ids -> Value a ids tp -> ArchAbsValue a tp Source #

Compute abstract value from value and current registers.

abstractULt :: forall (w :: Natural) (u :: Nat). MemWidth w => NatRepr u -> AbsValue w (BVType u) -> AbsValue w (BVType u) -> (AbsValue w (BVType u), AbsValue w (BVType u)) Source #

abstractULt x y refines x and y with the knowledge that x < y is unsigned. For example, given {2, 3} and {2, 3, 4}, we know (only) that {2, 3} and {3, 4} because we may pick any element from either set.

abstractULeq :: forall (w :: Natural) (u :: Nat). MemWidth w => NatRepr u -> AbsValue w (BVType u) -> AbsValue w (BVType u) -> (AbsValue w (BVType u), AbsValue w (BVType u)) Source #

abstractULeq u v returns a pair (u',v') where for each x in u, and y in v, such that x <= y, we have that x in u' and y in v'.

isBottom :: forall (w :: Nat) (tp :: Type). AbsValue w tp -> Bool Source #

Returns true if this value represents the empty set.

transferApp :: forall a ids (tp :: Type). (RegisterInfo (ArchReg a), HasCallStack) => AbsProcessorState (ArchReg a) ids -> App (Value a ids) tp -> ArchAbsValue a tp Source #

Utilities

hasMaximum :: forall (w :: Nat) (p :: Nat). NatRepr w -> AbsValue p (BVType w) -> Maybe Integer Source #