From 64bc008c3ac2fd581ff5d232368f9806e8d070c2 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 11 May 2020 14:28:15 +0200 Subject: [PATCH] core: fix inconsistent state after failed 'trace' This patch fixes the handling of the corner case where the allocation of a trace buffer throws 'Out_of_caps' or 'Out_of_ram'. Under this circumstance, the '_buffer' would still be flagged with the 'size', which prevented any subsequent allocation attempt. This patch fixes the problem by initializing the 'size' after the potentially throwing allocation. The problem triggered with the test-trace_logger after the accounting of core's TRACE service (replacing the 'Allocator_guard' by 'Constrained_ram_allocator') became more accurate. Related to issue #3750 --- repos/base/src/core/include/trace/subject_registry.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/repos/base/src/core/include/trace/subject_registry.h b/repos/base/src/core/include/trace/subject_registry.h index d708fd8e76..9d2c44d6bb 100644 --- a/repos/base/src/core/include/trace/subject_registry.h +++ b/repos/base/src/core/include/trace/subject_registry.h @@ -88,9 +88,9 @@ class Genode::Trace::Subject if (_size) _ram_ptr->free(_ds); + _ds = ram.alloc(size); /* may throw */ _ram_ptr = &ram; _size = size; - _ds = ram.alloc(size); } /** @@ -220,11 +220,9 @@ class Genode::Trace::Subject /* check state and throw error in case subject is not traceable */ _traceable_or_throw(); - _policy_id = policy_id; - _buffer.setup(ram, size); if(!_policy.setup(ram, local_rm, policy_ds, policy_size)) - throw Already_traced(); + throw Already_traced(); /* inform trace source about the new buffer */ Locked_ptr source(_source); @@ -232,6 +230,8 @@ class Genode::Trace::Subject if (!source->try_acquire(*this)) throw Traced_by_other_session(); + _policy_id = policy_id; + _allocated_memory = policy_size + size; source->trace(_policy.dataspace(), _buffer.dataspace());