From cd9cfa5d9938d600a419b324b672567330376783 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:32:52 +0800 Subject: [PATCH] Memory (SunOS): simplify --- src/detection/memory/memory_sunos.c | 30 +++-------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/detection/memory/memory_sunos.c b/src/detection/memory/memory_sunos.c index 4633eb6c0..1df271055 100644 --- a/src/detection/memory/memory_sunos.c +++ b/src/detection/memory/memory_sunos.c @@ -1,34 +1,10 @@ #include "memory.h" -#include - -static inline void kstatFreeWrap(kstat_ctl_t** pkc) -{ - assert(pkc); - if (*pkc) - kstat_close(*pkc); -} +#include const char* ffDetectMemory(FFMemoryResult* ram) { - __attribute__((__cleanup__(kstatFreeWrap))) kstat_ctl_t* kc = kstat_open(); - if (!kc) - return "kstat_open() failed"; - - kstat_t* ks = kstat_lookup(kc, "unix", -1, "system_pages"); - if (!ks) - return "kstat_lookup() failed"; - - if (kstat_read(kc, ks, NULL) < 0) - return "kstat_read() failed"; - - { - kstat_named_t* kn = kstat_data_lookup(ks, "pagestotal"); - ram->bytesTotal = kn->value.ui64 * instance.state.platform.sysinfo.pageSize; - } - { - kstat_named_t* kn = kstat_data_lookup(ks, "pagesfree"); - ram->bytesUsed = ram->bytesTotal - kn->value.ui64 * instance.state.platform.sysinfo.pageSize; - } + ram->bytesTotal = sysconf(_SC_PHYS_PAGES) * instance.state.platform.sysinfo.pageSize; + ram->bytesUsed = ram->bytesTotal - sysconf(_SC_AVPHYS_PAGES) * instance.state.platform.sysinfo.pageSize; return NULL; }