OLD | NEW |
(Empty) | |
| 1 #include <sys/sysinfo.h> |
| 2 #include "syscall.h" |
| 3 #include "libc.h" |
| 4 |
| 5 #define klong long long |
| 6 #define kulong unsigned long long |
| 7 |
| 8 struct kernel_sysinfo { |
| 9 klong uptime; |
| 10 kulong loads[3]; |
| 11 kulong totalram; |
| 12 kulong freeram; |
| 13 kulong sharedram; |
| 14 kulong bufferram; |
| 15 kulong totalswap; |
| 16 kulong freeswap; |
| 17 short procs; |
| 18 short pad; |
| 19 kulong totalhigh; |
| 20 kulong freehigh; |
| 21 unsigned mem_unit; |
| 22 }; |
| 23 |
| 24 int __lsysinfo(struct sysinfo *info) |
| 25 { |
| 26 struct kernel_sysinfo tmp; |
| 27 int ret = syscall(SYS_sysinfo, &tmp); |
| 28 if(ret == -1) return ret; |
| 29 info->uptime = tmp.uptime; |
| 30 info->loads[0] = tmp.loads[0]; |
| 31 info->loads[1] = tmp.loads[1]; |
| 32 info->loads[2] = tmp.loads[2]; |
| 33 kulong shifts; |
| 34 kulong max = tmp.totalram | tmp.totalswap; |
| 35 __asm__("bsr %1,%0" : "=r"(shifts) : "r"(max)); |
| 36 shifts = shifts >= 32 ? shifts - 31 : 0; |
| 37 info->totalram = tmp.totalram >> shifts; |
| 38 info->freeram = tmp.freeram >> shifts; |
| 39 info->sharedram = tmp.sharedram >> shifts; |
| 40 info->bufferram = tmp.bufferram >> shifts; |
| 41 info->totalswap = tmp.totalswap >> shifts; |
| 42 info->freeswap = tmp.freeswap >> shifts; |
| 43 info->procs = tmp.procs ; |
| 44 info->totalhigh = tmp.totalhigh >> shifts; |
| 45 info->freehigh = tmp.freehigh >> shifts; |
| 46 info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts; |
| 47 return ret; |
| 48 } |
| 49 |
| 50 weak_alias(__lsysinfo, sysinfo); |
OLD | NEW |