mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-01 08:48:20 +00:00
core: throw Trace::Out_of_metadata in subjects()
While importing trace sources as trace subjects into a TRACE session, the session quota might become depleted. The TRACE session already keeps track of the session quota via an allocator guard but the 'subjects' RPC function missed to handle the out-of-memory condition. This patch reflects the error condition as an 'Out_of_metadata' exception to the TRACE client. It also contains an extension of the trace test to exercise the corner case.
This commit is contained in:
parent
705257cf22
commit
5d678dba9e
@ -61,6 +61,8 @@ struct Genode::Trace::Session_client : Genode::Rpc_client<Genode::Trace::Session
|
||||
|
||||
/**
|
||||
* Retrieve subject directory
|
||||
*
|
||||
* \throw Out_of_metadata
|
||||
*/
|
||||
size_t subjects(Subject_id *dst, size_t dst_len)
|
||||
{
|
||||
|
@ -131,7 +131,8 @@ struct Genode::Trace::Session : Genode::Session
|
||||
GENODE_RPC_THROW(Rpc_resume, void, resume,
|
||||
GENODE_TYPE_LIST(Nonexistent_subject, Source_is_dead),
|
||||
Subject_id);
|
||||
GENODE_RPC(Rpc_subjects, size_t, subjects);
|
||||
GENODE_RPC_THROW(Rpc_subjects, size_t, subjects,
|
||||
GENODE_TYPE_LIST(Out_of_metadata));
|
||||
GENODE_RPC_THROW(Rpc_subject_info, Subject_info, subject_info,
|
||||
GENODE_TYPE_LIST(Nonexistent_subject), Subject_id);
|
||||
GENODE_RPC_THROW(Rpc_buffer, Dataspace_capability, buffer,
|
||||
|
@ -29,7 +29,14 @@ Dataspace_capability Session_component::dataspace()
|
||||
|
||||
size_t Session_component::subjects()
|
||||
{
|
||||
_subjects.import_new_sources(_sources);
|
||||
try {
|
||||
_subjects.import_new_sources(_sources);
|
||||
|
||||
} catch (Allocator::Out_of_memory) {
|
||||
|
||||
PWRN("TRACE session ran out of memory");
|
||||
throw Out_of_metadata();
|
||||
}
|
||||
|
||||
return _subjects.subjects((Subject_id *)_argument_buffer.base,
|
||||
_argument_buffer.size/sizeof(Subject_id));
|
||||
@ -155,7 +162,7 @@ Session_component::Session_component(Allocator &md_alloc, size_t ram_quota,
|
||||
_subjects(_subjects_slab, _ram, _sources),
|
||||
_argument_buffer(_ram, arg_buffer_size)
|
||||
{
|
||||
_md_alloc.withdraw(arg_buffer_size);
|
||||
_md_alloc.withdraw(_argument_buffer.size);
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <trace_session/connection.h>
|
||||
#include <timer_session/connection.h>
|
||||
#include <os/config.h>
|
||||
#include <base/sleep.h>
|
||||
|
||||
static char const *state_name(Genode::Trace::Subject_info::State state)
|
||||
{
|
||||
@ -117,12 +118,47 @@ class Trace_buffer_monitor
|
||||
};
|
||||
|
||||
|
||||
static void test_out_of_metadata()
|
||||
{
|
||||
printf("test Out_of_metadata exception of Trace::Session::subjects call\n");
|
||||
|
||||
/*
|
||||
* The call of 'subjects' will prompt core's TRACE service to import those
|
||||
* threads as trace subjects into the TRACE session. This step should fail
|
||||
* because we dimensioned the TRACE session with a very low amount of
|
||||
* session quota. The allocation failure is propagated to the TRACE client
|
||||
* by the 'Out_of_metadata' exception. The test validates this
|
||||
* error-handling procedure.
|
||||
*/
|
||||
|
||||
enum { MAX_SUBJECT_IDS = 16 };
|
||||
Genode::Trace::Subject_id subject_ids[MAX_SUBJECT_IDS];
|
||||
|
||||
Genode::Trace::Connection trace(sizeof(subject_ids) + 4096, sizeof(subject_ids), 0);
|
||||
|
||||
try {
|
||||
trace.subjects(subject_ids, MAX_SUBJECT_IDS);
|
||||
|
||||
/* we should never arrive here */
|
||||
struct Unexpectedly_got_no_exception{};
|
||||
throw Unexpectedly_got_no_exception();
|
||||
|
||||
} catch (Trace::Out_of_metadata) {
|
||||
printf("got Trace::Out_of_metadata exception as expected\n");
|
||||
}
|
||||
|
||||
printf("passed Out_of_metadata test\n");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
printf("--- test-trace started ---\n");
|
||||
|
||||
test_out_of_metadata();
|
||||
|
||||
static Genode::Trace::Connection trace(1024*1024, 64*1024, 0);
|
||||
|
||||
static Timer::Connection timer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user