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

Side by Side Diff: runtime/vm/object.h

Issue 2473553002: Fix unaligned access to TypedData from native code. (Closed)
Patch Set: Created 4 years, 1 month 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 | tests/language/language.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef RUNTIME_VM_OBJECT_H_ 5 #ifndef RUNTIME_VM_OBJECT_H_
6 #define RUNTIME_VM_OBJECT_H_ 6 #define RUNTIME_VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 7915 matching lines...) Expand 10 before | Expand all | Expand 10 after
7926 return reinterpret_cast<void*>( 7926 return reinterpret_cast<void*>(
7927 UnsafeMutableNonPointer(raw_ptr()->data()) + byte_offset); 7927 UnsafeMutableNonPointer(raw_ptr()->data()) + byte_offset);
7928 } 7928 }
7929 7929
7930 virtual bool CanonicalizeEquals(const Instance& other) const; 7930 virtual bool CanonicalizeEquals(const Instance& other) const;
7931 virtual uword ComputeCanonicalTableHash() const; 7931 virtual uword ComputeCanonicalTableHash() const;
7932 7932
7933 #define TYPED_GETTER_SETTER(name, type) \ 7933 #define TYPED_GETTER_SETTER(name, type) \
7934 type Get##name(intptr_t byte_offset) const { \ 7934 type Get##name(intptr_t byte_offset) const { \
7935 NoSafepointScope no_safepoint; \ 7935 NoSafepointScope no_safepoint; \
7936 return *reinterpret_cast<type*>(DataAddr(byte_offset)); \ 7936 type result; \
7937 memmove(&result, DataAddr(byte_offset), sizeof(type)); \
zra 2016/11/01 21:46:01 Should we specialize this by architecture?
Cutch 2016/11/01 21:48:21 +1 We should avoid calling memmove on architecture
7938 return result; \
7937 } \ 7939 } \
7938 void Set##name(intptr_t byte_offset, type value) const { \ 7940 void Set##name(intptr_t byte_offset, type value) const { \
7939 NoSafepointScope no_safepoint; \ 7941 NoSafepointScope no_safepoint; \
7940 *reinterpret_cast<type*>(DataAddr(byte_offset)) = value; \ 7942 memmove(DataAddr(byte_offset), &value, sizeof(type)); \
7941 } 7943 }
7942 TYPED_GETTER_SETTER(Int8, int8_t) 7944 TYPED_GETTER_SETTER(Int8, int8_t)
7943 TYPED_GETTER_SETTER(Uint8, uint8_t) 7945 TYPED_GETTER_SETTER(Uint8, uint8_t)
7944 TYPED_GETTER_SETTER(Int16, int16_t) 7946 TYPED_GETTER_SETTER(Int16, int16_t)
7945 TYPED_GETTER_SETTER(Uint16, uint16_t) 7947 TYPED_GETTER_SETTER(Uint16, uint16_t)
7946 TYPED_GETTER_SETTER(Int32, int32_t) 7948 TYPED_GETTER_SETTER(Int32, int32_t)
7947 TYPED_GETTER_SETTER(Uint32, uint32_t) 7949 TYPED_GETTER_SETTER(Uint32, uint32_t)
7948 TYPED_GETTER_SETTER(Int64, int64_t) 7950 TYPED_GETTER_SETTER(Int64, int64_t)
7949 TYPED_GETTER_SETTER(Uint64, uint64_t) 7951 TYPED_GETTER_SETTER(Uint64, uint64_t)
7950 TYPED_GETTER_SETTER(Float32, float) 7952 TYPED_GETTER_SETTER(Float32, float)
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after
9011 9013
9012 inline void TypeArguments::SetHash(intptr_t value) const { 9014 inline void TypeArguments::SetHash(intptr_t value) const {
9013 // This is only safe because we create a new Smi, which does not cause 9015 // This is only safe because we create a new Smi, which does not cause
9014 // heap allocation. 9016 // heap allocation.
9015 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 9017 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
9016 } 9018 }
9017 9019
9018 } // namespace dart 9020 } // namespace dart
9019 9021
9020 #endif // RUNTIME_VM_OBJECT_H_ 9022 #endif // RUNTIME_VM_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698