Skip to content

Commit

Permalink
Memory (NetBSD): change formula to be consistant with other systems
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Jan 13, 2025
1 parent 41e22ea commit fc969b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ elseif(NetBSD)
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_linux.c
src/detection/memory/memory_obsd.c
src/detection/memory/memory_nbsd.c
src/detection/mouse/mouse_nosupport.c
src/detection/netio/netio_bsd.c
src/detection/opengl/opengl_linux.c
Expand Down
8 changes: 1 addition & 7 deletions src/detection/memory/memory_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
const char* ffDetectMemory(FFMemoryResult* ram)
{
size_t length = sizeof(ram->bytesTotal);
if (sysctl((int[]){ CTL_HW,
#if __NetBSD__
HW_PHYSMEM64
#else
HW_PHYSMEM
#endif
}, 2, &ram->bytesTotal, &length, NULL, 0))
if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0))
return "Failed to read hw.physmem";

// vm.stats.vm.* are int values
Expand Down
18 changes: 18 additions & 0 deletions src/detection/memory/memory_nbsd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "memory.h"
#include "common/sysctl.h"

#include <sys/param.h>
#include <uvm/uvm_extern.h>

const char* ffDetectMemory(FFMemoryResult* ram)
{
struct uvmexp_sysctl buf;
size_t length = sizeof(buf);
if (sysctl((int[]){ CTL_VM, VM_UVMEXP2 }, 2, &buf, &length, NULL, 0) < 0)
return "sysctl(CTL_VM, VM_UVMEXP2) failed";

ram->bytesTotal = (uint64_t) buf.npages * instance.state.platform.sysinfo.pageSize;
ram->bytesUsed = ((uint64_t) buf.active + (uint64_t) buf.inactive + (uint64_t) buf.wired) * instance.state.platform.sysinfo.pageSize;

return NULL;
}

0 comments on commit fc969b0

Please sign in to comment.