mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
fix bug in page alignment logic
size, you can do this one liner: let aligned_size = ((unasigned_size + alignment_quanta - 1) / (alignment_quanta)) * alignment_quanta; before i was doing this with a `let mut` + `if` statement. this is not as obvious but more compact, probably you'll start to see this idiom more and more in the code. I think it's also computationally efficient, because as long as the alignment_quanta is a power of 2, the compiler does something like a shift right with the `/` operator (and it may also do something like a shift left with the `*` operator as well).
This commit is contained in:
parent
80be6d042a
commit
faa867e63d
1 changed files with 2 additions and 4 deletions
|
|
@ -63,10 +63,8 @@ impl IframRange {
|
|||
match send_message(conn, Message::new_blocking_scalar(0 /* MapIram */, length, bank_code, 0, 0)) {
|
||||
Ok(Result::Scalar5(_, maybe_size, maybe_phys_address, _, _)) => {
|
||||
if maybe_size != 0 && maybe_phys_address != 0 {
|
||||
let mut page_aligned_size = maybe_size / 4096;
|
||||
if maybe_size % 4096 != 0 {
|
||||
page_aligned_size += 1;
|
||||
}
|
||||
// round up to the nearest whole page
|
||||
let page_aligned_size = ((maybe_size + 4095) / 4096) * 4096;
|
||||
let virtual_pages = xous::map_memory(
|
||||
core::num::NonZeroUsize::new(maybe_phys_address),
|
||||
None,
|
||||
|
|
|
|||
Loading…
Reference in a new issue