2011-12-22 16:19:25 +01:00
|
|
|
/*
|
2016-04-15 14:19:51 +02:00
|
|
|
* \brief Sysctl facade
|
|
|
|
* \author Emery Hemingway
|
|
|
|
* \date 2016-04-27
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2019-04-26 12:47:33 +02:00
|
|
|
* Copyright (C) 2016-2019 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
2016-04-15 14:19:51 +02:00
|
|
|
/* Genode includes */
|
|
|
|
#include <util/string.h>
|
|
|
|
#include <base/env.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-04-15 14:19:51 +02:00
|
|
|
/* Genode-specific libc interfaces */
|
|
|
|
#include <libc-plugin/plugin.h>
|
|
|
|
#include <libc-plugin/fd_alloc.h>
|
|
|
|
|
libc: split task.cc into multiple files
This patch is the first step of re-organizing the internal structure of
the libc. The original version involved many direct calls of global
functions (often with side effects) across compilation units, which
made the control flow (e.g., the initialization sequence) hard to
follow.
The new version replaces those ad-hoc interactions with dedicated
interfaces (like suspend.h, resume.h, select.h, current_time.h). The
underlying facilities are provided by the central Libc::Kernel and
selectively propagated to the various compilation units. The latter is
done by a sequence of 'init_*' calls, which eventually will be replaced
by constructor calls.
The addition of new headers increases the chance for name clashes with
existing (public) headers. To disambiguate libc-internal header files
from public headers, this patch moves the former into a new 'internal/'
subdirectory. This makes the include directives easier to follow and the
libc's source-tree structure more tidy.
There are still a few legacies left, which cannot easily be removed
right now (e.g., because noux relies on them). However, the patch moves
those bad apples to legacy.h and legacy.cc, which highlights the
deprecation of those functions.
Issue #3497
2019-09-18 20:19:10 +02:00
|
|
|
/* libc includes */
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <errno.h>
|
2016-04-15 14:19:51 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
libc: split task.cc into multiple files
This patch is the first step of re-organizing the internal structure of
the libc. The original version involved many direct calls of global
functions (often with side effects) across compilation units, which
made the control flow (e.g., the initialization sequence) hard to
follow.
The new version replaces those ad-hoc interactions with dedicated
interfaces (like suspend.h, resume.h, select.h, current_time.h). The
underlying facilities are provided by the central Libc::Kernel and
selectively propagated to the various compilation units. The latter is
done by a sequence of 'init_*' calls, which eventually will be replaced
by constructor calls.
The addition of new headers increases the chance for name clashes with
existing (public) headers. To disambiguate libc-internal header files
from public headers, this patch moves the former into a new 'internal/'
subdirectory. This makes the include directives easier to follow and the
libc's source-tree structure more tidy.
There are still a few legacies left, which cannot easily be removed
right now (e.g., because noux relies on them). However, the patch moves
those bad apples to legacy.h and legacy.cc, which highlights the
deprecation of those functions.
Issue #3497
2019-09-18 20:19:10 +02:00
|
|
|
/* libc-internal includes */
|
|
|
|
#include <internal/errno.h>
|
|
|
|
#include <internal/init.h>
|
2016-04-15 14:19:51 +02:00
|
|
|
|
2019-09-19 20:37:17 +02:00
|
|
|
using namespace Libc;
|
2016-04-15 14:19:51 +02:00
|
|
|
|
|
|
|
enum { PAGESIZE = 4096 };
|
|
|
|
|
|
|
|
|
2017-02-22 14:23:06 +01:00
|
|
|
static Genode::Env *_global_env;
|
|
|
|
|
|
|
|
|
|
|
|
void Libc::sysctl_init(Genode::Env &env)
|
|
|
|
{
|
|
|
|
_global_env = &env;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-15 14:19:51 +02:00
|
|
|
extern "C" long sysconf(int name)
|
|
|
|
{
|
|
|
|
switch (name) {
|
|
|
|
case _SC_CHILD_MAX: return CHILD_MAX;
|
|
|
|
case _SC_OPEN_MAX: return getdtablesize();
|
|
|
|
case _SC_NPROCESSORS_CONF: return 1;
|
|
|
|
case _SC_NPROCESSORS_ONLN: return 1;
|
|
|
|
case _SC_PAGESIZE: return PAGESIZE;
|
|
|
|
|
|
|
|
case _SC_PHYS_PAGES:
|
2019-01-21 15:59:00 +01:00
|
|
|
return _global_env->pd().ram_quota().value / PAGESIZE;
|
2016-04-15 14:19:51 +02:00
|
|
|
default:
|
2019-09-19 20:37:17 +02:00
|
|
|
warning(__func__, "(", name, ") not implemented");
|
|
|
|
return Errno(EINVAL);
|
2016-04-15 14:19:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-26 12:47:33 +02:00
|
|
|
extern "C" int __sysctl(const int *name, u_int namelen,
|
|
|
|
void *oldp, size_t *oldlenp,
|
|
|
|
const void *newp, size_t newlen)
|
2016-04-15 14:19:51 +02:00
|
|
|
{
|
|
|
|
/* read only */
|
|
|
|
if (!oldp) /* check for write attempt */
|
2019-09-19 20:37:17 +02:00
|
|
|
return Errno(newp ? EPERM : EINVAL);
|
2016-04-15 14:19:51 +02:00
|
|
|
|
2019-09-19 20:37:17 +02:00
|
|
|
if (namelen != 2) return Errno(ENOENT);
|
2019-04-26 12:47:33 +02:00
|
|
|
|
2016-04-15 14:19:51 +02:00
|
|
|
char *buf = (char*)oldp;
|
|
|
|
int index_a = name[0];
|
|
|
|
int index_b = name[1];
|
|
|
|
|
|
|
|
|
2018-01-29 21:31:02 +01:00
|
|
|
Genode::memset(buf, 0x00, *oldlenp);
|
|
|
|
|
2016-04-15 14:19:51 +02:00
|
|
|
/* builtins */
|
|
|
|
{
|
|
|
|
switch(index_a) {
|
|
|
|
case CTL_HW: switch(index_b) {
|
|
|
|
|
|
|
|
case HW_PHYSMEM:
|
|
|
|
case HW_USERMEM:
|
2018-08-15 11:52:58 +02:00
|
|
|
switch (*oldlenp) {
|
|
|
|
case 4:
|
2019-01-21 15:59:00 +01:00
|
|
|
*(Genode::int32_t*)oldp = _global_env->pd().ram_quota().value;
|
2018-08-15 11:52:58 +02:00
|
|
|
break;
|
|
|
|
case 8:
|
2019-01-21 15:59:00 +01:00
|
|
|
*(Genode::int64_t*)oldp = _global_env->pd().ram_quota().value;
|
2018-08-15 11:52:58 +02:00
|
|
|
break;
|
|
|
|
default:
|
2019-09-19 20:37:17 +02:00
|
|
|
return Errno(EINVAL);
|
2018-08-15 11:52:58 +02:00
|
|
|
}
|
2016-04-15 14:19:51 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case HW_PAGESIZE:
|
|
|
|
*(int*)oldp = (int)PAGESIZE;
|
|
|
|
*oldlenp = sizeof(int);
|
|
|
|
return 0;
|
2019-05-29 11:15:54 +02:00
|
|
|
/*
|
|
|
|
* Used on ARM platforms to check HW fp support. Since the
|
|
|
|
* FP is enabled on all our ARM platforms we return true.
|
|
|
|
*/
|
|
|
|
case HW_FLOATINGPT:
|
|
|
|
*(int*)oldp = 1;
|
|
|
|
*oldlenp = sizeof(int);
|
|
|
|
return 0;
|
2016-04-15 14:19:51 +02:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CTL_P1003_1B: switch(index_b) {
|
|
|
|
|
|
|
|
case CTL_P1003_1B_PAGESIZE:
|
|
|
|
*(int*)oldp = PAGESIZE;
|
|
|
|
*oldlenp = sizeof(int);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fallback values */
|
|
|
|
{
|
|
|
|
switch(index_a) {
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-04-15 14:19:51 +02:00
|
|
|
case CTL_KERN:
|
|
|
|
switch(index_b) {
|
|
|
|
case KERN_OSTYPE:
|
2020-05-11 16:10:27 +02:00
|
|
|
copy_cstring(buf, "Genode", *oldlenp);
|
2016-04-15 14:19:51 +02:00
|
|
|
*oldlenp = Genode::strlen(buf);
|
|
|
|
return 0;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-04-15 14:19:51 +02:00
|
|
|
case KERN_OSRELEASE:
|
|
|
|
case KERN_OSREV:
|
|
|
|
case KERN_VERSION:
|
2016-06-09 16:06:41 +02:00
|
|
|
*oldlenp = 0;
|
2016-04-15 14:19:51 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case KERN_HOSTNAME:
|
2020-05-11 16:10:27 +02:00
|
|
|
copy_cstring(buf, "localhost", *oldlenp);
|
2016-04-15 14:19:51 +02:00
|
|
|
*oldlenp = Genode::strlen(buf);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CTL_HW: switch(index_b) {
|
|
|
|
|
|
|
|
case HW_MACHINE:
|
2016-06-09 16:06:41 +02:00
|
|
|
*oldlenp = 0;
|
2016-04-15 14:19:51 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case HW_NCPU:
|
|
|
|
*(int*)oldp = 1;
|
|
|
|
*oldlenp = sizeof(int);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 20:37:17 +02:00
|
|
|
warning("missing sysctl for [", index_a, "][", index_b, "]");
|
|
|
|
return Errno(ENOENT);
|
2016-04-15 14:19:51 +02:00
|
|
|
}
|