Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: fusl/arch/x32/src/sysinfo.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/arch/x32/src/syscall_cp_fixup.c ('k') | fusl/arch/x32/syscall_arch.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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);
OLDNEW
« no previous file with comments | « fusl/arch/x32/src/syscall_cp_fixup.c ('k') | fusl/arch/x32/syscall_arch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698