From 4e714d3f3a07a50b12f37a3cd78d7f58c91e4c15 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 9 Apr 2021 18:07:15 +0200 Subject: [PATCH] base: handle cap depletion during session upgrade When the own cap quota of a client does not suffice for a cap upgrade of an existing session to a server, the client must issue a cap-resource request to the parent. This logic was already in place for RAM quota but was missing for cap quota. Issue #4072 --- .../base/internal/expanding_parent_client.h | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/repos/base/src/include/base/internal/expanding_parent_client.h b/repos/base/src/include/base/internal/expanding_parent_client.h index f961d38ab9..a2ff3f6b74 100644 --- a/repos/base/src/include/base/internal/expanding_parent_client.h +++ b/repos/base/src/include/base/internal/expanding_parent_client.h @@ -144,14 +144,25 @@ class Genode::Expanding_parent_client : public Parent_client * immediately. The second upgrade attempt may fail too if the * parent handles the resource request asynchronously. In this * case, we escalate the problem to caller by propagating the - * 'Out_of_ram' exception. Now, it is the job of the caller to - * issue (and respond to) a resource request. + * 'Out_of_ram' or 'Out_of_caps' exception. Now, it is the job of + * the caller to issue (and respond to) a resource request. */ - enum { NUM_ATTEMPTS = 2 }; + Session::Resources const amount = session_resources_from_args(args.string()); + using Arg = String<64>; + return retry( - [&] () { return Parent_client::upgrade(id, args); }, - [&] () { resource_request(Resource_args(args.string())); }, - NUM_ATTEMPTS); + [&] () { + return retry( + [&] () { return Parent_client::upgrade(id, args); }, + [&] () { + Arg cap_arg("cap_quota=", amount.cap_quota); + resource_request(Resource_args(cap_arg.string())); + }); + }, + [&] () { + Arg ram_arg("ram_quota=", amount.ram_quota); + resource_request(Resource_args(ram_arg.string())); + }); } void resource_avail_sigh(Signal_context_capability sigh) override