libc: remove global env from sysctl

Issue #2280.
This commit is contained in:
Josef Söntgen 2017-02-22 14:23:06 +01:00 committed by Christian Helmuth
parent b2dd0ab436
commit b3af297058
3 changed files with 18 additions and 2 deletions

View File

@ -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_ */

View File

@ -27,11 +27,21 @@
#include <unistd.h>
#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;

View File

@ -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) {