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