Skip to content

Commit

Permalink
add support for nested virtualization
Browse files Browse the repository at this point in the history
Signed-off-by: Abiola Ibrahim <git@abiosoft.com>
  • Loading branch information
abiosoft committed Sep 17, 2024
1 parent c319894 commit a85de34
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package vz
# include "virtualization_11.h"
# include "virtualization_12.h"
# include "virtualization_13.h"
# include "virtualization_15.h"
*/
import "C"
import (
Expand Down Expand Up @@ -40,6 +41,14 @@ func (m *GenericPlatformConfiguration) MachineIdentifier() *GenericMachineIdenti
return m.machineIdentifier
}

// SetNestedVirtualizationEnabled toggles nested virtualization.
func (m *GenericPlatformConfiguration) SetNestedVirtualizationEnabled(enable bool) {
C.setNestedVirtualizationEnabled(
objc.Ptr(m),
C.bool(enable),
)
}

var _ PlatformConfiguration = (*GenericPlatformConfiguration)(nil)

// NewGenericPlatformConfiguration creates a new generic platform configuration.
Expand Down
10 changes: 10 additions & 0 deletions virtualization_15.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// virtualization_15.h

#pragma once

#import "virtualization_helper.h"
#import <Virtualization/Virtualization.h>

/* macOS 15 API */
void setNestedVirtualizationEnabled(void *config, bool nestedVirtualizationEnabled);
19 changes: 19 additions & 0 deletions virtualization_15.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// virtualization_15.m
//
#import "virtualization_15.h"

/*!
@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();
}
7 changes: 7 additions & 0 deletions virtualization_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ NSDictionary *dumpProcessinfo();
#pragma message("macOS 14 API has been disabled")
#endif

// for macOS 15 API
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 150000
#define INCLUDE_TARGET_OSX_15 1
#else
#pragma message("macOS 15 API has been disabled")
#endif

static inline int mac_os_x_version_max_allowed()
{
#ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
Expand Down

0 comments on commit a85de34

Please sign in to comment.