1 /** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_VERIFICATION_VERIFICATION_CONTEXT_HPP_ 17 #define PANDA_VERIFICATION_VERIFICATION_CONTEXT_HPP_ 18 19 #include "libpandabase/macros.h" 20 #include "runtime/include/method.h" 21 22 #include "verification/absint/exec_context.h" 23 #include "verification/absint/panda_types.h" 24 #include "verification/cflow/cflow_info.h" 25 #include "verification/jobs/job.h" 26 #include "verification/jobs/cache.h" 27 #include "verification/type/type_systems.h" 28 #include "verification/util/lazy.h" 29 #include "verification/util/callable.h" 30 #include "verification/value/variables.h" 31 32 #include <functional> 33 34 namespace panda::verifier { 35 using CallIntoRuntimeHandler = callable<void(callable<void()>)>; 36 37 class VerificationContext { 38 public: 39 using Var = Variables::Var; 40 VerificationContext(PandaTypes & panda_types,const Job & job,Type method_class_type)41 VerificationContext(PandaTypes &panda_types, const Job &job, Type method_class_type) 42 : Types_ {panda_types}, 43 Job_ {job}, 44 MethodClass_ {method_class_type}, 45 ExecCtx_ {CflowInfo().InstMap().AddrStart<const uint8_t *>(), 46 CflowInfo().InstMap().AddrEnd<const uint8_t *>()} 47 { 48 // set checkpoints for reg_context storage 49 // start of method is checkpoint too 50 ExecCtx().SetCheckPoints( 51 ConstLazyFetch(std::array<const uint8_t *, 1> {CflowInfo().InstMap().AddrStart<const uint8_t *>()})); 52 ExecCtx().SetCheckPoints(CflowInfo().JmpsMap().AllTargetsLazy<const uint8_t *>()); 53 // set checkpoints for entries of exception handlers 54 ExecCtx().SetCheckPoints(Transform(ConstLazyFetch(CflowInfo().ExcHandlers()), 55 [](const auto &exc_handler) { return exc_handler.Start; })); 56 ExecCtx().SetCheckPoints(Transform(ConstLazyFetch(CflowInfo().ExcHandlers()), 57 [](const auto &exc_handler) { return exc_handler.TryBlock.Start; })); 58 ExecCtx().SetCheckPoints(Transform(ConstLazyFetch(CflowInfo().ExcHandlers()), 59 [](const auto &exc_handler) { return exc_handler.TryBlock.End; })); 60 } 61 62 ~VerificationContext() = default; 63 GetJob()64 const Job &GetJob() const 65 { 66 return Job_; 67 } 68 CflowInfo()69 const CflowMethodInfo &CflowInfo() const 70 { 71 return Job_.JobMethodCflow(); 72 } 73 GetCachedMethod()74 const LibCache::CachedMethod &GetCachedMethod() const 75 { 76 return Job_.JobCachedMethod(); 77 } 78 GetMethodClass()79 Type GetMethodClass() const 80 { 81 return MethodClass_; 82 } 83 ExecCtx()84 ExecContext &ExecCtx() 85 { 86 return ExecCtx_; 87 } 88 ExecCtx()89 const ExecContext &ExecCtx() const 90 { 91 return ExecCtx_; 92 } 93 Types()94 PandaTypes &Types() 95 { 96 return Types_; 97 } 98 NewVar()99 Var NewVar() 100 { 101 return Types_.NewVar(); 102 } 103 ReturnType()104 const Type &ReturnType() const 105 { 106 return ReturnType_; 107 } 108 SetReturnType(const Type & type)109 void SetReturnType(const Type &type) 110 { 111 ReturnType_ = type; 112 } 113 114 private: 115 PandaTypes &Types_; 116 const Job &Job_; 117 Type ReturnType_; 118 Type MethodClass_; 119 ExecContext ExecCtx_; 120 }; 121 } // namespace panda::verifier 122 123 #endif // !PANDA_VERIFICATION_VERIFICATION_CONTEXT_HPP_ 124