diff --git a/CMakeLists.txt b/CMakeLists.txt index fd1913975..08fcd9f29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -781,7 +781,7 @@ elseif(SunOS) src/detection/localip/localip_linux.c src/detection/gamepad/gamepad_nosupport.c src/detection/media/media_linux.c - src/detection/memory/memory_nosupport.c + src/detection/memory/memory_sunos.c src/detection/monitor/monitor_nosupport.c src/detection/netio/netio_nosupport.c src/detection/opengl/opengl_linux.c diff --git a/src/detection/memory/memory_sunos.c b/src/detection/memory/memory_sunos.c new file mode 100644 index 000000000..9e9f0f11e --- /dev/null +++ b/src/detection/memory/memory_sunos.c @@ -0,0 +1,34 @@ +#include "memory.h" +#include + +static inline void kstatFreeWrap(kstat_ctl_t** pkc) +{ + assert(pkc); + if (*pkc) + kstat_close(*pkc); +} + +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.pageSize; + } + { + kstat_named_t* kn = kstat_data_lookup(ks, "pagesfree"); + ram->bytesUsed = ram->bytesTotal - kn->value.ui64 * instance.state.platform.pageSize; + } + + return NULL; +}