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.
I noticed that the rust bindings apparently don't have a way to map MMIO regions at the moment. This PR adds
map_mmio
to provide this functionality.Some things that I'm unhappy with, but don't see a way to make them better at the moment (feedback very welcome):
mmio_map
to take a pointer to the user data and then move theBox
es of the user data intoself.inner_mut().mmio_callbacks
only works, because the pointer isn't checked by regular borrowing rules. This is basically the same method as used for hook callbacks and AIUI theBox
guarantees that the contents of the box will always stay in the same location, so this should be safe. But I would be slightly more satisfied with a solution that would also work under normal borrowing rules.MmioCallbackScope.unmap
is kinda complicated and easy to get wrong. I'm not really confident that I didn't make any off-by-one errors. Unfortunately I'm also not really sure how to properly write automated tests for this, because the test suite doesn't have access toUnicorn.inner()
to check that deallocation is actually working as intended.Unicorn<D>.mmio_unmap
could probably be made more efficient by keeping theMmioCallbackScope
s sorted and using some sort of binary search to find regions to unmap. However, I wanted to keep this implementation simple for the moment. The introduced logic is already complicated as-is and I would imagine thatmem_unmap
isn't very performance critical for most use cases. But if you think a more performant implementation is needed, I can take a look at it again.