Skip to content
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

Cleanup of deprecated functions + Behavioral Clarifications #307

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Commits on Nov 13, 2024

  1. fix: move .cargo/config to .cargo/config.toml

    This fixes a cargo warning printed in recent toolchains. Since we do not
    support toolchains older than 1.38, there is no need to symlink to the
    new file to the old one.
    
    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    5e62fa9 View commit details
    Browse the repository at this point in the history
  2. fix: remove superfluous calls to .subslice in io.rs

    The call to `.subslice()` ensures that the range `[0, total]` is a valid
    subslice of the `buf: VolatileSlice` passed in. But `total =
    min(buf.len(), self.len()) <= buf.len()`, and thus `[0, total]` is
    definitely a valid subslice of `buf`.
    
    The `copy_{from,to}_volatile_slice` functions do not actually care about
    the length of the `VolatileSlice` passed in - it relies on the safety
    invariant to ensure that the passed slice has length at least `total`.
    Thus it doesn't matter if we pass a slice of length `total`, or of a
    length greater than `total`. It will simply access the first `total`
    bytes in the slice.
    
    Also clarify the safety comment, as some slightly mistakes seemingly
    snuck in when copying them.
    
    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    1264194 View commit details
    Browse the repository at this point in the history
  3. Clarify behavior of VolatileMemory::compute_end_offset

    Fix the doc comment, and add a unit test for this functions.
    Particularly the "allow length 0 accesses at the end of the slice"
    behavior was undocumented before.
    
    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    8179125 View commit details
    Browse the repository at this point in the history
  4. Drop assert from read/write_volatile in GuestMemory

    The comment on the assertion was wrong, as we are not even doing
    anything unsafe in the first place. Additionally, the `offset` variable
    is unused by these functions, so the assertion is at best a sanity check
    that the `try_access` implementation is correct, although I don't
    particularly see the value of that. Remove the assertion to prevent
    confusion.
    
    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    807e68d View commit details
    Browse the repository at this point in the history
  5. Implement VolatileMemory::get_slice in terms of subslice

    The two functions contain exactly the same body, so just have one call
    the other.
    
    No functional change intended.
    
    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    31e32c1 View commit details
    Browse the repository at this point in the history
  6. add retry_eintr! utility macro

    Add a macro that automatically retries a given I/O operation if EINTR is
    returned. This is a fairly common pattern in vm-memory.
    
    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    1e8512a View commit details
    Browse the repository at this point in the history
  7. Introduce VolatileSlice::truncate

    This function reduces the length of a volatile slice. Many of the I/O
    primitives rely on volatile slice lengths to determine how many bytes
    should be read/written, and in cases where we want to read/write "up to
    X bytes", calling `.truncate` is needed.
    
    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    7b4d418 View commit details
    Browse the repository at this point in the history
  8. chore: remove deprecated methods

    The old `Read`/`Write` based APIs for operating on guest memory have
    been deprecated for a fairly long time now, and are superseceded by
    their `ReadVolatile`/`WriteVolatile` equivalents.
    
    The `fold` and friends functions have been deprecated for way longer.
    
    Various `.as_ptr` APIs in volatile_memory.rs are deprecated in favor of
    pointer guards.
    
    Let's clean up the crate and remove all of these.
    
    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    09a0fad View commit details
    Browse the repository at this point in the history
  9. fix: move volatile memory access methods to Bytes trait

    The `read_[exact_]_volatile_from` and `write_[all_]volatile_to`
    functions were intended to be replacements for their `Read` and `Write`
    based counterparts. However, those used to live in the `Bytes` trait,
    not the `GuestMemory` trait. Fix up this goof on my part by moving them
    to the `Bytes` trait.
    
    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    96443bb View commit details
    Browse the repository at this point in the history
  10. doc: clarify behavior of Bytes::read and co

    Capture the actual behavior of various edge cases around empty buffers
    and containers in the doc comment.
    
    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    e7fa4d4 View commit details
    Browse the repository at this point in the history
  11. chore: update coverage

    Signed-off-by: Patrick Roy <[email protected]>
    roypat committed Nov 13, 2024
    Configuration menu
    Copy the full SHA
    8fd12ef View commit details
    Browse the repository at this point in the history