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

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 7912 matching lines...) Expand 10 before | Expand all | Expand 10 after
7923 void* DataAddr(intptr_t byte_offset) const { 7923 void* DataAddr(intptr_t byte_offset) const {
7924 ASSERT((byte_offset == 0) || 7924 ASSERT((byte_offset == 0) ||
7925 ((byte_offset > 0) && (byte_offset < LengthInBytes()))); 7925 ((byte_offset > 0) && (byte_offset < LengthInBytes())));
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 #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
7933 #define TYPED_GETTER_SETTER(name, type) \ 7934 #define TYPED_GETTER_SETTER(name, type) \
7934 type Get##name(intptr_t byte_offset) const { \ 7935 type Get##name(intptr_t byte_offset) const { \
7935 NoSafepointScope no_safepoint; \ 7936 NoSafepointScope no_safepoint; \
7936 return *reinterpret_cast<type*>(DataAddr(byte_offset)); \ 7937 return *reinterpret_cast<type*>(DataAddr(byte_offset)); \
7937 } \ 7938 } \
7938 void Set##name(intptr_t byte_offset, type value) const { \ 7939 void Set##name(intptr_t byte_offset, type value) const { \
7939 NoSafepointScope no_safepoint; \ 7940 NoSafepointScope no_safepoint; \
7940 *reinterpret_cast<type*>(DataAddr(byte_offset)) = value; \ 7941 *reinterpret_cast<type*>(DataAddr(byte_offset)) = value; \
7941 } 7942 }
7943 #else // defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
7944 #define TYPED_GETTER_SETTER(name, type) \
7945 type Get##name(intptr_t byte_offset) const { \
7946 NoSafepointScope no_safepoint; \
7947 type result; \
7948 memmove(&result, DataAddr(byte_offset), sizeof(type)); \
7949 return result; \
7950 } \
7951 void Set##name(intptr_t byte_offset, type value) const { \
7952 NoSafepointScope no_safepoint; \
7953 memmove(DataAddr(byte_offset), &value, sizeof(type)); \
7954 }
7955 #endif // defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
7956
7942 TYPED_GETTER_SETTER(Int8, int8_t) 7957 TYPED_GETTER_SETTER(Int8, int8_t)
7943 TYPED_GETTER_SETTER(Uint8, uint8_t) 7958 TYPED_GETTER_SETTER(Uint8, uint8_t)
7944 TYPED_GETTER_SETTER(Int16, int16_t) 7959 TYPED_GETTER_SETTER(Int16, int16_t)
7945 TYPED_GETTER_SETTER(Uint16, uint16_t) 7960 TYPED_GETTER_SETTER(Uint16, uint16_t)
7946 TYPED_GETTER_SETTER(Int32, int32_t) 7961 TYPED_GETTER_SETTER(Int32, int32_t)
7947 TYPED_GETTER_SETTER(Uint32, uint32_t) 7962 TYPED_GETTER_SETTER(Uint32, uint32_t)
7948 TYPED_GETTER_SETTER(Int64, int64_t) 7963 TYPED_GETTER_SETTER(Int64, int64_t)
7949 TYPED_GETTER_SETTER(Uint64, uint64_t) 7964 TYPED_GETTER_SETTER(Uint64, uint64_t)
7950 TYPED_GETTER_SETTER(Float32, float) 7965 TYPED_GETTER_SETTER(Float32, float)
7951 TYPED_GETTER_SETTER(Float64, double) 7966 TYPED_GETTER_SETTER(Float64, double)
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after
9011 9026
9012 inline void TypeArguments::SetHash(intptr_t value) const { 9027 inline void TypeArguments::SetHash(intptr_t value) const {
9013 // This is only safe because we create a new Smi, which does not cause 9028 // This is only safe because we create a new Smi, which does not cause
9014 // heap allocation. 9029 // heap allocation.
9015 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 9030 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
9016 } 9031 }
9017 9032
9018 } // namespace dart 9033 } // namespace dart
9019 9034
9020 #endif // RUNTIME_VM_OBJECT_H_ 9035 #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