1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_RUNTIME_OAT_FILE_INL_H_
18 #define ART_RUNTIME_OAT_FILE_INL_H_
19 
20 #include "oat_file.h"
21 
22 #include "base/utils.h"
23 #include "oat_quick_method_header.h"
24 
25 namespace art {
26 
GetOatQuickMethodHeader()27 inline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const {
28   const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
29   if (code == nullptr) {
30     return nullptr;
31   }
32   // Return a pointer to the packed struct before the code.
33   return reinterpret_cast<const OatQuickMethodHeader*>(code) - 1;
34 }
35 
GetOatQuickMethodHeaderOffset()36 inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const {
37   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
38   if (method_header == nullptr) {
39     return 0u;
40   }
41   return reinterpret_cast<const uint8_t*>(method_header) - begin_;
42 }
43 
GetQuickCodeSizeOffset()44 inline uint32_t OatFile::OatMethod::GetQuickCodeSizeOffset() const {
45   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
46   if (method_header == nullptr) {
47     return 0u;
48   }
49   return reinterpret_cast<const uint8_t*>(method_header->GetCodeSizeAddr()) - begin_;
50 }
51 
GetFrameSizeInBytes()52 inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const {
53   const void* code = EntryPointToCodePointer(GetQuickCode());
54   if (code == nullptr) {
55     return 0u;
56   }
57   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FrameSizeInBytes();
58 }
59 
GetCoreSpillMask()60 inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const {
61   const void* code = EntryPointToCodePointer(GetQuickCode());
62   if (code == nullptr) {
63     return 0u;
64   }
65   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().CoreSpillMask();
66 }
67 
GetFpSpillMask()68 inline uint32_t OatFile::OatMethod::GetFpSpillMask() const {
69   const void* code = EntryPointToCodePointer(GetQuickCode());
70   if (code == nullptr) {
71     return 0u;
72   }
73   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FpSpillMask();
74 }
75 
GetVmapTableOffset()76 inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const {
77   const uint8_t* vmap_table = GetVmapTable();
78   return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u);
79 }
80 
GetVmapTableOffsetOffset()81 inline uint32_t OatFile::OatMethod::GetVmapTableOffsetOffset() const {
82   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
83   if (method_header == nullptr) {
84     return 0u;
85   }
86   return reinterpret_cast<const uint8_t*>(method_header->GetVmapTableOffsetAddr()) - begin_;
87 }
88 
GetVmapTable()89 inline const uint8_t* OatFile::OatMethod::GetVmapTable() const {
90   const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
91   if (code == nullptr) {
92     return nullptr;
93   }
94   uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetVmapTableOffset();
95   if (UNLIKELY(offset == 0u)) {
96     return nullptr;
97   }
98   return reinterpret_cast<const uint8_t*>(code) - offset;
99 }
100 
GetQuickCodeSize()101 inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const {
102   const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
103   if (code == nullptr) {
104     return 0u;
105   }
106   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeSize();
107 }
108 
GetCodeOffset()109 inline uint32_t OatFile::OatMethod::GetCodeOffset() const {
110   return (GetQuickCodeSize() == 0) ? 0 : code_offset_;
111 }
112 
GetQuickCode()113 inline const void* OatFile::OatMethod::GetQuickCode() const {
114   return GetOatPointer<const void*>(GetCodeOffset());
115 }
116 
117 }  // namespace art
118 
119 #endif  // ART_RUNTIME_OAT_FILE_INL_H_
120