Skip to content

Fix implicit_provenance_casts warnings on Xous#159174

Open
bjorn3 wants to merge 3 commits into
rust-lang:mainfrom
bjorn3:fix_xous_warnings
Open

Fix implicit_provenance_casts warnings on Xous#159174
bjorn3 wants to merge 3 commits into
rust-lang:mainfrom
bjorn3:fix_xous_warnings

Conversation

@bjorn3

@bjorn3 bjorn3 commented Jul 12, 2026

Copy link
Copy Markdown
Member

@bjorn3 bjorn3 added the O-xous OS: A microkernel OS for privacy in computing label Jul 12, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 12, 2026
@rustbot

rustbot commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

r? @clarfonthey

rustbot has assigned @clarfonthey.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from Darksonn, JohnTitor, Mark-Simulacrum, clarfonthey, jhpratt

@bjorn3

bjorn3 commented Jul 12, 2026

Copy link
Copy Markdown
Member Author

cc @xobs

@xobs

xobs commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Thank you for addressing these.

Comment thread library/std/src/os/xous/ffi.rs
@RalfJung

Copy link
Copy Markdown
Member

The point of these warnings is to actually audit whether exposing is necessary or whether strict provenance could be used instead. Did you actually check this or just replace is everywhere?

@bjorn3

bjorn3 commented Jul 12, 2026

Copy link
Copy Markdown
Member Author

For lend_mut_impl and lend_impl the kernel will read through the passed in pointer. It might be possible to directly pass the pointer to the as block instead. For map_memory the kernel will replace the memory allocation at the given address if there was one. And unmap_memory will deallocate the allocation. And finally create_thread will invoke the function pointer and use the passed in stack for the new thread.

In Thread::new, guard_page_pre and data are both read/deallocated by the thread_start. And tls_table_slow also need the pointer to be exposed for TLS accesses to be allowed.

@xobs

xobs commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

The documentation isn't very clear. It seems that for strict provenance, you use .with_addr(), but to do that you already need to have a pointer.

The problem is that these addresses come from the kernel via a syscall, so they're just a bare usize when the functions return. What's the correct way to go from a syscall return value to a pointer without using .exposed_provenance()?

@RalfJung

RalfJung commented Jul 12, 2026

Copy link
Copy Markdown
Member

@xobs there is no exposed_provenance. There is expose_provenance which goes from a pointer to an integer, which is the opposite direction of what you are talking about. So I can't quite follow your question.

It seems that @bjorn3 is saying that the kernel APIs here are all designed such that they take integers when they actually should take pointers (i.e. this is about inputs to syscalls, not return values)? Yeah if APIs don't use pointer types properly then expose_provenance is what one has to do. Might be worth a few comments.

@clarfonthey

Copy link
Copy Markdown
Contributor

There's with_exposed_provenance, but based upon what the docs say, it's not possible to start from exposed provenance, only return to it. But maybe this is the right choice for this kind of API.

I know that the provenance of external addresses is something that has been discussed a lot and not really resolved. From a libs perspective, the code looks okay (r=me), but I'm going to defer to opsem for review since it feels more important that this is semantically correct rather than just passing a lint.

r? RalfJung since you've already taken a look, but feel free to reroll if you'd rather not review.

@rustbot rustbot assigned RalfJung and unassigned clarfonthey Jul 12, 2026
@rustbot

rustbot commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@RalfJung

Copy link
Copy Markdown
Member

There's with_exposed_provenance, but based upon what the docs say, it's not possible to start from exposed provenance, only return to it. But maybe this is the right choice for this kind of API.

As long as they have been exposed "on the other side" of the FFI (which we can generally assume for cases like this), that's fine.

But this PR doesn't even call with_exposed_provenance.

@RalfJung

Copy link
Copy Markdown
Member

@rustbot author
for more comments

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 17, 2026
In favor of passing raw pointers to inline asm.
@bjorn3

bjorn3 commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

I've removed all exposed_provenance calls in favor of passing raw pointers to the inline asm blocks. I think this is fine.

@bjorn3 bjorn3 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 20, 2026
@bjorn3
bjorn3 force-pushed the fix_xous_warnings branch from 67d0825 to d3e8e6b Compare July 20, 2026 14:19
@RalfJung

Copy link
Copy Markdown
Member

That makes a lot of sense to me conceptually, thanks!
However, I can't review changes of this sort...
@rustbot reroll
And @xobs if you could take another look at the latest version that'd be great.

@rustbot rustbot assigned Darksonn and unassigned RalfJung Jul 20, 2026

@Darksonn Darksonn 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.

Overall looks fine, but some comments.

@rustbot author

View changes since this review

Comment thread library/std/src/os/xous/ffi.rs Outdated
Comment thread library/std/src/os/xous/ffi.rs
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 21, 2026
@bjorn3 bjorn3 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 21, 2026
} else {
Err(Error::InternalError)
}
}

/// Creates a thread with a given stack and up to four arguments.
pub(crate) fn create_thread(
start: *mut usize,
pub(crate) unsafe fn create_thread<T>(

@Darksonn Darksonn Jul 25, 2026

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.

Will this generic lead to extra machine code due to monomorphisation?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There is only a single monomorphic caller.

@Darksonn Darksonn added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 25, 2026

@Darksonn Darksonn 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.

@rust-bors

rust-bors Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7b0af92 has been approved by Darksonn

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 25, 2026
@rust-bors

rust-bors Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit 7b0af92 with merge d4fe0ef...

Workflow: https://github.com/rust-lang/rust/actions/runs/30166393781

rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
Fix implicit_provenance_casts warnings on Xous
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors yield

@rust-bors

rust-bors Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #159455.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 25, 2026
Fix implicit_provenance_casts warnings on Xous
rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
…uwer

Rollup of 25 pull requests

Successful merges:

 - #138618 (Support using const pointers in asm `const` operand)
 - #157962 (Lower paths to functions in const args as ConstKind::Error)
 - #158404 (trait_solver: normalize next-gen region constraints)
 - #158709 (rustdoc: warn on improperly interleaved HTML/MD)
 - #159174 (Fix implicit_provenance_casts warnings on Xous)
 - #159179 (enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group)
 - #159518 (iter: extend step_by specialization to cover StepBy<RangeIter<{integer}>>)
 - #159673 (bootstrap: forward -fdebug-prefix-map when using cc)
 - #159700 (Split non-local `semicolon_in_expressions_from_macros` into a separate lint)
 - #159720 (document #[global_allocator] constraints)
 - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled)
 - #159738 (implement `CovariantUnsafeCell`)
 - #159740 (reuse regular exported_non_generic_symbols logic in Miri)
 - #159780 (check `extern "custom"` function pointers)
 - #159785 (Share _Unwind_Exception definition between native and wasm)
 - #159786 (rustdoc-js: ignore editor temp files in test folder discovery)
 - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new)
 - #155388 (stepping into where-clauses during normalization may be productive)
 - #155914 (when bailing on ambiguity, don't force other results to ambig)
 - #159204 (Add support to caller_location to rustc_public)
 - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`)
 - #159676 (Update wasm-component-ld to 0.5.27)
 - #159695 (proc_macro: Fix cfg_attr inner attrs in file modules)
 - #159730 (allow accessing the contents of UnsafeCell without going through get)
 - #159809 (Avoid `#[target_features]`)
rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
…uwer

Rollup of 25 pull requests

Successful merges:

 - #138618 (Support using const pointers in asm `const` operand)
 - #157962 (Lower paths to functions in const args as ConstKind::Error)
 - #158404 (trait_solver: normalize next-gen region constraints)
 - #158709 (rustdoc: warn on improperly interleaved HTML/MD)
 - #159174 (Fix implicit_provenance_casts warnings on Xous)
 - #159179 (enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group)
 - #159518 (iter: extend step_by specialization to cover StepBy<RangeIter<{integer}>>)
 - #159673 (bootstrap: forward -fdebug-prefix-map when using cc)
 - #159700 (Split non-local `semicolon_in_expressions_from_macros` into a separate lint)
 - #159720 (document #[global_allocator] constraints)
 - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled)
 - #159738 (implement `CovariantUnsafeCell`)
 - #159740 (reuse regular exported_non_generic_symbols logic in Miri)
 - #159780 (check `extern "custom"` function pointers)
 - #159785 (Share _Unwind_Exception definition between native and wasm)
 - #159786 (rustdoc-js: ignore editor temp files in test folder discovery)
 - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new)
 - #155388 (stepping into where-clauses during normalization may be productive)
 - #155914 (when bailing on ambiguity, don't force other results to ambig)
 - #159204 (Add support to caller_location to rustc_public)
 - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`)
 - #159676 (Update wasm-component-ld to 0.5.27)
 - #159695 (proc_macro: Fix cfg_attr inner attrs in file modules)
 - #159730 (allow accessing the contents of UnsafeCell without going through get)
 - #159809 (Avoid `#[target_features]`)
rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
…uwer

Rollup of 25 pull requests

Successful merges:

 - #138618 (Support using const pointers in asm `const` operand)
 - #157962 (Lower paths to functions in const args as ConstKind::Error)
 - #158404 (trait_solver: normalize next-gen region constraints)
 - #158709 (rustdoc: warn on improperly interleaved HTML/MD)
 - #159174 (Fix implicit_provenance_casts warnings on Xous)
 - #159179 (enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group)
 - #159518 (iter: extend step_by specialization to cover StepBy<RangeIter<{integer}>>)
 - #159673 (bootstrap: forward -fdebug-prefix-map when using cc)
 - #159700 (Split non-local `semicolon_in_expressions_from_macros` into a separate lint)
 - #159720 (document #[global_allocator] constraints)
 - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled)
 - #159738 (implement `CovariantUnsafeCell`)
 - #159740 (reuse regular exported_non_generic_symbols logic in Miri)
 - #159780 (check `extern "custom"` function pointers)
 - #159785 (Share _Unwind_Exception definition between native and wasm)
 - #159786 (rustdoc-js: ignore editor temp files in test folder discovery)
 - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new)
 - #155388 (stepping into where-clauses during normalization may be productive)
 - #155914 (when bailing on ambiguity, don't force other results to ambig)
 - #159204 (Add support to caller_location to rustc_public)
 - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`)
 - #159676 (Update wasm-component-ld to 0.5.27)
 - #159695 (proc_macro: Fix cfg_attr inner attrs in file modules)
 - #159730 (allow accessing the contents of UnsafeCell without going through get)
 - #159809 (Avoid `#[target_features]`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 25, 2026
Fix implicit_provenance_casts warnings on Xous
rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
…uwer

Rollup of 25 pull requests

Successful merges:

 - #159825 (codegen: handle OperandValue::Uninit in codegen_return_terminator)
 - #138618 (Support using const pointers in asm `const` operand)
 - #157962 (Lower paths to functions in const args as ConstKind::Error)
 - #158404 (trait_solver: normalize next-gen region constraints)
 - #158709 (rustdoc: warn on improperly interleaved HTML/MD)
 - #159174 (Fix implicit_provenance_casts warnings on Xous)
 - #159179 (enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group)
 - #159518 (iter: extend step_by specialization to cover StepBy<RangeIter<{integer}>>)
 - #159673 (bootstrap: forward -fdebug-prefix-map when using cc)
 - #159700 (Split non-local `semicolon_in_expressions_from_macros` into a separate lint)
 - #159720 (document #[global_allocator] constraints)
 - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled)
 - #159738 (implement `CovariantUnsafeCell`)
 - #159740 (reuse regular exported_non_generic_symbols logic in Miri)
 - #159780 (check `extern "custom"` function pointers)
 - #159786 (rustdoc-js: ignore editor temp files in test folder discovery)
 - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new)
 - #155388 (stepping into where-clauses during normalization may be productive)
 - #155914 (when bailing on ambiguity, don't force other results to ambig)
 - #159204 (Add support to caller_location to rustc_public)
 - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`)
 - #159676 (Update wasm-component-ld to 0.5.27)
 - #159695 (proc_macro: Fix cfg_attr inner attrs in file modules)
 - #159730 (allow accessing the contents of UnsafeCell without going through get)
 - #159809 (Avoid `#[target_features]`)
rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
…uwer

Rollup of 25 pull requests

Successful merges:

 - #159825 (codegen: handle OperandValue::Uninit in codegen_return_terminator)
 - #138618 (Support using const pointers in asm `const` operand)
 - #157962 (Lower paths to functions in const args as ConstKind::Error)
 - #158404 (trait_solver: normalize next-gen region constraints)
 - #158709 (rustdoc: warn on improperly interleaved HTML/MD)
 - #159174 (Fix implicit_provenance_casts warnings on Xous)
 - #159179 (enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group)
 - #159518 (iter: extend step_by specialization to cover StepBy<RangeIter<{integer}>>)
 - #159673 (bootstrap: forward -fdebug-prefix-map when using cc)
 - #159700 (Split non-local `semicolon_in_expressions_from_macros` into a separate lint)
 - #159720 (document #[global_allocator] constraints)
 - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled)
 - #159738 (implement `CovariantUnsafeCell`)
 - #159740 (reuse regular exported_non_generic_symbols logic in Miri)
 - #159780 (check `extern "custom"` function pointers)
 - #159786 (rustdoc-js: ignore editor temp files in test folder discovery)
 - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new)
 - #155388 (stepping into where-clauses during normalization may be productive)
 - #155914 (when bailing on ambiguity, don't force other results to ambig)
 - #159204 (Add support to caller_location to rustc_public)
 - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`)
 - #159676 (Update wasm-component-ld to 0.5.27)
 - #159695 (proc_macro: Fix cfg_attr inner attrs in file modules)
 - #159730 (allow accessing the contents of UnsafeCell without going through get)
 - #159809 (Avoid `#[target_features]`)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 26, 2026
Fix implicit_provenance_casts warnings on Xous
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 26, 2026
Fix implicit_provenance_casts warnings on Xous
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-xous OS: A microkernel OS for privacy in computing S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants