Files
fastfetch/src/detection/memory/memory_apple.c
T

28 lines
876 B
C
Raw Normal View History

#include "memory.h"
2022-09-05 02:46:53 -07:00
2022-09-08 14:51:31 +02:00
#include <string.h>
2022-09-05 02:46:53 -07:00
#include <mach/mach.h>
#include <sys/sysctl.h>
2023-05-11 20:39:54 +08:00
#include <unistd.h>
2023-05-11 20:39:54 +08:00
const char* ffDetectMemory(FFMemoryResult* ram)
{
size_t length = sizeof(ram->bytesTotal);
if (sysctl((int[]){ CTL_HW, HW_MEMSIZE }, 2, &ram->bytesTotal, &length, NULL, 0))
2023-05-11 20:39:54 +08:00
return "Failed to read hw.memsize";
2022-09-05 02:46:53 -07:00
uint32_t pagesize;
length = sizeof(pagesize);
if (sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &pagesize, &length, NULL, 0))
2023-05-11 20:39:54 +08:00
return "Failed to read hw.pagesize";
2022-09-05 02:46:53 -07:00
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
vm_statistics64_data_t vmstat;
if(host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) (&vmstat), &count) != KERN_SUCCESS)
2023-05-11 20:39:54 +08:00
return "Failed to read host_statistics64";
2022-09-05 02:46:53 -07:00
2022-09-20 15:21:39 +02:00
ram->bytesUsed = ((uint64_t) vmstat.active_count + vmstat.wire_count) * pagesize;
2023-05-11 20:39:54 +08:00
return NULL;
2022-09-20 15:12:24 +02:00
}