Skip to content

Commit e2d145c

Browse files
committed
Memory (Apple): use sysctl instead of sysctlbyname
1 parent b634c70 commit e2d145c

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/detection/memory/memory_apple.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
#include "memory.h"
2-
#include "common/sysctl.h"
32

43
#include <string.h>
54
#include <mach/mach.h>
5+
#include <sys/sysctl.h>
66

77
void ffDetectMemory(FFMemoryStorage* ram)
88
{
9-
ram->bytesTotal = (uint64_t) ffSysctlGetInt64("hw.memsize", 0);
10-
if(ram->bytesTotal == 0)
9+
size_t length = sizeof(ram->bytesTotal);
10+
if (sysctl((int[]){ CTL_HW, HW_MEMSIZE }, 2, &ram->bytesTotal, &length, NULL, 0))
1111
{
1212
ffStrbufAppendS(&ram->error, "Failed to read hw.memsize");
1313
return;
1414
}
1515

16-
uint32_t pagesize = (uint32_t) ffSysctlGetInt("hw.pagesize", 0);
17-
if(pagesize == 0)
16+
uint32_t pagesize;
17+
length = sizeof(pagesize);
18+
if (sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &pagesize, &length, NULL, 0))
1819
{
1920
ffStrbufAppendS(&ram->error, "Failed to read hw.pagesize");
2021
return;
2122
}
2223

23-
mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
24-
vm_statistics_data_t vmstat;
25-
if(host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t) (&vmstat), &count) != KERN_SUCCESS)
24+
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
25+
vm_statistics64_data_t vmstat;
26+
if(host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) (&vmstat), &count) != KERN_SUCCESS)
2627
{
27-
ffStrbufAppendS(&ram->error, "Failed to read vm statistics");
28+
ffStrbufAppendS(&ram->error, "Failed to read host_statistics64");
2829
return;
2930
}
3031

src/detection/swap/swap_apple.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "swap.h"
2-
#include "common/sysctl.h"
32

43
#include <mach/mach.h>
4+
#include <sys/sysctl.h>
55

66
void ffDetectSwap(FFMemoryStorage* swap)
77
{
88
struct xsw_usage xsw;
99
size_t size = sizeof(xsw);
10-
if(sysctlbyname("vm.swapusage", &xsw, &size, 0, 0) != 0)
10+
if(sysctl((int[]){ CTL_VM, VM_SWAPUSAGE }, 2, &xsw, &size, NULL, 0) != 0)
1111
{
1212
ffStrbufAppendS(&swap->error, "Failed to read vm.swapusage");
1313
return;

0 commit comments

Comments
 (0)