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 #include "oat_quick_method_header.h"
22 
23 namespace art {
24 
GetOatQuickMethodHeader()25 inline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const {
26   const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
27   if (code == nullptr) {
28     return nullptr;
29   }
30   // Return a pointer to the packed struct before the code.
31   return reinterpret_cast<const OatQuickMethodHeader*>(code) - 1;
32 }
33 
GetOatQuickMethodHeaderOffset()34 inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const {
35   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
36   if (method_header == nullptr) {
37     return 0u;
38   }
39   return reinterpret_cast<const uint8_t*>(method_header) - begin_;
40 }
41 
GetQuickCodeSizeOffset()42 inline uint32_t OatFile::OatMethod::GetQuickCodeSizeOffset() const {
43   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
44   if (method_header == nullptr) {
45     return 0u;
46   }
47   return reinterpret_cast<const uint8_t*>(method_header->GetCodeSizeAddr()) - begin_;
48 }
49 
GetFrameSizeInBytes()50 inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const {
51   const void* code = EntryPointToCodePointer(GetQuickCode());
52   if (code == nullptr) {
53     return 0u;
54   }
55   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FrameSizeInBytes();
56 }
57 
GetCoreSpillMask()58 inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const {
59   const void* code = EntryPointToCodePointer(GetQuickCode());
60   if (code == nullptr) {
61     return 0u;
62   }
63   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().CoreSpillMask();
64 }
65 
GetFpSpillMask()66 inline uint32_t OatFile::OatMethod::GetFpSpillMask() const {
67   const void* code = EntryPointToCodePointer(GetQuickCode());
68   if (code == nullptr) {
69     return 0u;
70   }
71   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FpSpillMask();
72 }
73 
GetVmapTableOffset()74 inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const {
75   const uint8_t* vmap_table = GetVmapTable();
76   return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u);
77 }
78 
GetVmapTableOffsetOffset()79 inline uint32_t OatFile::OatMethod::GetVmapTableOffsetOffset() const {
80   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
81   if (method_header == nullptr) {
82     return 0u;
83   }
84   return reinterpret_cast<const uint8_t*>(method_header->GetVmapTableOffsetAddr()) - begin_;
85 }
86 
GetVmapTable()87 inline const uint8_t* OatFile::OatMethod::GetVmapTable() const {
88   const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
89   if (code == nullptr) {
90     return nullptr;
91   }
92   uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetVmapTableOffset();
93   if (UNLIKELY(offset == 0u)) {
94     return nullptr;
95   }
96   return reinterpret_cast<const uint8_t*>(code) - offset;
97 }
98 
GetQuickCodeSize()99 inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const {
100   const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
101   if (code == nullptr) {
102     return 0u;
103   }
104   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeSize();
105 }
106 
GetCodeOffset()107 inline uint32_t OatFile::OatMethod::GetCodeOffset() const {
108   return (GetQuickCodeSize() == 0) ? 0 : code_offset_;
109 }
110 
GetQuickCode()111 inline const void* OatFile::OatMethod::GetQuickCode() const {
112   return GetOatPointer<const void*>(GetCodeOffset());
113 }
114 
115 }  // namespace art
116 
117 #endif  // ART_RUNTIME_OAT_FILE_INL_H_
118