17 #ifndef ABSL_BASE_INTERNAL_UNALIGNED_ACCESS_H_ 18 #define ABSL_BASE_INTERNAL_UNALIGNED_ACCESS_H_ 31 #if defined(__cplusplus) 33 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) ||\ 34 defined(MEMORY_SANITIZER) 50 uint16_t __sanitizer_unaligned_load16(
const void *p);
51 uint32_t __sanitizer_unaligned_load32(
const void *p);
52 uint64_t __sanitizer_unaligned_load64(
const void *p);
53 void __sanitizer_unaligned_store16(
void *p, uint16_t
v);
54 void __sanitizer_unaligned_store32(
void *p, uint32_t
v);
55 void __sanitizer_unaligned_store64(
void *p, uint64_t
v);
59 namespace base_internal {
61 inline uint16_t UnalignedLoad16(
const void *p) {
62 return __sanitizer_unaligned_load16(p);
65 inline uint32_t UnalignedLoad32(
const void *p) {
66 return __sanitizer_unaligned_load32(p);
69 inline uint64_t UnalignedLoad64(
const void *p) {
70 return __sanitizer_unaligned_load64(p);
73 inline void UnalignedStore16(
void *p, uint16_t
v) {
74 __sanitizer_unaligned_store16(p, v);
77 inline void UnalignedStore32(
void *p, uint32_t
v) {
78 __sanitizer_unaligned_store32(p, v);
81 inline void UnalignedStore64(
void *p, uint64_t
v) {
82 __sanitizer_unaligned_store64(p, v);
88 #define ABSL_INTERNAL_UNALIGNED_LOAD16(_p) \ 89 (absl::base_internal::UnalignedLoad16(_p)) 90 #define ABSL_INTERNAL_UNALIGNED_LOAD32(_p) \ 91 (absl::base_internal::UnalignedLoad32(_p)) 92 #define ABSL_INTERNAL_UNALIGNED_LOAD64(_p) \ 93 (absl::base_internal::UnalignedLoad64(_p)) 95 #define ABSL_INTERNAL_UNALIGNED_STORE16(_p, _val) \ 96 (absl::base_internal::UnalignedStore16(_p, _val)) 97 #define ABSL_INTERNAL_UNALIGNED_STORE32(_p, _val) \ 98 (absl::base_internal::UnalignedStore32(_p, _val)) 99 #define ABSL_INTERNAL_UNALIGNED_STORE64(_p, _val) \ 100 (absl::base_internal::UnalignedStore64(_p, _val)) 105 namespace base_internal {
107 inline uint16_t UnalignedLoad16(
const void *p) {
109 memcpy(&t, p,
sizeof t);
113 inline uint32_t UnalignedLoad32(
const void *p) {
115 memcpy(&t, p,
sizeof t);
119 inline uint64_t UnalignedLoad64(
const void *p) {
121 memcpy(&t, p,
sizeof t);
125 inline void UnalignedStore16(
void *p, uint16_t
v) { memcpy(p, &v,
sizeof v); }
127 inline void UnalignedStore32(
void *p, uint32_t
v) { memcpy(p, &v,
sizeof v); }
129 inline void UnalignedStore64(
void *p, uint64_t
v) { memcpy(p, &v,
sizeof v); }
134 #define ABSL_INTERNAL_UNALIGNED_LOAD16(_p) \ 135 (absl::base_internal::UnalignedLoad16(_p)) 136 #define ABSL_INTERNAL_UNALIGNED_LOAD32(_p) \ 137 (absl::base_internal::UnalignedLoad32(_p)) 138 #define ABSL_INTERNAL_UNALIGNED_LOAD64(_p) \ 139 (absl::base_internal::UnalignedLoad64(_p)) 141 #define ABSL_INTERNAL_UNALIGNED_STORE16(_p, _val) \ 142 (absl::base_internal::UnalignedStore16(_p, _val)) 143 #define ABSL_INTERNAL_UNALIGNED_STORE32(_p, _val) \ 144 (absl::base_internal::UnalignedStore32(_p, _val)) 145 #define ABSL_INTERNAL_UNALIGNED_STORE64(_p, _val) \ 146 (absl::base_internal::UnalignedStore64(_p, _val)) 150 #endif // defined(__cplusplus), end of unaligned API 152 #endif // ABSL_BASE_INTERNAL_UNALIGNED_ACCESS_H_