Repository navigation
Roll back the heap zone when the guest's memory refuses a write - #50
Merged
Merged
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
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.
HeapZoneleaked blocks and master pointers when itsGuestMemoryrefused a write. On a real Mac a heap write can't fault, but BlueBox's checked guest memory can refuse one, and BlueBox now usesHeapZoneas its application heap.The leaks
newPointer(clear:)kept the block when clearing it failed.newHandlereleased its master pointer, but not the block it had placed, when clearing the block or setting the master pointer failed.takeMasterkept a new block of master pointers when zeroing it failed.newEmptyHandlekept its master pointer live when writing it failed.disposeHandleandfreeBlock, used byemptyHandle,reallocateHandleand purging, forgot the block before writing the nil master pointer. A refused write left the guest's master pointer pointing at a block the zone had freed.disposeHandlehad also already calledresourceDisposed.setHandleSizedropped the old block before copying the bytes and repointing the master pointer. A refused write lost the block's place.The fix
Each path either writes to guest memory before changing the zone's records, or undoes the records if the write fails. Two outcomes differ from "nothing changed":
reallocateHandle: if the new block's address can't be written, the handle is left empty. The old block was already freed and its master pointer set to nil, so the zone and guest memory still agree.compactBlocks.The failing call reports memAdrErr (-110), as before.
Testing
HeapZoneFaultTestsuses aGuestMemorythat refuses chosen writes. For each path it checks thatfreeBytesandlargestBlockare unchanged, that the next handle or pointer is the one that would have come anyway, and that the handle's size, state and contents are intact. All eight of these tests fail without the fix.swift testpasses: all 16 test runs.Follow-up in swift-pef
BlueBox's
GuestHeapcurrently works around the clearing case itself. That workaround can go once this is merged.