-
Notifications
You must be signed in to change notification settings - Fork 762
[applevz] Basic VM functions #4561
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
Draft
sharder996
wants to merge
53
commits into
main
Choose a base branch
from
feature/apple/basic-vm-functions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+1,977
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d87a67b to
30ad1db
Compare
f7a30a3 to
7078e60
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feature/apple-vz-boilerplate #4561 +/- ##
================================================================
+ Coverage 87.19% 87.20% +0.01%
================================================================
Files 246 246
Lines 14134 14134
================================================================
+ Hits 12323 12324 +1
+ Misses 1811 1810 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
We wrap all calls into the Virtualization Framework in a mockable singleton for testing purposes
Co-authored-by: Mustafa Kemal Gılor <mustafa.gilor@canonical.com> Signed-off-by: ScottH <59572507+sharder996@users.noreply.github.com>
Many of these operations can be performed asynchronously, but Multipass is not so we block until the operation has finished.
Keep ObjCpp code in the bridge and return custom Cpp types for objects that need to be accessed outside the bridge. This helps maintain memory safety and reference counting.
We prefer to contain logic in the VM class so it can be properly tested.
6fda222 to
cd9efab
Compare
7078e60 to
cd9efab
Compare
cd9efab to
1773097
Compare
76f3d57 to
febbbeb
Compare
Closed
d655f8e to
0d4f2d5
Compare
f895466 to
7519cea
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements some of the basic functions for manipulating the state of a virtual machine using the Apple Virtualization Framework. This includes:
start()shutdown(ShutdownPolicy shutdown_policy)suspend()All Objective-C++ code, other helper functions needed to perform these actions, and unit tests for these functions are also included.
On top of being able to manually manage memory, Objective-C uses Automatic Reference Counting (ARC) where the system reference counting to automatically insert appropriate memory management method calls for you at compile-time. However, in order for objects to persist across the Objective-C/C++ boundary, we must use some types from the
CoreFoundationlibrary instead of theFoundationlibrary, i.e.,CFErrorRefoverNSError, also known as Toll-Free Bridged Types. This allows us to control who owns the object and avoids having ARC and the Objective-C memory management system release memory before we are done with it. There are several macros that are used to tell the compiler about the ownership semantics of an object, but we mainly use:__bridge; for objects such as theVMHandlewhich were declared on the C++ side and where we don't want ownership to transfer when casting thestd::shared_ptr<void>to virtualization framework virtual machine type;VZVirtualMachine.__bridge_retained: for objects that were created on the Objective-C side and for which we want to persist even after the block in which they were created finishes. We are responsible for manually freeing this type of object, so care must be taken in order when using this macro to prevent memory leaks. The use of this macro here is limited to returning errors from the Objective-C side to the C++ side through the use of the custom C++ type;CFError, which automatically callsCFReleasewhen destructed.The other unique memory management mechanism that is used is the
autoreleasepoolblock. This is used in special circumstances when a large number of temporary autoreleased object. Theautoreleasepoolsends anautoreleasemessage to all objects in that block which are immediately released instead of at the end of the current event-loop iteration. This prevents temporary objects from unnecessarily accumulating and causing excessive overhead.Additional reading:
MULTI-2258
MULTI-2261