Skip to content

fix: Add #[track_caller] to many address, page, and frame methods - #615

Merged
phil-opp merged 1 commit into
rust-osdev:masterfrom
mkroening:track_caller
Sep 24, 2026
Merged

phil-opp merged 1 commit into
rust-osdev:masterfrom
mkroening:track_caller

Conversation

@mkroening

Copy link
Copy Markdown
Member

This PR adds a bunch of #[track_caller] attributes to creation and arithmetic on VirtAddr, PhysAddr, Page, and Frame. This makes Rust panic messages point to the problematic user code (or higher-level code in this crate) instead of the code that is expected to panic on certain inputs.

Example:

PhysAddr::new(u64::MAX);

Before:

panicked at /Users/mkroening/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/x86_64-0.16.0-rc.0/src/addr.rs:551:23:
physical addresses must not have any bits in the range 52 to 64 set

After (my kernel):

panicked at src/arch/x86_64/mm/paging.rs:226:5:
physical addresses must not have any bits in the range 52 to 64 set

This is very useful for debugging issues such as #611 but is also useful in general for users.

There might be more places where #[track_caller] might make sense, but these should be the obvious ones.

@phil-opp phil-opp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, thank you!

@phil-opp
phil-opp merged commit 7cd5367 into rust-osdev:master Sep 24, 2026
16 checks passed
@mkroening
mkroening deleted the track_caller branch September 24, 2026 20:15
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