Exemplo n.º 1
0
        private static Dictionary <Tuple <string, Cmd, AssertCmd>, bool> DecideAddressRegions(Program prog, Implementation impl, bool store)
        {
            Dictionary <Tuple <string, Cmd, AssertCmd>, bool> addressRegionDB;
            bool old_option = Options.splitMemoryModel;

            Options.splitMemoryModel = false;

            (new SpecialInstructionLifter()).Visit(prog);
            (new ModularVerificationSetup()).Visit(prog);
            (new EnvironmentSetup()).Visit(prog);
            (new IndiscriminateAssumeSlicer()).Visit(prog);

            VCSplitter.LaunchVCSplitter(impl);
            if (store)
            {
                (new StoreAddressDecider()).Visit(prog);
                addressRegionDB = VCSplitter.Instance.VerifyInstrumentedProcedures(prog);
            }
            else
            {
                (new LoadAddressDecider()).Visit(prog);
                addressRegionDB = VCSplitter.Instance.VerifyInstrumentedProcedures(prog);
            }

            Options.splitMemoryModel = old_option;

            return(addressRegionDB);
        }
Exemplo n.º 2
0
        private static void InstrumentEnclave(
            Program prog,
            Implementation impl,
            Dictionary <Tuple <string, Cmd, AssertCmd>, bool> storeAddressRegionDB,
            Dictionary <Tuple <string, Cmd, AssertCmd>, bool> loadAddressRegionDB)
        {
            Console.WriteLine("CfiVerifier found " + impl.Blocks.Count + " basic blocks");
            (new SpecialInstructionLifter()).Visit(prog);
            // (new ConstantExpressionSimplifier()).Visit(prog);
            Utils.PrintProg(prog);
            if (Options.splitMemoryModel)
            {
                (new SplitMemoryModeler(storeAddressRegionDB, loadAddressRegionDB, false)).Visit(prog);
                (new HavocingLoader()).Visit(prog);
            }
            Utils.PrintProg(prog);
            (new ModularVerificationSetup()).Visit(prog);
            Utils.PrintProg(prog);
            //(new Utils.DeadCodeEliminator()).Visit(prog); //mostly to remove assingments to useless CPU flags

            //if (Utils.verbosityLevel(2)) { Console.WriteLine("InstrumentEnclave: replacing call instructions with CallCmd"); }
            // (new Utils.HavocingAdversary()).Visit(impl); //FIXME: this should be enabled.
            LoopDetector loopDetector = new LoopDetector();

            loopDetector.Visit(impl); //necessary before querying the stack size estimate
            List <Block> blocksInNaturalLoops = loopDetector.getBlocksInNaturalLoops();

            if (blocksInNaturalLoops.Count > 0)
            {
                Console.WriteLine("CfiVerifier found one or more loops");
                Console.WriteLine("Blocks in loops: {0}", blocksInNaturalLoops.MapConcat(x => x.Label, ","));
            }

            List <Block> loopHeaders = loopDetector.getLoopHeaders();

            if (loopHeaders.Count > 0)
            {
                Console.WriteLine("LOOP HEADERS: {0}", loopHeaders.MapConcat(x => x.Label, ","));
                Tuple <String, List <String> > result = Utils.HandleLoops(prog, impl);
                String        memCheckpointLabel      = result.Item1;
                List <String> loopHeaderLabels        = result.Item2;
                Utils.InstrumentLoopInvariant(prog, impl, memCheckpointLabel, loopHeaderLabels);
            }

            VCSplitter.LaunchVCSplitter(impl);

            (new EnvironmentSetup()).Visit(prog); //TODO move this earlier, maybe before DeadCodeEliminator
            (new ProofObligations()).Visit(prog);
            Console.WriteLine("\nInstrumented Program with CFI assertions and generated output file {0}", Options.instrumentedFile);
            Utils.PrintProg(prog);
            VCSplitter.Instance.PrintInstrumentedProcedures(prog);
            VCSplitter.Instance.PrintAssertionTypes();
        }
Exemplo n.º 3
0
 public static void LaunchVCSplitter(Implementation impl)
 {
     instance      = new VCSplitter();
     assertions    = new List <Tuple <string, Cmd, AssertCmd, SlashVerifyCmdType> >();
     original_impl = new Duplicator().VisitImplementation(impl);
 }