Skip to content

Commit 993d29b

Browse files
Handle globals in x86 postconditons. (#795)
1 parent 2bd86b3 commit 993d29b

File tree

1 file changed

+18
-7
lines changed
  • src/SAWScript/Crucible/LLVM

1 file changed

+18
-7
lines changed

src/SAWScript/Crucible/LLVM/X86.hs

+18-7
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,28 @@ assumePointsTo ::
544544
assumePointsTo env tyenv nameEnv (LLVMPointsTo _ cond tptr tptval) = do
545545
when (isJust cond) $ throwX86 "unsupported x86_64 command: crucible_conditional_points_to"
546546
tval <- checkConcreteSizePointsToValue tptval
547+
sym <- use x86Sym
548+
cc <- use x86CrucibleContext
549+
mem <- use x86Mem
550+
ptr <- resolvePtrSetupValue env tyenv tptr
551+
val <- liftIO $ resolveSetupVal cc mem env tyenv Map.empty tval
552+
storTy <- liftIO $ C.LLVM.toStorableType =<< typeOfSetupValue cc tyenv nameEnv tval
553+
mem' <- liftIO $ C.LLVM.storeConstRaw sym mem ptr storTy C.LLVM.noAlignment val
554+
x86Mem .= mem'
555+
556+
resolvePtrSetupValue ::
557+
X86Constraints =>
558+
Map MS.AllocIndex Ptr ->
559+
Map MS.AllocIndex LLVMAllocSpec ->
560+
MS.SetupValue LLVM ->
561+
X86Sim Ptr
562+
resolvePtrSetupValue env tyenv tptr = do
547563
sym <- use x86Sym
548564
cc <- use x86CrucibleContext
549565
mem <- use x86Mem
550566
elf <- use x86Elf
551567
base <- use x86GlobalBase
552-
ptr <- case tptr of
568+
case tptr of
553569
MS.SetupGlobal () nm -> case
554570
(Vector.!? 0)
555571
. Vector.filter (\e -> Elf.steName e == encodeUtf8 (Text.pack nm))
@@ -562,10 +578,6 @@ assumePointsTo env tyenv nameEnv (LLVMPointsTo _ cond tptr tptval) = do
562578
liftIO $ C.LLVM.doPtrAddOffset sym mem base =<< W4.bvLit sym knownNat (BV.mkBV knownNat addr)
563579
_ -> liftIO $ C.LLVM.unpackMemValue sym (C.LLVM.LLVMPointerRepr $ knownNat @64)
564580
=<< resolveSetupVal cc mem env tyenv Map.empty tptr
565-
val <- liftIO $ resolveSetupVal cc mem env tyenv Map.empty tval
566-
storTy <- liftIO $ C.LLVM.toStorableType =<< typeOfSetupValue cc tyenv nameEnv tval
567-
mem' <- liftIO $ C.LLVM.storeConstRaw sym mem ptr storTy C.LLVM.noAlignment val
568-
x86Mem .= mem'
569581

570582
checkConcreteSizePointsToValue :: LLVMPointsToValue LLVMArch -> X86Sim (MS.SetupValue LLVM)
571583
checkConcreteSizePointsToValue = \case
@@ -700,8 +712,7 @@ assertPointsTo env tyenv nameEnv (LLVMPointsTo _ cond tptr tptexpected) = do
700712
cc <- use x86CrucibleContext
701713
ms <- use x86MethodSpec
702714
mem <- use x86Mem
703-
ptr <- liftIO $ C.LLVM.unpackMemValue sym (C.LLVM.LLVMPointerRepr $ knownNat @64)
704-
=<< resolveSetupVal cc mem env tyenv Map.empty tptr
715+
ptr <- resolvePtrSetupValue env tyenv tptr
705716
memTy <- liftIO $ typeOfSetupValue cc tyenv nameEnv texpected
706717
storTy <- liftIO $ C.LLVM.toStorableType memTy
707718
actual <- liftIO $ C.LLVM.assertSafe sym =<< C.LLVM.loadRaw sym mem ptr storTy C.LLVM.noAlignment

0 commit comments

Comments
 (0)