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

fix sysinfo system call #103

Merged
merged 2 commits into from
Jun 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/sys/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,36 @@ DEFINE_SYSCALL(sysinfo, gaddr_t, info_ptr)

int64_t memsize;
len = sizeof memsize;
if (sysctlbyname("hw.memsize", &memsize, &len, NULL, 0) < 0) exit(1);
if (sysctlbyname("hw.memsize", &memsize, &len, NULL, 0) < 0){
perror("sysinfo:");
exit(1);
}
info.totalram = memsize;

int64_t freepages;
len = sizeof freepages;
if (sysctlbyname("vm.page_free_count", &freepages, &len, NULL, 0) < 0) exit(1);
if (sysctlbyname("vm.page_free_count", &freepages, &len, NULL, 0) < 0){
perror("sysinfo:");
exit(1);
}
info.freeram = freepages * 0x1000;

uint64_t swapinfo[3];
/*
* 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) exit(1);
if (sysctlbyname("vm.swapusage", &swapinfo, &len, NULL, 0) < 0){
perror("sysinfo:");
exit(1);
}
info.totalswap = swapinfo[0];
info.freeswap = swapinfo[2];

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

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