Skip to content

Commit

Permalink
Merge branch 'feature/altkit' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Nov 6, 2021
2 parents 7fd0f08 + b527a17 commit 3220514
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Platform/Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ struct ContentView: View {
#if !WITH_QEMU_TCI
if !Main.jitAvailable {
data.busyWork {
#if canImport(AltKit)
try data.startAltJIT()
#else
throw NSLocalizedString("Your version of iOS does not support running VMs while unmodified. You must either run UTM while jailbroken or with a remote debugger attached.", comment: "ContentView")
#endif
}
}
#endif
Expand Down
57 changes: 53 additions & 4 deletions Platform/UTMData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import AppKit
#else
import UIKit
#endif
#if canImport(AltKit)
import AltKit
#endif

@available(iOS 14, macOS 11, *)
struct AlertMessage: Identifiable {
Expand Down Expand Up @@ -69,8 +72,11 @@ class UTMData: ObservableObject {
fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
}

private var busyQueue: DispatchQueue

init() {
let defaults = UserDefaults.standard
self.busyQueue = DispatchQueue(label: "UTM Busy Queue", qos: .userInitiated)
self.showSettingsModal = false
self.showNewVMSheet = false
self.busy = false
Expand Down Expand Up @@ -525,10 +531,10 @@ class UTMData: ObservableObject {
}

func busyWork(_ work: @escaping () throws -> Void) {
DispatchQueue.main.async {
self.busy = true
}
DispatchQueue.global(qos: .userInitiated).async {
busyQueue.async {
DispatchQueue.main.async {
self.busy = true
}
defer {
DispatchQueue.main.async {
self.busy = false
Expand Down Expand Up @@ -602,4 +608,47 @@ class UTMData: ObservableObject {
tryClickAtPoint(point: point, button: button)
#endif
}

// MARK: - AltKit

#if canImport(AltKit)
func startAltJIT() throws {
let event = DispatchSemaphore(value: 0)
var connectError: Error?
DispatchQueue.main.async {
ServerManager.shared.autoconnect { result in
switch result
{
case .failure(let error):
logger.error("Could not auto-connect to server. \(error.localizedDescription)")
connectError = error
event.signal()
case .success(let connection):
connection.enableUnsignedCodeExecution { result in
switch result
{
case .failure(let error):
logger.error("Could not enable JIT compilation. \(error.localizedDescription)")
connectError = error
case .success:
logger.debug("Successfully enabled JIT compilation!")
}

connection.disconnect()
event.signal()
}
}
}
ServerManager.shared.startDiscovering()
}
defer {
ServerManager.shared.stopDiscovering()
}
if event.wait(timeout: .now() + 10) == .timedOut {
throw NSLocalizedString("Cannot find AltServer for JIT enable. You cannot run VMs until JIT is enabled.", comment: "UTMData")
} else if let error = connectError {
throw NSLocalizedString("AltJIT error: \(error.localizedDescription)", comment: "UTMData")
}
}
#endif
}
8 changes: 8 additions & 0 deletions Platform/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ALTDeviceID</key>
<string>None</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDocumentTypes</key>
Expand Down Expand Up @@ -57,6 +59,12 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSBonjourServices</key>
<array>
<string>_altserver._tcp</string>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>UTM uses the local network to find and communicate with AltServer.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>VM background access requires location services. Location data will never leave the device.</string>
<key>NSLocationAlwaysUsageDescription</key>
Expand Down
26 changes: 25 additions & 1 deletion UTM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
8401FD71269BEB2B00265F0D /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = CE6B240A25F1F3CE0020D43E /* main.c */; };
8401FD72269BEB3000265F0D /* Bootstrap.c in Sources */ = {isa = PBXBuildFile; fileRef = CE0DF17125A80B6300A51894 /* Bootstrap.c */; };
8401FD7A269BECE200265F0D /* QEMULauncher.app in Embed Launcher */ = {isa = PBXBuildFile; fileRef = 8401FD62269BE9C500265F0D /* QEMULauncher.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
B329049C270FE136002707AC /* AltKit in Frameworks */ = {isa = PBXBuildFile; productRef = B329049B270FE136002707AC /* AltKit */; };
B3DDF57226E9BBA300CE47F0 /* AltKit in Frameworks */ = {isa = PBXBuildFile; productRef = B3DDF57126E9BBA300CE47F0 /* AltKit */; };
CE020BA324AEDC7C00B44AB6 /* UTMData.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE020BA224AEDC7C00B44AB6 /* UTMData.swift */; };
CE020BA424AEDC7C00B44AB6 /* UTMData.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE020BA224AEDC7C00B44AB6 /* UTMData.swift */; };
CE020BA724AEDEF000B44AB6 /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = CE020BA624AEDEF000B44AB6 /* Logging */; };
Expand Down Expand Up @@ -2116,6 +2118,7 @@
CE2D933724AD46670059923A /* libgstplayback.a in Frameworks */,
CE2D933824AD46670059923A /* libgstadder.a in Frameworks */,
CE2D933A24AD46670059923A /* libgstaudiorate.a in Frameworks */,
B3DDF57226E9BBA300CE47F0 /* AltKit in Frameworks */,
CE2D933B24AD46670059923A /* libgstvideofilter.a in Frameworks */,
CE2D933C24AD46670059923A /* libgstapp.a in Frameworks */,
CE2D933D24AD46670059923A /* libgstgio.a in Frameworks */,
Expand All @@ -2130,6 +2133,7 @@
CE2D934524AD46670059923A /* gthread-2.0.0.framework in Frameworks */,
CE2D934624AD46670059923A /* gstrtp-1.0.0.framework in Frameworks */,
CE2D934724AD46670059923A /* gstriff-1.0.0.framework in Frameworks */,
B329049C270FE136002707AC /* AltKit in Frameworks */,
CEA9058F25FC6A1400801E7C /* usbredirhost.1.framework in Frameworks */,
CE2D934924AD46670059923A /* gstreamer-1.0.0.framework in Frameworks */,
CE2D934B24AD46670059923A /* json-glib-1.0.0.framework in Frameworks */,
Expand Down Expand Up @@ -3193,6 +3197,7 @@
CE020BA624AEDEF000B44AB6 /* Logging */,
CE93759824BB821F0074066F /* IQKeyboardManagerSwift */,
83993291272F68550059355F /* ZIPFoundation */,
B329049B270FE136002707AC /* AltKit */,
);
productName = UTM;
productReference = CE2D93BE24AD46670059923A /* UTM.app */;
Expand Down Expand Up @@ -3328,6 +3333,7 @@
CE020BA524AEDEF000B44AB6 /* XCRemoteSwiftPackageReference "swift-log" */,
CE93759724BB821F0074066F /* XCRemoteSwiftPackageReference "IQKeyboardManager" */,
8399328E272F4A400059355F /* XCRemoteSwiftPackageReference "ZIPFoundation" */,
B329049A270FE136002707AC /* XCRemoteSwiftPackageReference "AltKit" */,
);
productRefGroup = CE550BCA225947990063E575 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -4914,6 +4920,14 @@
minimumVersion = 0.9.9;
};
};
B329049A270FE136002707AC /* XCRemoteSwiftPackageReference "AltKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/utmapp/AltKit.git";
requirement = {
branch = main;
kind = branch;
};
};
CE020BA524AEDEF000B44AB6 /* XCRemoteSwiftPackageReference "swift-log" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/swift-log";
Expand Down Expand Up @@ -4943,7 +4957,7 @@
repositoryURL = "https://github.com/hackiftekhar/IQKeyboardManager.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 6.5.5;
minimumVersion = 6.5.6;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand All @@ -4964,6 +4978,16 @@
package = 8399328E272F4A400059355F /* XCRemoteSwiftPackageReference "ZIPFoundation" */;
productName = ZIPFoundation;
};
B329049B270FE136002707AC /* AltKit */ = {
isa = XCSwiftPackageProductDependency;
package = B329049A270FE136002707AC /* XCRemoteSwiftPackageReference "AltKit" */;
productName = AltKit;
};
B3DDF57126E9BBA300CE47F0 /* AltKit */ = {
isa = XCSwiftPackageProductDependency;
package = B3DDF57026E9BBA300CE47F0 /* XCRemoteSwiftPackageReference "AltKit" */;
productName = AltKit;
};
CE020BA624AEDEF000B44AB6 /* Logging */ = {
isa = XCSwiftPackageProductDependency;
package = CE020BA524AEDEF000B44AB6 /* XCRemoteSwiftPackageReference "swift-log" */;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"object": {
"pins": [
{
"package": "AltKit",
"repositoryURL": "https://github.com/utmapp/AltKit.git",
"state": {
"branch": "main",
"revision": "71ec1d505cbb7cb53dc16c7c98cb94c93953f3ff",
"version": null
}
},
{
"package": "IQKeyboardManagerSwift",
"repositoryURL": "https://github.com/hackiftekhar/IQKeyboardManager.git",
"state": {
"branch": null,
"revision": "4dc6bc7d1c9747bd0c261c8c055903f9fdef91f7",
"version": "6.5.6"
}
},
{
"package": "swift-log",
"repositoryURL": "https://github.com/apple/swift-log",
"state": {
"branch": null,
"revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7",
"version": "1.4.2"
}
},
{
"package": "ZIPFoundation",
"repositoryURL": "https://github.com/weichsel/ZIPFoundation.git",
"state": {
"branch": null,
"revision": "cf10bbff6ac3b873e97b36b9784c79866a051a8e",
"version": "0.9.12"
}
}
]
},
"version": 1
}

0 comments on commit 3220514

Please sign in to comment.