Skip to content

Commit 92c24c4

Browse files
committed
Auto merge of #2529 - RalfJung:yesffi, r=RalfJung
re-enable FFI support tov/libffi-rs#58 landed so the license should no longer be an issue. :) Fixes #2526
2 parents 8c8b479 + 2f348ab commit 92c24c4

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

Cargo.lock

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ doctest = false # and no doc tests
2020
[dependencies]
2121
getrandom = { version = "0.2", features = ["std"] }
2222
env_logger = "0.9"
23-
#FIXME(miri#2526): libffi = "3.0.0"
23+
libffi = "3.0.0"
2424
libloading = "0.7"
2525
log = "0.4"
2626
shell-escape = "0.1.4"

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,17 @@ to Miri failing to detect cases of undefined behavior in a program.
346346
this flag is **unsound**.
347347
* `-Zmiri-disable-weak-memory-emulation` disables the emulation of some C++11 weak
348348
memory effects.
349+
* `-Zmiri-extern-so-file=<path to a shared object file>` is an experimental flag for providing support
350+
for FFI calls. Functions not provided by that file are still executed via the usual Miri shims.
351+
**WARNING**: If an invalid/incorrect `.so` file is specified, this can cause undefined behaviour in Miri itself!
352+
And of course, Miri cannot do any checks on the actions taken by the external code.
353+
Note that Miri has its own handling of file descriptors, so if you want to replace *some* functions
354+
working on file descriptors, you will have to replace *all* of them, or the two kinds of
355+
file descriptors will be mixed up.
356+
This is **work in progress**; currently, only integer arguments and return values are
357+
supported (and no, pointer/integer casts to work around this limitation will not work;
358+
they will fail horribly).
359+
Follow [the discussion on supporting other types](https://github.com/rust-lang/miri/issues/2365).
349360
* `-Zmiri-measureme=<name>` enables `measureme` profiling for the interpreted program.
350361
This can be used to find which parts of your program are executing slowly under Miri.
351362
The profile is written out to a file with the prefix `<name>`, and can be processed

src/shims/foreign_items.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_target::{
2323

2424
use super::backtrace::EvalContextExt as _;
2525
use crate::helpers::{convert::Truncate, target_os_is_unix};
26-
//FIXME(miri#2526): use crate::shims::ffi_support::EvalContextExt as _;
26+
use crate::shims::ffi_support::EvalContextExt as _;
2727
use crate::*;
2828

2929
/// Returned by `emulate_foreign_item_by_name`.
@@ -375,9 +375,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
375375
// An Ok(false) here means that the function being called was not exported
376376
// by the specified `.so` file; we should continue and check if it corresponds to
377377
// a provided shim.
378-
/*FIXME(miri#2526): if this.call_external_c_fct(link_name, dest, args)? {
378+
if this.call_external_c_fct(link_name, dest, args)? {
379379
return Ok(EmulateByNameResult::NeedsJumping);
380-
}*/
380+
}
381381
}
382382

383383
// When adding a new shim, you should follow the following pattern:

src/shims/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![warn(clippy::integer_arithmetic)]
22

33
mod backtrace;
4-
//FIXME(miri#2526): pub mod ffi_support;
4+
pub mod ffi_support;
55
pub mod foreign_items;
66
pub mod intrinsics;
77
pub mod unix;

tests/compiletest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ fn main() -> Result<()> {
212212
ui(Mode::Panic, "tests/panic", WithDependencies)?;
213213
ui(Mode::Fail { require_patterns: true }, "tests/fail", WithDependencies)?;
214214
if cfg!(target_os = "linux") {
215-
//FIXME(miri#2526): ui(Mode::Pass, "tests/extern-so/pass", WithoutDependencies)?;
216-
//FIXME(miri#2526): ui(Mode::Fail { require_patterns: true }, "tests/extern-so/fail", WithDependencies)?;
215+
ui(Mode::Pass, "tests/extern-so/pass", WithoutDependencies)?;
216+
ui(Mode::Fail { require_patterns: true }, "tests/extern-so/fail", WithDependencies)?;
217217
}
218218

219219
Ok(())

0 commit comments

Comments
 (0)