x86_64 icon indicating copy to clipboard operation
x86_64 copied to clipboard

Add checked arithmetic operations traits

Open ncatelli opened this issue 4 years ago • 6 comments

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

ncatelli avatar Aug 19 '21 18:08 ncatelli

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 avatar Aug 20 '21 14:08 ncatelli

@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)

josephlr avatar Aug 22 '21 08:08 josephlr

Also @ncatelli per https://github.com/rust-osdev/x86_64/issues/293#issuecomment-903237326 can you remove the usize implementations here.

josephlr avatar Aug 22 '21 09:08 josephlr

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).

ncatelli avatar Aug 23 '21 00:08 ncatelli

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.

ncatelli avatar Aug 24 '21 20:08 ncatelli

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?

phil-opp avatar Nov 06 '21 13:11 phil-opp