From 5a468919bbbca60c6ec56f225baf12e11cbf4d55 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sun, 7 May 2017 23:44:48 +0200 Subject: [PATCH] base: new session-creation helper types This patch augments the existing session/session.h with useful types for the session creation: * The new 'Insufficient_ram_quota' and 'Insufficient_cap_quota' exceptions are meant to supersede the old 'Quota_exceeded' exception of the 'Parent' and 'Root' interfaces. * The 'Session::Resources' struct subsumes the information about the session quota provided by the client. * The boolean 'Session::Diag' type will allow sessions to operate in a diagnostic mode. * The existing 'Session_label' is not also available under the alias 'Session::Label'. * A few helper functions ease the extraction of typed session arguments from the session-argument string. Issue #2398 --- repos/base/include/session/session.h | 54 +++++++++++++++++++++++++++- repos/os/src/init/types.h | 2 -- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/repos/base/include/session/session.h b/repos/base/include/session/session.h index c60deb965..e69f50a59 100644 --- a/repos/base/include/session/session.h +++ b/repos/base/include/session/session.h @@ -14,6 +14,10 @@ #ifndef _INCLUDE__SESSION__SESSION_H_ #define _INCLUDE__SESSION__SESSION_H_ +#include +#include +#include + /* * Each session interface declares an RPC interface and, therefore, relies on * the RPC framework. By including 'base/rpc.h' here, we relieve the interfaces @@ -21,7 +25,16 @@ */ #include -namespace Genode { struct Session; } +namespace Genode { + + struct Session; + + /* + * Exceptions that may occur during the session creation + */ + struct Insufficient_ram_quota : Exception { }; + struct Insufficient_cap_quota : Exception { }; +} /** @@ -29,6 +42,16 @@ namespace Genode { struct Session; } */ struct Genode::Session { + struct Resources + { + Ram_quota ram_quota; + Cap_quota cap_quota; + }; + + struct Diag { bool enabled; }; + + typedef Session_label Label; + /* * Each session interface must implement the class function 'service_name' * ! static const char *service_name(); @@ -39,4 +62,33 @@ struct Genode::Session virtual ~Session() { } }; + +namespace Genode { + + static inline Ram_quota ram_quota_from_args(char const *args) + { + return { Arg_string::find_arg(args, "ram_quota").ulong_value(0) }; + } + + static inline Cap_quota cap_quota_from_args(char const *args) + { + return { Arg_string::find_arg(args, "cap_quota").ulong_value(0) }; + } + + static inline Session::Label session_label_from_args(char const *args) + { + return label_from_args(args); + } + + static inline Session::Resources session_resources_from_args(char const *args) + { + return { ram_quota_from_args(args), cap_quota_from_args(args) }; + } + + static inline Session::Diag session_diag_from_args(char const *args) + { + return { Arg_string::find_arg(args, "diag").bool_value(false) }; + } +} + #endif /* _INCLUDE__SESSION__SESSION_H_ */ diff --git a/repos/os/src/init/types.h b/repos/os/src/init/types.h index 418723899..b39915ae9 100644 --- a/repos/os/src/init/types.h +++ b/repos/os/src/init/types.h @@ -25,8 +25,6 @@ namespace Init { using Genode::size_t; using Genode::strlen; - struct Ram_quota { size_t value; }; - struct Prio_levels { long value; }; typedef List > Child_list;