Skip to content

added ValidateSaveRestoreSupport method of config #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions configuration_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//go:build darwin && arm64
// +build darwin,arm64

package vz

/*
#cgo darwin CFLAGS: -mmacosx-version-min=11 -x objective-c -fno-objc-arc
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
# include "virtualization_14_arm64.h"
*/
import "C"
import "github.com/Code-Hex/vz/v3/internal/objc"

// ValidateSaveRestoreSupport Determines whether the framework can save or restore the VM’s current configuration.
//
// Verify that a virtual machine with this configuration is savable.
// Not all configuration options can be safely saved and restored from file.
//
// If this evaluates to false, the caller should expect future calls to `(*VirtualMachine).SaveMachineStateToPath` to fail.
// error If not nil, assigned with an error describing the unsupported configuration option.
func (v *VirtualMachineConfiguration) ValidateSaveRestoreSupport() (bool, error) {
nserrPtr := newNSErrorAsNil()
ret := C.validateSaveRestoreSupportWithError(objc.Ptr(v), &nserrPtr)
err := newNSError(nserrPtr)
if err != nil {
return false, err
}
return (bool)(ret), nil
}
1 change: 1 addition & 0 deletions virtualization_14_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ uint32_t maximumPathLengthVZLinuxRosettaUnixSocketCachingOptions();
uint32_t maximumNameLengthVZLinuxRosettaAbstractSocketCachingOptions();
void setOptionsVZLinuxRosettaDirectoryShare(void *rosetta, void *cachingOptions);
void *newVZMacKeyboardConfiguration();
bool validateSaveRestoreSupportWithError(void *config, void **error);
#endif
22 changes: 21 additions & 1 deletion virtualization_14_arm64.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,24 @@ void setOptionsVZLinuxRosettaDirectoryShare(void *rosetta, void *cachingOptions)
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
}

/*!
@abstract Validate the configuration is savable.
@discussion
Verify that a virtual machine with this configuration is savable.
Not all configuration options can be safely saved and restored from file.
If this evaluates to NO, the caller should expect future calls to saveMachineStateToURL:completionHandler: to fail.
@param error If not nil, assigned with an error describing the unsupported configuration option.
@return YES if the configuration is savable.
*/
bool validateSaveRestoreSupportWithError(void *config, void **error)
{
#ifdef INCLUDE_TARGET_OSX_14
if (@available(macOS 14, *)) {
return (bool)[(VZVirtualMachineConfiguration *)config
validateSaveRestoreSupportWithError:(NSError *_Nullable *_Nullable)error];
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
}
6 changes: 6 additions & 0 deletions virtualization_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ func (m *MacOSInstaller) Done() <-chan struct{} { return m.doneCh }
//
// If this method is successful, the framework writes the file, and the VM state remains unchanged.
//
// Note that If you want to implement proper error handling, please make sure to call the
// `(*VirtualMachineConfiguration).ValidateSaveRestoreSupport` method before calling this method.
//
// If you want to listen status change events, use the "StateChangedNotify" method.
//
// This is only supported on macOS 14 and newer, error will
Expand Down Expand Up @@ -615,6 +618,9 @@ func (v *VirtualMachine) SaveMachineStateToPath(saveFilePath string) error {
//
// If this method is successful, the framework restores the VM and places it in the paused state.
//
// Note that If you want to implement proper error handling, please make sure to call the
// `(*VirtualMachineConfiguration).ValidateSaveRestoreSupport` method before calling this method.
//
// If you want to listen status change events, use the "StateChangedNotify" method.
//
// This is only supported on macOS 14 and newer, error will
Expand Down