x86_64
x86_64 copied to clipboard
Add checked arithmetic operations traits
General
This is an initial attempt to define a CheckedAdd and CheckedSub set of traits per the traits discussed in the linked issue below. I've applied these traits to the ~~VirtAddr~~ addressing types listed in the issue to check address, page and frame arithmetic.
Related Issues
#293
I've made all requested changes and have mostly stuck to your requests directly, the only difference would be retention of the chain in the VirtAddr::checked_* methods due to the from_canonical change keeping the chain fairly readable.
@ncatelli I've resolved all the comments that you've fixed (I think there are still a few more comment nits to fixed).
Can you add implementations for the other address types (PhysAddr, PhysFrame, Page)
Also @ncatelli per https://github.com/rust-osdev/x86_64/issues/293#issuecomment-903237326 can you remove the usize implementations here.
Alright, that should be the last of my changes until the next review cycle. I wanted to make sure intent was either clear or documented with examples (that hopefully make it clear).
One additional note, while I'm aware of the discussion in #293 about removing the usize impls for Add and Sub this PR doesn't currently contain that since it was still under discussion, and I'd assumed out of scope. I'd be happy to add that or more preferably provide a follow up PR with those changes. Additionally I'm working off the assumption that #299 and the corresponding jumping_add method/trait fell out of scope of this PR.
Triage: This PR has been waiting for some time. @josephlr Do you have time for a new review, or should I try to take over?