diff --git a/repos/libports/src/lib/libc/libc_init.h b/repos/libports/src/lib/libc/libc_init.h index df2a2f5d6..3265fbbe2 100644 --- a/repos/libports/src/lib/libc/libc_init.h +++ b/repos/libports/src/lib/libc/libc_init.h @@ -28,6 +28,11 @@ namespace Libc { * Global memory allocator */ void init_mem_alloc(Genode::Env &env); + + /** + * Support for querying available RAM quota in sysctl functions + */ + void sysctl_init(Genode::Env &env); } #endif /* _LIBC_INIT_H_ */ diff --git a/repos/libports/src/lib/libc/sysctl.cc b/repos/libports/src/lib/libc/sysctl.cc index f02c03720..9f1d7f69b 100644 --- a/repos/libports/src/lib/libc/sysctl.cc +++ b/repos/libports/src/lib/libc/sysctl.cc @@ -27,11 +27,21 @@ #include #include "libc_errno.h" +#include "libc_init.h" enum { PAGESIZE = 4096 }; +static Genode::Env *_global_env; + + +void Libc::sysctl_init(Genode::Env &env) +{ + _global_env = &env; +} + + extern "C" long sysconf(int name) { switch (name) { @@ -42,7 +52,7 @@ extern "C" long sysconf(int name) case _SC_PAGESIZE: return PAGESIZE; case _SC_PHYS_PAGES: - return Genode::env()->ram_session()->quota() / PAGESIZE; + return _global_env->ram().quota() / PAGESIZE; default: Genode::warning(__func__, "(", name, ") not implemented"); return Libc::Errno(EINVAL); @@ -117,7 +127,7 @@ extern "C" int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, case HW_PHYSMEM: case HW_USERMEM: - *(unsigned long*)oldp = Genode::env()->ram_session()->quota(); + *(unsigned long*)oldp = _global_env->ram().quota(); *oldlenp = sizeof(unsigned long); return 0; diff --git a/repos/libports/src/lib/libc/task.cc b/repos/libports/src/lib/libc/task.cc index cbc94233a..33be2a7ac 100644 --- a/repos/libports/src/lib/libc/task.cc +++ b/repos/libports/src/lib/libc/task.cc @@ -836,6 +836,7 @@ void Component::construct(Genode::Env &env) /* pass Genode::Env to libc subsystems that depend on it */ Libc::init_mem_alloc(env); Libc::init_dl(env); + Libc::sysctl_init(env); /* initialize plugins that require Genode::Env */ auto init_plugin = [&] (Libc::Plugin &plugin) {