From ded38efb1ab9c510a5a6a674900f1df4a043d089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 11 Oct 2024 14:14:51 +0800 Subject: [PATCH] Memory (OpenBSD): fix detection of used memory size Fix #1331 --- src/detection/memory/memory_obsd.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/detection/memory/memory_obsd.c b/src/detection/memory/memory_obsd.c index c4119efb3..9efc21ead 100644 --- a/src/detection/memory/memory_obsd.c +++ b/src/detection/memory/memory_obsd.c @@ -1,20 +1,17 @@ #include "memory.h" #include "common/sysctl.h" -#include +#include const char* ffDetectMemory(FFMemoryResult* ram) { - size_t length = sizeof(ram->bytesTotal); - if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0) < 0) - return "Failed to read hw.physmem"; + struct uvmexp buf; + size_t length = sizeof(buf); + if (sysctl((int[]){ CTL_VM, VM_UVMEXP }, 2, &buf, &length, NULL, 0) < 0) + return "sysctl(CTL_VM, VM_UVMEXP) failed"; - struct vmtotal vmtotal; - length = sizeof(vmtotal); - if (sysctl((int[]) {CTL_VM, VM_METER}, 2, &vmtotal, &length, NULL, 0) < 0) - return "sysctl(VM_METER) failed"; - - ram->bytesUsed = ram->bytesTotal - vmtotal.t_free * instance.state.platform.sysinfo.pageSize; + ram->bytesTotal = (uint64_t) buf.npages * instance.state.platform.sysinfo.pageSize; + ram->bytesUsed = ram->bytesTotal - (uint64_t) buf.free * instance.state.platform.sysinfo.pageSize; return NULL; }