Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Bundle GPU compiler plugin and merge it during firmware preparation

Lakrf9e7abbdfef9
diff --git a/docs/guides/create-and-run.md b/docs/guides/create-and-run.md
index c2d18fa1..8faa741c 100644
--- a/docs/guides/create-and-run.md
+++ b/docs/guides/create-and-run.md
@@ -19,6 +19,8 @@ Creation runs prepare → JB patch → online DFU restore → host-mounted CFW i
`fw prepare` creates a temporary vphone VM, starts it in DFU, and restores the selected cloudOS IPSW using this project's restore backend. It mounts the restored System volume read-only, extracts the GPU bundle, then removes the temporary VM. This first restore supplies the GPU driver for the second, hybrid iPhone restore. `vm create` and `fw prepare` also accept `--gpu-driver-bundle /path/to/AppleParavirtGPUMetalIOGPUFamily.bundle` to reuse a previously extracted bundle without the temporary restore. The CLI checks its iPhoneOS platform version against the selected cloudOS version. Each restore obtains its own ticket online.
+The build also ships an arm64e GPU compiler plugin as a compressed app resource. `fw prepare` extracts it and merges it into the staged GPU bundle before firmware patching and installation.
+
Success ends with `First boot: vphoned ping succeeded` and `JB VM created; vphoned connected`. **The verification VM is then stopped.** The ping proves the daemon answered over the host control socket during that boot; it does not leave a running VM behind.
```sh
diff --git a/research/0_binary_patch_comparison.md b/research/0_binary_patch_comparison.md
index 0d3f7ecd..fdee544c 100644
--- a/research/0_binary_patch_comparison.md
+++ b/research/0_binary_patch_comparison.md
@@ -1237,9 +1237,16 @@ Both the JB host-mount installer and the filesystem merge copy this staged
bundle into the iPhone guest. The 26.4 `23E5207q` restored bundle has
`DTPlatformVersion=26.4`, `CFBundleVersion=64.4.4`, and binary SHA-256
`29ba36c7bc87d82c40fa1cecdf357e7a383fa70eb46df0d75869f5ac562aedbc`.
-It lacks the compiler-plugin dylib present in the 26.1 bundle, so the installer
-only sets that file's permissions if it exists. This is a payload-source and
-installation change, not a new binary patch.
+It lacks the compiler-plugin dylib present in the 26.1 bundle. A first boot
+without it connected vphoned but left the VM window black: `MTLCompilerService`
+repeatedly aborted in `messageHandler`, and `backboardd` reported
+`XPC_ERROR_CONNECTION_INTERRUPTED` after repeated Metal compilation attempts.
+The repository now builds `siblings/gpu/main.mm` (the 0xjohnnydev compiler
+plugin reimplementation) into an arm64e iPhoneOS dylib. `build.sh` signs and
+compresses it into `vphone-cli.app/Contents/Resources/gpu/compiler-plugin.tar.zst`.
+`fw prepare` decompresses and merges that dylib into the firmware-sourced GPU
+bundle, and both JB installation paths require it. This adds a guest payload;
+it does not patch the Apple GPU driver binary.
**`find -name '._*' -delete` → `deleteAppleDoubleFiles`,** and this one was nearly a
silent regression worth writing down. On a volume with native extended attributes,
diff --git a/scripts/build.sh b/scripts/build.sh
index b81f3c26..36bece16 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -167,6 +167,22 @@ cp .build/guest/vphoned .build/vphoned
cp .build/vphoned .build/vphoned.signed
echo " signed → .build/vphoned.signed"
+# The restored PCC System volume supplies the GPU driver but cloudOS 26.4
+# omits the compiler plugin needed by MTLCompilerService. Build our guest
+# implementation and ship it compressed for fw prepare to merge.
+echo "=== Building PCC GPU compiler plugin (arm64e, iphoneos) ==="
+make -C siblings gpu
+GPU_PLUGIN=".build/siblings/stage/gpu/libAppleParavirtCompilerPluginIOGPUFamily.dylib"
+if ! file "$GPU_PLUGIN" | grep -q arm64e; then
+ echo "Error: ${GPU_PLUGIN} is not arm64e." >&2
+ exit 1
+fi
+codesign -v "$GPU_PLUGIN"
+mkdir -p .build/guest/gpu-plugin-archive
+cp -f "$GPU_PLUGIN" .build/guest/gpu-plugin-archive/
+"$ARCHIVE_BINARY" create --file .build/guest/gpu-compiler-plugin.tar.zst \
+ --directory .build/guest/gpu-plugin-archive --zstd
+
# --- Bundle the standalone runtime mini-repo into Contents/Resources ---
RES="${BUNDLE}/Contents/Resources"
echo "=== Bundling runtime assets → ${RES} ==="
@@ -183,7 +199,7 @@ echo "=== Bundling runtime assets → ${RES} ==="
# and the only reason the dependency gate had anything left to find. The trust
# cache itself is generated by /System/Library/SecurityResearch's cryptexctl.
rm -rf "${RES}/scripts" "${RES}/guest" "${RES}/tools" "${RES}/.tools" \
- "${RES}/vphoned.signed" "${RES}/requirements.txt" "${RES}/debs.list"
+ "${RES}/gpu" "${RES}/vphoned.signed" "${RES}/requirements.txt" "${RES}/debs.list"
mkdir -p "${RES}/scripts"
# An ALLOWLIST, from each script's own `# vphone-tier:` line. This used to be a
# list of exclusions, which meant anything new shipped by default — and so the
@@ -195,6 +211,8 @@ zsh scripts/dist_manifest.sh | rsync -a --files-from=- scripts/ "${RES}/scripts/
mkdir -p "${RES}/guest"
cp -f .build/guest/vphoned "${RES}/guest/vphoned"
cp -f .build/guest/icli "${RES}/guest/icli"
+mkdir -p "${RES}/gpu"
+cp -f .build/guest/gpu-compiler-plugin.tar.zst "${RES}/gpu/compiler-plugin.tar.zst"
[[ -f .build/vphoned.signed ]] && cp -f .build/vphoned.signed "${RES}/vphoned.signed" || true
# The compatibility guide is the only documentation `fw prepare` reads at runtime.
# Remove an old bundled README so it cannot silently become a stale data source.
@@ -202,7 +220,7 @@ rm -f "${RES}/README.md"
rm -rf "${RES}/docs"
mkdir -p "${RES}/docs/guides"
cp -f docs/guides/compatibility.md "${RES}/docs/guides/compatibility.md"
-echo " bundled: scripts/ (dist tier), guest/vphoned, guest/icli, vphoned.signed, compatibility.md"
+echo " bundled: scripts/ (dist tier), guest/vphoned, guest/icli, gpu/compiler-plugin.tar.zst, vphoned.signed, compatibility.md"
# Re-sign: codesign seals Contents/Resources at sign time, so the earlier
# bundle-step signature (made before these assets existed) is now stale —
diff --git a/siblings/Makefile b/siblings/Makefile
index 18df6a27..062b8798 100644
--- a/siblings/Makefile
+++ b/siblings/Makefile
@@ -1,5 +1,5 @@
-# Sibling guest components. The four source components compile with the iPhoneOS SDK.
-# The GPU item is provenance only: fw prepare extracts the actual Apple bundle.
+# Sibling guest components compile with the iPhoneOS SDK.
+# The GPU driver comes from firmware; its compiler plugin is built here.
OUT := $(abspath ../.build/siblings)
STAGE := $(OUT)/stage
@@ -11,14 +11,17 @@ CAMFIX := $(STAGE)/camfix/libcamfix.dylib
VCAMCAPTURED := $(STAGE)/vcamcaptured/libvcamcaptured.dylib
TWEAKLOADER := $(STAGE)/tweakloader/TweakLoader.dylib
VPREGISTER := $(STAGE)/vpregister/vpregister
-ARTIFACTS := $(CAMFIX) $(VCAMCAPTURED) $(TWEAKLOADER) $(VPREGISTER)
+GPU_PLUGIN := $(STAGE)/gpu/libAppleParavirtCompilerPluginIOGPUFamily.dylib
+ARTIFACTS := $(CAMFIX) $(VCAMCAPTURED) $(TWEAKLOADER) $(VPREGISTER) $(GPU_PLUGIN)
PLISTS := $(STAGE)/camfix/libcamfix.plist $(STAGE)/vcamcaptured/libvcamcaptured.plist
GPU_PROVENANCE := $(STAGE)/gpu/README.md
-.PHONY: all package clean
+.PHONY: all gpu package clean
all: $(ARTIFACTS) $(PLISTS) $(GPU_PROVENANCE)
+gpu: $(GPU_PLUGIN)
+
package: all
@rm -f $(ARCHIVE)
@/usr/bin/tar -cf $(ARCHIVE) -C $(STAGE) camfix vcamcaptured tweakloader vpregister gpu
@@ -53,6 +56,14 @@ $(VPREGISTER): vpregister/vpregister.m | $(STAGE)/vpregister
$(CLANG) $(COMMON_FLAGS) -o $@ $< -framework Foundation
@codesign --force --sign - $@
+$(GPU_PLUGIN): gpu/main.mm | $(STAGE)/gpu
+ xcrun --sdk iphoneos clang++ -arch arm64e -miphoneos-version-min=26.1 \
+ -std=c++17 -O2 -dynamiclib -Wl,-undefined,dynamic_lookup \
+ -Wl,-not_for_dyld_shared_cache \
+ -install_name /System/Library/Extensions/AppleParavirtGPUMetalIOGPUFamily.bundle/libAppleParavirtCompilerPluginIOGPUFamily.dylib \
+ -o $@ $<
+ @codesign --force --sign - $@
+
$(STAGE)/camfix/libcamfix.plist: camfix/libcamfix.plist | $(STAGE)/camfix
@cp $< $@
diff --git a/siblings/gpu/README.md b/siblings/gpu/README.md
index 772b0528..10f75f21 100644
--- a/siblings/gpu/README.md
+++ b/siblings/gpu/README.md
@@ -1,7 +1,7 @@
# PCC GPU component
-`AppleParavirtGPUMetalIOGPUFamily.bundle` is Apple firmware content. There is
-no source here to compile and no binary to package in `vphone-cli.app`.
+`AppleParavirtGPUMetalIOGPUFamily.bundle` is Apple firmware content. Its
+compiler plugin is built from source in this directory.
`vphone-cli fw prepare` creates a temporary PV=3 VM, boots it into DFU, and
restores the selected cloudOS IPSW with the project's in-process idevicerestore
@@ -13,6 +13,13 @@ same PCC release used for the VM's kernel.
The cloudOS 26.4 `23E5207q` bundle recovered from its restored System volume
has `DTPlatformVersion=26.4`, `CFBundleVersion=64.4.4`, and no
-`libAppleParavirtCompilerPluginIOGPUFamily.dylib`. The older 26.1 bundle has
-that dylib. Neither is compiled by this project; the installer preserves the
-files Apple actually provides for the selected release.
+`libAppleParavirtCompilerPluginIOGPUFamily.dylib`. Without it,
+`MTLCompilerService` repeatedly aborts and `backboardd` reports interrupted
+Metal compilation, leaving the host VM window black even while vphoned connects.
+
+`main.mm` is the compiler-plugin reimplementation from
+[0xjohnnydev's metal-patch](https://github.com/0xjohnnydev/0xjohnnydev.github.io/blob/main/blog/assets/metal-patch/main.mm).
+`make -C siblings gpu` builds and ad-hoc signs it for iPhoneOS arm64e.
+`scripts/build.sh` stores it as `Resources/gpu/compiler-plugin.tar.zst` in the
+app. `fw prepare` extracts that archive and puts the dylib alongside the
+firmware-sourced GPU driver before exposing the complete restore tree.
diff --git a/siblings/gpu/main.mm b/siblings/gpu/main.mm
new file mode 100644
index 00000000..65764b24
--- /dev/null
+++ b/siblings/gpu/main.mm
@@ -0,0 +1,264 @@
+// Reimplementation of libAppleParavirtCompilerPluginIOGPUFamily.dylib
+// Metal shader compiler plugin for the paravirtualized GPU.
+// Bridges between Metal's compiler interface and the GPUCompiler/LLVM pipeline.
+//
+// Reverse-engineered from the PCC DSC module.
+
+#include <cstdlib>
+#include <cstring>
+#include <cstdint>
+
+// --- LLVM C API (from libLLVM.dylib) ---
+extern "C" {
+ // Opaque types
+ typedef struct LLVMOpaqueModule *LLVMModuleRef;
+ typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
+ typedef struct LLVMOpaqueValue *LLVMValueRef;
+
+ // LLVM buffer/module functions (confirmed exported via DSC auth_stubs)
+ void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
+ const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
+ size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
+ const char *LLVMGetTarget(LLVMModuleRef M);
+ LLVMModuleRef LLVMExtraMakeSharedModule(LLVMModuleRef M);
+ void LLVMExtraDisposeSharedModule(LLVMModuleRef M);
+
+ // LLVM metadata access (older C API, available since LLVM 3.x)
+ unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
+ void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name, LLVMValueRef *Dest);
+ unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
+ void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
+ const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length);
+}
+
+// --- GPUCompiler API (from libGPUCompiler.dylib) ---
+extern "C" {
+ typedef void *MTLGPUCompilerRef;
+ typedef void *MTLMetalLibRef;
+ typedef void *MTLMetalFunctionRef;
+
+ MTLGPUCompilerRef MTLGPUCompilerCreate(int version);
+ void MTLGPUCompilerDestroy(MTLGPUCompilerRef compiler);
+ int MTLDowngradeAIRModule(LLVMModuleRef module, const char *targetTriple, int flags);
+ MTLMetalLibRef MTLMetalLibCreateExecutableWithTriple(LLVMModuleRef sharedModule, const char *entryPointData);
+ MTLMetalFunctionRef MTLMetalFunctionCreate(LLVMModuleRef sharedModule, const char *entryName);
+ void MTLMetalLibInsertFunction(MTLMetalLibRef lib, MTLMetalFunctionRef func);
+ LLVMMemoryBufferRef MTLWriteMetalLibToMemoryBuffer(MTLMetalLibRef lib);
+}
+
+// --- Compiler target info struct (passed by Metal framework) ---
+struct AppleParavirtCompilerTargetInfo {
+ const char *targetTriple;
+};
+
+// --- AppleParavirtCompiler class ---
+class AppleParavirtCompiler {
+public:
+ virtual ~AppleParavirtCompiler();
+
+ bool init(const AppleParavirtCompilerTargetInfo *info);
+
+ bool buildRequestWithOptions(
+ const void *inputData, size_t inputSize, unsigned int flags,
+ LLVMModuleRef module,
+ const void **outCode, size_t *outCodeSize,
+ const void **outReflection, size_t *outReflectionSize,
+ const void **outDebug, size_t *outDebugSize,
+ const char **outError);
+
+ void deleteCompilerReply();
+
+private:
+ LLVMMemoryBufferRef _bufferRef = nullptr;
+ MTLGPUCompilerRef _gpuCompiler = nullptr;
+ const char *_targetTriple = nullptr;
+};
+
+// Entry point metadata names to search in LLVM IR modules
+static const char *entryPointsMetadata[] = {
+ "air.vertex",
+ "air.fragment",
+ "air.kernel",
+};
+static const int numEntryPointsMetadata = 3;
+
+// --- Implementation ---
+
+AppleParavirtCompiler::~AppleParavirtCompiler() {
+ if (_gpuCompiler) {
+ MTLGPUCompilerDestroy(_gpuCompiler);
+ _gpuCompiler = nullptr;
+ }
+}
+
+bool AppleParavirtCompiler::init(const AppleParavirtCompilerTargetInfo *info) {
+ _targetTriple = info->targetTriple;
+ _gpuCompiler = MTLGPUCompilerCreate(1);
+ return (_gpuCompiler != nullptr);
+}
+
+void AppleParavirtCompiler::deleteCompilerReply() {
+ if (_bufferRef) {
+ LLVMDisposeMemoryBuffer(_bufferRef);
+ _bufferRef = nullptr;
+ }
+}
+
+bool AppleParavirtCompiler::buildRequestWithOptions(
+ const void *inputData, size_t inputSize, unsigned int flags,
+ LLVMModuleRef module,
+ const void **outCode, size_t *outCodeSize,
+ const void **outReflection, size_t *outReflectionSize,
+ const void **outDebug, size_t *outDebugSize,
+ const char **outError)
+{
+ _bufferRef = nullptr;
+
+ if (!module) {
+ *outError = "null module";
+ return true; // error
+ }
+
+ // Downgrade the AIR module for this target
+ int result = MTLDowngradeAIRModule(module, _targetTriple, 0);
+ if (!result) {
+ // Downgrade returned 0 = success with nothing to do
+ *outError = nullptr;
+ return false; // success (no error)
+ }
+
+ if (!_gpuCompiler) {
+ *outError = "no gpu compiler";
+ return true;
+ }
+
+ // Search for entry point metadata in the module
+ const char *entryName = nullptr;
+ size_t entryNameLen = 0;
+
+ for (int i = 0; i < numEntryPointsMetadata; i++) {
+ unsigned numNamedOps = LLVMGetNamedMetadataNumOperands(module, entryPointsMetadata[i]);
+ if (numNamedOps > 0) {
+ LLVMValueRef *namedOps = (LLVMValueRef *)alloca(numNamedOps * sizeof(LLVMValueRef));
+ LLVMGetNamedMetadataOperands(module, entryPointsMetadata[i], namedOps);
+ LLVMValueRef mdNode = namedOps[0];
+ if (mdNode) {
+ unsigned numOps = LLVMGetMDNodeNumOperands(mdNode);
+ if (numOps > 0) {
+ LLVMValueRef *ops = (LLVMValueRef *)alloca(numOps * sizeof(LLVMValueRef));
+ LLVMGetMDNodeOperands(mdNode, ops);
+ if (ops[0]) {
+ entryName = LLVMGetValueName2(ops[0], &entryNameLen);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ // Get the target triple from the module
+ const char *triple = LLVMGetTarget(module);
+
+ // Create a metallib executable
+ LLVMModuleRef sharedModule = LLVMExtraMakeSharedModule(module);
+
+ // Build the entry point name string (may need null-termination)
+ char *entryNameStr = nullptr;
+ if (entryName && entryNameLen > 0) {
+ entryNameStr = (char *)malloc(entryNameLen + 1);
+ memcpy(entryNameStr, entryName, entryNameLen);
+ entryNameStr[entryNameLen] = '\0';
+ }
+
+ // Create metallib with triple
+ MTLMetalLibRef metalLib = MTLMetalLibCreateExecutableWithTriple(sharedModule,
+ entryNameStr ? entryNameStr : "");
+
+ if (entryNameStr) {
+ free(entryNameStr);
+ }
+
+ if (!metalLib) {
+ LLVMExtraDisposeSharedModule(sharedModule);
+ *outError = "failed to create metallib";
+ return true;
+ }
+
+ // Create and insert function
+ MTLMetalFunctionRef func = MTLMetalFunctionCreate(sharedModule, entryName);
+ MTLMetalLibInsertFunction(metalLib, func);
+
+ // Write to memory buffer
+ _bufferRef = MTLWriteMetalLibToMemoryBuffer(metalLib);
+ if (!_bufferRef) {
+ LLVMExtraDisposeSharedModule(sharedModule);
+ *outError = "failed to write metallib";
+ return true;
+ }
+
+ // Cleanup shared module
+ LLVMExtraDisposeSharedModule(sharedModule);
+
+ // Return compiled data
+ *outCode = LLVMGetBufferStart(_bufferRef);
+ *outCodeSize = LLVMGetBufferSize(_bufferRef);
+ *outReflection = nullptr;
+ *outReflectionSize = 0;
+ *outDebug = nullptr;
+ *outDebugSize = 0;
+ *outError = nullptr;
+ return false; // success (no error)
+}
+
+// --- Exported C interface ---
+
+extern "C" {
+
+__attribute__((visibility("default")))
+void *MTLCompilerCreate(void *targetInfo, uint64_t version) {
+ if (version != 8)
+ return nullptr;
+
+ AppleParavirtCompiler *compiler = new AppleParavirtCompiler();
+ if (!compiler->init((const AppleParavirtCompilerTargetInfo *)targetInfo)) {
+ delete compiler;
+ return nullptr;
+ }
+ return compiler;
+}
+
+__attribute__((visibility("default")))
+bool MTLCompilerBuildRequestWithOptions(
+ void *compilerObj,
+ const void *inputData, size_t inputSize, unsigned int flags,
+ LLVMModuleRef module,
+ const void **outCode, size_t *outCodeSize,
+ const void **outReflection, size_t *outReflectionSize,
+ const void **outDebug, size_t *outDebugSize,
+ const char **outError)
+{
+ AppleParavirtCompiler *compiler = (AppleParavirtCompiler *)compilerObj;
+ return compiler->buildRequestWithOptions(inputData, inputSize, flags, module,
+ outCode, outCodeSize,
+ outReflection, outReflectionSize,
+ outDebug, outDebugSize,
+ outError);
+}
+
+__attribute__((visibility("default")))
+void MTLCompilerDelete(void *compilerObj) {
+ if (compilerObj) {
+ AppleParavirtCompiler *compiler = (AppleParavirtCompiler *)compilerObj;
+ delete compiler;
+ }
+}
+
+__attribute__((visibility("default")))
+void MTLCompilerReleaseReply(void *compilerObj) {
+ if (compilerObj) {
+ AppleParavirtCompiler *compiler = (AppleParavirtCompiler *)compilerObj;
+ compiler->deleteCompilerReply();
+ }
+}
+
+} // extern "C"
diff --git a/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcherGuestPayload.swift b/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcherGuestPayload.swift
index 9a1c54d5..893dbc76 100644
--- a/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcherGuestPayload.swift
+++ b/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcherGuestPayload.swift
@@ -127,9 +127,12 @@ extension CryptexFilesystemPatcher {
try setMode(0o755, at: path)
}
let compilerPlugin = bundle.appending(path: "libAppleParavirtCompilerPluginIOGPUFamily.dylib")
- if FileManager.default.fileExists(atPath: compilerPlugin.path) {
- try setMode(0o755, at: compilerPlugin)
+ guard FileManager.default.fileExists(atPath: compilerPlugin.path) else {
+ throw FirmwarePatcher.PatcherError.patchVerificationFailed(
+ "PCC GPU compiler plugin is missing: \(compilerPlugin.path). Re-run fw prepare with a complete vphone-cli.app.",
+ )
}
+ try setMode(0o755, at: compilerPlugin)
for path in [
bundle.appending(path: "/_CodeSignature/CodeResources"),
bundle.appending(path: "/Info.plist"),
diff --git a/sources/VPhoneCore/VPhoneResources.swift b/sources/VPhoneCore/VPhoneResources.swift
index 6a7af60f..25b2596a 100644
--- a/sources/VPhoneCore/VPhoneResources.swift
+++ b/sources/VPhoneCore/VPhoneResources.swift
@@ -110,6 +110,14 @@ public struct VPhoneResources: Sendable {
return base.appendingPathComponent(".build/vphoned.signed")
}
+ public var gpuCompilerPluginArchive: URL {
+ let bundled = base.appendingPathComponent("gpu/compiler-plugin.tar.zst")
+ if FileManager.default.fileExists(atPath: bundled.path) {
+ return bundled
+ }
+ return base.appendingPathComponent(".build/guest/gpu-compiler-plugin.tar.zst")
+ }
+
// MARK: - Cache dirs
/// The per-user data root: `$VPHONE_ROOT` when set, else `~/.vphone`. Both
diff --git a/sources/vphone-cli/VPhoneCFWInstaller.swift b/sources/vphone-cli/VPhoneCFWInstaller.swift
index dd534bf5..f349baf9 100644
--- a/sources/vphone-cli/VPhoneCFWInstaller.swift
+++ b/sources/vphone-cli/VPhoneCFWInstaller.swift
@@ -170,9 +170,10 @@ struct VPhoneCFWInstaller {
try fm.setAttributes([.posixPermissions: NSNumber(value: 0o755)], ofItemAtPath: file.path)
}
let compilerPlugin = gpu.appendingPathComponent("libAppleParavirtCompilerPluginIOGPUFamily.dylib")
- if fm.fileExists(atPath: compilerPlugin.path) {
- try fm.setAttributes([.posixPermissions: NSNumber(value: 0o755)], ofItemAtPath: compilerPlugin.path)
+ guard fm.fileExists(atPath: compilerPlugin.path) else {
+ throw ValidationError("PCC GPU compiler plugin is missing: \(compilerPlugin.path). Re-run fw prepare with a complete vphone-cli.app.")
}
+ try fm.setAttributes([.posixPermissions: NSNumber(value: 0o755)], ofItemAtPath: compilerPlugin.path)
for file in [gpu.appendingPathComponent("Info.plist"),
gpu.appendingPathComponent("_CodeSignature/CodeResources")]
{
diff --git a/sources/vphone-cli/VPhoneCreateOrchestrator.swift b/sources/vphone-cli/VPhoneCreateOrchestrator.swift
index ac4441fa..a8dc2d06 100644
--- a/sources/vphone-cli/VPhoneCreateOrchestrator.swift
+++ b/sources/vphone-cli/VPhoneCreateOrchestrator.swift
@@ -247,7 +247,7 @@ public struct VPhoneCreateOrchestrator {
try VPhoneFirmwarePreparer.prepare(
iPhoneSource: phone, cloudOSSource: cloud,
gpuDriverBundle: options.gpuDriverBundle,
- bundle: bundle, cacheDirectory: resources.ipswCacheDir,
+ bundle: bundle, resources: resources,
)
print("[+] Firmware prepared (iPhone + cloudOS merged into bundle).")
}
diff --git a/sources/vphone-cli/VPhoneFWCLI.swift b/sources/vphone-cli/VPhoneFWCLI.swift
index 99757df4..167a572e 100644
--- a/sources/vphone-cli/VPhoneFWCLI.swift
+++ b/sources/vphone-cli/VPhoneFWCLI.swift
@@ -259,7 +259,7 @@ struct VPhoneFWPrepareCommand: ParsableCommand {
try VPhoneFirmwarePreparer.prepare(
iPhoneSource: phone, cloudOSSource: cloud,
gpuDriverBundle: gpuDriverBundle.map { URL(fileURLWithPath: ($0 as NSString).expandingTildeInPath) },
- bundle: bundle, cacheDirectory: resources.ipswCacheDir,
+ bundle: bundle, resources: resources,
)
}
}
diff --git a/sources/vphone-cli/VPhoneFirmwarePreparer.swift b/sources/vphone-cli/VPhoneFirmwarePreparer.swift
index e6ec65bd..b5c97abb 100644
--- a/sources/vphone-cli/VPhoneFirmwarePreparer.swift
+++ b/sources/vphone-cli/VPhoneFirmwarePreparer.swift
@@ -31,7 +31,7 @@ enum VPhoneFirmwarePreparer {
cloudOSSource: String,
gpuDriverBundle: URL? = nil,
bundle: VPhoneBundle,
- cacheDirectory: URL,
+ resources: VPhoneResources,
) throws {
let fm = FileManager.default
let existing = try fm.contentsOfDirectory(
@@ -45,11 +45,11 @@ enum VPhoneFirmwarePreparer {
print("[*] Resolving iPhone IPSW...")
let phone = try vphoneRunBlocking {
- try await VPhoneIPSWCache.resolve(iPhoneSource, in: cacheDirectory)
+ try await VPhoneIPSWCache.resolve(iPhoneSource, in: resources.ipswCacheDir)
}
print("[*] Resolving cloudOS IPSW...")
let cloud = try vphoneRunBlocking {
- try await VPhoneIPSWCache.resolve(cloudOSSource, in: cacheDirectory)
+ try await VPhoneIPSWCache.resolve(cloudOSSource, in: resources.ipswCacheDir)
}
try checkIPhoneName(iPhoneSource, archive: phone)
print("[+] iPhone \(phone.version) (\(phone.build)); cloudOS \(cloud.version) (\(cloud.build))")
@@ -87,6 +87,22 @@ enum VPhoneFirmwarePreparer {
)
}
+ let archive = resources.gpuCompilerPluginArchive
+ guard fm.fileExists(atPath: archive.path) else { throw Error.missingComponent(archive) }
+ let unpacked = staging.appendingPathComponent("compiler-plugin")
+ try fm.createDirectory(at: unpacked, withIntermediateDirectories: true)
+ print("[*] Merging bundled GPU compiler plugin...")
+ try VPhoneArchiveExtractor.extract(archive, into: unpacked, options: .intoHostDirectory)
+ let pluginName = "libAppleParavirtCompilerPluginIOGPUFamily.dylib"
+ let source = unpacked.appendingPathComponent(pluginName)
+ guard fm.fileExists(atPath: source.path) else { throw Error.missingComponent(source) }
+ let destinationPlugin = VPhonePCCGPUDriver.stagedBundle(in: phoneTree).appendingPathComponent(pluginName)
+ if fm.fileExists(atPath: destinationPlugin.path) {
+ try fm.removeItem(at: destinationPlugin)
+ }
+ try fm.copyItem(at: source, to: destinationPlugin)
+ try fm.setAttributes([.posixPermissions: NSNumber(value: 0o755)], ofItemAtPath: destinationPlugin.path)
+
// The destination did not exist at entry and the staging directory is
// on the same volume. One rename exposes the complete restore tree.
guard !fm.fileExists(atPath: destination.path) else { throw Error.existingRestore(destination) }