genode/libports/src/lib/libc/sysctl.cc

69 lines
1.4 KiB
C++
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief C-library back end
* \author Norman Feske
* \date 2008-11-11
*/
/*
2012-01-03 15:35:05 +01:00
* Copyright (C) 2008-2012 Genode Labs GmbH
2011-12-22 16:19:25 +01:00
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#include <base/printf.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <errno.h>
#include "libc_debug.h"
extern "C" int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen)
{
int i;
raw_write_str("__sysctl called\n");
/*
* During printf, __sysctl is called by malloc with the parameters
*
* name[0] == 6 (CTL_HW)
* name[1] == 3 (HW_NCPU)
*
* In this case, we can return -1, and the libC assumes that we
* have one CPU.
*/
if ((name[0] == CTL_HW) && (name[1] == HW_NCPU))
return -1;
if ((name[0] == CTL_HW) && (name[1] == HW_PAGESIZE)) {
int result = 4096;
if (oldp) {
if (*oldlenp >= sizeof(result)) {
*(int*)oldp = result;
*oldlenp = sizeof(result);
return 0;
} else {
PERR("not enough room to store the old value");
return -1;
}
} else {
PERR("cannot store the result in oldp, since it is NULL");
return -1;
}
}
raw_write_str(newp ? "newp provided\n" : "no newp provided\n");
for (i = 0; i < name[0]; i++)
raw_write_str("*");
raw_write_str("\n");
for (i = 0; i < name[1]; i++)
raw_write_str("%");
raw_write_str("\n");
return 0;
}