Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Commit

Permalink
Better fix for sysctlbyname()
Browse files Browse the repository at this point in the history
  • Loading branch information
johnothwolo committed Feb 8, 2020
1 parent b367b67 commit c339845
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/sys/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ DEFINE_SYSCALL(sysinfo, gaddr_t, info_ptr)
}
info.freeram = freepages * 0x1000;

uint64_t swapinfo[4];
/*
* sysctlbyname() changed in macos 15. Any older os will leave swapinfo[4] as 0.
*/

uint64_t swapinfo[4] = {0};
len = sizeof swapinfo;
if (sysctlbyname("vm.swapusage", &swapinfo, &len, NULL, 0) < 0){
perror("sysinfo:");
exit(1);
}
info.totalswap = swapinfo[0];
info.freeswap = swapinfo[1];

if(swapinfo[3] == 0)
info.freeswap = swapinfo[2];
else
info.freeswap = swapinfo[1];

/* TODO */
info.sharedram = 0;
Expand Down

0 comments on commit c339845

Please sign in to comment.