Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for panicking in the emulated application when unsupported functionality is encountered #1818

Merged

Conversation

landaire
Copy link
Contributor

@landaire landaire commented May 26, 2021

This PR fixes #1807 and allows an optional flag to be specified to panic when an unsupported syscall is encountered. In essence, instead of bubbling up an error in the context of the Miri application Miri will panic within the context of the emulated application. This feature is desired to allow CI pipelines to determine if a Miri failure is unsupported functionality or actual UB. Please read this comment for the rationale behind this change.

Note: this change does not cover all cases where unsupported functionality errors may be raised. If you search the repo for throw_unsup_format! there are many cases that I think are less likely to occur and may still be problematic for some folks.

TODO:

  • README documentation on this new flag
  • Add tests

@landaire
Copy link
Contributor Author

Note: this change does not cover all cases where unsupported functionality errors may be raised. If you search the repo for throw_unsup_format! there are many cases that I think are less likely to occur and may still be problematic for some folks.

Would it be desired to expand this PR to encompass these areas, or perhaps make the flag more generic for future expansion?

src/bin/miri.rs Outdated Show resolved Hide resolved
src/eval.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

Seems reasonable to me. :) Besides the TODOs you'd mention, I think it might make sense to create a helper function that encapsulates the if ... { start_panic } else { throw_unsup } pattern.

@RalfJung
Copy link
Member

Btw, you probably also want to adjust this here to panic when the flag is set:

_ => throw_unsup_format!("can't call (diverging) foreign function: {}", link_name),

@bors
Copy link
Collaborator

bors commented May 30, 2021

☔ The latest upstream changes (presumably #1791) made this pull request unmergeable. Please resolve the merge conflicts.

@landaire landaire force-pushed the feature/panic-on-unsupported-syscalls branch from a3808f9 to c3d235d Compare June 2, 2021 20:24
@landaire
Copy link
Contributor Author

landaire commented Jun 2, 2021

Perhaps someone with a keen eye can spot why the test I added is failing. The diff doesn't actually show a delta.

@landaire landaire marked this pull request as ready for review June 2, 2021 20:25
src/shims/panic.rs Outdated Show resolved Hide resolved
@landaire landaire changed the title Add support for panicking in the emulated application when unsupported syscalls are encountered Add support for panicking in the emulated application when unsupported functionality is encountered Jun 2, 2021
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/shims/panic.rs Outdated Show resolved Hide resolved
@bors
Copy link
Collaborator

bors commented Jun 3, 2021

☔ The latest upstream changes (presumably #1776) made this pull request unmergeable. Please resolve the merge conflicts.

@landaire landaire force-pushed the feature/panic-on-unsupported-syscalls branch from 20da2f1 to 4291aba Compare June 4, 2021 23:24
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@landaire landaire force-pushed the feature/panic-on-unsupported-syscalls branch from 510580a to ae23709 Compare June 7, 2021 22:36
@RalfJung
Copy link
Member

RalfJung commented Jun 9, 2021

Looking great, thanks a lot for working with me through the review. :-)
@bors r+

@bors
Copy link
Collaborator

bors commented Jun 9, 2021

📌 Commit ae23709 has been approved by RalfJung

@bors
Copy link
Collaborator

bors commented Jun 9, 2021

⌛ Testing commit ae23709 with merge e5c3af6...

@landaire
Copy link
Contributor Author

landaire commented Jun 9, 2021

Looking great, thanks a lot for working with me through the review. :-)

Seriously, thank you for your patience and great feedback. Hopefully this will not be my last contribution!

@bors
Copy link
Collaborator

bors commented Jun 9, 2021

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing e5c3af6 to master...

@bors bors merged commit e5c3af6 into rust-lang:master Jun 9, 2021
id => throw_unsup_format!("Miri does not support syscall ID {}", id),
id => {
this.handle_unsupported(format!("can't execute syscall with ID {}", id))?;
return Ok(EmulateByNameResult::NotSupported);
Copy link

Choose a reason for hiding this comment

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

Should this be EmulateByNameResult::AlreadyJumped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, I think you are right. This is one of the scenarios I did not test and may have been a merge error.

Copy link
Member

@RalfJung RalfJung Jun 10, 2021

Choose a reason for hiding this comment

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

Ah right, NotSupported means "look up exported function symbol".

I wonder if we should look up the exported symbol first, and only then run our own shim? Then we might not even need the NotSupported variant.

Copy link

Choose a reason for hiding this comment

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

I wonder if we should look up the exported symbol first, and only then run our own shim? Then we might not even need the NotSupported variant.

I think the variant is still needed -- the exported symbol will only be run if no shim implementation can be found, and NotSupported is required to represent that.

bors added a commit that referenced this pull request Jun 11, 2021
Fix the wrong `EmulateByNameResult::NotSupported` in `syscall` shim

Without the change, the newly added test will fail with:
```diff
-thread 'main' panicked at 'unsupported Miri functionality: can't execute syscall with ID 0', $DIR/unsupported_syscall.rs:10:9
+thread 'main' panicked at 'unsupported Miri functionality: can't call foreign function: syscall', $DIR/unsupported_syscall.rs:10:9
 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
cc #1818 (comment)
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.

Allow suppressing unsupported FFI calls
3 participants