Skip to content

Commit 511be6a

Browse files
committed
added ValidateSaveRestoreSupport method of config
1 parent a924e22 commit 511be6a

4 files changed

+50
-1
lines changed

configuration_arm64.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//go:build darwin && arm64
2+
// +build darwin,arm64
3+
4+
package vz
5+
6+
/*
7+
#cgo darwin CFLAGS: -mmacosx-version-min=11 -x objective-c -fno-objc-arc
8+
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
9+
# include "virtualization_14_arm64.h"
10+
*/
11+
import "C"
12+
import "github.com/Code-Hex/vz/v3/internal/objc"
13+
14+
func (v *VirtualMachineConfiguration) ValidateSaveRestoreSupport() (bool, error) {
15+
nserrPtr := newNSErrorAsNil()
16+
ret := C.validateSaveRestoreSupportWithError(objc.Ptr(v), &nserrPtr)
17+
err := newNSError(nserrPtr)
18+
if err != nil {
19+
return false, err
20+
}
21+
return (bool)(ret), nil
22+
}

virtualization_14_arm64.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ uint32_t maximumPathLengthVZLinuxRosettaUnixSocketCachingOptions();
2222
uint32_t maximumNameLengthVZLinuxRosettaAbstractSocketCachingOptions();
2323
void setOptionsVZLinuxRosettaDirectoryShare(void *rosetta, void *cachingOptions);
2424
void *newVZMacKeyboardConfiguration();
25+
bool validateSaveRestoreSupportWithError(void *config, void **error);
2526
#endif

virtualization_14_arm64.m

+21-1
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,24 @@ void setOptionsVZLinuxRosettaDirectoryShare(void *rosetta, void *cachingOptions)
155155
}
156156
#endif
157157
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
158-
}
158+
}
159+
160+
/*!
161+
@abstract Validate the configuration is savable.
162+
@discussion
163+
Verify that a virtual machine with this configuration is savable.
164+
Not all configuration options can be safely saved and restored from file.
165+
If this evaluates to NO, the caller should expect future calls to saveMachineStateToURL:completionHandler: to fail.
166+
@param error If not nil, assigned with an error describing the unsupported configuration option.
167+
@return YES if the configuration is savable.
168+
*/
169+
bool validateSaveRestoreSupportWithError(void *config, void **error)
170+
{
171+
#ifdef INCLUDE_TARGET_OSX_14
172+
if (@available(macOS 14, *)) {
173+
return (bool)[(VZVirtualMachineConfiguration *)config
174+
validateSaveRestoreSupportWithError:(NSError *_Nullable *_Nullable)error];
175+
}
176+
#endif
177+
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
178+
}

virtualization_arm64.go

+6
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ func (m *MacOSInstaller) Done() <-chan struct{} { return m.doneCh }
587587
//
588588
// If this method is successful, the framework writes the file, and the VM state remains unchanged.
589589
//
590+
// Note that If you want to implement proper error handling, please make sure to call the
591+
// `(*VirtualMachineConfiguration).ValidateSaveRestoreSupport` method before calling this method.
592+
//
590593
// If you want to listen status change events, use the "StateChangedNotify" method.
591594
//
592595
// This is only supported on macOS 14 and newer, error will
@@ -615,6 +618,9 @@ func (v *VirtualMachine) SaveMachineStateToPath(saveFilePath string) error {
615618
//
616619
// If this method is successful, the framework restores the VM and places it in the paused state.
617620
//
621+
// Note that If you want to implement proper error handling, please make sure to call the
622+
// `(*VirtualMachineConfiguration).ValidateSaveRestoreSupport` method before calling this method.
623+
//
618624
// If you want to listen status change events, use the "StateChangedNotify" method.
619625
//
620626
// This is only supported on macOS 14 and newer, error will

0 commit comments

Comments
 (0)