-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
virtualization_15.m
190 lines (180 loc) · 6.41 KB
/
virtualization_15.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//
// virtualization_15.m
//
// Created by codehex.
//
#import "virtualization_15.h"
/*!
@abstract Check if nested virtualization is supported.
@return true if supported.
*/
bool isNestedVirtualizationSupported()
{
#ifdef INCLUDE_TARGET_OSX_15
if (@available(macOS 15, *)) {
return (bool)VZGenericPlatformConfiguration.isNestedVirtualizationSupported;
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
/*!
@abstract Set nestedVirtualizationEnabled. The default is false.
*/
void setNestedVirtualizationEnabled(void *config, bool nestedVirtualizationEnabled)
{
#ifdef INCLUDE_TARGET_OSX_15
if (@available(macOS 15, *)) {
VZGenericPlatformConfiguration *platformConfig = (VZGenericPlatformConfiguration *)config;
platformConfig.nestedVirtualizationEnabled = (BOOL)nestedVirtualizationEnabled;
return;
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
/*!
@abstract Configuration for the USB XHCI controller.
@discussion This configuration creates a USB XHCI controller device for the guest.
*/
void *newVZXHCIControllerConfiguration()
{
#ifdef INCLUDE_TARGET_OSX_15
if (@available(macOS 15, *)) {
return [[VZXHCIControllerConfiguration alloc] init];
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
void setUSBControllersVZVirtualMachineConfiguration(void *config, void *usbControllers)
{
#ifdef INCLUDE_TARGET_OSX_15
if (@available(macOS 15, *)) {
[(VZVirtualMachineConfiguration *)config
setUsbControllers:[(NSMutableArray *)usbControllers copy]];
return;
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
/*!
@abstract Device UUID.
@discussion
Device UUID from device configuration objects that conform to `VZUSBDeviceConfiguration`.
@see VZUSBDeviceConfiguration
*/
const char *getUUIDUSBDevice(void *usbDevice)
{
#ifdef INCLUDE_TARGET_OSX_15
if (@available(macOS 15, *)) {
NSString *uuid = [[(id<VZUSBDevice>)usbDevice uuid] UUIDString];
return [uuid UTF8String];
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
/*!
@abstract Return a list of USB devices attached to controller.
@discussion
If corresponding USB controller configuration included in VZVirtualMachineConfiguration contained any USB devices,
those devices will appear here when virtual machine is started.
@see VZUSBDevice
@see VZUSBDeviceConfiguration
@see VZUSBControllerConfiguration
@see VZVirtualMachineConfiguration
*/
void *usbDevicesVZUSBController(void *usbController)
{
#ifdef INCLUDE_TARGET_OSX_15
if (@available(macOS 15, *)) {
return [(VZUSBController *)usbController usbDevices];
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
/*!
@abstract Return the list of USB controllers configured on this virtual machine. Return an empty array if no USB controller is configured.
@see VZUSBControllerConfiguration
@see VZVirtualMachineConfiguration
*/
void *VZVirtualMachine_usbControllers(void *machine)
{
#ifdef INCLUDE_TARGET_OSX_15
if (@available(macOS 15, *)) {
return [(VZVirtualMachine *)machine usbControllers]; // NSArray<VZUSBController *>
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
/*!
@abstract Attach a USB device.
@discussion
If the device is successfully attached to the controller, it will appear in the usbDevices property,
its usbController property will be set to point to the USB controller that it is attached to
and completion handler will return nil.
If the device was previously attached to this or another USB controller, attach function will fail
with the `VZErrorDeviceAlreadyAttached`. If the device cannot be initialized correctly, attach
function will fail with `VZErrorDeviceInitializationFailure`.
This method must be called on the virtual machine's queue.
@param device USB device to attach.
@param completionHandler Block called after the device has been attached or on error.
The error parameter passed to the block is nil if the attach was successful.
It will be also invoked on an virtual machine's queue.
@see VZUSBDevice
*/
void attachDeviceVZUSBController(void *usbController, void *usbDevice, void *queue, uintptr_t cgoHandle)
{
#ifdef INCLUDE_TARGET_OSX_15
if (@available(macOS 15, *)) {
dispatch_sync((dispatch_queue_t)queue, ^{
[(VZUSBController *)usbController attachDevice:(id<VZUSBDevice>)usbDevice
completionHandler:^(NSError *error) {
usbAttachDetachCompletionHandler(cgoHandle, error);
}];
});
return;
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
/*!
@abstract Detach a USB device.
@discussion
If the device is successfully detached from the controller, it will disappear from the usbDevices property,
its usbController property will be set to nil and completion handler will return nil.
If the device wasn't attached to the controller at the time of calling detach method, it will fail
with the `VZErrorDeviceNotFound` error.
This method must be called on the virtual machine's queue.
@param device USB device to detach.
@param completionHandler Block called after the device has been detached or on error.
The error parameter passed to the block is nil if the detach was successful.
It will be also invoked on an virtual machine's queue.
@see VZUSBDevice
*/
void detachDeviceVZUSBController(void *usbController, void *usbDevice, void *queue, uintptr_t cgoHandle)
{
#ifdef INCLUDE_TARGET_OSX_15
if (@available(macOS 15, *)) {
dispatch_sync((dispatch_queue_t)queue, ^{
[(VZUSBController *)usbController detachDevice:(id<VZUSBDevice>)usbDevice
completionHandler:^(NSError *error) {
usbAttachDetachCompletionHandler(cgoHandle, error);
}];
});
return;
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
/*!
@abstract Initialize the runtime USB Mass Storage device object.
@param configuration The configuration of the USB Mass Storage device.
@see VZUSBMassStorageDeviceConfiguration
*/
void *newVZUSBMassStorageDeviceWithConfiguration(void *config)
{
#ifdef INCLUDE_TARGET_OSX_15
if (@available(macOS 15, *)) {
return [[VZUSBMassStorageDevice alloc] initWithConfiguration:(VZUSBMassStorageDeviceConfiguration *)config];
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}