blob: 9307598a77807b2c134f9e73420e5b647d1114a9 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 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 */
Brian Carlstrome24fa612011-09-29 00:53:55 -070016
17#include "oat.h"
18
Andreas Gampe22f8e5c2014-07-09 11:38:21 -070019#include <string.h>
Brian Carlstrome24fa612011-09-29 00:53:55 -070020#include <zlib.h>
21
Ian Rogersd582fa42014-11-05 23:46:43 -080022#include "arch/instruction_set_features.h"
23#include "utils.h"
24
Brian Carlstrome24fa612011-09-29 00:53:55 -070025namespace art {
26
27const uint8_t OatHeader::kOatMagic[] = { 'o', 'a', 't', '\n' };
Elliott Hughes956af0f2014-12-11 14:34:28 -080028const uint8_t OatHeader::kOatVersion[] = { '0', '5', '2', '\0' };
Brian Carlstrome24fa612011-09-29 00:53:55 -070029
Andreas Gampe22f8e5c2014-07-09 11:38:21 -070030static size_t ComputeOatHeaderSize(const SafeMap<std::string, std::string>* variable_data) {
31 size_t estimate = 0U;
32 if (variable_data != nullptr) {
33 SafeMap<std::string, std::string>::const_iterator it = variable_data->begin();
34 SafeMap<std::string, std::string>::const_iterator end = variable_data->end();
35 for ( ; it != end; ++it) {
36 estimate += it->first.length() + 1;
37 estimate += it->second.length() + 1;
38 }
39 }
40 return sizeof(OatHeader) + estimate;
41}
42
43OatHeader* OatHeader::Create(InstructionSet instruction_set,
Ian Rogers6f3dbba2014-10-14 17:41:57 -070044 const InstructionSetFeatures* instruction_set_features,
Andreas Gampe22f8e5c2014-07-09 11:38:21 -070045 const std::vector<const DexFile*>* dex_files,
46 uint32_t image_file_location_oat_checksum,
47 uint32_t image_file_location_oat_data_begin,
48 const SafeMap<std::string, std::string>* variable_data) {
49 // Estimate size of optional data.
50 size_t needed_size = ComputeOatHeaderSize(variable_data);
51
52 // Reserve enough memory.
53 void* memory = operator new (needed_size);
54
55 // Create the OatHeader in-place.
56 return new (memory) OatHeader(instruction_set,
57 instruction_set_features,
58 dex_files,
59 image_file_location_oat_checksum,
60 image_file_location_oat_data_begin,
61 variable_data);
Elliott Hughesa72ec822012-03-05 17:12:22 -080062}
63
Brian Carlstrom81f3ca12012-03-17 00:27:35 -070064OatHeader::OatHeader(InstructionSet instruction_set,
Ian Rogers6f3dbba2014-10-14 17:41:57 -070065 const InstructionSetFeatures* instruction_set_features,
Brian Carlstrom81f3ca12012-03-17 00:27:35 -070066 const std::vector<const DexFile*>* dex_files,
Brian Carlstrom28db0122012-10-18 16:20:41 -070067 uint32_t image_file_location_oat_checksum,
Brian Carlstrom700c8d32012-11-05 10:42:02 -080068 uint32_t image_file_location_oat_data_begin,
Andreas Gampe22f8e5c2014-07-09 11:38:21 -070069 const SafeMap<std::string, std::string>* variable_data) {
Brian Carlstrome24fa612011-09-29 00:53:55 -070070 memcpy(magic_, kOatMagic, sizeof(kOatMagic));
71 memcpy(version_, kOatVersion, sizeof(kOatVersion));
Alex Lighta59dd802014-07-02 16:28:08 -070072 executable_offset_ = 0;
73 image_patch_delta_ = 0;
Brian Carlstrom81f3ca12012-03-17 00:27:35 -070074
Brian Carlstrome24fa612011-09-29 00:53:55 -070075 adler32_checksum_ = adler32(0L, Z_NULL, 0);
Brian Carlstrom81f3ca12012-03-17 00:27:35 -070076
Brian Carlstromf852fb22012-10-19 11:01:58 -070077 CHECK_NE(instruction_set, kNone);
Elliott Hughesa72ec822012-03-05 17:12:22 -080078 instruction_set_ = instruction_set;
79 UpdateChecksum(&instruction_set_, sizeof(instruction_set_));
Brian Carlstrom81f3ca12012-03-17 00:27:35 -070080
Ian Rogers6f3dbba2014-10-14 17:41:57 -070081 instruction_set_features_bitmap_ = instruction_set_features->AsBitmap();
82 UpdateChecksum(&instruction_set_features_bitmap_, sizeof(instruction_set_features_bitmap_));
Dave Allison70202782013-10-22 17:52:19 -070083
Brian Carlstrome24fa612011-09-29 00:53:55 -070084 dex_file_count_ = dex_files->size();
85 UpdateChecksum(&dex_file_count_, sizeof(dex_file_count_));
Brian Carlstrom81f3ca12012-03-17 00:27:35 -070086
Brian Carlstrom28db0122012-10-18 16:20:41 -070087 image_file_location_oat_checksum_ = image_file_location_oat_checksum;
88 UpdateChecksum(&image_file_location_oat_checksum_, sizeof(image_file_location_oat_checksum_));
89
Brian Carlstrom700c8d32012-11-05 10:42:02 -080090 CHECK(IsAligned<kPageSize>(image_file_location_oat_data_begin));
91 image_file_location_oat_data_begin_ = image_file_location_oat_data_begin;
92 UpdateChecksum(&image_file_location_oat_data_begin_, sizeof(image_file_location_oat_data_begin_));
Brian Carlstrom81f3ca12012-03-17 00:27:35 -070093
Andreas Gampe22f8e5c2014-07-09 11:38:21 -070094 // Flatten the map. Will also update variable_size_data_size_.
95 Flatten(variable_data);
96
97 // Update checksum for variable data size.
98 UpdateChecksum(&key_value_store_size_, sizeof(key_value_store_size_));
99
100 // Update for data, if existing.
101 if (key_value_store_size_ > 0U) {
102 UpdateChecksum(&key_value_store_, key_value_store_size_);
103 }
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700104
Ian Rogers468532e2013-08-05 10:56:33 -0700105 interpreter_to_interpreter_bridge_offset_ = 0;
106 interpreter_to_compiled_code_bridge_offset_ = 0;
107 jni_dlsym_lookup_offset_ = 0;
Andreas Gampe2da88232014-02-27 12:26:20 -0800108 quick_generic_jni_trampoline_offset_ = 0;
Jeff Hao88474b42013-10-23 16:24:40 -0700109 quick_imt_conflict_trampoline_offset_ = 0;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700110 quick_resolution_trampoline_offset_ = 0;
Ian Rogers468532e2013-08-05 10:56:33 -0700111 quick_to_interpreter_bridge_offset_ = 0;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700112}
113
114bool OatHeader::IsValid() const {
Brian Carlstromf852fb22012-10-19 11:01:58 -0700115 if (memcmp(magic_, kOatMagic, sizeof(kOatMagic)) != 0) {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700116 return false;
117 }
Brian Carlstromf852fb22012-10-19 11:01:58 -0700118 if (memcmp(version_, kOatVersion, sizeof(kOatVersion)) != 0) {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700119 return false;
120 }
Alex Lighta59dd802014-07-02 16:28:08 -0700121 if (!IsAligned<kPageSize>(executable_offset_)) {
122 return false;
123 }
124 if (!IsAligned<kPageSize>(image_patch_delta_)) {
125 return false;
126 }
Brian Carlstrome24fa612011-09-29 00:53:55 -0700127 return true;
128}
129
130const char* OatHeader::GetMagic() const {
131 CHECK(IsValid());
132 return reinterpret_cast<const char*>(magic_);
133}
134
Brian Carlstrome24fa612011-09-29 00:53:55 -0700135uint32_t OatHeader::GetChecksum() const {
136 CHECK(IsValid());
137 return adler32_checksum_;
138}
139
140void OatHeader::UpdateChecksum(const void* data, size_t length) {
141 DCHECK(IsValid());
142 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
143 adler32_checksum_ = adler32(adler32_checksum_, bytes, length);
144}
145
Elliott Hughesa72ec822012-03-05 17:12:22 -0800146InstructionSet OatHeader::GetInstructionSet() const {
147 CHECK(IsValid());
148 return instruction_set_;
149}
150
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700151uint32_t OatHeader::GetInstructionSetFeaturesBitmap() const {
Dave Allison70202782013-10-22 17:52:19 -0700152 CHECK(IsValid());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700153 return instruction_set_features_bitmap_;
Dave Allison70202782013-10-22 17:52:19 -0700154}
155
Brian Carlstrome24fa612011-09-29 00:53:55 -0700156uint32_t OatHeader::GetExecutableOffset() const {
157 DCHECK(IsValid());
Elliott Hughes06b37d92011-10-16 11:51:29 -0700158 DCHECK_ALIGNED(executable_offset_, kPageSize);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700159 CHECK_GT(executable_offset_, sizeof(OatHeader));
160 return executable_offset_;
161}
162
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700163void OatHeader::SetExecutableOffset(uint32_t executable_offset) {
164 DCHECK_ALIGNED(executable_offset, kPageSize);
165 CHECK_GT(executable_offset, sizeof(OatHeader));
166 DCHECK(IsValid());
167 DCHECK_EQ(executable_offset_, 0U);
168
169 executable_offset_ = executable_offset;
170 UpdateChecksum(&executable_offset_, sizeof(executable_offset));
171}
172
Ian Rogers468532e2013-08-05 10:56:33 -0700173const void* OatHeader::GetInterpreterToInterpreterBridge() const {
174 return reinterpret_cast<const uint8_t*>(this) + GetInterpreterToInterpreterBridgeOffset();
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700175}
176
Ian Rogers468532e2013-08-05 10:56:33 -0700177uint32_t OatHeader::GetInterpreterToInterpreterBridgeOffset() const {
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700178 DCHECK(IsValid());
Dave Allisonc6104ae2014-03-12 11:05:39 -0700179 CHECK(interpreter_to_interpreter_bridge_offset_ == 0 ||
180 interpreter_to_interpreter_bridge_offset_ >= executable_offset_);
Ian Rogers468532e2013-08-05 10:56:33 -0700181 return interpreter_to_interpreter_bridge_offset_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700182}
183
Ian Rogers468532e2013-08-05 10:56:33 -0700184void OatHeader::SetInterpreterToInterpreterBridgeOffset(uint32_t offset) {
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700185 CHECK(offset == 0 || offset >= executable_offset_);
186 DCHECK(IsValid());
Ian Rogers468532e2013-08-05 10:56:33 -0700187 DCHECK_EQ(interpreter_to_interpreter_bridge_offset_, 0U) << offset;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700188
Ian Rogers468532e2013-08-05 10:56:33 -0700189 interpreter_to_interpreter_bridge_offset_ = offset;
190 UpdateChecksum(&interpreter_to_interpreter_bridge_offset_, sizeof(offset));
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700191}
192
Ian Rogers468532e2013-08-05 10:56:33 -0700193const void* OatHeader::GetInterpreterToCompiledCodeBridge() const {
194 return reinterpret_cast<const uint8_t*>(this) + GetInterpreterToCompiledCodeBridgeOffset();
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700195}
196
Ian Rogers468532e2013-08-05 10:56:33 -0700197uint32_t OatHeader::GetInterpreterToCompiledCodeBridgeOffset() const {
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700198 DCHECK(IsValid());
Ian Rogers468532e2013-08-05 10:56:33 -0700199 CHECK_GE(interpreter_to_compiled_code_bridge_offset_, interpreter_to_interpreter_bridge_offset_);
200 return interpreter_to_compiled_code_bridge_offset_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700201}
202
Ian Rogers468532e2013-08-05 10:56:33 -0700203void OatHeader::SetInterpreterToCompiledCodeBridgeOffset(uint32_t offset) {
204 CHECK(offset == 0 || offset >= interpreter_to_interpreter_bridge_offset_);
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700205 DCHECK(IsValid());
Ian Rogers468532e2013-08-05 10:56:33 -0700206 DCHECK_EQ(interpreter_to_compiled_code_bridge_offset_, 0U) << offset;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700207
Ian Rogers468532e2013-08-05 10:56:33 -0700208 interpreter_to_compiled_code_bridge_offset_ = offset;
209 UpdateChecksum(&interpreter_to_compiled_code_bridge_offset_, sizeof(offset));
210}
211
212const void* OatHeader::GetJniDlsymLookup() const {
213 return reinterpret_cast<const uint8_t*>(this) + GetJniDlsymLookupOffset();
214}
215
216uint32_t OatHeader::GetJniDlsymLookupOffset() const {
217 DCHECK(IsValid());
218 CHECK_GE(jni_dlsym_lookup_offset_, interpreter_to_compiled_code_bridge_offset_);
219 return jni_dlsym_lookup_offset_;
220}
221
222void OatHeader::SetJniDlsymLookupOffset(uint32_t offset) {
223 CHECK(offset == 0 || offset >= interpreter_to_compiled_code_bridge_offset_);
224 DCHECK(IsValid());
225 DCHECK_EQ(jni_dlsym_lookup_offset_, 0U) << offset;
226
227 jni_dlsym_lookup_offset_ = offset;
228 UpdateChecksum(&jni_dlsym_lookup_offset_, sizeof(offset));
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700229}
230
Andreas Gampe2da88232014-02-27 12:26:20 -0800231const void* OatHeader::GetQuickGenericJniTrampoline() const {
232 return reinterpret_cast<const uint8_t*>(this) + GetQuickGenericJniTrampolineOffset();
233}
234
235uint32_t OatHeader::GetQuickGenericJniTrampolineOffset() const {
236 DCHECK(IsValid());
Elliott Hughes956af0f2014-12-11 14:34:28 -0800237 CHECK_GE(quick_generic_jni_trampoline_offset_, jni_dlsym_lookup_offset_);
Andreas Gampe2da88232014-02-27 12:26:20 -0800238 return quick_generic_jni_trampoline_offset_;
239}
240
241void OatHeader::SetQuickGenericJniTrampolineOffset(uint32_t offset) {
Elliott Hughes956af0f2014-12-11 14:34:28 -0800242 CHECK(offset == 0 || offset >= jni_dlsym_lookup_offset_);
Andreas Gampe2da88232014-02-27 12:26:20 -0800243 DCHECK(IsValid());
244 DCHECK_EQ(quick_generic_jni_trampoline_offset_, 0U) << offset;
245
246 quick_generic_jni_trampoline_offset_ = offset;
247 UpdateChecksum(&quick_generic_jni_trampoline_offset_, sizeof(offset));
248}
249
Jeff Hao88474b42013-10-23 16:24:40 -0700250const void* OatHeader::GetQuickImtConflictTrampoline() const {
251 return reinterpret_cast<const uint8_t*>(this) + GetQuickImtConflictTrampolineOffset();
252}
253
254uint32_t OatHeader::GetQuickImtConflictTrampolineOffset() const {
255 DCHECK(IsValid());
Andreas Gampe2da88232014-02-27 12:26:20 -0800256 CHECK_GE(quick_imt_conflict_trampoline_offset_, quick_generic_jni_trampoline_offset_);
Jeff Hao88474b42013-10-23 16:24:40 -0700257 return quick_imt_conflict_trampoline_offset_;
258}
259
260void OatHeader::SetQuickImtConflictTrampolineOffset(uint32_t offset) {
Andreas Gampe2da88232014-02-27 12:26:20 -0800261 CHECK(offset == 0 || offset >= quick_generic_jni_trampoline_offset_);
Jeff Hao88474b42013-10-23 16:24:40 -0700262 DCHECK(IsValid());
263 DCHECK_EQ(quick_imt_conflict_trampoline_offset_, 0U) << offset;
264
265 quick_imt_conflict_trampoline_offset_ = offset;
266 UpdateChecksum(&quick_imt_conflict_trampoline_offset_, sizeof(offset));
267}
268
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700269const void* OatHeader::GetQuickResolutionTrampoline() const {
270 return reinterpret_cast<const uint8_t*>(this) + GetQuickResolutionTrampolineOffset();
271}
272
273uint32_t OatHeader::GetQuickResolutionTrampolineOffset() const {
274 DCHECK(IsValid());
Jeff Hao88474b42013-10-23 16:24:40 -0700275 CHECK_GE(quick_resolution_trampoline_offset_, quick_imt_conflict_trampoline_offset_);
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700276 return quick_resolution_trampoline_offset_;
277}
278
279void OatHeader::SetQuickResolutionTrampolineOffset(uint32_t offset) {
Jeff Hao88474b42013-10-23 16:24:40 -0700280 CHECK(offset == 0 || offset >= quick_imt_conflict_trampoline_offset_);
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700281 DCHECK(IsValid());
282 DCHECK_EQ(quick_resolution_trampoline_offset_, 0U) << offset;
283
284 quick_resolution_trampoline_offset_ = offset;
285 UpdateChecksum(&quick_resolution_trampoline_offset_, sizeof(offset));
286}
287
Ian Rogers468532e2013-08-05 10:56:33 -0700288const void* OatHeader::GetQuickToInterpreterBridge() const {
289 return reinterpret_cast<const uint8_t*>(this) + GetQuickToInterpreterBridgeOffset();
290}
291
292uint32_t OatHeader::GetQuickToInterpreterBridgeOffset() const {
293 DCHECK(IsValid());
294 CHECK_GE(quick_to_interpreter_bridge_offset_, quick_resolution_trampoline_offset_);
295 return quick_to_interpreter_bridge_offset_;
296}
297
298void OatHeader::SetQuickToInterpreterBridgeOffset(uint32_t offset) {
299 CHECK(offset == 0 || offset >= quick_resolution_trampoline_offset_);
300 DCHECK(IsValid());
301 DCHECK_EQ(quick_to_interpreter_bridge_offset_, 0U) << offset;
302
303 quick_to_interpreter_bridge_offset_ = offset;
304 UpdateChecksum(&quick_to_interpreter_bridge_offset_, sizeof(offset));
305}
306
Alex Lighta59dd802014-07-02 16:28:08 -0700307int32_t OatHeader::GetImagePatchDelta() const {
308 CHECK(IsValid());
309 return image_patch_delta_;
310}
311
312void OatHeader::RelocateOat(off_t delta) {
313 CHECK(IsValid());
314 CHECK_ALIGNED(delta, kPageSize);
315 image_patch_delta_ += delta;
316 if (image_file_location_oat_data_begin_ != 0) {
317 image_file_location_oat_data_begin_ += delta;
318 }
319}
320
321void OatHeader::SetImagePatchDelta(int32_t off) {
322 CHECK(IsValid());
323 CHECK_ALIGNED(off, kPageSize);
324 image_patch_delta_ = off;
325}
326
Brian Carlstrom28db0122012-10-18 16:20:41 -0700327uint32_t OatHeader::GetImageFileLocationOatChecksum() const {
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700328 CHECK(IsValid());
Brian Carlstrom28db0122012-10-18 16:20:41 -0700329 return image_file_location_oat_checksum_;
330}
331
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800332uint32_t OatHeader::GetImageFileLocationOatDataBegin() const {
Brian Carlstrom28db0122012-10-18 16:20:41 -0700333 CHECK(IsValid());
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800334 return image_file_location_oat_data_begin_;
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700335}
336
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700337uint32_t OatHeader::GetKeyValueStoreSize() const {
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700338 CHECK(IsValid());
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700339 return key_value_store_size_;
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700340}
341
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700342const uint8_t* OatHeader::GetKeyValueStore() const {
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700343 CHECK(IsValid());
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700344 return key_value_store_;
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700345}
346
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700347// Advance start until it is either end or \0.
348static const char* ParseString(const char* start, const char* end) {
349 while (start < end && *start != 0) {
350 start++;
351 }
352 return start;
353}
354
355const char* OatHeader::GetStoreValueByKey(const char* key) const {
356 const char* ptr = reinterpret_cast<const char*>(&key_value_store_);
357 const char* end = ptr + key_value_store_size_;
358
359 while (ptr < end) {
360 // Scan for a closing zero.
361 const char* str_end = ParseString(ptr, end);
362 if (str_end < end) {
363 if (strcmp(key, ptr) == 0) {
364 // Same as key. Check if value is OK.
365 if (ParseString(str_end + 1, end) < end) {
366 return str_end + 1;
367 }
368 } else {
369 // Different from key. Advance over the value.
370 ptr = ParseString(str_end + 1, end) + 1;
371 }
372 } else {
373 break;
374 }
375 }
376 // Not found.
377 return nullptr;
378}
379
380bool OatHeader::GetStoreKeyValuePairByIndex(size_t index, const char** key,
381 const char** value) const {
382 const char* ptr = reinterpret_cast<const char*>(&key_value_store_);
383 const char* end = ptr + key_value_store_size_;
384 ssize_t counter = static_cast<ssize_t>(index);
385
386 while (ptr < end && counter >= 0) {
387 // Scan for a closing zero.
388 const char* str_end = ParseString(ptr, end);
389 if (str_end < end) {
390 const char* maybe_key = ptr;
391 ptr = ParseString(str_end + 1, end) + 1;
392 if (ptr <= end) {
393 if (counter == 0) {
394 *key = maybe_key;
395 *value = str_end + 1;
396 return true;
397 } else {
398 counter--;
399 }
400 } else {
401 return false;
402 }
403 } else {
404 break;
405 }
406 }
407 // Not found.
408 return false;
409}
410
411size_t OatHeader::GetHeaderSize() const {
412 return sizeof(OatHeader) + key_value_store_size_;
413}
414
Igor Murashkin46774762014-10-22 11:37:02 -0700415bool OatHeader::IsPic() const {
416 const char* pic_string = GetStoreValueByKey(OatHeader::kPicKey);
417 static const char kTrue[] = "true";
418 return (pic_string != nullptr && strncmp(pic_string, kTrue, sizeof(kTrue)) == 0);
419}
420
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700421void OatHeader::Flatten(const SafeMap<std::string, std::string>* key_value_store) {
422 char* data_ptr = reinterpret_cast<char*>(&key_value_store_);
423 if (key_value_store != nullptr) {
424 SafeMap<std::string, std::string>::const_iterator it = key_value_store->begin();
425 SafeMap<std::string, std::string>::const_iterator end = key_value_store->end();
426 for ( ; it != end; ++it) {
427 strcpy(data_ptr, it->first.c_str());
428 data_ptr += it->first.length() + 1;
429 strcpy(data_ptr, it->second.c_str());
430 data_ptr += it->second.length() + 1;
431 }
432 }
433 key_value_store_size_ = data_ptr - reinterpret_cast<char*>(&key_value_store_);
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700434}
435
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800436OatMethodOffsets::OatMethodOffsets(uint32_t code_offset) : code_offset_(code_offset) {
437}
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700438
439OatMethodOffsets::~OatMethodOffsets() {}
440
Vladimir Marko7624d252014-05-02 14:40:15 +0100441OatQuickMethodHeader::OatQuickMethodHeader(
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800442 uint32_t mapping_table_offset, uint32_t vmap_table_offset, uint32_t gc_map_offset,
443 uint32_t frame_size_in_bytes, uint32_t core_spill_mask, uint32_t fp_spill_mask,
444 uint32_t code_size)
445 : mapping_table_offset_(mapping_table_offset), vmap_table_offset_(vmap_table_offset),
446 gc_map_offset_(gc_map_offset),
447 frame_info_(frame_size_in_bytes, core_spill_mask, fp_spill_mask), code_size_(code_size) {
448}
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100449
Vladimir Marko7624d252014-05-02 14:40:15 +0100450OatQuickMethodHeader::~OatQuickMethodHeader() {}
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100451
Brian Carlstrome24fa612011-09-29 00:53:55 -0700452} // namespace art