forked from rust-lang/miri
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Adding support for external C functions that have integer (or empty) args and/or returns #1
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rustup; ptr atomics Adds support for the operations added in rust-lang/rust#96935. I made the pointer-binops always return the provenance of the *left* argument; `@thomcc` I hope that is what you intended. I have honestly no idea if it has anything to do with what LLVM does... I also simplified our pointer comparison code while I was at it -- now that *all* comparison operators support wide pointers, we can unify those branches.
adjust for removed unsized_locals The Miri side of rust-lang/rust#98831
remove a dead optimization This became dead code when I removed "Untagged".
fix comment in ./miri pointed out in rust-lang#2288 (comment)
🤯 did you mean to open this here? This is not the main miri repository |
… comments in the same files
... that grabs things from the front instead of splitting at spaces and colons and hoping for the best
Print one . character per test instead of one line `./miri bless -- --quiet` now prints a dot per test, along with the regular Rust unit tests that listen to this flag
fix auto-toolchain pwd `rustup-toolchain` needs to be called in the right directory
remove rand (large dependency) and page-size (testing the dependency, not cargo-miri). keep only byteorder as a "demo" dependency, it is a leaf and builds quickly.
and move crate tests to their own folders
… a runtime toolchain
cargo-miri: set RUSTC to us Works around rust-lang/cargo#10885.
make test-cargo-miri only about cargo Move the things that actually test dependency behavior into the regular test suite, now that we can do that. :)
Some cleanups and docs around the auto ops
emarteca
force-pushed
the
int-function-args-returns
branch
from
July 21, 2022 21:32
20cc3b6
to
62926b7
Compare
Closing in favor of the real PR |
bors
added a commit
to rust-lang/miri
that referenced
this pull request
Aug 26, 2022
Adding support for external C functions that have integer (or empty) args and/or returns Starts addressing `@https://github.com/rust-lang/miri/issues/11` ### Implementation Adding support for calling external C functions that have any number of integer arguments (types of integers: `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`) and an integer return type (or `void`). As suggested in `@https://github.com/rust-lang/miri/issues/11,` the [`libffi` crate](https://docs.rs/libffi/latest/libffi/index.html) is used to dispatch the calls to external C functions. #### Modifications Main modifications are to: * [helper.rs](https://github.com/emarteca/miri/blob/int-function-args-returns/src/helpers.rs) : adding a function `call_and_add_external_c_fct_to_context` to read the code pointer to the external C function, dispatch the call, and save the return in MIRI internal memory. Handles all conversions between MIRI and C values (using some macros, also defined in this file). * [foreign_items.rs](https://github.com/emarteca/miri/blob/int-function-args-returns/src/shims/foreign_items.rs) : handles the calling of `call_and_add_external_c_fct_to_context` in [helper.rs](https://github.com/emarteca/miri/blob/int-function-args-returns/src/helpers.rs) when a foreign item is encountered. Also adds some structs to model C representations of arguments, and the signature of the external C call. ### Testing Adds tests for the following external functions which are now supported: * [int tests](https://github.com/emarteca/miri/blob/int-function-args-returns/tests/pass/external_C/int_c_tests.rs): - adds 2 to a provided int (no type of int specified, so autocasts) - takes the sum of its 12 arguments (tests stack spill) - adds 3 to a 16 bit int - adds an `i16` to an `i64` - returns -10 as an unsigned int * [void tests](https://github.com/emarteca/miri/blob/int-function-args-returns/tests/pass/external_C/print_from_c.rs) - void function that prints from C ### Code review The code in this PR was reviewed by `@maurer` on [another fork](maurer#1) -- thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Starts addressing @rust-lang#11
Implementation
Adding support for calling external C functions that have any number of integer arguments (types of integers:
i8
,i16
,i32
,i64
,u8
,u16
,u32
,u64
) and an integer return type (orvoid
).As suggested in @rust-lang#11, the
libffi
crate is used to dispatch the calls to external C functions.Modifications
Main modifications are to:
call_and_add_external_c_fct_to_context
to read the code pointer to the external C function, dispatch the call, and save the return in MIRI internal memory. Handles all conversions between MIRI and C values.call_and_add_external_c_fct_to_context
in helper.rs when a foreign item is encountered. Also adds some structs to model C representations of arguments, and the signature of the external C call.Testing
Adds tests for the following external functions which are now supported:
i16
to ani64