Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b181bb5

Browse files
Added support for Apple macOS
1 parent aad65d8 commit b181bb5

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

‎Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ CFLAGS += -O2
2929
# Pass linker flags here
3030
LDFLAGS =
3131

32+
# Flags for Apple macOS
33+
ifeq ($(shell uname -s),Darwin)
34+
CFLAGS += -Wno-constant-logical-operand
35+
LDFLAGS += -framework CoreServices -framework IOKit
36+
endif
37+
3238
DESTDIR =
3339
prefix = /usr/local
3440
sbindir = $(prefix)/sbin

‎config.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#endif
2323

2424
/* Use memory alignment workaround or not */
25-
#ifdef__ia64__
25+
#if defined(__ia64__) || defined(__LP64__)
2626
#define ALIGNMENT_WORKAROUND
2727
#endif
2828

‎dmidecode.c‎

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
* https://trustedcomputinggroup.org/pc-client-platform-tpm-profile-ptp-specification/
5959
*/
6060

61+
#if defined(__APPLE__)
62+
#include <Carbon/Carbon.h>
63+
#endif
64+
6165
#include <stdio.h>
6266
#include <string.h>
6367
#include <strings.h>
@@ -79,6 +83,7 @@ static const char *bad_index = "<BAD INDEX>";
7983

8084
#define FLAG_NO_FILE_OFFSET (1 << 0)
8185
#define FLAG_STOP_AT_EOT (1 << 1)
86+
#define FLAG_FROM_API (1 << 2)
8287

8388
#define SYS_FIRMWARE_DIR "/sys/firmware/dmi/tables"
8489
#define SYS_ENTRY_FILE SYS_FIRMWARE_DIR "/smbios_entry_point"
@@ -4727,7 +4732,7 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
47274732
if (num)
47284733
printf("%u structures occupying %u bytes.\n",
47294734
num, len);
4730-
if (!(opt.flags & FLAG_FROM_DUMP))
4735+
if (!(flags&FLAG_FROM_API) && !(opt.flags & FLAG_FROM_DUMP))
47314736
printf("Table at 0x%08llX.\n",
47324737
(unsigned long long)base);
47334738
}
@@ -4758,6 +4763,61 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
47584763
else
47594764
buf = mem_chunk(base, len, devmem);
47604765

4766+
#ifdef __APPLE__
4767+
// read tables returned by API call
4768+
if (flags & FLAG_FROM_API)
4769+
{
4770+
mach_port_t masterPort;
4771+
CFMutableDictionaryRef properties = NULL;
4772+
io_service_t service = MACH_PORT_NULL;
4773+
CFDataRef dataRef;
4774+
4775+
IOMasterPort(MACH_PORT_NULL, &masterPort);
4776+
service = IOServiceGetMatchingService(masterPort,
4777+
IOServiceMatching("AppleSMBIOS"));
4778+
if (service == MACH_PORT_NULL)
4779+
{
4780+
fprintf(stderr, "AppleSMBIOS service is unreachable, sorry.\n");
4781+
return;
4782+
}
4783+
4784+
if (kIOReturnSuccess != IORegistryEntryCreateCFProperties(service,
4785+
&properties, kCFAllocatorDefault, kNilOptions))
4786+
{
4787+
fprintf(stderr, "No data in AppleSMBIOS IOService, sorry.\n");
4788+
return;
4789+
}
4790+
4791+
if (!CFDictionaryGetValueIfPresent(properties, CFSTR( "SMBIOS"),
4792+
(const void **)&dataRef))
4793+
{
4794+
fprintf(stderr, "SMBIOS property data is unreachable, sorry.\n");
4795+
return;
4796+
}
4797+
4798+
len = CFDataGetLength(dataRef);
4799+
if((buf = malloc(sizeof(u8) * len)) == NULL)
4800+
{
4801+
perror("malloc");
4802+
return;
4803+
}
4804+
4805+
CFDataGetBytes(dataRef, CFRangeMake(0, len), (UInt8*)buf);
4806+
4807+
if (NULL != dataRef)
4808+
CFRelease(dataRef);
4809+
4810+
/*
4811+
* This CFRelease throws 'Segmentation fault: 11' since macOS 10.12, if
4812+
* the compiled binary is not signed with an Apple developer profile.
4813+
*/
4814+
if (NULL != properties)
4815+
CFRelease(properties);
4816+
4817+
IOObjectRelease(service);
4818+
}
4819+
#endif // __APPLE__
4820+
47614821
if (buf == NULL)
47624822
{
47634823
fprintf(stderr, "Failed to read table, sorry.\n");
@@ -5052,6 +5112,55 @@ int main(int argc, char * const argv[])
50525112
goto done;
50535113
}
50545114

5115+
#if defined(__APPLE__)
5116+
mach_port_t masterPort;
5117+
io_service_t service = MACH_PORT_NULL;
5118+
CFDataRef dataRef;
5119+
5120+
if (!(opt.flags & FLAG_QUIET))
5121+
printf("Getting SMBIOS data from Apple SMBIOS service.\n");
5122+
5123+
IOMasterPort(MACH_PORT_NULL, &masterPort);
5124+
service = IOServiceGetMatchingService(masterPort,
5125+
IOServiceMatching("AppleSMBIOS"));
5126+
if (service == MACH_PORT_NULL)
5127+
{
5128+
fprintf(stderr, "AppleSMBIOS service is unreachable, sorry.");
5129+
ret = 1;
5130+
goto exit_free;
5131+
}
5132+
5133+
dataRef = (CFDataRef) IORegistryEntryCreateCFProperty(service,
5134+
CFSTR("SMBIOS-EPS"), kCFAllocatorDefault, kNilOptions);
5135+
5136+
if (dataRef == NULL)
5137+
{
5138+
fprintf(stderr, "SMBIOS entry point is unreachable, sorry.\n");
5139+
ret = 1;
5140+
goto exit_free;
5141+
}
5142+
5143+
if((buf = malloc(0x20)) == NULL)
5144+
{
5145+
perror("malloc");
5146+
ret = 1;
5147+
goto exit_free;
5148+
}
5149+
5150+
CFDataGetBytes(dataRef, CFRangeMake(0, 0x20), (UInt8*)buf);
5151+
5152+
if (NULL != dataRef)
5153+
CFRelease(dataRef);
5154+
IOObjectRelease(service);
5155+
5156+
if (smbios_decode(buf, NULL, FLAG_FROM_API))
5157+
{
5158+
found++;
5159+
goto done;
5160+
}
5161+
5162+
#endif // __APPLE__
5163+
50555164
/*
50565165
* First try reading from sysfs tables. The entry point file could
50575166
* contain one of several types of entry points, so read enough for

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /