Skip to content

Commit fc969b0

Browse files
committed
Memory (NetBSD): change formula to be consistant with other systems
1 parent 41e22ea commit fc969b0

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ elseif(NetBSD)
752752
src/detection/localip/localip_linux.c
753753
src/detection/gamepad/gamepad_nosupport.c
754754
src/detection/media/media_linux.c
755-
src/detection/memory/memory_obsd.c
755+
src/detection/memory/memory_nbsd.c
756756
src/detection/mouse/mouse_nosupport.c
757757
src/detection/netio/netio_bsd.c
758758
src/detection/opengl/opengl_linux.c

src/detection/memory/memory_bsd.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
const char* ffDetectMemory(FFMemoryResult* ram)
55
{
66
size_t length = sizeof(ram->bytesTotal);
7-
if (sysctl((int[]){ CTL_HW,
8-
#if __NetBSD__
9-
HW_PHYSMEM64
10-
#else
11-
HW_PHYSMEM
12-
#endif
13-
}, 2, &ram->bytesTotal, &length, NULL, 0))
7+
if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0))
148
return "Failed to read hw.physmem";
159

1610
// vm.stats.vm.* are int values

src/detection/memory/memory_nbsd.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "memory.h"
2+
#include "common/sysctl.h"
3+
4+
#include <sys/param.h>
5+
#include <uvm/uvm_extern.h>
6+
7+
const char* ffDetectMemory(FFMemoryResult* ram)
8+
{
9+
struct uvmexp_sysctl buf;
10+
size_t length = sizeof(buf);
11+
if (sysctl((int[]){ CTL_VM, VM_UVMEXP2 }, 2, &buf, &length, NULL, 0) < 0)
12+
return "sysctl(CTL_VM, VM_UVMEXP2) failed";
13+
14+
ram->bytesTotal = (uint64_t) buf.npages * instance.state.platform.sysinfo.pageSize;
15+
ram->bytesUsed = ((uint64_t) buf.active + (uint64_t) buf.inactive + (uint64_t) buf.wired) * instance.state.platform.sysinfo.pageSize;
16+
17+
return NULL;
18+
}

0 commit comments

Comments
 (0)