• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CFLOW_INFO_HPP_
17 #define PANDA_VERIFICATION_CFLOW_INFO_HPP_
18 
19 #include "instructions_map.h"
20 #include "jumps_map.h"
21 #include "exception_source_map.h"
22 
23 #include "runtime/include/mem/panda_containers.h"
24 
25 #include "runtime/include/mem/panda_smart_pointers.h"
26 
27 #include "verification/jobs/cache.h"
28 
29 #include <cstdint>
30 #include <optional>
31 
32 namespace panda::verifier {
33 enum class InstructionType { NORMAL, JUMP, COND_JUMP, RETURN, THROW };
34 
35 struct CflowBlockInfo {
36     const uint8_t *Start;
37     const uint8_t *End;
38     JumpsMap JmpsMap;
39     InstructionType LastInstType;
40 };
41 
42 struct CflowExcHandlerInfo {
43     CflowBlockInfo TryBlock;
44     const uint8_t *Start;
45     size_t Size;  // Note. In Java the catch block size is not defined
46     OptionalConstRef<LibCache::CachedClass> CachedException;
47 };
48 
49 class CflowMethodInfo {
50 public:
51     CflowMethodInfo() = delete;
CflowMethodInfo(const uint8_t * addr_start,size_t code_size)52     CflowMethodInfo(const uint8_t *addr_start, size_t code_size)
53         : InstMap_ {addr_start, code_size}, JmpsMap_ {addr_start, code_size}, ExcSrcMap_ {addr_start, code_size}
54     {
55     }
56     ~CflowMethodInfo() = default;
InstMap()57     const InstructionsMap &InstMap() const
58     {
59         return InstMap_;
60     }
JmpsMap()61     const JumpsMap &JmpsMap() const
62     {
63         return JmpsMap_;
64     }
ExcSrcMap()65     const ExceptionSourceMap &ExcSrcMap() const
66     {
67         return ExcSrcMap_;
68     }
BodyBlocks()69     const PandaVector<CflowBlockInfo> &BodyBlocks() const
70     {
71         return BodyBlocks_;
72     }
ExcTryBlocks()73     const PandaVector<CflowBlockInfo> &ExcTryBlocks() const
74     {
75         return ExcTryBlocks_;
76     }
ExcHandlers()77     const PandaVector<CflowExcHandlerInfo> &ExcHandlers() const
78     {
79         return ExcHandlers_;
80     }
81 
82 private:
83     InstructionsMap InstMap_;
84     JumpsMap JmpsMap_;
85     ExceptionSourceMap ExcSrcMap_;
86     PandaVector<CflowBlockInfo> BodyBlocks_;
87     PandaVector<CflowBlockInfo> ExcTryBlocks_;
88     PandaVector<CflowExcHandlerInfo> ExcHandlers_;
89     friend PandaUniquePtr<CflowMethodInfo> GetCflowMethodInfo(const LibCache::CachedMethod &method, LibCache &cache);
90 };
91 
92 PandaUniquePtr<CflowMethodInfo> GetCflowMethodInfo(const LibCache::CachedMethod &method, LibCache &cache);
93 }  // namespace panda::verifier
94 
95 #endif  // !PANDA_VERIFICATION_CFLOW_INFO_HPP_
96