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
This commit is contained in:
Johannes Schlatow 2022-02-18 09:31:47 +01:00 committed by Christian Helmuth
parent 91b6032a71
commit e35837e14b

View File

@ -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 */