blob: 7b13430765fd97cef5452e2159201c08525aca18 [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
Andreas Gampe46ee31b2016-12-14 10:11:49 -080021#include "android-base/stringprintf.h"
22
Andreas Gampe639b2b12019-01-08 10:32:50 -080023#include "arch/instruction_set.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080024#include "arch/instruction_set_features.h"
Vladimir Marko80afd022015-05-19 18:08:00 +010025#include "base/bit_utils.h"
Andreas Gampef45d61c2017-06-07 10:29:33 -070026#include "base/strlcpy.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080027
Brian Carlstrome24fa612011-09-29 00:53:55 -070028namespace art {
29
Andreas Gampe46ee31b2016-12-14 10:11:49 -080030using android::base::StringPrintf;
31
Sebastien Hertz0de11332015-05-13 12:14:05 +020032constexpr const char OatHeader::kTrueValue[];
33constexpr const char OatHeader::kFalseValue[];
Brian Carlstrome24fa612011-09-29 00:53:55 -070034
Andreas Gampe22f8e5c2014-07-09 11:38:21 -070035static size_t ComputeOatHeaderSize(const SafeMap<std::string, std::string>* variable_data) {
36 size_t estimate = 0U;
37 if (variable_data != nullptr) {
38 SafeMap<std::string, std::string>::const_iterator it = variable_data->begin();
39 SafeMap<std::string, std::string>::const_iterator end = variable_data->end();
40 for ( ; it != end; ++it) {
41 estimate += it->first.length() + 1;
42 estimate += it->second.length() + 1;
43 }
44 }
45 return sizeof(OatHeader) + estimate;
46}
47
48OatHeader* OatHeader::Create(InstructionSet instruction_set,
Ian Rogers6f3dbba2014-10-14 17:41:57 -070049 const InstructionSetFeatures* instruction_set_features,
Vladimir Marko49b0f452015-12-10 13:49:19 +000050 uint32_t dex_file_count,
Andreas Gampe22f8e5c2014-07-09 11:38:21 -070051 const SafeMap<std::string, std::string>* variable_data) {
52 // Estimate size of optional data.
53 size_t needed_size = ComputeOatHeaderSize(variable_data);
54
55 // Reserve enough memory.
56 void* memory = operator new (needed_size);
57
58 // Create the OatHeader in-place.
59 return new (memory) OatHeader(instruction_set,
60 instruction_set_features,
Vladimir Marko49b0f452015-12-10 13:49:19 +000061 dex_file_count,
Andreas Gampe22f8e5c2014-07-09 11:38:21 -070062 variable_data);
Elliott Hughesa72ec822012-03-05 17:12:22 -080063}
64
Brian Carlstrom81f3ca12012-03-17 00:27:35 -070065OatHeader::OatHeader(InstructionSet instruction_set,
Ian Rogers6f3dbba2014-10-14 17:41:57 -070066 const InstructionSetFeatures* instruction_set_features,
Vladimir Marko49b0f452015-12-10 13:49:19 +000067 uint32_t dex_file_count,
68 const SafeMap<std::string, std::string>* variable_data)
Vladimir Markoc10a0c62018-11-16 11:39:22 +000069 : oat_checksum_(0u),
Vladimir Marko49b0f452015-12-10 13:49:19 +000070 instruction_set_(instruction_set),
71 instruction_set_features_bitmap_(instruction_set_features->AsBitmap()),
72 dex_file_count_(dex_file_count),
Vladimir Marko0eb882b2017-05-15 13:39:18 +010073 oat_dex_files_offset_(0),
Vladimir Marko49b0f452015-12-10 13:49:19 +000074 executable_offset_(0),
Vladimir Marko7dac8642019-11-06 17:09:30 +000075 jni_dlsym_lookup_trampoline_offset_(0),
Vladimir Marko49b0f452015-12-10 13:49:19 +000076 quick_generic_jni_trampoline_offset_(0),
77 quick_imt_conflict_trampoline_offset_(0),
78 quick_resolution_trampoline_offset_(0),
Vladimir Marko0ace5632018-12-14 11:11:47 +000079 quick_to_interpreter_bridge_offset_(0) {
Andreas Gampe2bcb3b22014-12-12 15:25:14 -080080 // Don't want asserts in header as they would be checked in each file that includes it. But the
81 // fields are private, so we check inside a method.
82 static_assert(sizeof(magic_) == sizeof(kOatMagic),
83 "Oat magic and magic_ have different lengths.");
84 static_assert(sizeof(version_) == sizeof(kOatVersion),
85 "Oat version and version_ have different lengths.");
86
David Srbeckye5d93b52019-02-27 15:10:52 +000087 magic_ = kOatMagic;
88 version_ = kOatVersion;
Brian Carlstrom81f3ca12012-03-17 00:27:35 -070089
Vladimir Marko33bff252017-11-01 14:35:42 +000090 CHECK_NE(instruction_set, InstructionSet::kNone);
Brian Carlstrom81f3ca12012-03-17 00:27:35 -070091
Andreas Gampe22f8e5c2014-07-09 11:38:21 -070092 // Flatten the map. Will also update variable_size_data_size_.
93 Flatten(variable_data);
Brian Carlstrome24fa612011-09-29 00:53:55 -070094}
95
96bool OatHeader::IsValid() const {
David Srbeckye5d93b52019-02-27 15:10:52 +000097 if (magic_ != kOatMagic) {
Brian Carlstrome24fa612011-09-29 00:53:55 -070098 return false;
99 }
David Srbeckye5d93b52019-02-27 15:10:52 +0000100 if (version_ != kOatVersion) {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700101 return false;
102 }
Alex Lighta59dd802014-07-02 16:28:08 -0700103 if (!IsAligned<kPageSize>(executable_offset_)) {
104 return false;
105 }
Vladimir Marko09d09432015-09-08 13:47:48 +0100106 if (!IsValidInstructionSet(instruction_set_)) {
107 return false;
108 }
Brian Carlstrome24fa612011-09-29 00:53:55 -0700109 return true;
110}
111
Andreas Gampe2bcb3b22014-12-12 15:25:14 -0800112std::string OatHeader::GetValidationErrorMessage() const {
David Srbeckye5d93b52019-02-27 15:10:52 +0000113 if (magic_ != kOatMagic) {
Andreas Gampe2bcb3b22014-12-12 15:25:14 -0800114 static_assert(sizeof(kOatMagic) == 4, "kOatMagic has unexpected length");
Vladimir Marko49af4ca2019-11-27 14:35:49 +0000115 return StringPrintf("Invalid oat magic, expected 0x%02x%02x%02x%02x, got 0x%02x%02x%02x%02x.",
Andreas Gampe2bcb3b22014-12-12 15:25:14 -0800116 kOatMagic[0], kOatMagic[1], kOatMagic[2], kOatMagic[3],
117 magic_[0], magic_[1], magic_[2], magic_[3]);
118 }
David Srbeckye5d93b52019-02-27 15:10:52 +0000119 if (version_ != kOatVersion) {
Andreas Gampe2bcb3b22014-12-12 15:25:14 -0800120 static_assert(sizeof(kOatVersion) == 4, "kOatVersion has unexpected length");
Vladimir Marko49af4ca2019-11-27 14:35:49 +0000121 return StringPrintf("Invalid oat version, expected 0x%02x%02x%02x%02x, got 0x%02x%02x%02x%02x.",
Andreas Gampe2bcb3b22014-12-12 15:25:14 -0800122 kOatVersion[0], kOatVersion[1], kOatVersion[2], kOatVersion[3],
123 version_[0], version_[1], version_[2], version_[3]);
124 }
125 if (!IsAligned<kPageSize>(executable_offset_)) {
126 return "Executable offset not page-aligned.";
127 }
Vladimir Marko09d09432015-09-08 13:47:48 +0100128 if (!IsValidInstructionSet(instruction_set_)) {
129 return StringPrintf("Invalid instruction set, %d.", static_cast<int>(instruction_set_));
130 }
Andreas Gampe2bcb3b22014-12-12 15:25:14 -0800131 return "";
132}
133
David Srbeckye5d93b52019-02-27 15:10:52 +0000134// Do not move this into the header. The method must be compiled in the runtime library,
135// so that we can check that the compile-time oat version matches the version in the caller.
136void OatHeader::CheckOatVersion(std::array<uint8_t, 4> version) {
137 constexpr std::array<uint8_t, 4> expected = kOatVersion; // Runtime oat version.
138 if (version != kOatVersion) {
Vladimir Marko49af4ca2019-11-27 14:35:49 +0000139 LOG(FATAL) << StringPrintf("Invalid oat version, expected 0x%02x%02x%02x%02x, "
140 "got 0x%02x%02x%02x%02x.",
David Srbeckye5d93b52019-02-27 15:10:52 +0000141 expected[0], expected[1], expected[2], expected[3],
142 version[0], version[1], version[2], version[3]);
143 }
144}
145
Brian Carlstrome24fa612011-09-29 00:53:55 -0700146const char* OatHeader::GetMagic() const {
147 CHECK(IsValid());
David Srbeckye5d93b52019-02-27 15:10:52 +0000148 return reinterpret_cast<const char*>(magic_.data());
Brian Carlstrome24fa612011-09-29 00:53:55 -0700149}
150
Brian Carlstrome24fa612011-09-29 00:53:55 -0700151uint32_t OatHeader::GetChecksum() const {
152 CHECK(IsValid());
Vladimir Markoc10a0c62018-11-16 11:39:22 +0000153 return oat_checksum_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700154}
155
Vladimir Markoc10a0c62018-11-16 11:39:22 +0000156void OatHeader::SetChecksum(uint32_t oat_checksum) {
157 oat_checksum_ = oat_checksum;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700158}
159
Elliott Hughesa72ec822012-03-05 17:12:22 -0800160InstructionSet OatHeader::GetInstructionSet() const {
161 CHECK(IsValid());
162 return instruction_set_;
163}
164
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700165uint32_t OatHeader::GetInstructionSetFeaturesBitmap() const {
Dave Allison70202782013-10-22 17:52:19 -0700166 CHECK(IsValid());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700167 return instruction_set_features_bitmap_;
Dave Allison70202782013-10-22 17:52:19 -0700168}
169
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100170uint32_t OatHeader::GetOatDexFilesOffset() const {
171 DCHECK(IsValid());
172 DCHECK_GT(oat_dex_files_offset_, sizeof(OatHeader));
173 return oat_dex_files_offset_;
174}
175
176void OatHeader::SetOatDexFilesOffset(uint32_t oat_dex_files_offset) {
177 DCHECK_GT(oat_dex_files_offset, sizeof(OatHeader));
178 DCHECK(IsValid());
179 DCHECK_EQ(oat_dex_files_offset_, 0u);
180
181 oat_dex_files_offset_ = oat_dex_files_offset;
182}
183
Brian Carlstrome24fa612011-09-29 00:53:55 -0700184uint32_t OatHeader::GetExecutableOffset() const {
185 DCHECK(IsValid());
Elliott Hughes06b37d92011-10-16 11:51:29 -0700186 DCHECK_ALIGNED(executable_offset_, kPageSize);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700187 CHECK_GT(executable_offset_, sizeof(OatHeader));
188 return executable_offset_;
189}
190
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700191void OatHeader::SetExecutableOffset(uint32_t executable_offset) {
192 DCHECK_ALIGNED(executable_offset, kPageSize);
193 CHECK_GT(executable_offset, sizeof(OatHeader));
194 DCHECK(IsValid());
195 DCHECK_EQ(executable_offset_, 0U);
196
197 executable_offset_ = executable_offset;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700198}
199
Vladimir Marko98fb0832019-03-13 16:52:11 +0000200static const void* GetTrampoline(const OatHeader& header, uint32_t offset) {
201 return (offset != 0u) ? reinterpret_cast<const uint8_t*>(&header) + offset : nullptr;
Ian Rogers468532e2013-08-05 10:56:33 -0700202}
203
Vladimir Marko7dac8642019-11-06 17:09:30 +0000204const void* OatHeader::GetJniDlsymLookupTrampoline() const {
205 return GetTrampoline(*this, GetJniDlsymLookupTrampolineOffset());
Ian Rogers468532e2013-08-05 10:56:33 -0700206}
207
Vladimir Marko7dac8642019-11-06 17:09:30 +0000208uint32_t OatHeader::GetJniDlsymLookupTrampolineOffset() const {
Ian Rogers468532e2013-08-05 10:56:33 -0700209 DCHECK(IsValid());
Vladimir Marko7dac8642019-11-06 17:09:30 +0000210 return jni_dlsym_lookup_trampoline_offset_;
Ian Rogers468532e2013-08-05 10:56:33 -0700211}
212
Vladimir Marko7dac8642019-11-06 17:09:30 +0000213void OatHeader::SetJniDlsymLookupTrampolineOffset(uint32_t offset) {
Ian Rogers468532e2013-08-05 10:56:33 -0700214 DCHECK(IsValid());
Vladimir Marko7dac8642019-11-06 17:09:30 +0000215 DCHECK_EQ(jni_dlsym_lookup_trampoline_offset_, 0U) << offset;
Ian Rogers468532e2013-08-05 10:56:33 -0700216
Vladimir Marko7dac8642019-11-06 17:09:30 +0000217 jni_dlsym_lookup_trampoline_offset_ = offset;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700218}
219
Andreas Gampe2da88232014-02-27 12:26:20 -0800220const void* OatHeader::GetQuickGenericJniTrampoline() const {
Vladimir Marko98fb0832019-03-13 16:52:11 +0000221 return GetTrampoline(*this, GetQuickGenericJniTrampolineOffset());
Andreas Gampe2da88232014-02-27 12:26:20 -0800222}
223
224uint32_t OatHeader::GetQuickGenericJniTrampolineOffset() const {
225 DCHECK(IsValid());
Vladimir Marko7dac8642019-11-06 17:09:30 +0000226 CHECK_GE(quick_generic_jni_trampoline_offset_, jni_dlsym_lookup_trampoline_offset_);
Andreas Gampe2da88232014-02-27 12:26:20 -0800227 return quick_generic_jni_trampoline_offset_;
228}
229
230void OatHeader::SetQuickGenericJniTrampolineOffset(uint32_t offset) {
Vladimir Marko7dac8642019-11-06 17:09:30 +0000231 CHECK(offset == 0 || offset >= jni_dlsym_lookup_trampoline_offset_);
Andreas Gampe2da88232014-02-27 12:26:20 -0800232 DCHECK(IsValid());
233 DCHECK_EQ(quick_generic_jni_trampoline_offset_, 0U) << offset;
234
235 quick_generic_jni_trampoline_offset_ = offset;
Andreas Gampe2da88232014-02-27 12:26:20 -0800236}
237
Jeff Hao88474b42013-10-23 16:24:40 -0700238const void* OatHeader::GetQuickImtConflictTrampoline() const {
Vladimir Marko98fb0832019-03-13 16:52:11 +0000239 return GetTrampoline(*this, GetQuickImtConflictTrampolineOffset());
Jeff Hao88474b42013-10-23 16:24:40 -0700240}
241
242uint32_t OatHeader::GetQuickImtConflictTrampolineOffset() const {
243 DCHECK(IsValid());
Andreas Gampe2da88232014-02-27 12:26:20 -0800244 CHECK_GE(quick_imt_conflict_trampoline_offset_, quick_generic_jni_trampoline_offset_);
Jeff Hao88474b42013-10-23 16:24:40 -0700245 return quick_imt_conflict_trampoline_offset_;
246}
247
248void OatHeader::SetQuickImtConflictTrampolineOffset(uint32_t offset) {
Andreas Gampe2da88232014-02-27 12:26:20 -0800249 CHECK(offset == 0 || offset >= quick_generic_jni_trampoline_offset_);
Jeff Hao88474b42013-10-23 16:24:40 -0700250 DCHECK(IsValid());
251 DCHECK_EQ(quick_imt_conflict_trampoline_offset_, 0U) << offset;
252
253 quick_imt_conflict_trampoline_offset_ = offset;
Jeff Hao88474b42013-10-23 16:24:40 -0700254}
255
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700256const void* OatHeader::GetQuickResolutionTrampoline() const {
Vladimir Marko98fb0832019-03-13 16:52:11 +0000257 return GetTrampoline(*this, GetQuickResolutionTrampolineOffset());
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700258}
259
260uint32_t OatHeader::GetQuickResolutionTrampolineOffset() const {
261 DCHECK(IsValid());
Jeff Hao88474b42013-10-23 16:24:40 -0700262 CHECK_GE(quick_resolution_trampoline_offset_, quick_imt_conflict_trampoline_offset_);
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700263 return quick_resolution_trampoline_offset_;
264}
265
266void OatHeader::SetQuickResolutionTrampolineOffset(uint32_t offset) {
Jeff Hao88474b42013-10-23 16:24:40 -0700267 CHECK(offset == 0 || offset >= quick_imt_conflict_trampoline_offset_);
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700268 DCHECK(IsValid());
269 DCHECK_EQ(quick_resolution_trampoline_offset_, 0U) << offset;
270
271 quick_resolution_trampoline_offset_ = offset;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700272}
273
Ian Rogers468532e2013-08-05 10:56:33 -0700274const void* OatHeader::GetQuickToInterpreterBridge() const {
Vladimir Marko98fb0832019-03-13 16:52:11 +0000275 return GetTrampoline(*this, GetQuickToInterpreterBridgeOffset());
Ian Rogers468532e2013-08-05 10:56:33 -0700276}
277
278uint32_t OatHeader::GetQuickToInterpreterBridgeOffset() const {
279 DCHECK(IsValid());
280 CHECK_GE(quick_to_interpreter_bridge_offset_, quick_resolution_trampoline_offset_);
281 return quick_to_interpreter_bridge_offset_;
282}
283
284void OatHeader::SetQuickToInterpreterBridgeOffset(uint32_t offset) {
285 CHECK(offset == 0 || offset >= quick_resolution_trampoline_offset_);
286 DCHECK(IsValid());
287 DCHECK_EQ(quick_to_interpreter_bridge_offset_, 0U) << offset;
288
289 quick_to_interpreter_bridge_offset_ = offset;
Ian Rogers468532e2013-08-05 10:56:33 -0700290}
291
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700292uint32_t OatHeader::GetKeyValueStoreSize() const {
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700293 CHECK(IsValid());
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700294 return key_value_store_size_;
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700295}
296
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700297const uint8_t* OatHeader::GetKeyValueStore() const {
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700298 CHECK(IsValid());
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700299 return key_value_store_;
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700300}
301
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700302// Advance start until it is either end or \0.
303static const char* ParseString(const char* start, const char* end) {
304 while (start < end && *start != 0) {
305 start++;
306 }
307 return start;
308}
309
310const char* OatHeader::GetStoreValueByKey(const char* key) const {
311 const char* ptr = reinterpret_cast<const char*>(&key_value_store_);
312 const char* end = ptr + key_value_store_size_;
313
314 while (ptr < end) {
315 // Scan for a closing zero.
316 const char* str_end = ParseString(ptr, end);
317 if (str_end < end) {
318 if (strcmp(key, ptr) == 0) {
319 // Same as key. Check if value is OK.
320 if (ParseString(str_end + 1, end) < end) {
321 return str_end + 1;
322 }
323 } else {
324 // Different from key. Advance over the value.
325 ptr = ParseString(str_end + 1, end) + 1;
326 }
327 } else {
328 break;
329 }
330 }
331 // Not found.
332 return nullptr;
333}
334
335bool OatHeader::GetStoreKeyValuePairByIndex(size_t index, const char** key,
336 const char** value) const {
337 const char* ptr = reinterpret_cast<const char*>(&key_value_store_);
338 const char* end = ptr + key_value_store_size_;
339 ssize_t counter = static_cast<ssize_t>(index);
340
341 while (ptr < end && counter >= 0) {
342 // Scan for a closing zero.
343 const char* str_end = ParseString(ptr, end);
344 if (str_end < end) {
345 const char* maybe_key = ptr;
346 ptr = ParseString(str_end + 1, end) + 1;
347 if (ptr <= end) {
348 if (counter == 0) {
349 *key = maybe_key;
350 *value = str_end + 1;
351 return true;
352 } else {
353 counter--;
354 }
355 } else {
356 return false;
357 }
358 } else {
359 break;
360 }
361 }
362 // Not found.
363 return false;
364}
365
366size_t OatHeader::GetHeaderSize() const {
367 return sizeof(OatHeader) + key_value_store_size_;
368}
369
Sebastien Hertz0de11332015-05-13 12:14:05 +0200370bool OatHeader::IsDebuggable() const {
371 return IsKeyEnabled(OatHeader::kDebuggableKey);
372}
373
Andreas Gampef8cd8902017-01-18 16:05:01 -0800374bool OatHeader::IsConcurrentCopying() const {
375 return IsKeyEnabled(OatHeader::kConcurrentCopying);
376}
377
David Srbecky5d950762016-03-07 20:47:29 +0000378bool OatHeader::IsNativeDebuggable() const {
379 return IsKeyEnabled(OatHeader::kNativeDebuggableKey);
380}
381
Andreas Gampe7bcfcb82016-03-23 15:31:51 +0000382CompilerFilter::Filter OatHeader::GetCompilerFilter() const {
383 CompilerFilter::Filter filter;
384 const char* key_value = GetStoreValueByKey(kCompilerFilter);
385 CHECK(key_value != nullptr) << "compiler-filter not found in oat header";
386 CHECK(CompilerFilter::ParseCompilerFilter(key_value, &filter))
387 << "Invalid compiler-filter in oat header: " << key_value;
388 return filter;
Calin Juravleb077e152016-02-18 18:47:37 +0000389}
390
391bool OatHeader::KeyHasValue(const char* key, const char* value, size_t value_size) const {
392 const char* key_value = GetStoreValueByKey(key);
393 return (key_value != nullptr && strncmp(key_value, value, value_size) == 0);
David Brazdilce4b0ba2016-01-28 15:05:49 +0000394}
395
Sebastien Hertz0de11332015-05-13 12:14:05 +0200396bool OatHeader::IsKeyEnabled(const char* key) const {
Calin Juravleb077e152016-02-18 18:47:37 +0000397 return KeyHasValue(key, kTrueValue, sizeof(kTrueValue));
Igor Murashkin46774762014-10-22 11:37:02 -0700398}
399
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700400void OatHeader::Flatten(const SafeMap<std::string, std::string>* key_value_store) {
401 char* data_ptr = reinterpret_cast<char*>(&key_value_store_);
402 if (key_value_store != nullptr) {
403 SafeMap<std::string, std::string>::const_iterator it = key_value_store->begin();
404 SafeMap<std::string, std::string>::const_iterator end = key_value_store->end();
405 for ( ; it != end; ++it) {
Andreas Gampef45d61c2017-06-07 10:29:33 -0700406 strlcpy(data_ptr, it->first.c_str(), it->first.length() + 1);
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700407 data_ptr += it->first.length() + 1;
Andreas Gampef45d61c2017-06-07 10:29:33 -0700408 strlcpy(data_ptr, it->second.c_str(), it->second.length() + 1);
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700409 data_ptr += it->second.length() + 1;
410 }
411 }
412 key_value_store_size_ = data_ptr - reinterpret_cast<char*>(&key_value_store_);
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700413}
414
Brian Carlstrome24fa612011-09-29 00:53:55 -0700415} // namespace art