Skip to content

Names, updates, and an overflow fix#68

Merged
dancrossnyc merged 3 commits intomainfrom
fixes
Apr 18, 2026
Merged

Names, updates, and an overflow fix#68
dancrossnyc merged 3 commits intomainfrom
fixes

Conversation

@dancrossnyc
Copy link
Copy Markdown
Collaborator

Tested on sn6.

It is possible to map a loadable ELF segment at the very top of
virtual memory, and if we do so, then the end address of the
resulting region will overflow and wrap around to 0.  This is
expected.

The virtual memory code correctly handles this, but the loader
uses `end - begin` to calculate the lengths of segments, and
that can wrap when `end` is rounded "up" to 0.  To make explicit
that this is permissible (and to avoid panics in debug builds),
we should use `.wrapping_sub` instead of bare subtraction.

I should stress that, while this behavior is supported, it does
not happen in practice, as no binary that we load with `phbl`
maps anything in that region of the virtual address space; in
that sense, this change is a no-op.  But as a code hygiene
issue, the program should be correct in all regards, and hence
should handle this case explicitly.

Signed-off-by: Dan Cross <cross@oxidecomputer.com>
ELF "sections" are not exactly the same thing as loadable
"segments", and we should be clear with nomenclature.  The ELF
standard uses the term "segment" for what is described by the
program headers, which are the things that we load, so we
should, too.

Signed-off-by: Dan Cross <cross@oxidecomputer.com>
Trivial update to a newer Rust version and updating dependencies
via `cargo update`.

Signed-off-by: Dan Cross <cross@oxidecomputer.com>
@dancrossnyc dancrossnyc requested a review from citrus-it April 17, 2026 18:43
@dancrossnyc dancrossnyc merged commit 2a84dd4 into main Apr 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants