mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
parent
b2dd0ab436
commit
b3af297058
@ -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_ */
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user