From e35837e14bad5dae5e6f59e8e8899b9bf41f2698 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Fri, 18 Feb 2022 09:31:47 +0100 Subject: [PATCH] trace_buffer: fix wrap condition When committing a new entry, the buffer wrapped if the last entry fit perfectly into the buffer. Otherwise, the length field of the next entry was set to 0 to mark the new head. Yet, if there was still some padding but not enough to hold the length field of another entry, we ended up with a headless buffer. genodelabs/genode#4430 --- repos/base/include/base/trace/buffer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/repos/base/include/base/trace/buffer.h b/repos/base/include/base/trace/buffer.h index 605b11b2f9..15f54f706b 100644 --- a/repos/base/include/base/trace/buffer.h +++ b/repos/base/include/base/trace/buffer.h @@ -99,9 +99,9 @@ class Genode::Trace::Buffer */ size_t *old_head_len = &_head_entry()->len; - /* advance head offset, wrap when reaching buffer boundary */ + /* advance head offset, wrap when next entry does not fit into buffer */ _head_offset += sizeof(_Entry) + len; - if (_head_offset == _size) + if (_head_offset + sizeof(_Entry) > _size) _buffer_wrapped(); /* mark entry next to new entry with len 0 */