Libc: use caller integer width for return value of sysctl PHYSMEM

Return a value in the same width as provided by the caller of sysctl for
PHYSMEM and USERMEM. This is to ensure that if a caller provides a
64-bit integer, a 64-bit value will be returned for 32-bit machines.

issue #3060
This commit is contained in:
Emery Hemingway 2018-08-15 11:52:58 +02:00 committed by Christian Helmuth
parent 98518e39cd
commit 2d17af9f28
1 changed files with 10 additions and 2 deletions

View File

@ -129,8 +129,16 @@ extern "C" int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
case HW_PHYSMEM:
case HW_USERMEM:
*(unsigned long*)oldp = _global_env->ram().ram_quota().value;
*oldlenp = sizeof(unsigned long);
switch (*oldlenp) {
case 4:
*(Genode::int32_t*)oldp = _global_env->ram().ram_quota().value;
break;
case 8:
*(Genode::int64_t*)oldp = _global_env->ram().ram_quota().value;
break;
default:
return Libc::Errno(EINVAL);
}
return 0;
case HW_PAGESIZE: