2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief C-library back end
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2008-11-11
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2008-2013 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;
|
|
|
|
|
2014-01-13 15:22:38 +01:00
|
|
|
/*
|
|
|
|
* CTL_P1003_1B is used by sysconf(_SC_PAGESIZE) to determine
|
|
|
|
* the actual page size.
|
|
|
|
*/
|
|
|
|
if (((name[0] == CTL_HW) && (name[1] == HW_PAGESIZE)) ||
|
2014-09-09 14:32:31 +02:00
|
|
|
((name[0] == CTL_P1003_1B) && (name[1] == CTL_P1003_1B_PAGESIZE))) {
|
2011-12-22 16:19:25 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|