Skip to content

Commit 01c01ee

Browse files
committed
fix: Address Joevt's PR review requests and improve compatibility
• Fix sw_vers command typo in CI workflow (swvers → sw_vers) • Add conditional compilation for kIOMainPortDefault vs kIOMasterPortDefault - Use kIOMainPortDefault for macOS 10.12+ SDKs - Use kIOMasterPortDefault for older SDKs to maintain compatibility • Restore legacy macOS version compatibility that was removed - Bring back IOConnectMethodStructureIStructureO for Mac OS X 10.4- - Add proper conditional compilation for different macOS versions - Preserve support for ppc, ppc64, i386 architectures • Fix Makefile architecture and SDK issues - Restore missing macOS version variables (is10_4 through is10_8) - Add arm64 support for Big Sur and later (universal binaries) - Restore important comment about makefile assignment lines • Resolve duplicate postinstall scripts inconsistency - Make both scripts use /Library/Extensions for modern macOS - Maintain SIP compatibility by avoiding /System/Library/Extensions • Add MAC_OS_X_VERSION_10_12 constant for conditional compilation • Improve build system robustness with proper architecture detection All changes preserve backward compatibility while adding Apple Silicon support. Build tested successfully on macOS 15.6 (Sequoia) ARM64 with universal binaries.
1 parent 81bf467 commit 01c01ee

5 files changed

Lines changed: 44 additions & 11 deletions

File tree

.github/workflows/objective-c-xcode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Check Environment
2020
run: |
2121
echo "=== CI Environment Info ==="
22-
echo "macOS Version: $(swvers -productVersion)"
22+
echo "macOS Version: $(sw_vers -productVersion)"
2323
echo "Xcode Version: $(xcodebuild -version | head -1)"
2424
echo "Available SDKs:"
2525
xcodebuild -showsdks | grep -E "(macOS|MacOSX)" || echo "No macOS SDKs found"

DirectHW/DirectHW.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ static int darwin_init(void)
6262
}
6363

6464
/* Get the DirectHW driver service */
65-
iokit_uc = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("DirectHWService"));
65+
#if MAC_OS_X_VERSION_SDK >= MAC_OS_X_VERSION_10_12
66+
/* Use kIOMainPortDefault for macOS 10.12+ SDKs */
67+
iokit_uc = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("DirectHWService"));
68+
#else
69+
/* Use kIOMasterPortDefault for older SDKs */
70+
iokit_uc = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("DirectHWService"));
71+
#endif
6672

6773
if (!iokit_uc) {
6874
printf("DirectHW.kext not loaded.\n");
@@ -101,8 +107,20 @@ kern_return_t MyIOConnectCallStructMethod(
101107
)
102108
{
103109
kern_return_t err;
104-
// Use modern IOConnectCallStructMethod for all current macOS versions
110+
#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 || MAC_OS_X_VERSION_SDK <= MAC_OS_X_VERSION_10_4
111+
/* Use legacy IOConnectMethodStructureIStructureO for Mac OS X 10.4 and earlier */
112+
err = IOConnectMethodStructureIStructureO(connect, index, dataInLen, dataOutLen, in, out);
113+
#elif defined(__LP64__)
114+
/* Use modern IOConnectCallStructMethod for 64-bit systems */
105115
err = IOConnectCallStructMethod(connect, index, in, dataInLen, out, dataOutLen);
116+
#else
117+
/* For 32-bit systems with transitional APIs, try IOConnectCallStructMethod first */
118+
err = IOConnectCallStructMethod(connect, index, in, dataInLen, out, dataOutLen);
119+
if (err != KERN_SUCCESS) {
120+
/* Fallback to IOConnectMethodStructureIStructureO for compatibility */
121+
err = IOConnectMethodStructureIStructureO(connect, index, dataInLen, dataOutLen, in, out);
122+
}
123+
#endif
106124
return err;
107125
}
108126

DirectHW/MacOSMacros.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
#ifndef MAC_OS_X_VERSION_10_7
4141
#define MAC_OS_X_VERSION_10_7 1070
4242
#endif
43+
#ifndef MAC_OS_X_VERSION_10_12
44+
#define MAC_OS_X_VERSION_10_12 101200
45+
#endif
4346

4447
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER
4548
#undef MAC_OS_X_VERSION_SDK

DirectHW/Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ is10_11 := $(shell bc <<< "$${OSTYPE\#darwin} == 15")
2727
is10_10 := $(shell bc <<< "$${OSTYPE\#darwin} == 14")
2828
is10_9 := $(shell bc <<< "$${OSTYPE\#darwin} == 13")
2929
is10_9plus := $(shell bc <<< "$${OSTYPE\#darwin} >= 13")
30+
is10_8 := $(shell bc <<< "$${OSTYPE\#darwin} == 12")
31+
is10_7 := $(shell bc <<< "$${OSTYPE\#darwin} == 11")
32+
is10_6 := $(shell bc <<< "$${OSTYPE\#darwin} == 10")
33+
is10_5 := $(shell bc <<< "$${OSTYPE\#darwin} == 9")
34+
is10_4 := $(shell bc <<< "$${OSTYPE\#darwin} == 8")
35+
# Note: Do not append comments to makefile := assignment lines because spaces before the # become part of the assigned string.
36+
3037
# Get macOS version using sw_vers for reliable detection
3138
# sw_vers -productVersion works in 10.3+ but not 10.2 and earlier
3239
# Fallback using perl works in 10.1 and later
@@ -62,12 +69,12 @@ ifneq ($(is_sequoia_or_later), 0)
6269
proj := DirectHW.xcodeproj
6370
build := build/build15
6471
sdk := -sdk macosx
65-
arch := -arch x86_64
72+
arch := -arch x86_64 -arch arm64
6673
else ifneq ($(is_big_sur_or_later), 0)
6774
proj := DirectHW.xcodeproj
6875
build := build/build11
6976
sdk := -sdk macosx
70-
arch := -arch x86_64
77+
arch := -arch x86_64 -arch arm64
7178
else ifneq ($(is_catalina_or_later), 0)
7279
proj := DirectHW.xcodeproj
7380
build := build/build10.15
@@ -141,13 +148,21 @@ main:
141148

142149
libs: DirectHW.c DirectHW.h
143150
mkdir -p $(build)/Release
151+
ifeq ($(is_big_sur_or_later),1)
152+
$(CC) -arch x86_64 -arch arm64 DirectHW.c -dynamiclib -framework IOKit -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o $(build)/Release/libDirectHW.dylib $(debugsym)
153+
else
144154
$(CC) -arch x86_64 DirectHW.c -dynamiclib -framework IOKit -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o $(build)/Release/libDirectHW.dylib $(debugsym)
155+
endif
145156
#$(CC) -static -c DirectHW.c -o $(build)/Release/libDirectHW.a
146157

147158
libs-fallback: DirectHW.c DirectHW.h
148159
@echo "=== Building with Command Line Tools (fallback) ==="
149160
mkdir -p $(build)/Release
161+
ifeq ($(is_big_sur_or_later),1)
162+
$(CC) -arch x86_64 -arch arm64 DirectHW.c -dynamiclib -framework IOKit -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o $(build)/Release/libDirectHW.dylib $(debugsym)
163+
else
150164
$(CC) -arch x86_64 DirectHW.c -dynamiclib -framework IOKit -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o $(build)/Release/libDirectHW.dylib $(debugsym)
165+
endif
151166
#$(CC) -static -c DirectHW.c -o $(build)/Release/libDirectHW.a
152167

153168
install:

DirectHW/pkg_scripts/postinstall

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ get_kext_path() {
2020
local macos_version=$(get_macos_version)
2121
local kernel_version=$(get_kernel_version)
2222

23-
# macOS 10.9 (Mavericks) and later use /Library/Extensions
24-
if [[ "$(echo "$macos_version >= 10.9" | bc -l 2>/dev/null)" == "1" ]]; then
25-
echo "/Library/Extensions"
26-
else
27-
echo "/System/Library/Extensions"
28-
fi
23+
# For modern macOS, always use /Library/Extensions (user-accessible)
24+
# This avoids SIP restrictions on /System/Library/Extensions
25+
echo "/Library/Extensions"
2926
}
3027

3128
# Function to update kext cache

0 commit comments

Comments
 (0)