From fb675cefbda09ecadc656878fb27ee72a12692f0 Mon Sep 17 00:00:00 2001 From: Brendan Shanks Date: Fri, 17 Sep 2021 15:57:07 -0700 Subject: [PATCH] ntdll: Factor out get_smbios_from_iokit(). Signed-off-by: Brendan Shanks Signed-off-by: Alexandre Julliard --- dlls/ntdll/unix/system.c | 126 +++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 59 deletions(-) diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index 41a7d70fa21..57360c2c95c 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -1634,6 +1634,70 @@ static NTSTATUS get_firmware_info( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULON #elif defined(__APPLE__) +static NTSTATUS get_smbios_from_iokit( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len, + ULONG *required_len ) +{ + io_service_t service; + CFDataRef data; + const UInt8 *ptr; + CFIndex len; + struct smbios_prologue *prologue; + BYTE major_version = 2, minor_version = 0; + + if (!(service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleSMBIOS")))) + { + WARN("can't find AppleSMBIOS service\n"); + return STATUS_NO_MEMORY; + } + + if (!(data = IORegistryEntryCreateCFProperty(service, CFSTR("SMBIOS-EPS"), kCFAllocatorDefault, 0))) + { + WARN("can't find SMBIOS entry point\n"); + IOObjectRelease(service); + return STATUS_NO_MEMORY; + } + + len = CFDataGetLength(data); + ptr = CFDataGetBytePtr(data); + if (len >= 8 && !memcmp(ptr, "_SM_", 4)) + { + major_version = ptr[6]; + minor_version = ptr[7]; + } + CFRelease(data); + + if (!(data = IORegistryEntryCreateCFProperty(service, CFSTR("SMBIOS"), kCFAllocatorDefault, 0))) + { + WARN("can't find SMBIOS table\n"); + IOObjectRelease(service); + return STATUS_NO_MEMORY; + } + + len = CFDataGetLength(data); + ptr = CFDataGetBytePtr(data); + sfti->TableBufferLength = sizeof(*prologue) + len; + *required_len = sfti->TableBufferLength + FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer); + if (available_len < *required_len) + { + CFRelease(data); + IOObjectRelease(service); + return STATUS_BUFFER_TOO_SMALL; + } + + prologue = (struct smbios_prologue *)sfti->TableBuffer; + prologue->calling_method = 0; + prologue->major_version = major_version; + prologue->minor_version = minor_version; + prologue->revision = 0; + prologue->length = sfti->TableBufferLength - sizeof(*prologue); + + memcpy(sfti->TableBuffer + sizeof(*prologue), ptr, len); + + CFRelease(data); + IOObjectRelease(service); + return STATUS_SUCCESS; +} + static NTSTATUS get_firmware_info( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len, ULONG *required_len ) { @@ -1641,65 +1705,9 @@ static NTSTATUS get_firmware_info( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULON { case RSMB: { - io_service_t service; - CFDataRef data; - const UInt8 *ptr; - CFIndex len; - struct smbios_prologue *prologue; - BYTE major_version = 2, minor_version = 0; - - if (!(service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleSMBIOS")))) - { - WARN("can't find AppleSMBIOS service\n"); - return STATUS_NO_MEMORY; - } - - if (!(data = IORegistryEntryCreateCFProperty(service, CFSTR("SMBIOS-EPS"), kCFAllocatorDefault, 0))) - { - WARN("can't find SMBIOS entry point\n"); - IOObjectRelease(service); - return STATUS_NO_MEMORY; - } - - len = CFDataGetLength(data); - ptr = CFDataGetBytePtr(data); - if (len >= 8 && !memcmp(ptr, "_SM_", 4)) - { - major_version = ptr[6]; - minor_version = ptr[7]; - } - CFRelease(data); - - if (!(data = IORegistryEntryCreateCFProperty(service, CFSTR("SMBIOS"), kCFAllocatorDefault, 0))) - { - WARN("can't find SMBIOS table\n"); - IOObjectRelease(service); - return STATUS_NO_MEMORY; - } - - len = CFDataGetLength(data); - ptr = CFDataGetBytePtr(data); - sfti->TableBufferLength = sizeof(*prologue) + len; - *required_len = sfti->TableBufferLength + FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer); - if (available_len < *required_len) - { - CFRelease(data); - IOObjectRelease(service); - return STATUS_BUFFER_TOO_SMALL; - } - - prologue = (struct smbios_prologue *)sfti->TableBuffer; - prologue->calling_method = 0; - prologue->major_version = major_version; - prologue->minor_version = minor_version; - prologue->revision = 0; - prologue->length = sfti->TableBufferLength - sizeof(*prologue); - - memcpy(sfti->TableBuffer + sizeof(*prologue), ptr, len); - - CFRelease(data); - IOObjectRelease(service); - return STATUS_SUCCESS; + NTSTATUS ret; + ret = get_smbios_from_iokit(sfti, available_len, required_len); + return ret; } default: FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION provider %08x\n", sfti->ProviderSignature);