Signed-off-by: Brendan Shanks bshanks@codeweavers.com --- dlls/ntdll/unix/system.c | 374 +++++++++++++++++++++------------------ 1 file changed, 202 insertions(+), 172 deletions(-)
diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index 2cdc6278f3d..145cb0810cd 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -1264,13 +1264,200 @@ static NTSTATUS create_cpuset_info(SYSTEM_CPU_SET_INFORMATION *info)
#ifdef linux
-static void copy_smbios_string( char **buffer, char *s, size_t len ) +static void copy_smbios_string( char **buffer, const char *s, size_t len ) { if (!len) return; memcpy(*buffer, s, len + 1); *buffer += len + 1; }
+#define S(s) const char * s, size_t s ## _len +static NTSTATUS create_smbios_tables( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len, + ULONG *required_len, + S(bios_vendor), S(bios_version), S(bios_date), + S(system_vendor), S(system_product), S(system_version), + S(system_serial), const GUID *system_uuid, S(system_sku), + S(system_family), + S(board_vendor), S(board_product), S(board_version), + S(board_serial), S(board_asset_tag), + S(chassis_vendor), BYTE chassis_type, S(chassis_version), + S(chassis_serial), S(chassis_asset_tag) ) +#undef S +{ + char *buffer = (char*)sfti->TableBuffer; + BYTE string_count; + BYTE handle_count = 0; + struct smbios_prologue *prologue; + struct smbios_bios *bios; + struct smbios_system *system; + struct smbios_board *board; + struct smbios_chassis *chassis; + struct smbios_boot_info *boot_info; + struct smbios_header *end_of_table; + + *required_len = sizeof(struct smbios_prologue); + +#define L(l) (l + (l ? 1 : 0)) + *required_len += sizeof(struct smbios_bios); + *required_len += max(L(bios_vendor_len) + L(bios_version_len) + L(bios_date_len) + 1, 2); + + *required_len += sizeof(struct smbios_system); + *required_len += max(L(system_vendor_len) + L(system_product_len) + L(system_version_len) + + L(system_serial_len) + L(system_sku_len) + L(system_family_len) + 1, 2); + + *required_len += sizeof(struct smbios_board); + *required_len += max(L(board_vendor_len) + L(board_product_len) + L(board_version_len) + + L(board_serial_len) + L(board_asset_tag_len) + 1, 2); + + *required_len += sizeof(struct smbios_chassis); + *required_len += max(L(chassis_vendor_len) + L(chassis_version_len) + L(chassis_serial_len) + + L(chassis_asset_tag_len) + 1, 2); + + *required_len += sizeof(struct smbios_boot_info); + *required_len += 2; + + *required_len += sizeof(struct smbios_header); + *required_len += 2; +#undef L + + sfti->TableBufferLength = *required_len; + + *required_len += FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer); + + if (available_len < *required_len) + return STATUS_BUFFER_TOO_SMALL; + + prologue = (struct smbios_prologue*)buffer; + prologue->calling_method = 0; + prologue->major_version = 2; + prologue->minor_version = 4; + prologue->revision = 0; + prologue->length = sfti->TableBufferLength - sizeof(struct smbios_prologue); + buffer += sizeof(struct smbios_prologue); + + string_count = 0; + bios = (struct smbios_bios*)buffer; + bios->hdr.type = 0; + bios->hdr.length = sizeof(struct smbios_bios); + bios->hdr.handle = handle_count++; + bios->vendor = bios_vendor_len ? ++string_count : 0; + bios->version = bios_version_len ? ++string_count : 0; + bios->start = 0; + bios->date = bios_date_len ? ++string_count : 0; + bios->size = 0; + bios->characteristics = 0x4; /* not supported */ + bios->characteristics_ext[0] = 0; + bios->characteristics_ext[1] = 0; + bios->system_bios_major_release = 0xFF; /* not supported */ + bios->system_bios_minor_release = 0xFF; /* not supported */ + bios->ec_firmware_major_release = 0xFF; /* not supported */ + bios->ec_firmware_minor_release = 0xFF; /* not supported */ + buffer += sizeof(struct smbios_bios); + + copy_smbios_string(&buffer, bios_vendor, bios_vendor_len); + copy_smbios_string(&buffer, bios_version, bios_version_len); + copy_smbios_string(&buffer, bios_date, bios_date_len); + if (!string_count) *buffer++ = 0; + *buffer++ = 0; + + string_count = 0; + system = (struct smbios_system*)buffer; + system->hdr.type = 1; + system->hdr.length = sizeof(struct smbios_system); + system->hdr.handle = handle_count++; + system->vendor = system_vendor_len ? ++string_count : 0; + system->product = system_product_len ? ++string_count : 0; + system->version = system_version_len ? ++string_count : 0; + system->serial = system_serial_len ? ++string_count : 0; + memcpy( system->uuid, system_uuid, sizeof(GUID) ); + system->wake_up_type = 0x02; /* unknown */ + system->sku_number = system_sku_len ? ++string_count : 0; + system->family = system_family_len ? ++string_count : 0; + buffer += sizeof(struct smbios_system); + + copy_smbios_string(&buffer, system_vendor, system_vendor_len); + copy_smbios_string(&buffer, system_product, system_product_len); + copy_smbios_string(&buffer, system_version, system_version_len); + copy_smbios_string(&buffer, system_serial, system_serial_len); + copy_smbios_string(&buffer, system_sku, system_sku_len); + copy_smbios_string(&buffer, system_family, system_family_len); + if (!string_count) *buffer++ = 0; + *buffer++ = 0; + + string_count = 0; + chassis = (struct smbios_chassis*)buffer; + chassis->hdr.type = 3; + chassis->hdr.length = sizeof(struct smbios_chassis); + chassis->hdr.handle = handle_count++; + chassis->vendor = chassis_vendor_len ? ++string_count : 0; + chassis->type = chassis_type; + chassis->version = chassis_version_len ? ++string_count : 0; + chassis->serial = chassis_serial_len ? ++string_count : 0; + chassis->asset_tag = chassis_asset_tag_len ? ++string_count : 0; + chassis->boot_state = 0x02; /* unknown */ + chassis->power_supply_state = 0x02; /* unknown */ + chassis->thermal_state = 0x02; /* unknown */ + chassis->security_status = 0x02; /* unknown */ + chassis->oem_defined = 0; + chassis->height = 0; /* undefined */ + chassis->num_power_cords = 0; /* unspecified */ + chassis->num_contained_elements = 0; + chassis->contained_element_rec_length = 3; + buffer += sizeof(struct smbios_chassis); + + copy_smbios_string(&buffer, chassis_vendor, chassis_vendor_len); + copy_smbios_string(&buffer, chassis_version, chassis_version_len); + copy_smbios_string(&buffer, chassis_serial, chassis_serial_len); + copy_smbios_string(&buffer, chassis_asset_tag, chassis_asset_tag_len); + if (!string_count) *buffer++ = 0; + *buffer++ = 0; + + string_count = 0; + board = (struct smbios_board*)buffer; + board->hdr.type = 2; + board->hdr.length = sizeof(struct smbios_board); + board->hdr.handle = handle_count++; + board->vendor = board_vendor_len ? ++string_count : 0; + board->product = board_product_len ? ++string_count : 0; + board->version = board_version_len ? ++string_count : 0; + board->serial = board_serial_len ? ++string_count : 0; + board->asset_tag = board_asset_tag_len ? ++string_count : 0; + board->feature_flags = 0x5; /* hosting board, removable */ + board->location = 0; + board->chassis_handle = chassis->hdr.handle; + board->board_type = 0xa; /* motherboard */ + board->num_contained_handles = 0; + buffer += sizeof(struct smbios_board); + + copy_smbios_string(&buffer, board_vendor, board_vendor_len); + copy_smbios_string(&buffer, board_product, board_product_len); + copy_smbios_string(&buffer, board_version, board_version_len); + copy_smbios_string(&buffer, board_serial, board_serial_len); + copy_smbios_string(&buffer, board_asset_tag, board_asset_tag_len); + if (!string_count) *buffer++ = 0; + *buffer++ = 0; + + boot_info = (struct smbios_boot_info*)buffer; + boot_info->hdr.type = 32; + boot_info->hdr.length = sizeof(struct smbios_boot_info); + boot_info->hdr.handle = handle_count++; + memset(boot_info->reserved, 0, sizeof(boot_info->reserved)); + memset(boot_info->boot_status, 0, sizeof(boot_info->boot_status)); /* no errors detected */ + buffer += sizeof(struct smbios_boot_info); + *buffer++ = 0; + *buffer++ = 0; + + end_of_table = (struct smbios_header*)buffer; + end_of_table->type = 127; + end_of_table->length = sizeof(struct smbios_header); + end_of_table->handle = handle_count++; + buffer += sizeof(struct smbios_header); + *buffer++ = 0; + *buffer++ = 0; + + return STATUS_SUCCESS; +} + static size_t get_smbios_string( const char *path, char *str, size_t size ) { FILE *file; @@ -1343,16 +1530,7 @@ static NTSTATUS get_firmware_info( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULON char chassis_vendor[128], chassis_version[128], chassis_serial[128], chassis_asset_tag[128]; char chassis_type[11] = "2"; /* unknown */ size_t chassis_vendor_len, chassis_version_len, chassis_serial_len, chassis_asset_tag_len; - char *buffer = (char*)sfti->TableBuffer; - BYTE string_count; - BYTE handle_count = 0; - struct smbios_prologue *prologue; - struct smbios_bios *bios; - struct smbios_system *system; - struct smbios_board *board; - struct smbios_chassis *chassis; - struct smbios_boot_info *boot_info; - struct smbios_header *end_of_table; + GUID system_uuid;
#define S(s) s, sizeof(s) bios_vendor_len = get_smbios_string("/sys/class/dmi/id/bios_vendor", S(bios_vendor)); @@ -1376,167 +1554,19 @@ static NTSTATUS get_firmware_info( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULON get_smbios_string("/sys/class/dmi/id/chassis_type", S(chassis_type)); #undef S
- *required_len = sizeof(struct smbios_prologue); - -#define L(l) (l + (l ? 1 : 0)) - *required_len += sizeof(struct smbios_bios); - *required_len += max(L(bios_vendor_len) + L(bios_version_len) + L(bios_date_len) + 1, 2); - - *required_len += sizeof(struct smbios_system); - *required_len += max(L(system_vendor_len) + L(system_product_len) + L(system_version_len) + - L(system_serial_len) + L(system_sku_len) + L(system_family_len) + 1, 2); - - *required_len += sizeof(struct smbios_board); - *required_len += max(L(board_vendor_len) + L(board_product_len) + L(board_version_len) + - L(board_serial_len) + L(board_asset_tag_len) + 1, 2); - - *required_len += sizeof(struct smbios_chassis); - *required_len += max(L(chassis_vendor_len) + L(chassis_version_len) + L(chassis_serial_len) + - L(chassis_asset_tag_len) + 1, 2); - - *required_len += sizeof(struct smbios_boot_info); - *required_len += 2; - - *required_len += sizeof(struct smbios_header); - *required_len += 2; -#undef L - - sfti->TableBufferLength = *required_len; - - *required_len += FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer); - - if (available_len < *required_len) - return STATUS_BUFFER_TOO_SMALL; - - prologue = (struct smbios_prologue*)buffer; - prologue->calling_method = 0; - prologue->major_version = 2; - prologue->minor_version = 4; - prologue->revision = 0; - prologue->length = sfti->TableBufferLength - sizeof(struct smbios_prologue); - buffer += sizeof(struct smbios_prologue); - - string_count = 0; - bios = (struct smbios_bios*)buffer; - bios->hdr.type = 0; - bios->hdr.length = sizeof(struct smbios_bios); - bios->hdr.handle = handle_count++; - bios->vendor = bios_vendor_len ? ++string_count : 0; - bios->version = bios_version_len ? ++string_count : 0; - bios->start = 0; - bios->date = bios_date_len ? ++string_count : 0; - bios->size = 0; - bios->characteristics = 0x4; /* not supported */ - bios->characteristics_ext[0] = 0; - bios->characteristics_ext[1] = 0; - bios->system_bios_major_release = 0xFF; /* not supported */ - bios->system_bios_minor_release = 0xFF; /* not supported */ - bios->ec_firmware_major_release = 0xFF; /* not supported */ - bios->ec_firmware_minor_release = 0xFF; /* not supported */ - buffer += sizeof(struct smbios_bios); - - copy_smbios_string(&buffer, bios_vendor, bios_vendor_len); - copy_smbios_string(&buffer, bios_version, bios_version_len); - copy_smbios_string(&buffer, bios_date, bios_date_len); - if (!string_count) *buffer++ = 0; - *buffer++ = 0; - - string_count = 0; - system = (struct smbios_system*)buffer; - system->hdr.type = 1; - system->hdr.length = sizeof(struct smbios_system); - system->hdr.handle = handle_count++; - system->vendor = system_vendor_len ? ++string_count : 0; - system->product = system_product_len ? ++string_count : 0; - system->version = system_version_len ? ++string_count : 0; - system->serial = system_serial_len ? ++string_count : 0; - get_system_uuid( (GUID *)system->uuid ); - system->wake_up_type = 0x02; /* unknown */ - system->sku_number = system_sku_len ? ++string_count : 0; - system->family = system_family_len ? ++string_count : 0; - buffer += sizeof(struct smbios_system); - - copy_smbios_string(&buffer, system_vendor, system_vendor_len); - copy_smbios_string(&buffer, system_product, system_product_len); - copy_smbios_string(&buffer, system_version, system_version_len); - copy_smbios_string(&buffer, system_serial, system_serial_len); - copy_smbios_string(&buffer, system_sku, system_sku_len); - copy_smbios_string(&buffer, system_family, system_family_len); - if (!string_count) *buffer++ = 0; - *buffer++ = 0; - - string_count = 0; - chassis = (struct smbios_chassis*)buffer; - chassis->hdr.type = 3; - chassis->hdr.length = sizeof(struct smbios_chassis); - chassis->hdr.handle = handle_count++; - chassis->vendor = chassis_vendor_len ? ++string_count : 0; - chassis->type = atoi(chassis_type); - chassis->version = chassis_version_len ? ++string_count : 0; - chassis->serial = chassis_serial_len ? ++string_count : 0; - chassis->asset_tag = chassis_asset_tag_len ? ++string_count : 0; - chassis->boot_state = 0x02; /* unknown */ - chassis->power_supply_state = 0x02; /* unknown */ - chassis->thermal_state = 0x02; /* unknown */ - chassis->security_status = 0x02; /* unknown */ - chassis->oem_defined = 0; - chassis->height = 0; /* undefined */ - chassis->num_power_cords = 0; /* unspecified */ - chassis->num_contained_elements = 0; - chassis->contained_element_rec_length = 3; - buffer += sizeof(struct smbios_chassis); - - copy_smbios_string(&buffer, chassis_vendor, chassis_vendor_len); - copy_smbios_string(&buffer, chassis_version, chassis_version_len); - copy_smbios_string(&buffer, chassis_serial, chassis_serial_len); - copy_smbios_string(&buffer, chassis_asset_tag, chassis_asset_tag_len); - if (!string_count) *buffer++ = 0; - *buffer++ = 0; - - string_count = 0; - board = (struct smbios_board*)buffer; - board->hdr.type = 2; - board->hdr.length = sizeof(struct smbios_board); - board->hdr.handle = handle_count++; - board->vendor = board_vendor_len ? ++string_count : 0; - board->product = board_product_len ? ++string_count : 0; - board->version = board_version_len ? ++string_count : 0; - board->serial = board_serial_len ? ++string_count : 0; - board->asset_tag = board_asset_tag_len ? ++string_count : 0; - board->feature_flags = 0x5; /* hosting board, removable */ - board->location = 0; - board->chassis_handle = chassis->hdr.handle; - board->board_type = 0xa; /* motherboard */ - board->num_contained_handles = 0; - buffer += sizeof(struct smbios_board); - - copy_smbios_string(&buffer, board_vendor, board_vendor_len); - copy_smbios_string(&buffer, board_product, board_product_len); - copy_smbios_string(&buffer, board_version, board_version_len); - copy_smbios_string(&buffer, board_serial, board_serial_len); - copy_smbios_string(&buffer, board_asset_tag, board_asset_tag_len); - if (!string_count) *buffer++ = 0; - *buffer++ = 0; - - boot_info = (struct smbios_boot_info*)buffer; - boot_info->hdr.type = 32; - boot_info->hdr.length = sizeof(struct smbios_boot_info); - boot_info->hdr.handle = handle_count++; - memset(boot_info->reserved, 0, sizeof(boot_info->reserved)); - memset(boot_info->boot_status, 0, sizeof(boot_info->boot_status)); /* no errors detected */ - buffer += sizeof(struct smbios_boot_info); - *buffer++ = 0; - *buffer++ = 0; - - end_of_table = (struct smbios_header*)buffer; - end_of_table->type = 127; - end_of_table->length = sizeof(struct smbios_header); - end_of_table->handle = handle_count++; - buffer += sizeof(struct smbios_header); - *buffer++ = 0; - *buffer++ = 0; - - return STATUS_SUCCESS; + get_system_uuid(&system_uuid); + +#define S(s) s, s ## _len + return create_smbios_tables( sfti, available_len, required_len, + S(bios_vendor), S(bios_version), S(bios_date), + S(system_vendor), S(system_product), S(system_version), + S(system_serial), &system_uuid, S(system_sku), + S(system_family), + S(board_vendor), S(board_product), S(board_version), + S(board_serial), S(board_asset_tag), + S(chassis_vendor), atoi(chassis_type), S(chassis_version), + S(chassis_serial), S(chassis_asset_tag) ); +#undef S } default: FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION provider %08x\n", sfti->ProviderSignature);
Signed-off-by: Brendan Shanks bshanks@codeweavers.com --- dlls/ntdll/unix/system.c | 118 +++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 55 deletions(-)
diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index 145cb0810cd..70636020489 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -1576,72 +1576,80 @@ static NTSTATUS get_firmware_info( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULON
#elif defined(__APPLE__)
-static NTSTATUS get_firmware_info( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len, - ULONG *required_len ) +static NTSTATUS get_smbios_from_iokit( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len, + ULONG *required_len ) { - switch (sfti->ProviderSignature) + 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")))) { - case RSMB: + WARN("can't find AppleSMBIOS service\n"); + return STATUS_NO_MEMORY; + } + + if (!(data = IORegistryEntryCreateCFProperty(service, CFSTR("SMBIOS-EPS"), kCFAllocatorDefault, 0))) { - io_service_t service; - CFDataRef data; - const UInt8 *ptr; - CFIndex len; - struct smbios_prologue *prologue; - BYTE major_version = 2, minor_version = 0; + WARN("can't find SMBIOS entry point\n"); + IOObjectRelease(service); + return STATUS_NO_MEMORY; + }
- if (!(service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleSMBIOS")))) - { - WARN("can't find AppleSMBIOS service\n"); - 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-EPS"), kCFAllocatorDefault, 0))) - { - WARN("can't find SMBIOS entry point\n"); - IOObjectRelease(service); - return STATUS_NO_MEMORY; - } + 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); - if (len >= 8 && !memcmp(ptr, "_SM_", 4)) - { - major_version = ptr[6]; - minor_version = ptr[7]; - } + 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; + }
- 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);
- 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);
- memcpy(sfti->TableBuffer + sizeof(*prologue), ptr, len); + CFRelease(data); + IOObjectRelease(service); + return STATUS_SUCCESS; +}
- CFRelease(data); - IOObjectRelease(service); - return STATUS_SUCCESS; +static NTSTATUS get_firmware_info( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len, + ULONG *required_len ) +{ + switch (sfti->ProviderSignature) + { + case RSMB: + { + 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);
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51557 Signed-off-by: Brendan Shanks bshanks@codeweavers.com --- dlls/ntdll/unix/system.c | 105 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index 70636020489..960a737028f 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -1262,7 +1262,7 @@ static NTSTATUS create_cpuset_info(SYSTEM_CPU_SET_INFORMATION *info) return STATUS_SUCCESS; }
-#ifdef linux +#if defined(linux) || defined(__APPLE__)
static void copy_smbios_string( char **buffer, const char *s, size_t len ) { @@ -1458,6 +1458,10 @@ static NTSTATUS create_smbios_tables( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, U return STATUS_SUCCESS; }
+#endif + +#ifdef linux + static size_t get_smbios_string( const char *path, char *str, size_t size ) { FILE *file; @@ -1640,6 +1644,103 @@ static NTSTATUS get_smbios_from_iokit( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, return STATUS_SUCCESS; }
+static size_t cf_to_string( CFTypeRef type_ref, char *buffer, size_t buffer_size ) +{ + size_t length = 0; + + if (!type_ref) + return 0; + + if (CFGetTypeID(type_ref) == CFDataGetTypeID()) + { + length = MIN(CFDataGetLength(type_ref), buffer_size); + CFDataGetBytes(type_ref, CFRangeMake(0, length), (UInt8*)buffer); + buffer[length] = 0; + length = strlen(buffer); + } + else if (CFGetTypeID(type_ref) == CFStringGetTypeID()) + { + if (CFStringGetCString(type_ref, buffer, buffer_size, kCFStringEncodingASCII)) + length = strlen(buffer); + } + + CFRelease(type_ref); + return length; +} + +static NTSTATUS generate_smbios( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len, + ULONG *required_len ) +{ + /* Apple Silicon Macs don't have SMBIOS, we need to generate it. + * Use strings and data from IOKit when available. + */ + io_service_t platform_expert; + CFDataRef cf_manufacturer, cf_model; + CFStringRef cf_serial_number, cf_uuid_string; + char manufacturer[128], model[128], serial_number[128]; + size_t manufacturer_len = 0, model_len = 0, serial_number_len = 0; + GUID system_uuid = {0}; + + platform_expert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); + if (!platform_expert) + return STATUS_NO_MEMORY; + + cf_manufacturer = IORegistryEntryCreateCFProperty(platform_expert, CFSTR("manufacturer"), kCFAllocatorDefault, 0); + cf_model = IORegistryEntryCreateCFProperty(platform_expert, CFSTR("model"), kCFAllocatorDefault, 0); + cf_serial_number = IORegistryEntryCreateCFProperty(platform_expert, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0); + cf_uuid_string = IORegistryEntryCreateCFProperty(platform_expert, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); + + manufacturer_len = cf_to_string(cf_manufacturer, manufacturer, sizeof(manufacturer)); + model_len = cf_to_string(cf_model, model, sizeof(model)); + serial_number_len = cf_to_string(cf_serial_number, serial_number, sizeof(serial_number)); + + if (cf_uuid_string) + { + CFUUIDRef cf_uuid; + CFUUIDBytes bytes; + + cf_uuid = CFUUIDCreateFromString(kCFAllocatorDefault, cf_uuid_string); + bytes = CFUUIDGetUUIDBytes(cf_uuid); + + system_uuid.Data1 = (bytes.byte0 << 24) | (bytes.byte1 << 16) | (bytes.byte2 << 8) | bytes.byte3; + system_uuid.Data2 = (bytes.byte4 << 8) | bytes.byte5; + system_uuid.Data3 = (bytes.byte6 << 8) | bytes.byte7; + memcpy(&system_uuid.Data4, &bytes.byte8, sizeof(system_uuid.Data4)); + + CFRelease(cf_uuid); + CFRelease(cf_uuid_string); + } + + IOObjectRelease(platform_expert); + +#define S(s) s, s ## _len +#define STR(s) s, sizeof(s)-1 + return create_smbios_tables( sfti, available_len, required_len, + S(manufacturer), /* BIOS vendor */ + STR("1.0"), /* BIOS version (required) */ + STR("01/01/2021"), /* BIOS date (required) */ + S(manufacturer), /* system vendor */ + S(model), /* system product */ + STR("1.0"), /* system version */ + S(serial_number), /* system serial number */ + &system_uuid, /* system UUID */ + NULL, 0, /* system SKU */ + S(model), /* system family */ + S(manufacturer), /* board vendor */ + S(model), /* board product */ + S(model), /* board version */ + S(serial_number), /* board serial number */ + NULL, 0, /* board asset tag */ + S(manufacturer), /* chassis vendor */ + 2, /* chassis type: unknown */ + NULL, 0, /* chassis version */ + S(serial_number), /* chassis serial number */ + NULL, 0 /* chassis asset tag */ + ); +#undef STR +#undef S +} + static NTSTATUS get_firmware_info( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len, ULONG *required_len ) { @@ -1649,6 +1750,8 @@ static NTSTATUS get_firmware_info( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULON { NTSTATUS ret; ret = get_smbios_from_iokit(sfti, available_len, required_len); + if (ret == STATUS_NO_MEMORY) + ret = generate_smbios(sfti, available_len, required_len); return ret; } default:
Brendan Shanks bshanks@codeweavers.com writes:
@@ -1264,13 +1264,200 @@ static NTSTATUS create_cpuset_info(SYSTEM_CPU_SET_INFORMATION *info)
#ifdef linux
-static void copy_smbios_string( char **buffer, char *s, size_t len ) +static void copy_smbios_string( char **buffer, const char *s, size_t len ) { if (!len) return; memcpy(*buffer, s, len + 1); *buffer += len + 1; }
+#define S(s) const char * s, size_t s ## _len +static NTSTATUS create_smbios_tables( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len,
ULONG *required_len,
S(bios_vendor), S(bios_version), S(bios_date),
S(system_vendor), S(system_product), S(system_version),
S(system_serial), const GUID *system_uuid, S(system_sku),
S(system_family),
S(board_vendor), S(board_product), S(board_version),
S(board_serial), S(board_asset_tag),
S(chassis_vendor), BYTE chassis_type, S(chassis_version),
S(chassis_serial), S(chassis_asset_tag) )
+#undef S
If you have to add macros to define the function parameters, it's probably a sign that you should be passing some sort of array or structure instead.