Skip to content

Commit c339845

Browse files
committed
Better fix for sysctlbyname()
1 parent b367b67 commit c339845

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/sys/sys.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,22 @@ DEFINE_SYSCALL(sysinfo, gaddr_t, info_ptr)
4747
}
4848
info.freeram = freepages * 0x1000;
4949

50-
uint64_t swapinfo[4];
50+
/*
51+
* sysctlbyname() changed in macos 15. Any older os will leave swapinfo[4] as 0.
52+
*/
53+
54+
uint64_t swapinfo[4] = {0};
5155
len = sizeof swapinfo;
5256
if (sysctlbyname("vm.swapusage", &swapinfo, &len, NULL, 0) < 0){
5357
perror("sysinfo:");
5458
exit(1);
5559
}
5660
info.totalswap = swapinfo[0];
57-
info.freeswap = swapinfo[1];
61+
62+
if(swapinfo[3] == 0)
63+
info.freeswap = swapinfo[2];
64+
else
65+
info.freeswap = swapinfo[1];
5866

5967
/* TODO */
6068
info.sharedram = 0;

0 commit comments

Comments
 (0)