Add ByteRepr for Ptr#225
Open
lucic71 wants to merge 15 commits into
Open
Conversation
In C and Rust refcount struct sizes are different. Make sure that the pointer serialization uses the C size.
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.
ByteRepr::to_bytes and ByteRepr::from_bytes are implemented using the new PtrRegistry. PtrRegistry is a global collection that keeps mappings between Ptr and
[base, base + byte_len]. The right side of the interval includes base + byte_len because it's valid to have a pointer +1 OOB.When switching from Ptr to the integer representation, the program is free to do arithmetic on the integer representation. When switching back form integer to Ptr, we construct a Ptr if the integer representation is describing a valid Ptr inside PtrRegistry, otherwise panic.
The PtrRegistry interface is defined as follows:
ByteRepr::to_bytes becomes a call to:
ByteRepr::from_bytes becomes a call to PtrRegistry::get + reconstructing the Ptr with the correct offset and the correct type.
Notes about this implementation:
&a is serialized as a Ptr with
[base_a, base_a + 4], then on the integer representation of the Ptr, the program doesbase_a + 50which happens to fit into[base_b, base_b + 100]. Ptr::from_bytes happily deserializesbase_a + 50as being part of the b range. This is not ideal, a panic should be generated instead. @nunoplopes should we focus on fixing this now or can we consider it a known limitation?[base, base + size]is inclusive in order to accept creating a +1 OOB pointer