From 2d17af9f28e819a17997f1234ba2136041618de8 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 15 Aug 2018 11:52:58 +0200 Subject: [PATCH] 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 --- repos/libports/src/lib/libc/sysctl.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/repos/libports/src/lib/libc/sysctl.cc b/repos/libports/src/lib/libc/sysctl.cc index 133a8e1572..a473186466 100644 --- a/repos/libports/src/lib/libc/sysctl.cc +++ b/repos/libports/src/lib/libc/sysctl.cc @@ -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: