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
This commit is contained in:
Norman Feske 2020-05-11 14:28:15 +02:00
parent 236e02a2dd
commit 64bc008c3a
1 changed files with 4 additions and 4 deletions

View File

@ -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(_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());