diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 13:54:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 13:54:38 +0000 |
commit | 8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch) | |
tree | df55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-top-half/musl/src/linux/x32 | |
parent | Initial commit. (diff) | |
download | wasi-libc-upstream/0.0_git20221206.8b7148f.tar.xz wasi-libc-upstream/0.0_git20221206.8b7148f.zip |
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/linux/x32')
-rw-r--r-- | libc-top-half/musl/src/linux/x32/sysinfo.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/linux/x32/sysinfo.c b/libc-top-half/musl/src/linux/x32/sysinfo.c new file mode 100644 index 0000000..59b3bb7 --- /dev/null +++ b/libc-top-half/musl/src/linux/x32/sysinfo.c @@ -0,0 +1,49 @@ +#include <sys/sysinfo.h> +#include "syscall.h" + +#define klong long long +#define kulong unsigned long long + +struct kernel_sysinfo { + klong uptime; + kulong loads[3]; + kulong totalram; + kulong freeram; + kulong sharedram; + kulong bufferram; + kulong totalswap; + kulong freeswap; + short procs; + short pad; + kulong totalhigh; + kulong freehigh; + unsigned mem_unit; +}; + +int __lsysinfo(struct sysinfo *info) +{ + struct kernel_sysinfo tmp; + int ret = syscall(SYS_sysinfo, &tmp); + if(ret == -1) return ret; + info->uptime = tmp.uptime; + info->loads[0] = tmp.loads[0]; + info->loads[1] = tmp.loads[1]; + info->loads[2] = tmp.loads[2]; + kulong shifts; + kulong max = tmp.totalram | tmp.totalswap; + __asm__("bsr %1,%0" : "=r"(shifts) : "r"(max)); + shifts = shifts >= 32 ? shifts - 31 : 0; + info->totalram = tmp.totalram >> shifts; + info->freeram = tmp.freeram >> shifts; + info->sharedram = tmp.sharedram >> shifts; + info->bufferram = tmp.bufferram >> shifts; + info->totalswap = tmp.totalswap >> shifts; + info->freeswap = tmp.freeswap >> shifts; + info->procs = tmp.procs ; + info->totalhigh = tmp.totalhigh >> shifts; + info->freehigh = tmp.freehigh >> shifts; + info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts; + return ret; +} + +weak_alias(__lsysinfo, sysinfo); |