From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/detection/swap/swap_sunos.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/detection/swap/swap_sunos.c (limited to 'src/detection/swap/swap_sunos.c') diff --git a/src/detection/swap/swap_sunos.c b/src/detection/swap/swap_sunos.c new file mode 100644 index 0000000..fa3260d --- /dev/null +++ b/src/detection/swap/swap_sunos.c @@ -0,0 +1,32 @@ +#include "swap.h" +#include +#include +#include +#include + +enum { FFMaxNSwap = 8 }; + +const char* ffDetectSwap(FFlist* result) { + char strings[FFMaxNSwap][PATH_MAX]; + alignas(swaptbl_t) uint8_t buffer[sizeof(swaptbl_t) + sizeof(swapent_t) * (FFMaxNSwap - 1)] = {}; + swaptbl_t* table = (swaptbl_t*) buffer; + table->swt_n = FFMaxNSwap; + for (int i = 0; i < FFMaxNSwap; ++i) { + table->swt_ent[i].ste_path = strings[i]; + } + + int size = swapctl(SC_LIST, table); + if (size < 0) { + return "swapctl() failed"; + } + + uint32_t pageSize = instance.state.platform.sysinfo.pageSize; + for (int i = 0; i < size; ++i) { + FFSwapResult* swap = FF_LIST_ADD(FFSwapResult, *result); + ffStrbufInitS(&swap->name, table->swt_ent[i].ste_path); + swap->bytesTotal = (uint64_t) table->swt_ent[i].ste_pages * pageSize; + swap->bytesUsed = swap->bytesTotal - (uint64_t) table->swt_ent[i].ste_free * pageSize; + } + + return NULL; +} -- cgit v1.2.3