Fix macaw-x86-symbolic and update crucible.

This commit is contained in:
Joe Hendrix 2019-02-27 01:43:53 -08:00
parent e8d2efcaae
commit 89ffdf088a
No known key found for this signature in database
GPG Key ID: 8DFA5FF784098C4F
5 changed files with 31 additions and 33 deletions

2
deps/crucible vendored

@ -1 +1 @@
Subproject commit da77394455d06241c4c01807745922ebb97fe40c Subproject commit d0c8f1e1a712e779f9995363689b352ce10b17dd

View File

@ -30,6 +30,9 @@ module Data.Macaw.Symbolic.Backend (
, MO.doGetGlobal , MO.doGetGlobal
, MO.doLookupFunctionHandle , MO.doLookupFunctionHandle
, MO.doPtrToBits , MO.doPtrToBits
, MO.getMem
, MO.setMem
, MO.tryGlobPtr
-- ** Register Mapping -- ** Register Mapping
, PS.RegIndexMap , PS.RegIndexMap
, PS.mkRegIndexMap , PS.mkRegIndexMap

View File

@ -595,7 +595,7 @@ memReprToStorageType reqEnd memRep =
case memRep of case memRep of
M.BVMemRepr bytes endian -> do M.BVMemRepr bytes endian -> do
checkEndian reqEnd endian checkEndian reqEnd endian
pure $ Mem.bitvectorType (Bytes (natValue bytes)) pure $ Mem.bitvectorType (Bytes (intValue bytes))
M.FloatMemRepr floatRep endian -> do M.FloatMemRepr floatRep endian -> do
checkEndian reqEnd endian checkEndian reqEnd endian
case floatRep of case floatRep of
@ -605,7 +605,7 @@ memReprToStorageType reqEnd memRep =
_ -> Left $ "Do not support memory accesses to " ++ show floatRep ++ " values." _ -> Left $ "Do not support memory accesses to " ++ show floatRep ++ " values."
M.PackedVecMemRepr n eltType -> do M.PackedVecMemRepr n eltType -> do
eltStorageType <- memReprToStorageType reqEnd eltType eltStorageType <- memReprToStorageType reqEnd eltType
pure $ Mem.arrayType (Bytes (natValue n)) eltStorageType pure $ Mem.arrayType (Bytes (intValue n)) eltStorageType
-- | Convert a Crucible register value to a LLVM memory mode lvalue -- | Convert a Crucible register value to a LLVM memory mode lvalue
resolveMemVal :: MemRepr ty -> -- ^ What/how we are writing resolveMemVal :: MemRepr ty -> -- ^ What/how we are writing
@ -623,7 +623,7 @@ resolveMemVal (M.FloatMemRepr floatRep _endian) _ val =
_ -> error $ "Do not support memory accesses to " ++ show floatRep ++ " values." _ -> error $ "Do not support memory accesses to " ++ show floatRep ++ " values."
resolveMemVal (M.PackedVecMemRepr n eltType) stp val = resolveMemVal (M.PackedVecMemRepr n eltType) stp val =
case Mem.storageTypeF stp of case Mem.storageTypeF stp of
Mem.Array cnt eltStp | cnt == fromIntegral (natValue n), fromIntegral (V.length val) == natValue n -> Mem.Array cnt eltStp | cnt == Bytes (intValue n), fromIntegral (V.length val) == natValue n ->
Mem.LLVMValArray eltStp (resolveMemVal eltType eltStp <$> val) Mem.LLVMValArray eltStp (resolveMemVal eltType eltStp <$> val)
_ -> error $ "Unexpected storage type for packed vec." _ -> error $ "Unexpected storage type for packed vec."

View File

@ -70,13 +70,13 @@ import Lang.Crucible.LLVM.MemModel
) )
import qualified Data.Macaw.CFG.Core as M import qualified Data.Macaw.CFG.Core as M
import qualified Data.Macaw.CFG.Core as MC
import qualified Data.Macaw.Memory as M import qualified Data.Macaw.Memory as M
import qualified Data.Macaw.Types as M
import Data.Macaw.Symbolic import Data.Macaw.Symbolic
import Data.Macaw.Symbolic.Backend import Data.Macaw.Symbolic.Backend
import qualified Data.Macaw.Types as M
import qualified Data.Macaw.X86 as M import qualified Data.Macaw.X86 as M
import qualified Data.Macaw.X86.ArchTypes as M import qualified Data.Macaw.X86.ArchTypes as M
import qualified Data.Macaw.CFG.Core as MC
import Prelude import Prelude
@ -134,35 +134,29 @@ stmtSemantics _sym_funs global_var_mem globals stmt state = do
let mem_repr = M.repValSizeMemRepr val_size let mem_repr = M.repValSizeMemRepr val_size
curr_dest_ptr <- ptrAdd sym knownNat (regValue dest) offset curr_dest_ptr <- ptrAdd sym knownNat (regValue dest) offset
curr_src_ptr <- ptrAdd sym knownNat (regValue src) offset curr_src_ptr <- ptrAdd sym knownNat (regValue src) offset
(val, after_read_state) <- doReadMem -- Get simulator and memory
acc_state mem <- getMem acc_state global_var_mem
global_var_mem -- Resolve source pointer
globals resolvedSrcPtr <- tryGlobPtr sym mem globals curr_src_ptr
M.Addr64 -- Read resolvePtr
mem_repr val <- doReadMem sym mem M.Addr64 mem_repr resolvedSrcPtr
(RegEntry knownRepr curr_src_ptr) -- Resolve destination pointer
(_, after_write_state) <- doWriteMem resolvedDestPtr <- tryGlobPtr sym mem globals curr_dest_ptr
after_read_state afterWriteMem <- doWriteMem sym mem M.Addr64 mem_repr resolvedDestPtr val
global_var_mem -- Update the final state
globals pure $! setMem acc_state global_var_mem afterWriteMem
M.Addr64
mem_repr
(RegEntry knownRepr curr_dest_ptr)
(RegEntry (typeToCrucible $ M.typeRepr mem_repr) val)
return after_write_state
M.RepStos val_size (AtomWrapper dest) (AtomWrapper val) count dir -> M.RepStos val_size (AtomWrapper dest) (AtomWrapper val) count dir ->
withConcreteCountAndDir state val_size count dir $ \acc_state offset -> do withConcreteCountAndDir state val_size count dir $ \acc_state offset -> do
let mem_repr = M.repValSizeMemRepr val_size let mem_repr = M.repValSizeMemRepr val_size
curr_dest_ptr <- ptrAdd sym knownNat (regValue dest) offset -- Get simulator and memory
(_, after_write_state) <- doWriteMem mem <- getMem acc_state global_var_mem
acc_state -- Resolve address to write to.
global_var_mem curr_dest_ptr <- ptrAdd sym knownNat (regValue dest) offset
globals resolvedDestPtr <- tryGlobPtr sym mem globals curr_dest_ptr
M.Addr64 -- Perform write
mem_repr afterWriteMem <- doWriteMem sym mem M.Addr64 mem_repr resolvedDestPtr (regValue val)
(RegEntry knownRepr curr_dest_ptr) -- Update the final state
val pure $! setMem acc_state global_var_mem afterWriteMem
return after_write_state
_ -> error $ _ -> error $
"Symbolic execution semantics for x86 statement are not implemented yet: " "Symbolic execution semantics for x86 statement are not implemented yet: "
<> (show $ MC.ppArchStmt (liftAtomIn (pretty . regType)) stmt) <> (show $ MC.ppArchStmt (liftAtomIn (pretty . regType)) stmt)

View File

@ -216,6 +216,7 @@ freshValue sym str w ty =
WI.freshConstant sym nm C.BaseBoolRepr WI.freshConstant sym nm C.BaseBoolRepr
M.TupleTypeRepr {} -> crash [ "Unexpected symbolic tuple:", show str ] M.TupleTypeRepr {} -> crash [ "Unexpected symbolic tuple:", show str ]
M.VecTypeRepr {} -> crash [ "Unexpected symbolic vector:", show str ]
where where
symName x = symName x =