From 82107bef9b123e9e80e0aece23f729aa6935b51e Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 8 Nov 2016 16:37:27 +0100 Subject: [PATCH] base: buffer session args in 'Connection' This patch is a preparation of the forthcoming async parent interface. Note that this patch increases the size of connection objects. Furthermore it adds a diagnostic message whenever a connection fails. Issue #2166 --- repos/base/include/base/connection.h | 61 +++++++++++++-------- repos/base/include/rom_session/connection.h | 18 +++--- repos/libports/run/ldso.run | 1 + repos/os/run/report_rom.run | 1 + 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/repos/base/include/base/connection.h b/repos/base/include/base/connection.h index bf634aef6..fbf51ccc0 100644 --- a/repos/base/include/base/connection.h +++ b/repos/base/include/base/connection.h @@ -33,40 +33,51 @@ class Genode::Connection : public Noncopyable private: /* - * Because the argument string is used with the parent interface, - * the message-buffer size of the parent-interface provides a - * realistic upper bound for dimensioning the format- string - * buffer. + * Buffer for storing the session arguments passed to the + * 'session' method that is called before the 'Connection' is + * constructed. */ enum { FORMAT_STRING_SIZE = Parent::Session_args::MAX_SIZE }; - Capability _cap; + char _session_args[FORMAT_STRING_SIZE]; + char _affinity_arg[sizeof(Affinity)]; Parent &_parent; On_destruction _on_destruction; - Capability _session(Parent &parent, - Affinity const &affinity, - const char *format_args, va_list list) + void _session(Parent &parent, + Affinity const &affinity, + const char *format_args, va_list list) { - char buf[FORMAT_STRING_SIZE]; - - String_console sc(buf, FORMAT_STRING_SIZE); + String_console sc(_session_args, FORMAT_STRING_SIZE); sc.vprintf(format_args, list); - va_end(list); - /* call parent interface with the resulting argument buffer */ - return parent.session(buf, affinity); + memcpy(_affinity_arg, &affinity, sizeof(Affinity)); } + Capability _request_cap() + { + Affinity affinity; + memcpy(&affinity, _affinity_arg, sizeof(Affinity)); + + try { + return env()->parent()->session(_session_args, affinity); } + catch (...) { + error(SESSION_TYPE::service_name(), "-session creation failed " + "(", Cstring(_session_args), ")"); + throw; + } + } + + Capability _cap = _request_cap(); + public: /** * Constructor * - * \param cap session capability * \param od session policy applied when destructing the connection * * The 'op' argument defines whether the session should automatically @@ -76,8 +87,8 @@ class Genode::Connection : public Noncopyable * session capability of the connection to another party but never * invokes any of the session's RPC functions. */ - Connection(Env &env, Capability cap, On_destruction od = CLOSE) - : _cap(cap), _parent(env.parent()), _on_destruction(od) { } + Connection(Env &env, Capability, On_destruction od = CLOSE) + : _parent(env.parent()), _on_destruction(od) { } /** * Constructor @@ -86,8 +97,8 @@ class Genode::Connection : public Noncopyable * \deprecated Use the constructor with 'Env &' as first * argument instead */ - Connection(Capability cap, On_destruction od = CLOSE) - : _cap(cap), _parent(*env()->parent()), _on_destruction(od) { } + Connection(Capability, On_destruction od = CLOSE) + : _parent(*env()->parent()), _on_destruction(od) { } /** * Destructor @@ -116,7 +127,8 @@ class Genode::Connection : public Noncopyable va_list list; va_start(list, format_args); - return _session(parent, Affinity(), format_args, list); + _session(parent, Affinity(), format_args, list); + return Capability(); } /** @@ -129,7 +141,8 @@ class Genode::Connection : public Noncopyable va_list list; va_start(list, format_args); - return _session(parent, affinity, format_args, list); + _session(parent, affinity, format_args, list); + return Capability(); } /** @@ -143,7 +156,8 @@ class Genode::Connection : public Noncopyable va_list list; va_start(list, format_args); - return _session(*env()->parent(), Affinity(), format_args, list); + _session(*env()->parent(), Affinity(), format_args, list); + return Capability(); } /** @@ -158,7 +172,8 @@ class Genode::Connection : public Noncopyable va_list list; va_start(list, format_args); - return _session(affinity, format_args, list); + _session(affinity, format_args, list); + return Capability(); } }; diff --git a/repos/base/include/rom_session/connection.h b/repos/base/include/rom_session/connection.h index db796ef37..6d962a85e 100644 --- a/repos/base/include/rom_session/connection.h +++ b/repos/base/include/rom_session/connection.h @@ -32,11 +32,7 @@ class Genode::Rom_connection : public Connection, Rom_session_capability _session(Parent &parent, char const *label) { - try { return session("ram_quota=4K, label=\"%s\"", label); } - catch (...) { - error("Could not open ROM session for \"", label, "\""); - throw Rom_connection_failed(); - } + return session("ram_quota=4K, label=\"%s\"", label); } public: @@ -49,10 +45,14 @@ class Genode::Rom_connection : public Connection, * \throw Rom_connection_failed */ Rom_connection(Env &env, const char *label) - : + try : Connection(env, _session(env.parent(), label)), Rom_session_client(cap()) { } + catch (...) { + error("Could not open ROM session for \"", label, "\""); + throw Rom_connection_failed(); + } /** * Constructor @@ -62,10 +62,14 @@ class Genode::Rom_connection : public Connection, * argument instead */ Rom_connection(const char *label) - : + try : Connection(_session(*env()->parent(), label)), Rom_session_client(cap()) { } + catch (...) { + error("Could not open ROM session for \"", label, "\""); + throw Rom_connection_failed(); + } }; #endif /* _INCLUDE__ROM_SESSION__CONNECTION_H_ */ diff --git a/repos/libports/run/ldso.run b/repos/libports/run/ldso.run index 8e7f3ea0e..c86060846 100644 --- a/repos/libports/run/ldso.run +++ b/repos/libports/run/ldso.run @@ -80,6 +80,7 @@ compare_output_to { [init -> test-ldso] Catch exceptions in program [init -> test-ldso] --------------------------- [init -> test-ldso] exception in remote procedure call: +[init -> test-ldso] Error: ROM-session creation failed (ram_quota=4K, label="unknown_file") [init -> test-ldso] Error: Could not open ROM session for "unknown_file" [init -> test-ldso] caught [init -> test-ldso] exception in program: caught diff --git a/repos/os/run/report_rom.run b/repos/os/run/report_rom.run index c3b4d9810..7f81560b3 100644 --- a/repos/os/run/report_rom.run +++ b/repos/os/run/report_rom.run @@ -68,6 +68,7 @@ compare_output_to { [init -> test-report_rom] Reporter: start reporting (while the ROM client still listens) [init -> test-report_rom] ROM client: wait for update notification [init -> test-report_rom] ROM client: try to open the same report again + [init -> test-report_rom] Error: Report-session creation failed (label="brightness", ram_quota=12288, buffer_size=4096) [init -> test-report_rom] ROM client: catched Parent::Service_denied - OK [init -> test-report_rom] --- test-report_rom finished --- }