crucible-llvm-0.7.1: Support for translating and executing LLVM code in Crucible
Copyright(c) Galois Inc 2015-2016
LicenseBSD3
MaintainerRob Dockins <rdockins@galois.com>
Stabilityprovisional
Safe HaskellSafe-Inferred
LanguageHaskell2010

Lang.Crucible.LLVM.MemModel.Pointer

Description

 
Synopsis

Pointer bitwidth

type HasPtrWidth w = (1 <= w, 16 <= w, ?ptrWidth :: NatRepr w) Source #

This constraint captures the idea that there is a distinguished pointer width in scope which is appropriate according to the C notion of pointer, and object size. In particular, it must be at least 16-bits wide (as required for the size_t type).

pattern PtrWidth :: HasPtrWidth w => w ~ w' => NatRepr w' Source #

withPtrWidth :: forall w a. 16 <= w => NatRepr w -> (HasPtrWidth w => a) -> a Source #

Crucible pointer representation

type LLVMPointerType w = IntrinsicType "LLVM_pointer" (EmptyCtx ::> BVType w) Source #

Crucible type of pointers/bitvector values of width w.

type LLVMPtr sym w = RegValue sym (LLVMPointerType w) Source #

Symbolic LLVM pointer or bitvector values of width w.

data SomePointer sym Source #

A pointer with an existentially-quantified width

Constructors

forall w.1 <= w => SomePointer !(LLVMPtr sym w) 

pattern LLVMPointerRepr :: () => (1 <= w, ty ~ LLVMPointerType w) => NatRepr w -> TypeRepr ty Source #

This pattern synonym makes it easy to build and destruct runtime representatives of LLVMPointerType w.

pattern PtrRepr :: HasPtrWidth wptr => ty ~ LLVMPointerType wptr => TypeRepr ty Source #

This pattern creates/matches against the TypeRepr for LLVM pointer values that are of the distinguished pointer width.

pattern SizeT :: HasPtrWidth wptr => ty ~ BVType wptr => TypeRepr ty Source #

This pattern creates/matches against the TypeRepr for raw bitvector values that are of the distinguished pointer width.

pattern LLVMPointer :: SymNat sym -> SymBV sym w -> LLVMPointer sym w Source #

A pointer is a base point offset.

ptrWidth :: IsExprBuilder sym => LLVMPtr sym w -> NatRepr w Source #

Compute the width of a pointer value.

llvmPointerView :: LLVMPtr sym w -> (SymNat sym, SymBV sym w) Source #

Alternative to the LLVMPointer pattern synonym, this function can be used as a view constructor instead to silence incomplete pattern warnings.

llvmPointerBlock :: LLVMPtr sym w -> SymNat sym Source #

Retrieve this pointer's block number.

Use of this function is discouraged, as it is abstraction-breaking.

llvmPointerOffset :: LLVMPtr sym w -> SymBV sym w Source #

Retrieve this pointer's offset.

Use of this function is discouraged, as it is abstraction-breaking.

muxLLVMPtr :: 1 <= w => IsSymInterface sym => sym -> Pred sym -> LLVMPtr sym w -> LLVMPtr sym w -> IO (LLVMPtr sym w) Source #

Mux function specialized to LLVM pointer values.

llvmPointer_bv :: IsSymInterface sym => sym -> SymBV sym w -> IO (LLVMPtr sym w) Source #

Convert a raw bitvector value into an LLVM pointer value.

mkNullPointer :: (1 <= w, IsSymInterface sym) => sym -> NatRepr w -> IO (LLVMPtr sym w) Source #

Produce the distinguished null pointer value.

Concretization

data ConcLLVMPtr w Source #

A concrete LLVM pointer

Constructors

ConcLLVMPtr 

Fields

concLLVMPtr Source #

Arguments

:: IsExprBuilder sym 
=> (forall tp. SymExpr sym tp -> IO (GroundValue tp))

Model from SMT solver

-> RegValue sym (LLVMPointerType w) 
-> IO (ConcLLVMPtr w) 

Concretize a symbolic pointer to a particular ConcLLVMPtr that is feasible in a model.

concLLVMPtrToSymbolic :: (IsExprBuilder sym, 1 <= w) => sym -> ConcLLVMPtr w -> IO (RegValue sym (LLVMPointerType w)) Source #

Create a symbolic pointer from a concrete one

concBV :: (IsExprBuilder sym, 1 <= w) => sym -> (forall tp. SymExpr sym tp -> IO (GroundValue tp)) -> SymBV sym w -> IO (SymBV sym w) Source #

concPtr :: (IsExprBuilder sym, 1 <= w) => sym -> (forall tp. SymExpr sym tp -> IO (GroundValue tp)) -> RegValue sym (LLVMPointerType w) -> IO (RegValue sym (LLVMPointerType w)) Source #

concPtr' :: (IsExprBuilder sym, 1 <= w) => sym -> (forall tp. SymExpr sym tp -> IO (GroundValue tp)) -> RegValue' sym (LLVMPointerType w) -> IO (RegValue' sym (LLVMPointerType w)) Source #

concPtrFn :: IntrinsicConcFn t "LLVM_pointer" Source #

An IntrinsicConcFn for LLVM pointers

concPtrFnMap :: MapF SymbolRepr (IntrinsicConcFn t) Source #

A singleton map suitable for use in a ConcCtx if LLVM pointers are the only intrinsic type in use

concToSymPtrFn :: IntrinsicConcToSymFn "LLVM_pointer" Source #

A IntrinsicConcToSymFn for LLVM pointers

concToSymPtrFnMap :: MapF SymbolRepr IntrinsicConcToSymFn Source #

A singleton map suitable for use in concToSym if LLVM pointers are the only intrinsic type in use

Operations on valid pointers

constOffset :: (1 <= w, IsExprBuilder sym) => sym -> NatRepr w -> Addr -> IO (SymBV sym w) Source #

Generate a concrete offset value from an Addr value.

ptrSameAlloc :: (1 <= w, IsSymInterface sym) => sym -> LLVMPtr sym w -> LLVMPtr sym w -> IO (Pred sym) Source #

Test whether two pointers point to the same allocation (i.e., have the same block number).

Using this function is preferred to pattern matching on LLVMPointer or llvmPointerBlock, because it operates at a higher level of abstraction (i.e., if the representation of pointers were changed, it could continue to work as intended).

ptrEq :: (1 <= w, IsSymInterface sym) => sym -> NatRepr w -> LLVMPtr sym w -> LLVMPtr sym w -> IO (Pred sym) Source #

Test whether two pointers are equal.

ptrLe :: (1 <= w, IsSymInterface sym, ?memOpts :: MemOptions) => sym -> NatRepr w -> LLVMPtr sym w -> LLVMPtr sym w -> IO (Pred sym, Pred sym) Source #

Test whether one pointer is less than or equal to the other.

The returned predicates assert (in this order): * the first pointer is less than or equal to the second * the comparison is valid: the pointers are to the same allocation

ptrAdd :: (1 <= w, IsExprBuilder sym) => sym -> NatRepr w -> LLVMPtr sym w -> SymBV sym w -> IO (LLVMPtr sym w) Source #

Add an offset to a pointer.

ptrDiff :: (1 <= w, IsSymInterface sym) => sym -> NatRepr w -> LLVMPtr sym w -> LLVMPtr sym w -> IO (SymBV sym w, Pred sym) Source #

Compute the difference between two pointers. The returned predicate asserts that the pointers point into the same allocation block.

ptrSub :: (1 <= w, IsSymInterface sym) => sym -> NatRepr w -> LLVMPtr sym w -> SymBV sym w -> IO (LLVMPtr sym w) Source #

Subtract an offset from a pointer.

ptrIsBv :: IsSymInterface sym => sym -> LLVMPtr sym w -> IO (Pred sym) Source #

Test if a pointer value is a bitvector (i.e., has a block number of 0)

Using this function is preferred to pattern matching on LLVMPointer or llvmPointerBlock, because it operates at a higher level of abstraction (i.e., if the representation of pointers were changed, it could continue to work as intended).

ptrIsNull :: (1 <= w, IsSymInterface sym) => sym -> NatRepr w -> LLVMPtr sym w -> IO (Pred sym) Source #

Test if a pointer value is the null pointer.

isGlobalPointer Source #

Arguments

:: forall sym w. IsSymInterface sym 
=> Map Natural Symbol

c.f. memImplSymbolMap

-> LLVMPtr sym w 
-> Maybe Symbol 

Look up a pointer in the memImplGlobalMap to see if it's a global.

This is best-effort and will only work if the pointer is fully concrete and matches the address of the global on the nose. It is used in SAWscript for friendly error messages.

isGlobalPointer' Source #

Arguments

:: forall sym w. IsSymInterface sym 
=> Map Natural Symbol

c.f. memImplSymbolMap

-> LLVMPtr sym w 
-> Maybe Symbol 

For when you don't know 1 <= w

Pretty printing

ppPtr :: IsExpr (SymExpr sym) => LLVMPtr sym wptr -> Doc ann Source #

Annotation

annotatePointerBlock :: forall sym w. IsSymInterface sym => sym -> LLVMPtr sym w -> IO (SymAnnotation sym BaseIntegerType, LLVMPointer sym w) Source #

annotatePointerOffset :: forall sym w. IsSymInterface sym => sym -> LLVMPtr sym w -> IO (SymAnnotation sym (BaseBVType w), LLVMPointer sym w) Source #

Orphan instances

IsSymInterface sym => IntrinsicClass sym "LLVM_pointer" Source # 
Instance details

Associated Types

type Intrinsic sym "LLVM_pointer" ctx #

Methods

pushBranchIntrinsic :: forall (ctx :: Ctx CrucibleType). sym -> IntrinsicTypes sym -> SymbolRepr "LLVM_pointer" -> CtxRepr ctx -> Intrinsic sym "LLVM_pointer" ctx -> IO (Intrinsic sym "LLVM_pointer" ctx) #

abortBranchIntrinsic :: forall (ctx :: Ctx CrucibleType). sym -> IntrinsicTypes sym -> SymbolRepr "LLVM_pointer" -> CtxRepr ctx -> Intrinsic sym "LLVM_pointer" ctx -> IO (Intrinsic sym "LLVM_pointer" ctx) #

muxIntrinsic :: forall (ctx :: Ctx CrucibleType). sym -> IntrinsicTypes sym -> SymbolRepr "LLVM_pointer" -> CtxRepr ctx -> Pred sym -> Intrinsic sym "LLVM_pointer" ctx -> Intrinsic sym "LLVM_pointer" ctx -> IO (Intrinsic sym "LLVM_pointer" ctx) #