rust-osdev / x86_64

Library to program x86_64 hardware.
https://docs.rs/x86_64
Apache License 2.0
797 stars 132 forks source link

fix align functions #375

Closed Freax13 closed 2 years ago

Freax13 commented 2 years ago

This pr fixes VirtAddr::align_up andVirtAddr::align_down. Previously those functions returned non-canonical addresses when aligning addresses near the address space gap. Two tests were added to test such cases.

This pr also fixesPhysAddr::align_up by adding a check to make sure the address is not too big.

josephlr commented 2 years ago

if we are panicking when the PhysAddr goes out of range, should we do the same if the VirtAddr goes out of range? It would make things more consistent.

Freax13 commented 2 years ago

if we are panicking when the PhysAddr goes out of range, should we do the same if the VirtAddr goes out of range? It would make things more consistent.

This pr added just that: https://github.com/rust-osdev/x86_64/blob/49b920493c423b6a2cd7a226fe1dc22c8b472e08/src/addr.rs#L162-L165

josephlr commented 2 years ago

Thanks for adding the tests.