Skip to content

miri: enforce proper types for c-variadic arguments in shims - #161734

Open
RalfJung wants to merge 2 commits into
rust-lang:mainfrom
RalfJung:c-variadic-types
Open

miri: enforce proper types for c-variadic arguments in shims#161734
RalfJung wants to merge 2 commits into
rust-lang:mainfrom
RalfJung:c-variadic-types

Conversation

@RalfJung

@RalfJung RalfJung commented Aug 25, 2026

Copy link
Copy Markdown
Member

This adds proper type checks for c-variadic argument handling in Miri shims. So far we would have ICEd for many type mismatches since the innards of the interpreter generally assume that things are well-typed. The checks are are using are the same as for next_arg.

This uncovered some interesting points:

  • We should accept &mut as equivalent to *mut. We don't allow &mut as a type in next_arg but we do allow it for c-variadic calls, so this change also affects a bit more code in const-eval (if the caller passes an &mut and the callee expects a *mut). Even CFI is okay with treating &mut and *mut as equivalent so this should be fine. Cc @folkertdev
  • Some places in the standard library futex handling used types for their variadic arguments that are not quite correct according to these rules. I fixed those. Cc @m-ou-se
  • One variadic function takes pointers to libc::timespec. A program with a libc dependency has two copies of libc (one in the sysroot, and the normal dependency), leading to Miri seeing a type mismatch. C generally considers two copies of the same type to be identical, so I implemented logic that does the same: the names of the type, and the names and types of all fields, must be identical. I then also used that logic for the normal ABI checks, where it will also help since we had similar trouble there in the past (that we had to find other work-arounds for).

@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @oli-obk, @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 25, 2026
@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

r? @mejrs

rustbot has assigned @mejrs.
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: compiler, mir
  • compiler, mir expanded to 75 candidates
  • Random selection from 16 candidates

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 25, 2026
@RalfJung

Copy link
Copy Markdown
Member Author

r? @saethlin

@rustbot rustbot assigned saethlin and unassigned mejrs Aug 25, 2026
@RalfJung RalfJung changed the title C variadic types miri: enforce proper types for c-variadic arguments in shims Aug 25, 2026
@RalfJung
RalfJung force-pushed the c-variadic-types branch 2 times, most recently from 8cec627 to 888931c Compare August 25, 2026 10:17
@RalfJung

This comment was marked as resolved.

@RalfJung

Copy link
Copy Markdown
Member Author

@bors try jobs=aux

rust-bors Bot pushed a commit that referenced this pull request Aug 25, 2026
miri: enforce proper types for c-variadic arguments in shims


try-job: *aux*
@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 7980ab1 (7980ab1bb9a58e8bf9c45898865099a8d7564457)
Base parent: cc05892 (cc05892c8346313865afd91ca12ee1fde6d3603c)

@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. has-merge-commits PR has merge commits, merge with caution. labels Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

4 participants