diff --git a/CMakeLists.txt b/CMakeLists.txt index 199e4a2cb..dbb42d1dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -949,14 +949,11 @@ elseif(APPLE) src/common/apple/osascript.m src/common/apple/smc_temps.c src/detection/battery/battery_apple.c - src/detection/bios/bios_apple.c src/detection/bluetooth/bluetooth_apple.m src/detection/bluetoothradio/bluetoothradio_apple.m - src/detection/board/board_apple.c src/detection/bootmgr/bootmgr_apple.c src/detection/brightness/brightness_apple.c src/detection/btrfs/btrfs_nosupport.c - src/detection/chassis/chassis_apple.c src/detection/cpu/cpu_apple.c src/detection/cpucache/cpucache_apple.c src/detection/cpuusage/cpuusage_apple.c @@ -964,13 +961,11 @@ elseif(APPLE) src/detection/disk/disk_bsd.c src/detection/dns/dns_apple.c src/detection/physicaldisk/physicaldisk_apple.c - src/detection/physicalmemory/physicalmemory_apple.m src/detection/diskio/diskio_apple.c src/detection/displayserver/displayserver_apple.c src/detection/font/font_apple.m src/detection/gpu/gpu_apple.c src/detection/gpu/gpu_apple.m - src/detection/host/host_apple.c src/detection/host/host_mac.c src/detection/icons/icons_nosupport.c src/detection/initsystem/initsystem_linux.c @@ -1007,6 +1002,24 @@ elseif(APPLE) src/detection/wmtheme/wmtheme_apple.m src/detection/camera/camera_apple.m ) + # CMAKE_SYSTEM_PROCESSOR has been normalized before + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64") + list(APPEND LIBFASTFETCH_SRC + src/detection/bios/bios_windows.c + src/detection/board/board_windows.c + src/detection/chassis/chassis_windows.c + src/detection/host/host_windows.c + src/detection/physicalmemory/physicalmemory_linux.c + ) + else() + list(APPEND LIBFASTFETCH_SRC + src/detection/bios/bios_apple.c + src/detection/board/board_apple.c + src/detection/chassis/chassis_apple.c + src/detection/host/host_apple.c + src/detection/physicalmemory/physicalmemory_apple.m + ) + endif() elseif(WIN32) list(APPEND LIBFASTFETCH_SRC src/common/impl/io_windows.c diff --git a/src/common/impl/smbiosHelper.c b/src/common/impl/smbiosHelper.c index 2872b3431..6a0ec6840 100644 --- a/src/common/impl/smbiosHelper.c +++ b/src/common/impl/smbiosHelper.c @@ -536,4 +536,70 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable() return &table; } +#elif defined(__APPLE__) +#include "common/apple/cf_helpers.h" + +const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable() +{ + static CFDataRef smbiosDataBuffer; + static FFSmbiosHeaderTable table; + + if (smbiosDataBuffer == NULL) + { + FF_DEBUG("Initializing SMBIOS buffer on Apple platform"); + + FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t registryEntry = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("AppleSMBIOS")); + + if (!registryEntry) + { + FF_DEBUG("IOServiceGetMatchingService() failed to find AppleSMBIOS"); + smbiosDataBuffer = CFDataCreate(NULL, NULL, 0); + return NULL; + } + + FF_DEBUG("AppleSMBIOS service found, retrieving SMBIOS data"); + smbiosDataBuffer = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("SMBIOS"), kCFAllocatorDefault, kNilOptions); + if (!smbiosDataBuffer) + { + FF_DEBUG("IORegistryEntryCreateCFProperty() failed to get SMBIOS data"); + smbiosDataBuffer = CFDataCreate(NULL, NULL, 0); + return NULL; + } + + FF_DEBUG("Successfully retrieved SMBIOS data: %lu bytes", CFDataGetLength(smbiosDataBuffer)); + + FF_DEBUG("Parsing SMBIOS table structures"); + FF_MAYBE_UNUSED int structureCount = 0; + for ( + const FFSmbiosHeader* header = (const FFSmbiosHeader*) CFDataGetBytePtr(smbiosDataBuffer), + *end = (const FFSmbiosHeader*) ((const uint8_t*) header + CFDataGetLength(smbiosDataBuffer)); + header < end; + header = ffSmbiosNextEntry(header) + ) + { + if (header->Type < FF_SMBIOS_TYPE_END_OF_TABLE) + { + if (!table[header->Type]) { + table[header->Type] = header; + FF_DEBUG("Found SMBIOS structure type %u, handle 0x%04X, length %u", + header->Type, header->Handle, header->Length); + structureCount++; + } + } + else if (header->Type == FF_SMBIOS_TYPE_END_OF_TABLE) { + FF_DEBUG("Reached end-of-table marker"); + break; + } + } + FF_DEBUG("Parsed %d SMBIOS structures", structureCount); + } + + if (CFDataGetLength(smbiosDataBuffer) == 0) + { + FF_DEBUG("No valid SMBIOS data available"); + return NULL; + } + + return &table; +} #endif diff --git a/src/detection/bios/bios_windows.c b/src/detection/bios/bios_windows.c index 716add370..f1196a3d4 100644 --- a/src/detection/bios/bios_windows.c +++ b/src/detection/bios/bios_windows.c @@ -11,10 +11,12 @@ #include #include - #elif __sun #include #include +#elif __APPLE__ +#include "common/apple/cf_helpers.h" +#include #endif typedef struct FFSmbiosBios @@ -90,8 +92,12 @@ const char* ffDetectBios(FFBiosResult* bios) } di_fini(rootNode); #elif __HAIKU__ || __OpenBSD__ - // Currently SMBIOS detection is supported in legancy BIOS only + // Currently SMBIOS detection is supported in legacy BIOS only ffStrbufSetStatic(&bios->type, "BIOS"); + #elif __APPLE__ + // Intel Macs use UEFI from day one + FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t deviceEfi = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/efi"); + ffStrbufSetStatic(&bios->type, deviceEfi ? "UEFI" : "BIOS"); #endif return NULL; diff --git a/src/detection/host/host_windows.c b/src/detection/host/host_windows.c index 3fa07fd75..a9c14e6ca 100644 --- a/src/detection/host/host_windows.c +++ b/src/detection/host/host_windows.c @@ -72,7 +72,7 @@ const char* ffDetectHost(FFHostResult* host) ffCleanUpSmbiosValue(&host->family); } - #if _WIN64 && __x86_64__ // aarch64 also defines _WIN64 + #if __x86_64__ ffHostDetectMac(host); #endif