From 7f6b6d7e13acd42ffd2e9834048df28c46537917 Mon Sep 17 00:00:00 2001 From: Pirmin Duss Date: Wed, 13 May 2020 10:48:25 +0200 Subject: [PATCH] core-linux: make RAM quota configurable Add the option to configure the RAM quota for core on base-linux. The environment variable GENODE_RAM_QUOTA if it exists is interpreted as number of bytes to provide to the first init. Issue #3762 --- repos/base-linux/src/core/include/platform.h | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/repos/base-linux/src/core/include/platform.h b/repos/base-linux/src/core/include/platform.h index e952ade6e5..8f4119afbd 100644 --- a/repos/base-linux/src/core/include/platform.h +++ b/repos/base-linux/src/core/include/platform.h @@ -24,6 +24,29 @@ #include #include +#include + +/** + * List of Unix environment variables, initialized by the startup code + */ +extern char **lx_environ; + + +/** + * Read environment variable as long value + */ +static unsigned long ram_quota_from_env() +{ + for (char **curr = lx_environ; curr && *curr; curr++) { + + Genode::Arg arg = Genode::Arg_string::find_arg(*curr, "GENODE_RAM_QUOTA"); + if (arg.valid()) + return arg.ulong_value(~0); + } + + return ~0; +} + namespace Genode { using namespace Genode; @@ -87,7 +110,7 @@ namespace Genode { int remove_range(addr_t, size_t) override { return 0; } void free(void *) override { } void free(void *, size_t) override { } - size_t avail() const override { return ~0; } + size_t avail() const override { return ram_quota_from_env(); } bool valid_addr(addr_t) const override { return true; } size_t overhead(size_t) const override { return 0; } bool need_size_for_free() const override { return true; }