Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/snapshot/serializer-common.h

Issue 2915323002: v8: Fix unaligned access when deserializing snapshots. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_SNAPSHOT_SERIALIZER_COMMON_H_ 5 #ifndef V8_SNAPSHOT_SERIALIZER_COMMON_H_
6 #define V8_SNAPSHOT_SERIALIZER_COMMON_H_ 6 #define V8_SNAPSHOT_SERIALIZER_COMMON_H_
7 7
8 #include "src/address-map.h" 8 #include "src/address-map.h"
9 #include "src/external-reference-table.h" 9 #include "src/external-reference-table.h"
10 #include "src/globals.h" 10 #include "src/globals.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 264 }
265 265
266 static const int kMagicNumberOffset = 0; 266 static const int kMagicNumberOffset = 0;
267 static const int kExtraExternalReferencesOffset = 267 static const int kExtraExternalReferencesOffset =
268 kMagicNumberOffset + kInt32Size; 268 kMagicNumberOffset + kInt32Size;
269 static const int kVersionHashOffset = 269 static const int kVersionHashOffset =
270 kExtraExternalReferencesOffset + kInt32Size; 270 kExtraExternalReferencesOffset + kInt32Size;
271 271
272 protected: 272 protected:
273 void SetHeaderValue(int offset, uint32_t value) { 273 void SetHeaderValue(int offset, uint32_t value) {
274 uint32_t* address = reinterpret_cast<uint32_t*>(data_ + offset); 274 memcpy(data_ + offset, &value, sizeof(value));
275 memcpy(reinterpret_cast<uint32_t*>(address), &value, sizeof(value));
276 } 275 }
277 276
278 uint32_t GetHeaderValue(int offset) const { 277 uint32_t GetHeaderValue(int offset) const {
279 uint32_t value; 278 uint32_t value;
280 memcpy(&value, reinterpret_cast<int*>(data_ + offset), sizeof(value)); 279 memcpy(&value, data_ + offset, sizeof(value));
281 return value; 280 return value;
282 } 281 }
283 282
284 void AllocateData(int size); 283 void AllocateData(int size);
285 284
286 static uint32_t ComputeMagicNumber(Isolate* isolate) { 285 static uint32_t ComputeMagicNumber(Isolate* isolate) {
287 return ComputeMagicNumber(ExternalReferenceTable::instance(isolate)); 286 return ComputeMagicNumber(ExternalReferenceTable::instance(isolate));
288 } 287 }
289 static uint32_t GetExtraReferences(Isolate* isolate) { 288 static uint32_t GetExtraReferences(Isolate* isolate) {
290 return GetExtraReferences(ExternalReferenceTable::instance(isolate)); 289 return GetExtraReferences(ExternalReferenceTable::instance(isolate));
291 } 290 }
292 291
293 void SetMagicNumber(Isolate* isolate) { 292 void SetMagicNumber(Isolate* isolate) {
294 SetHeaderValue(kMagicNumberOffset, ComputeMagicNumber(isolate)); 293 SetHeaderValue(kMagicNumberOffset, ComputeMagicNumber(isolate));
295 SetHeaderValue(kExtraExternalReferencesOffset, GetExtraReferences(isolate)); 294 SetHeaderValue(kExtraExternalReferencesOffset, GetExtraReferences(isolate));
296 } 295 }
297 296
298 byte* data_; 297 byte* data_;
299 int size_; 298 int size_;
300 bool owns_data_; 299 bool owns_data_;
301 300
302 private: 301 private:
303 DISALLOW_COPY_AND_ASSIGN(SerializedData); 302 DISALLOW_COPY_AND_ASSIGN(SerializedData);
304 }; 303 };
305 304
306 } // namespace internal 305 } // namespace internal
307 } // namespace v8 306 } // namespace v8
308 307
309 #endif // V8_SNAPSHOT_SERIALIZER_COMMON_H_ 308 #endif // V8_SNAPSHOT_SERIALIZER_COMMON_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698