diff --git a/BUILD b/BUILD index b62e93fb3e2..7b2a3966d86 100644 --- a/BUILD +++ b/BUILD @@ -1377,6 +1377,7 @@ perfetto_filegroup( srcs = [ "include/perfetto/base/build_config.h", "include/perfetto/base/compiler.h", + "include/perfetto/base/endian.h", "include/perfetto/base/export.h", "include/perfetto/base/flat_set.h", "include/perfetto/base/logging.h", @@ -1415,7 +1416,6 @@ perfetto_filegroup( "include/perfetto/ext/base/crash_keys.h", "include/perfetto/ext/base/ctrl_c_handler.h", "include/perfetto/ext/base/dynamic_string_writer.h", - "include/perfetto/ext/base/endian.h", "include/perfetto/ext/base/event_fd.h", "include/perfetto/ext/base/file_utils.h", "include/perfetto/ext/base/flags.h", diff --git a/gn/standalone/android.gni b/gn/standalone/android.gni index 3b82104369d..c9972f1fad7 100644 --- a/gn/standalone/android.gni +++ b/gn/standalone/android.gni @@ -44,7 +44,9 @@ declare_args() { android_abi_target = "aarch64-linux-android" android_llvm_arch = "aarch64" } else { - assert(false, "Need android libgcc support for this arch.") + assert(target_os != "android", "Need android libgcc support for this arch.") + android_abi_target = "" + android_llvm_arch = "" } if (current_cpu == "x86") { @@ -56,6 +58,7 @@ declare_args() { } else if (current_cpu == "arm64") { android_app_abi = "arm64-v8a" } else { - assert(false, "Unknown ABI: " + current_cpu) + assert(target_os != "android", "Unknown ABI: " + current_cpu) + android_app_abi = "" } } diff --git a/include/perfetto/base/BUILD.gn b/include/perfetto/base/BUILD.gn index 1fa5c9d536f..79c438c0721 100644 --- a/include/perfetto/base/BUILD.gn +++ b/include/perfetto/base/BUILD.gn @@ -18,6 +18,7 @@ source_set("base") { sources = [ "build_config.h", "compiler.h", + "endian.h", "export.h", "flat_set.h", "logging.h", diff --git a/include/perfetto/base/compiler.h b/include/perfetto/base/compiler.h index d0406c8dbab..8ffa94a0507 100644 --- a/include/perfetto/base/compiler.h +++ b/include/perfetto/base/compiler.h @@ -113,7 +113,7 @@ extern "C" void __msan_unpoison(void const volatile*, size_t); #endif // __clang__ #if defined(__GNUC__) || defined(__clang__) -#define PERFETTO_IS_LITTLE_ENDIAN() __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define PERFETTO_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) #else // Assume all MSVC targets are little endian. #define PERFETTO_IS_LITTLE_ENDIAN() 1 diff --git a/include/perfetto/base/endian.h b/include/perfetto/base/endian.h new file mode 100644 index 00000000000..269e9971dd0 --- /dev/null +++ b/include/perfetto/base/endian.h @@ -0,0 +1,249 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INCLUDE_PERFETTO_BASE_ENDIAN_H_ +#define INCLUDE_PERFETTO_BASE_ENDIAN_H_ + +#include +#include // For MSVC +#include + +#include "perfetto/base/build_config.h" +#include "perfetto/base/compiler.h" + +namespace perfetto { +namespace base { + +#if PERFETTO_BUILDFLAG(PERFETTO_COMPILER_MSVC) +inline uint16_t ByteSwap16(uint16_t x) { + return _byteswap_ushort(x); +} +inline uint32_t ByteSwap32(uint32_t x) { + return _byteswap_ulong(x); +} +inline uint64_t ByteSwap64(uint64_t x) { + return _byteswap_uint64(x); +} +#else +inline uint16_t ByteSwap16(uint16_t x) { + return __builtin_bswap16(x); +} +inline uint32_t ByteSwap32(uint32_t x) { + return __builtin_bswap32(x); +} +inline uint64_t ByteSwap64(uint64_t x) { + return __builtin_bswap64(x); +} +#endif + +#if PERFETTO_IS_LITTLE_ENDIAN() +inline uint16_t HostToLE16(uint16_t x) { + return x; +} +inline uint32_t HostToLE32(uint32_t x) { + return x; +} +inline uint64_t HostToLE64(uint64_t x) { + return x; +} +inline uint16_t LE16ToHost(uint16_t x) { + return x; +} +inline uint32_t LE32ToHost(uint32_t x) { + return x; +} +inline uint64_t LE64ToHost(uint64_t x) { + return x; +} +inline uint16_t HostToBE16(uint16_t x) { + return ByteSwap16(x); +} +inline uint32_t HostToBE32(uint32_t x) { + return ByteSwap32(x); +} +inline uint64_t HostToBE64(uint64_t x) { + return ByteSwap64(x); +} +inline uint16_t BE16ToHost(uint16_t x) { + return ByteSwap16(x); +} +inline uint32_t BE32ToHost(uint32_t x) { + return ByteSwap32(x); +} +inline uint64_t BE64ToHost(uint64_t x) { + return ByteSwap64(x); +} +inline float HostToLEFloat(float x) { + return x; +} +inline double HostToLEDouble(double x) { + return x; +} +inline float LEFloatToHost(float x) { + return x; +} +inline double LEDoubleToHost(double x) { + return x; +} +inline float HostToBEFloat(float x) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap32(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline double HostToBEDouble(double x) { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap64(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline float BEFloatToHost(float x) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap32(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline double BEDoubleToHost(double x) { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap64(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +#else +inline uint16_t HostToLE16(uint16_t x) { + return ByteSwap16(x); +} +inline uint32_t HostToLE32(uint32_t x) { + return ByteSwap32(x); +} +inline uint64_t HostToLE64(uint64_t x) { + return ByteSwap64(x); +} +inline uint16_t LE16ToHost(uint16_t x) { + return ByteSwap16(x); +} +inline uint32_t LE32ToHost(uint32_t x) { + return ByteSwap32(x); +} +inline uint64_t LE64ToHost(uint64_t x) { + return ByteSwap64(x); +} +inline uint16_t HostToBE16(uint16_t x) { + return x; +} +inline uint32_t HostToBE32(uint32_t x) { + return x; +} +inline uint64_t HostToBE64(uint64_t x) { + return x; +} +inline uint16_t BE16ToHost(uint16_t x) { + return x; +} +inline uint32_t BE32ToHost(uint32_t x) { + return x; +} +inline uint64_t BE64ToHost(uint64_t x) { + return x; +} +inline float HostToLEFloat(float x) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap32(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline double HostToLEDouble(double x) { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap64(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline float LEFloatToHost(float x) { + uint32_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap32(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline double LEDoubleToHost(double x) { + uint64_t u; + memcpy(&u, &x, sizeof(u)); + u = ByteSwap64(u); + memcpy(&x, &u, sizeof(u)); + return x; +} +inline float HostToBEFloat(float x) { + return x; +} +inline double HostToBEDouble(double x) { + return x; +} +inline float BEFloatToHost(float x) { + return x; +} +inline double BEDoubleToHost(double x) { + return x; +} +#endif + +inline uint32_t HostToLE(uint32_t x) { + return HostToLE32(x); +} +inline int32_t HostToLE(int32_t x) { + return static_cast(HostToLE32(static_cast(x))); +} +inline uint64_t HostToLE(uint64_t x) { + return HostToLE64(x); +} +inline int64_t HostToLE(int64_t x) { + return static_cast(HostToLE64(static_cast(x))); +} +inline float HostToLE(float x) { + return HostToLEFloat(x); +} +inline double HostToLE(double x) { + return HostToLEDouble(x); +} + +inline uint32_t LEToHost(uint32_t x) { + return LE32ToHost(x); +} +inline int32_t LEToHost(int32_t x) { + return static_cast(LE32ToHost(static_cast(x))); +} +inline uint64_t LEToHost(uint64_t x) { + return LE64ToHost(x); +} +inline int64_t LEToHost(int64_t x) { + return static_cast(LE64ToHost(static_cast(x))); +} +inline float LEToHost(float x) { + return LEFloatToHost(x); +} +inline double LEToHost(double x) { + return LEDoubleToHost(x); +} + +} // namespace base +} // namespace perfetto + +#endif // INCLUDE_PERFETTO_BASE_ENDIAN_H_ diff --git a/include/perfetto/ext/base/BUILD.gn b/include/perfetto/ext/base/BUILD.gn index 653908960ab..b543f0784f8 100644 --- a/include/perfetto/ext/base/BUILD.gn +++ b/include/perfetto/ext/base/BUILD.gn @@ -27,7 +27,6 @@ source_set("base") { "crash_keys.h", "ctrl_c_handler.h", "dynamic_string_writer.h", - "endian.h", "event_fd.h", "file_utils.h", "flags.h", diff --git a/include/perfetto/ext/base/endian.h b/include/perfetto/ext/base/endian.h deleted file mode 100644 index d4bac901881..00000000000 --- a/include/perfetto/ext/base/endian.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef INCLUDE_PERFETTO_EXT_BASE_ENDIAN_H_ -#define INCLUDE_PERFETTO_EXT_BASE_ENDIAN_H_ - -#include -#include // For MSVC - -#include "perfetto/base/build_config.h" -#include "perfetto/base/compiler.h" - -#if !PERFETTO_IS_LITTLE_ENDIAN() -#error "endian.h supports only little-endian archs" -#endif - -namespace perfetto { -namespace base { - -#if PERFETTO_BUILDFLAG(PERFETTO_COMPILER_MSVC) -inline uint16_t HostToBE16(uint16_t x) { - return _byteswap_ushort(x); -} -inline uint32_t HostToBE32(uint32_t x) { - return _byteswap_ulong(x); -} -inline uint64_t HostToBE64(uint64_t x) { - return _byteswap_uint64(x); -} -inline uint16_t BE16ToHost(uint16_t x) { - return _byteswap_ushort(x); -} -inline uint32_t BE32ToHost(uint32_t x) { - return _byteswap_ulong(x); -} -inline uint64_t BE64ToHost(uint64_t x) { - return _byteswap_uint64(x); -} -#else -inline uint16_t HostToBE16(uint16_t x) { - return __builtin_bswap16(x); -} -inline uint32_t HostToBE32(uint32_t x) { - return __builtin_bswap32(x); -} -inline uint64_t HostToBE64(uint64_t x) { - return __builtin_bswap64(x); -} -inline uint16_t BE16ToHost(uint16_t x) { - return __builtin_bswap16(x); -} -inline uint32_t BE32ToHost(uint32_t x) { - return __builtin_bswap32(x); -} -inline uint64_t BE64ToHost(uint64_t x) { - return __builtin_bswap64(x); -} -#endif - -} // namespace base -} // namespace perfetto - -#endif // INCLUDE_PERFETTO_EXT_BASE_ENDIAN_H_ diff --git a/include/perfetto/ext/base/uuid.h b/include/perfetto/ext/base/uuid.h index 4dd2a788600..dd5b6f81d24 100644 --- a/include/perfetto/ext/base/uuid.h +++ b/include/perfetto/ext/base/uuid.h @@ -22,6 +22,7 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/export.h" namespace perfetto { @@ -43,23 +44,29 @@ class PERFETTO_EXPORT_COMPONENT Uuid { explicit operator bool() const { return *this != Uuid(); } int64_t msb() const { - int64_t result; + uint64_t result; memcpy(&result, data_.data() + 8, 8); - return result; + return static_cast(LE64ToHost(result)); } int64_t lsb() const { - int64_t result; + uint64_t result; memcpy(&result, data_.data(), 8); - return result; + return static_cast(LE64ToHost(result)); } void set_lsb_msb(int64_t lsb, int64_t msb) { set_lsb(lsb); set_msb(msb); } - void set_msb(int64_t msb) { memcpy(data_.data() + 8, &msb, 8); } - void set_lsb(int64_t lsb) { memcpy(data_.data(), &lsb, 8); } + void set_msb(int64_t msb) { + uint64_t le = HostToLE64(static_cast(msb)); + memcpy(data_.data() + 8, &le, 8); + } + void set_lsb(int64_t lsb) { + uint64_t le = HostToLE64(static_cast(lsb)); + memcpy(data_.data(), &le, 8); + } std::string ToString() const; std::string ToPrettyString() const; diff --git a/include/perfetto/protozero/message.h b/include/perfetto/protozero/message.h index 1bcadaf688b..55ed0531f2f 100644 --- a/include/perfetto/protozero/message.h +++ b/include/perfetto/protozero/message.h @@ -24,6 +24,7 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/export.h" #include "perfetto/base/logging.h" #include "perfetto/protozero/contiguous_memory_range.h" @@ -135,7 +136,8 @@ class PERFETTO_EXPORT_COMPONENT Message { uint8_t* pos = buffer; pos = proto_utils::WriteVarInt(proto_utils::MakeTagFixed(field_id), pos); - memcpy(pos, &value, sizeof(T)); + T le_value = perfetto::base::HostToLE(value); + memcpy(pos, &le_value, sizeof(T)); pos += sizeof(T); // TODO: Optimize memcpy performance, see http://crbug.com/624311 . WriteToStream(buffer, pos); diff --git a/include/perfetto/protozero/packed_repeated_fields.h b/include/perfetto/protozero/packed_repeated_fields.h index dff45e7cb89..ed5ada6e867 100644 --- a/include/perfetto/protozero/packed_repeated_fields.h +++ b/include/perfetto/protozero/packed_repeated_fields.h @@ -23,6 +23,7 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" #include "perfetto/protozero/proto_utils.h" @@ -105,7 +106,8 @@ class PackedFixedSizeInt : public PackedBufferBase { "kMaxElementSize needs to be updated"); GrowIfNeeded(); PERFETTO_DCHECK(reinterpret_cast(write_ptr_) % alignof(T) == 0); - memcpy(reinterpret_cast(write_ptr_), &value, sizeof(T)); + T le_value = perfetto::base::HostToLE(value); + memcpy(reinterpret_cast(write_ptr_), &le_value, sizeof(T)); write_ptr_ += sizeof(T); } }; diff --git a/include/perfetto/protozero/proto_decoder.h b/include/perfetto/protozero/proto_decoder.h index 6cb299b3136..dd57983eb55 100644 --- a/include/perfetto/protozero/proto_decoder.h +++ b/include/perfetto/protozero/proto_decoder.h @@ -27,6 +27,7 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/export.h" #include "perfetto/base/logging.h" #include "perfetto/protozero/field.h" @@ -224,7 +225,7 @@ class PackedRepeatedFieldIterator { return *this; } - if (wire_type == ProtoWireType::kVarInt) { + if constexpr (wire_type == ProtoWireType::kVarInt) { uint64_t new_value = 0; const uint8_t* new_pos = proto_utils::ParseVarInt(read_ptr_, data_end_, &new_value); @@ -243,6 +244,7 @@ class PackedRepeatedFieldIterator { // NB: the raw buffer is not guaranteed to be aligned, so neither are // these copies. memcpy(&curr_value_, read_ptr_, sizeof(CppType)); + curr_value_ = perfetto::base::LEToHost(curr_value_); read_ptr_ += kStep; } diff --git a/include/perfetto/protozero/proto_utils.h b/include/perfetto/protozero/proto_utils.h index ce8b24e279c..defbaf57a3c 100644 --- a/include/perfetto/protozero/proto_utils.h +++ b/include/perfetto/protozero/proto_utils.h @@ -22,6 +22,7 @@ #include #include +#include "perfetto/base/compiler.h" #include "perfetto/base/logging.h" #include "perfetto/public/compiler.h" #include "perfetto/public/pb_utils.h" diff --git a/src/base/http/http_server.cc b/src/base/http/http_server.cc index f6c8c398f49..2ab9707a217 100644 --- a/src/base/http/http_server.cc +++ b/src/base/http/http_server.cc @@ -30,9 +30,9 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" #include "perfetto/ext/base/base64.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/http/sha1.h" #include "perfetto/ext/base/paged_memory.h" #include "perfetto/ext/base/string_utils.h" diff --git a/src/protozero/field.cc b/src/protozero/field.cc index 881ee4a1d9f..d6189e35338 100644 --- a/src/protozero/field.cc +++ b/src/protozero/field.cc @@ -17,14 +17,9 @@ #include "perfetto/protozero/field.h" #include "perfetto/base/compiler.h" +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" -#if !PERFETTO_IS_LITTLE_ENDIAN() -// The memcpy() for fixed32/64 below needs to be adjusted if we want to -// support big endian CPUs. There doesn't seem to be a compelling need today. -#error Unimplemented for big endian archs. -#endif - namespace protozero { template @@ -42,14 +37,16 @@ void Field::SerializeAndAppendToInternal(Container* dst) const { } case static_cast(pu::ProtoWireType::kFixed32): { wptr = pu::WriteVarInt(pu::MakeTagFixed(id_), wptr); - uint32_t value32 = static_cast(int_value_); + uint32_t value32 = + perfetto::base::HostToLE(static_cast(int_value_)); memcpy(wptr, &value32, sizeof(value32)); wptr += sizeof(uint32_t); break; } case static_cast(pu::ProtoWireType::kFixed64): { wptr = pu::WriteVarInt(pu::MakeTagFixed(id_), wptr); - memcpy(wptr, &int_value_, sizeof(int_value_)); + uint64_t value64 = perfetto::base::HostToLE(int_value_); + memcpy(wptr, &value64, sizeof(value64)); wptr += sizeof(uint64_t); break; } diff --git a/src/protozero/filtering/filter_bytecode_generator.cc b/src/protozero/filtering/filter_bytecode_generator.cc index d52b5bf0d0c..59583b0f0ee 100644 --- a/src/protozero/filtering/filter_bytecode_generator.cc +++ b/src/protozero/filtering/filter_bytecode_generator.cc @@ -20,9 +20,11 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/packed_repeated_fields.h" +#include "perfetto/protozero/proto_utils.h" #include "src/protozero/filtering/filter_bytecode_common.h" namespace protozero { @@ -144,7 +146,7 @@ FilterBytecodeGenerator::SerializeResult FilterBytecodeGenerator::Serialize() { perfetto::base::FnvHasher hasher; for (uint32_t word : bytecode_) { words.Append(word); - hasher.Update(word); + hasher.Update(perfetto::base::HostToLE(word)); } words.Append(static_cast(hasher.digest())); result.bytecode = @@ -157,7 +159,7 @@ FilterBytecodeGenerator::SerializeResult FilterBytecodeGenerator::Serialize() { perfetto::base::FnvHasher hasher; for (uint32_t word : v54_overlay_) { words.Append(word); - hasher.Update(word); + hasher.Update(perfetto::base::HostToLE(word)); } words.Append(static_cast(hasher.digest())); result.v54_overlay = diff --git a/src/protozero/filtering/filter_bytecode_parser.cc b/src/protozero/filtering/filter_bytecode_parser.cc index c199f155807..ec11410a62b 100644 --- a/src/protozero/filtering/filter_bytecode_parser.cc +++ b/src/protozero/filtering/filter_bytecode_parser.cc @@ -22,6 +22,7 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/proto_decoder.h" @@ -62,7 +63,7 @@ bool ParseAndVerifyChecksum(const uint8_t* data, break; } words->emplace_back(word); - hasher.Update(word); + hasher.Update(perfetto::base::HostToLE(word)); } if (packed_parse_err || !has_checksum) { words->clear(); diff --git a/src/protozero/filtering/filter_bytecode_parser_unittest.cc b/src/protozero/filtering/filter_bytecode_parser_unittest.cc index 98b2ecf4b2f..a166bd88b10 100644 --- a/src/protozero/filtering/filter_bytecode_parser_unittest.cc +++ b/src/protozero/filtering/filter_bytecode_parser_unittest.cc @@ -20,8 +20,10 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/ext/base/fnv_hash.h" #include "perfetto/protozero/packed_repeated_fields.h" +#include "perfetto/protozero/proto_utils.h" #include "src/protozero/filtering/filter_bytecode_common.h" #include "test/gtest_and_gmock.h" @@ -35,7 +37,7 @@ bool LoadBytecode(FilterBytecodeParser* parser, protozero::PackedVarInt words; for (uint32_t w : bytecode) { words.Append(w); - hasher.Update(w); + hasher.Update(perfetto::base::HostToLE(w)); } words.Append(static_cast(hasher.digest())); return parser->Load(words.data(), words.size()); @@ -46,7 +48,7 @@ std::vector MakeOverlay(std::initializer_list words) { protozero::PackedVarInt packed; for (uint32_t w : words) { packed.Append(w); - hasher.Update(w); + hasher.Update(perfetto::base::HostToLE(w)); } packed.Append(static_cast(hasher.digest())); return {packed.data(), packed.data() + packed.size()}; @@ -59,7 +61,7 @@ bool LoadBytecodeWithOverlay(FilterBytecodeParser* parser, protozero::PackedVarInt words; for (uint32_t w : bytecode) { words.Append(w); - hasher.Update(w); + hasher.Update(perfetto::base::HostToLE(w)); } words.Append(static_cast(hasher.digest())); diff --git a/src/protozero/filtering/message_filter.cc b/src/protozero/filtering/message_filter.cc index 36fd2b0b768..910a889c337 100644 --- a/src/protozero/filtering/message_filter.cc +++ b/src/protozero/filtering/message_filter.cc @@ -16,6 +16,7 @@ #include "src/protozero/filtering/message_filter.h" +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" #include "perfetto/protozero/proto_utils.h" #include "src/protozero/filtering/string_filter.h" @@ -42,7 +43,8 @@ template inline void AppendFixed(uint32_t field_id, INT_T value, uint8_t** out) { *out = proto_utils::WriteVarInt(proto_utils::MakeTagFixed(field_id), *out); - memcpy(*out, &value, sizeof(value)); + INT_T le_value = perfetto::base::HostToLE(value); + memcpy(*out, &le_value, sizeof(value)); *out += sizeof(value); } diff --git a/src/protozero/message.cc b/src/protozero/message.cc index 562438b0fa0..a4278c4e493 100644 --- a/src/protozero/message.cc +++ b/src/protozero/message.cc @@ -24,12 +24,6 @@ #include "perfetto/protozero/message_arena.h" #include "perfetto/protozero/message_handle.h" -#if !PERFETTO_IS_LITTLE_ENDIAN() -// The memcpy() for float and double below needs to be adjusted if we want to -// support big endian CPUs. There doesn't seem to be a compelling need today. -#error Unimplemented for big endian archs. -#endif - namespace protozero { namespace { diff --git a/src/protozero/proto_decoder.cc b/src/protozero/proto_decoder.cc index 496209c7c82..ba14fd55694 100644 --- a/src/protozero/proto_decoder.cc +++ b/src/protozero/proto_decoder.cc @@ -32,10 +32,6 @@ namespace protozero { using namespace proto_utils; -#if !PERFETTO_IS_LITTLE_ENDIAN() -#error Unimplemented for big endian archs. -#endif - const Field TypedProtoDecoderBase::kInvalidField{}; namespace { @@ -115,11 +111,14 @@ ParseOneField(const uint8_t* const buffer, const uint8_t* const end) { if (PERFETTO_UNLIKELY(new_pos > end)) return res; memcpy(&int_value, pos, sizeof(uint64_t)); + int_value = perfetto::base::LE64ToHost(int_value); } else if (field_type == static_cast(ProtoWireType::kFixed32)) { new_pos = pos + sizeof(uint32_t); if (PERFETTO_UNLIKELY(new_pos > end)) return res; - memcpy(&int_value, pos, sizeof(uint32_t)); + uint32_t value32; + memcpy(&value32, pos, sizeof(uint32_t)); + int_value = perfetto::base::LE32ToHost(value32); } else { PERFETTO_DLOG("Invalid proto field type: %u", field_type); return res; diff --git a/src/trace_processor/core/interpreter/bytecode_interpreter_impl.h b/src/trace_processor/core/interpreter/bytecode_interpreter_impl.h index 6de62ddd344..2734b5e7eae 100644 --- a/src/trace_processor/core/interpreter/bytecode_interpreter_impl.h +++ b/src/trace_processor/core/interpreter/bytecode_interpreter_impl.h @@ -30,8 +30,8 @@ #include #include "perfetto/base/compiler.h" +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/flat_hash_map.h" #include "perfetto/ext/base/string_view.h" #include "perfetto/ext/base/variant.h" diff --git a/src/trace_processor/core/util/sort.h b/src/trace_processor/core/util/sort.h index 76676bb618f..2641f0381b2 100644 --- a/src/trace_processor/core/util/sort.h +++ b/src/trace_processor/core/util/sort.h @@ -25,7 +25,7 @@ #include #include -#include "perfetto/ext/base/endian.h" +#include "perfetto/base/endian.h" namespace perfetto::trace_processor::core { namespace internal { diff --git a/src/trace_processor/core/util/sort_unittest.cc b/src/trace_processor/core/util/sort_unittest.cc index da73ae83e44..254446dc124 100644 --- a/src/trace_processor/core/util/sort_unittest.cc +++ b/src/trace_processor/core/util/sort_unittest.cc @@ -21,7 +21,7 @@ #include #include -#include "perfetto/ext/base/endian.h" +#include "perfetto/base/endian.h" #include "perfetto/ext/base/string_utils.h" #include "test/gtest_and_gmock.h" diff --git a/src/trace_processor/importers/art_hprof/art_heap_graph_builder.cc b/src/trace_processor/importers/art_hprof/art_heap_graph_builder.cc index baca8eed531..082272acd41 100644 --- a/src/trace_processor/importers/art_hprof/art_heap_graph_builder.cc +++ b/src/trace_processor/importers/art_hprof/art_heap_graph_builder.cc @@ -17,7 +17,7 @@ #include "src/trace_processor/importers/art_hprof/art_heap_graph_builder.h" #include #include -#include "perfetto/ext/base/endian.h" +#include "perfetto/base/endian.h" #include "perfetto/trace_processor/trace_blob.h" #include "src/trace_processor/importers/common/stats_tracker.h" diff --git a/src/trace_processor/importers/art_hprof/art_heap_graph_builder.h b/src/trace_processor/importers/art_hprof/art_heap_graph_builder.h index 27cc8267a3f..fe4064357c7 100644 --- a/src/trace_processor/importers/art_hprof/art_heap_graph_builder.h +++ b/src/trace_processor/importers/art_hprof/art_heap_graph_builder.h @@ -17,7 +17,7 @@ #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_ART_HPROF_ART_HEAP_GRAPH_BUILDER_H_ #define SRC_TRACE_PROCESSOR_IMPORTERS_ART_HPROF_ART_HEAP_GRAPH_BUILDER_H_ -#include "perfetto/ext/base/endian.h" +#include "perfetto/base/endian.h" #include "perfetto/ext/base/flat_hash_map.h" #include "perfetto/trace_processor/trace_blob_view.h" #include "src/trace_processor/importers/art_hprof/art_heap_graph.h" diff --git a/src/trace_processor/importers/art_hprof/art_hprof_parser.cc b/src/trace_processor/importers/art_hprof/art_hprof_parser.cc index 042b044c914..7eac976e651 100644 --- a/src/trace_processor/importers/art_hprof/art_hprof_parser.cc +++ b/src/trace_processor/importers/art_hprof/art_hprof_parser.cc @@ -27,8 +27,8 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/status.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/flat_hash_map.h" #include "perfetto/ext/base/murmur_hash.h" #include "perfetto/ext/base/string_view.h" diff --git a/src/trace_processor/plugins/flamegraph/flamegraph.cc b/src/trace_processor/plugins/flamegraph/flamegraph.cc index f6bb89b79f6..936577b3ed6 100644 --- a/src/trace_processor/plugins/flamegraph/flamegraph.cc +++ b/src/trace_processor/plugins/flamegraph/flamegraph.cc @@ -27,9 +27,9 @@ #include #include +#include "perfetto/base/endian.h" #include "perfetto/base/logging.h" #include "perfetto/base/status.h" -#include "perfetto/ext/base/endian.h" #include "perfetto/ext/base/flat_hash_map.h" #include "perfetto/ext/base/hash.h" #include "perfetto/ext/base/murmur_hash.h"