Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/perfetto/base/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ inline double HostToLE(double x) {
return HostToLEDouble(x);
}

inline uint16_t LEToHost(uint16_t x) {
return LE16ToHost(x);
}
inline uint32_t LEToHost(uint32_t x) {
return LE32ToHost(x);
}
Expand Down
5 changes: 5 additions & 0 deletions src/trace_processor/core/dataframe/arrow_deserializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ base::StatusOr<Dataframe> DeserializeFromArrow(
const util::TraceBlobViewReader& data,
StringPool* pool,
const DataframeSpec& spec) {
#if PERFETTO_IS_LITTLE_ENDIAN()
if (spec.column_names.size() != spec.column_specs.size() ||
spec.column_names.size() > std::numeric_limits<uint32_t>::max()) {
return base::ErrStatus("Invalid dataframe spec");
Expand Down Expand Up @@ -600,6 +601,10 @@ base::StatusOr<Dataframe> DeserializeFromArrow(
++dataframe.non_column_mutations_;
dataframe.Finalize();
return dataframe;
#else // PERFETTO_IS_LITTLE_ENDIAN()
return base::ErrStatus(
"Arrow deserialization is not supported on big-endian hosts");
#endif // PERFETTO_IS_LITTLE_ENDIAN()
}

} // namespace perfetto::trace_processor::core::dataframe
2 changes: 0 additions & 2 deletions src/trace_processor/core/dataframe/arrow_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace perfetto::trace_processor::core::dataframe::arrow_internal {

static_assert(PERFETTO_IS_LITTLE_ENDIAN());

// Constants and packed structs below mirror the official Arrow flatbuffer
// schema. Keeping them together makes the serializer and deserializer use the
// same wire definitions without depending on the full Arrow library.
Expand Down
5 changes: 5 additions & 0 deletions src/trace_processor/core/dataframe/arrow_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ base::Status ArrowSerializer::BuildFileFraming(const BodyPlan& plan) {
base::StatusOr<size_t> ArrowSerializer::Prepare(const Dataframe& dataframe,
const StringPool& pool) {
Reset();
#if PERFETTO_IS_LITTLE_ENDIAN()
if (!dataframe.finalized()) {
return base::ErrStatus(
"Arrow serialization requires a finalized dataframe");
Expand Down Expand Up @@ -654,6 +655,10 @@ base::StatusOr<size_t> ArrowSerializer::Prepare(const Dataframe& dataframe,
prepared_string_pool_ = &pool;
prepared_mutations_ = dataframe.mutations();
return static_cast<size_t>(total);
#else // PERFETTO_IS_LITTLE_ENDIAN()
return base::ErrStatus(
"Arrow serialization is not supported on big-endian hosts");
#endif // PERFETTO_IS_LITTLE_ENDIAN()
}

base::Status ArrowSerializer::WriteDictionary(const DictionaryPlan& dictionary,
Expand Down
8 changes: 7 additions & 1 deletion src/trace_processor/core/util/bit_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,22 @@ struct BitVector {
// ceil(size / 8) bytes holding bit i at byte i / 8, bit i % 8. This is the
// layout of the words below, so the bitmap is taken verbatim.
static BitVector CreateFromBitmap(const uint8_t* bitmap, uint64_t size) {
static_assert(PERFETTO_IS_LITTLE_ENDIAN());
if (size == 0) {
return {};
}
auto words = FlexVector<uint64_t>::CreateWithSize((size + 63u) / 64u);
size_t bitmap_bytes = static_cast<size_t>((size + 7u) / 8u);
size_t word_bytes = words.size() * sizeof(uint64_t);
#if PERFETTO_IS_LITTLE_ENDIAN()
memcpy(words.data(), bitmap, bitmap_bytes);
memset(reinterpret_cast<uint8_t*>(words.data()) + bitmap_bytes, 0,
word_bytes - bitmap_bytes);
#else
memset(words.data(), 0, word_bytes);
for (size_t i = 0; i < bitmap_bytes; ++i) {
words[i / 8u] |= static_cast<uint64_t>(bitmap[i]) << (8u * (i % 8u));
}
#endif
// Bits past `size` are unspecified in the source bitmap.
if (size % 64u != 0u) {
words.back() &= (1ull << (size % 64u)) - 1ull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <utility>
#include <vector>

#include "perfetto/base/endian.h"
#include "perfetto/base/logging.h"
#include "perfetto/base/status.h"
#include "perfetto/ext/base/status_macros.h"
Expand Down Expand Up @@ -80,20 +81,20 @@ std::string ConstructPathname(const std::string& class_name,

uint64_t ToLong(const TraceBlobView& tbv) {
uint64_t x = 0;
memcpy(base::AssumeLittleEndian(&x), tbv.data(), tbv.size());
return x;
memcpy(&x, tbv.data(), tbv.size());
return base::LEToHost(x);
}

uint32_t ToInt(const TraceBlobView& tbv) {
uint32_t x = 0;
memcpy(base::AssumeLittleEndian(&x), tbv.data(), tbv.size());
return x;
memcpy(&x, tbv.data(), tbv.size());
return base::LEToHost(x);
}

uint16_t ToShort(const TraceBlobView& tbv) {
uint16_t x = 0;
memcpy(base::AssumeLittleEndian(&x), tbv.data(), tbv.size());
return x;
memcpy(&x, tbv.data(), tbv.size());
return base::LEToHost(x);
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <string>
#include <vector>

#include "perfetto/base/endian.h"
#include "perfetto/base/logging.h"
#include "perfetto/base/status.h"
#include "perfetto/ext/base/status_macros.h"
Expand Down Expand Up @@ -91,13 +92,10 @@ const uint8_t* DecodeSignedLeb128(const uint8_t* data,

// Reads a simple little-endian integer from the byte stream.
uint64_t ReadNumber(const uint8_t* ptr, size_t num_bytes) {
static_assert(PERFETTO_IS_LITTLE_ENDIAN(),
"ART Method traces are little-endian. Perfetto requires a "
"little-endian host to parse these effectively.");
PERFETTO_DCHECK(num_bytes <= sizeof(uint64_t));
uint64_t number = 0;
memcpy(&number, ptr, num_bytes);
return number;
return base::LEToHost(number);
}

std::string ConstructPathname(base::StringView class_name,
Expand Down
9 changes: 3 additions & 6 deletions src/trace_processor/plugins/wattson/table_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <utility>
#include <vector>

#include "perfetto/base/compiler.h"
#include "perfetto/base/endian.h"
#include "perfetto/base/logging.h"
#include "perfetto/base/status.h"
#include "perfetto/ext/base/status_or.h"
Expand All @@ -46,21 +46,18 @@ using core::dataframe::ColumnSpec;
using core::dataframe::Dataframe;
using core::dataframe::DataframeSpec;

static_assert(PERFETTO_IS_LITTLE_ENDIAN(),
"wattson curve blobs are little-endian and require a "
"little-endian host");

class WattsonCurvesBlobReader {
public:
explicit WattsonCurvesBlobReader(const uint8_t* data, size_t size)
: data_(data), size_(size) {}

// Curve blobs are little-endian.
template <typename T>
T Read() {
static_assert(std::is_trivially_copyable_v<T>);
T value;
ReadInto(&value, sizeof(T));
return value;
return base::LEToHost(value);
}

base::StringView ReadStringView(uint16_t size) {
Expand Down
5 changes: 3 additions & 2 deletions src/trace_processor/util/zip_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <vector>

#include "perfetto/base/build_config.h"
#include "perfetto/base/endian.h"
#include "perfetto/base/logging.h"
#include "perfetto/base/status.h"
#include "perfetto/base/time.h"
Expand Down Expand Up @@ -86,9 +87,9 @@ const uint16_t kDeflate = 8;
template <typename T>
T ReadAndAdvance(const uint8_t** ptr) {
T res{};
memcpy(base::AssumeLittleEndian(&res), *ptr, sizeof(T));
memcpy(&res, *ptr, sizeof(T));
*ptr += sizeof(T);
return res;
return base::LEToHost(res);
}

} // namespace
Expand Down
Loading