diff --git a/include/perfetto/ext/tracing/core/shared_memory_abi.h b/include/perfetto/ext/tracing/core/shared_memory_abi.h index 451cafbd52..4e05599e09 100644 --- a/include/perfetto/ext/tracing/core/shared_memory_abi.h +++ b/include/perfetto/ext/tracing/core/shared_memory_abi.h @@ -424,7 +424,7 @@ class SharedMemoryABI { ChunkHeader* chunk_header = header(); auto packets = chunk_header->packets.load(std::memory_order_relaxed); if (packets.count < packet_count) - packets.count = packet_count; + packets.count = packet_count & ChunkHeader::Packets::kMaxCount; chunk_header->packets.store(packets, std::memory_order_release); return packets.count; } diff --git a/include/perfetto/protozero/field.h b/include/perfetto/protozero/field.h index d0163b1814..e601e06974 100644 --- a/include/perfetto/protozero/field.h +++ b/include/perfetto/protozero/field.h @@ -156,7 +156,7 @@ class Field { uint8_t type, uint64_t int_value, uint32_t size) { - id_ = id; + id_ = id & kMaxId; type_ = type; int_value_ = int_value; size_ = size; diff --git a/src/tracing/core/trace_buffer.cc b/src/tracing/core/trace_buffer.cc index 55c6cb9d75..bd5e4a59b9 100644 --- a/src/tracing/core/trace_buffer.cc +++ b/src/tracing/core/trace_buffer.cc @@ -135,7 +135,7 @@ void TraceBuffer::CopyChunkUntrusted(ProducerID producer_id_trusted, record.chunk_id = chunk_id; record.writer_id = writer_id; record.num_fragments = num_fragments; - record.flags = chunk_flags; + record.flags = chunk_flags & ChunkRecord::kFlagsBitMask; ChunkMeta::Key key(record); // Check whether we have already copied the same chunk previously. This may @@ -452,7 +452,7 @@ bool TraceBuffer::TryPatchChunkContents(ProducerID producer_id, stats_.set_patches_succeeded(stats_.patches_succeeded() + patches_size); if (!other_patches_pending) { chunk_meta.flags &= ~kChunkNeedsPatching; - chunk_record->flags = chunk_meta.flags; + chunk_record->flags = chunk_meta.flags & ChunkRecord::kFlagsBitMask; } return true; } diff --git a/src/tracing/core/trace_buffer.h b/src/tracing/core/trace_buffer.h index cdd47b6fc8..3ca3161ce1 100644 --- a/src/tracing/core/trace_buffer.h +++ b/src/tracing/core/trace_buffer.h @@ -339,6 +339,8 @@ class TraceBuffer { uint16_t size; uint8_t flags : 6; // See SharedMemoryABI::ChunkHeader::flags. + static constexpr size_t kFlagsBitMask = (1 << 6) - 1; + uint8_t is_padding : 1; uint8_t unused_flag : 1;