Explorar o código

macOS: enable Hypervisor.framework usage

osy %!s(int64=5) %!d(string=hai) anos
pai
achega
3d8fb53246

+ 15 - 3
Managers/UTMQemuSystemConfiguration.m

@@ -14,6 +14,7 @@
 // limitations under the License.
 // limitations under the License.
 //
 //
 
 
+#import <TargetConditionals.h>
 #import "UTMQemuSystemConfiguration.h"
 #import "UTMQemuSystemConfiguration.h"
 #import "UTMConfiguration.h"
 #import "UTMConfiguration.h"
 #import "UTMConfiguration+Constants.h"
 #import "UTMConfiguration+Constants.h"
@@ -189,7 +190,7 @@
     }
     }
 }
 }
 
 
-- (NSString *)acceleratorProperties {
+- (NSString *)tcgAccelProperties {
     NSString *accel = @"tcg";
     NSString *accel = @"tcg";
     
     
     if (self.configuration.systemForceMulticore) {
     if (self.configuration.systemForceMulticore) {
@@ -200,16 +201,23 @@
     }
     }
     
     
     // Avoid alias mapping if we support dynamic codesigning
     // Avoid alias mapping if we support dynamic codesigning
-    if (@available(iOS 14, macOS 11, *)) {
+#if TARGET_OS_IPHONE
+    if (@available(iOS 14, *)) {
         // only iOS 14 supports the pthread JIT calls
         // only iOS 14 supports the pthread JIT calls
         if (jb_has_jit_entitlement()) {
         if (jb_has_jit_entitlement()) {
             accel = [accel stringByAppendingString:@",mirror-rwx=off"];
             accel = [accel stringByAppendingString:@",mirror-rwx=off"];
         }
         }
     }
     }
+#endif
     
     
     return accel;
     return accel;
 }
 }
 
 
+- (BOOL)useHypervisor {
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+    return [defaults boolForKey:@"UseHypervisor"];
+}
+
 - (NSString *)machineProperties {
 - (NSString *)machineProperties {
     if (self.configuration.systemMachineProperties.length > 0) {
     if (self.configuration.systemMachineProperties.length > 0) {
         return self.configuration.systemMachineProperties; // use specified properties
         return self.configuration.systemMachineProperties; // use specified properties
@@ -240,8 +248,12 @@
     [self pushArgv:[NSString stringWithFormat:@"cpus=%@,sockets=1", self.configuration.systemCPUCount]];
     [self pushArgv:[NSString stringWithFormat:@"cpus=%@,sockets=1", self.configuration.systemCPUCount]];
     [self pushArgv:@"-machine"];
     [self pushArgv:@"-machine"];
     [self pushArgv:[NSString stringWithFormat:@"%@,%@", self.configuration.systemTarget, [self machineProperties]]];
     [self pushArgv:[NSString stringWithFormat:@"%@,%@", self.configuration.systemTarget, [self machineProperties]]];
+    if ([self useHypervisor]) {
+        [self pushArgv:@"-accel"];
+        [self pushArgv:@"hvf"];
+    }
     [self pushArgv:@"-accel"];
     [self pushArgv:@"-accel"];
-    [self pushArgv:[self acceleratorProperties]];
+    [self pushArgv:[self tcgAccelProperties]];
     [self architectureSpecificConfiguration];
     [self architectureSpecificConfiguration];
     [self targetSpecificConfiguration];
     [self targetSpecificConfiguration];
     if (![self.configuration.systemBootDevice isEqualToString:@"hdd"]) {
     if (![self.configuration.systemBootDevice isEqualToString:@"hdd"]) {

+ 7 - 0
Platform/macOS/SettingsView.swift

@@ -20,6 +20,7 @@ import SwiftUI
 struct SettingsView: View {
 struct SettingsView: View {
     @AppStorage("AlwaysNativeResolution") var isAlwaysNativeResolution = false
     @AppStorage("AlwaysNativeResolution") var isAlwaysNativeResolution = false
     @AppStorage("DisplayFixed") var isVMDisplayFixed = false
     @AppStorage("DisplayFixed") var isVMDisplayFixed = false
+    @AppStorage("UseHypervisor") var isHypervisorUsed = false
     
     
     var body: some View {
     var body: some View {
         Form {
         Form {
@@ -31,6 +32,11 @@ struct SettingsView: View {
                     Text("VM display size is fixed")
                     Text("VM display size is fixed")
                 })
                 })
             }
             }
+            Section(header: Text("Acceleration")) {
+                Toggle(isOn: $isHypervisorUsed, label: {
+                    Text("Try to use hardware hypervisor when available")
+                })
+            }
         }.padding()
         }.padding()
     }
     }
 }
 }
@@ -39,6 +45,7 @@ extension UserDefaults {
     @objc dynamic var NoCursorCaptureAlert: Bool { false }
     @objc dynamic var NoCursorCaptureAlert: Bool { false }
     @objc dynamic var AlwaysNativeResolution: Bool { false }
     @objc dynamic var AlwaysNativeResolution: Bool { false }
     @objc dynamic var DisplayFixed: Bool { false }
     @objc dynamic var DisplayFixed: Bool { false }
+    @objc dynamic var UseHypervisor: Bool { false }
 }
 }
 
 
 @available(macOS 11, *)
 @available(macOS 11, *)

+ 2 - 0
QEMUHelper/QEMUHelper.entitlements

@@ -4,6 +4,8 @@
 <dict>
 <dict>
 	<key>com.apple.security.app-sandbox</key>
 	<key>com.apple.security.app-sandbox</key>
 	<true/>
 	<true/>
+	<key>com.apple.security.hypervisor</key>
+	<true/>
 	<key>com.apple.security.network.client</key>
 	<key>com.apple.security.network.client</key>
 	<true/>
 	<true/>
 	<key>com.apple.security.network.server</key>
 	<key>com.apple.security.network.server</key>