From dfabcd84c1fd53a28604244f94b9795572e66185 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Thu, 23 Feb 2023 06:00:18 -0800 Subject: [PATCH] Fix sysinfo() The system call wrapper was wrongfully reinterpreting kernel data. The examples/sysinfo.c program is now updated to show how to correctly use what's returned. --- examples/sysinfo.c | 32 ++++++++++++++++---------------- libc/calls/sysinfo.c | 3 --- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/examples/sysinfo.c b/examples/sysinfo.c index c0ad1a32b..c29411e86 100644 --- a/examples/sysinfo.c +++ b/examples/sysinfo.c @@ -46,31 +46,31 @@ int main(int argc, char *argv[]) { 1. / 65536 * si.loads[1], // 1. / 65536 * si.loads[2]); // - sizefmt(ibuf, si.totalram, 1024); - printf("%-16s %s\n", "totalram", ibuf); + sizefmt(ibuf, si.totalram * si.mem_unit, 1024); + printf("%-16s %ld (%s)\n", "totalram", si.totalram, ibuf); - sizefmt(ibuf, si.freeram, 1024); - printf("%-16s %s\n", "freeram", ibuf); + sizefmt(ibuf, si.freeram * si.mem_unit, 1024); + printf("%-16s %ld (%s)\n", "freeram", si.freeram, ibuf); - sizefmt(ibuf, si.sharedram, 1024); - printf("%-16s %s\n", "sharedram", ibuf); + sizefmt(ibuf, si.sharedram * si.mem_unit, 1024); + printf("%-16s %ld (%s)\n", "sharedram", si.sharedram, ibuf); - sizefmt(ibuf, si.bufferram, 1024); - printf("%-16s %s\n", "bufferram", ibuf); + sizefmt(ibuf, si.bufferram * si.mem_unit, 1024); + printf("%-16s %ld (%s)\n", "bufferram", si.bufferram, ibuf); - sizefmt(ibuf, si.totalswap, 1024); - printf("%-16s %s\n", "totalswap", ibuf); + sizefmt(ibuf, si.totalswap * si.mem_unit, 1024); + printf("%-16s %ld (%s)\n", "totalswap", si.totalswap, ibuf); - sizefmt(ibuf, si.freeswap, 1024); - printf("%-16s %s\n", "freeswap", ibuf); + sizefmt(ibuf, si.freeswap * si.mem_unit, 1024); + printf("%-16s %ld (%s)\n", "freeswap", si.freeswap, ibuf); printf("%-16s %lu\n", "processes", si.procs); - sizefmt(ibuf, si.totalhigh, 1024); - printf("%-16s %s\n", "totalhigh", ibuf); + sizefmt(ibuf, si.totalhigh * si.mem_unit, 1024); + printf("%-16s %ld (%s)\n", "totalhigh", si.totalhigh, ibuf); - sizefmt(ibuf, si.freehigh, 1024); - printf("%-16s %s\n", "freehigh", ibuf); + sizefmt(ibuf, si.freehigh * si.mem_unit, 1024); + printf("%-16s %ld (%s)\n", "freehigh", si.freehigh, ibuf); sizefmt(ibuf, si.mem_unit, 1024); printf("%-16s %s\n", "mem_unit", ibuf); diff --git a/libc/calls/sysinfo.c b/libc/calls/sysinfo.c index 1e13afafa..95b2f29c1 100644 --- a/libc/calls/sysinfo.c +++ b/libc/calls/sysinfo.c @@ -81,9 +81,6 @@ int sysinfo(struct sysinfo *info) { rc = sys_sysinfo_nt(&x); } if (rc != -1) { - x.procs = MAX(1, x.procs); - x.mem_unit = MAX(1, x.mem_unit); - x.totalram = MAX((8 * 1024 * 1024) / x.mem_unit, x.totalram); memcpy(info, &x, sizeof(x)); } STRACE("sysinfo(%p) → %d% m", info, rc);