diff --git a/src/Summary.cpp b/src/Summary.cpp index b925232fd..8118f99d7 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -147,13 +147,13 @@ static void print_memory() continue; } - if (!memory.size()) { - Log::print(WHITE_BOLD(" %-13s") "%s: " BLACK_BOLD(""), "", memory.slot().data()); - continue; + if (memory.size()) { + Log::print(WHITE_BOLD(" %-13s") "%s: " CYAN_BOLD("%" PRIu64) CYAN(" GB ") WHITE_BOLD("%s @ %" PRIu64 " MHz ") BLACK_BOLD("%s"), + "", memory.slot().data(), memory.size() / oneGiB, memory.type(), memory.speed() / 1000000ULL, memory.product().data()); + } + else if (!Cpu::info()->isVM()) { + Log::print(WHITE_BOLD(" %-13s") "%s: " BLACK_BOLD(""), "", memory.slot().data()); } - - Log::print(WHITE_BOLD(" %-13s") "%s: " CYAN_BOLD("%" PRIu64) CYAN(" GB ") WHITE_BOLD("%s @ %" PRIu64 " MHz ") BLACK_BOLD("%s"), - "", memory.slot().data(), memory.size() / oneGiB, memory.type(), memory.speed() / 1000000ULL, memory.product().data()); } if (reader.board().isValid()) { diff --git a/src/hw/dmi/DmiReader.cpp b/src/hw/dmi/DmiReader.cpp index 8993531a6..5c6a9607f 100644 --- a/src/hw/dmi/DmiReader.cpp +++ b/src/hw/dmi/DmiReader.cpp @@ -70,6 +70,10 @@ bool xmrig::DmiReader::decode(uint8_t *buf) while (static_cast(next - buf + 1) < m_size && (next[0] != 0 || next[1] != 0)) { next++; } + +# ifdef XMRIG_OS_APPLE + while ((unsigned long)(next - buf + 1) < m_size && (next[0] == 0 && next[1] == 0)) +# endif next += 2; if (static_cast(next - buf) > m_size) { diff --git a/src/hw/dmi/DmiReader_mac.cpp b/src/hw/dmi/DmiReader_mac.cpp new file mode 100644 index 000000000..a23bfe47f --- /dev/null +++ b/src/hw/dmi/DmiReader_mac.cpp @@ -0,0 +1,108 @@ +/* XMRig + * Copyright (c) 2002-2006 Hugo Weber + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "hw/dmi/DmiReader.h" +#include "hw/dmi/DmiTools.h" + + +#include + + +namespace xmrig { + + +static int checksum(const uint8_t *buf, size_t len) +{ + uint8_t sum = 0; + + for (size_t a = 0; a < len; a++) { + sum += buf[a]; + } + + return (sum == 0); +} + + +static uint8_t *dmi_table(uint32_t base, uint32_t &len, io_service_t service) +{ + CFMutableDictionaryRef properties = nullptr; + if (IORegistryEntryCreateCFProperties(service, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) { + return nullptr; + } + + CFDataRef data; + uint8_t *buf = nullptr; + + if (CFDictionaryGetValueIfPresent(properties, CFSTR("SMBIOS"), (const void **)&data)) { + assert(len == CFDataGetLength(data)); + + len = CFDataGetLength(data); + buf = reinterpret_cast(malloc(len)); + + CFDataGetBytes(data, CFRangeMake(0, len), buf); + } + + CFRelease(properties); + + return buf; +} + + +static uint8_t *smbios_decode(uint8_t *buf, uint32_t &size, uint32_t &version, io_service_t service) +{ + if (buf[0x05] > 0x20 || !checksum(buf, buf[0x05]) || memcmp(buf + 0x10, "_DMI_", 5) != 0 || !checksum(buf + 0x10, 0x0F)) { + return nullptr; + } + + version = ((buf[0x06] << 8) + buf[0x07]) << 8; + size = dmi_get(buf + 0x16); + + return dmi_table(dmi_get(buf + 0x18), size, service); +} + +} // namespace xmrig + + +bool xmrig::DmiReader::read() +{ + mach_port_t port; + IOMasterPort(MACH_PORT_NULL, &port); + + io_service_t service = IOServiceGetMatchingService(port, IOServiceMatching("AppleSMBIOS")); + if (service == MACH_PORT_NULL) { + return false; + } + + CFDataRef data = reinterpret_cast(IORegistryEntryCreateCFProperty(service, CFSTR("SMBIOS-EPS"), kCFAllocatorDefault, kNilOptions)); + if (!data) { + return false; + } + + uint8_t buf[0x20]{}; + CFDataGetBytes(data, CFRangeMake(0, sizeof(buf)), buf); + CFRelease(data); + + auto smb = smbios_decode(buf, m_size, m_version, service); + const bool rc = smb ? decode(smb) : false; + + IOObjectRelease(service); + + return rc; +} diff --git a/src/hw/dmi/dmi.cmake b/src/hw/dmi/dmi.cmake index e10ec3ed4..aee0ff9a3 100644 --- a/src/hw/dmi/dmi.cmake +++ b/src/hw/dmi/dmi.cmake @@ -19,6 +19,10 @@ if (WITH_DMI) list(APPEND SOURCES src/hw/dmi/DmiReader_win.cpp) elseif(XMRIG_OS_LINUX OR XMRIG_OS_FREEBSD) list(APPEND SOURCES src/hw/dmi/DmiReader_unix.cpp) + elseif(XMRIG_OS_MACOS) + list(APPEND SOURCES src/hw/dmi/DmiReader_mac.cpp) + find_library(CORESERVICES_LIBRARY CoreServices) + list(APPEND EXTRA_LIBS ${CORESERVICES_LIBRARY}) endif() else() remove_definitions(/DXMRIG_FEATURE_DMI)