diff options
| author | bors <bors@rust-lang.org> | 2022-08-26 08:51:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-08-26 08:51:11 +0000 |
| commit | 64185014af8ffd81109cab1d1140c18933369071 (patch) | |
| tree | 83f91a3c04e512cb8f946199d0bea3b385cc2635 /tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.diff | |
| parent | d5853bc724d469287ca3aeab2585413625f1a4ba (diff) | |
| parent | 88a78826154870f9778af49d48974fd180e31df8 (diff) | |
| download | rust-64185014af8ffd81109cab1d1140c18933369071.tar.gz rust-64185014af8ffd81109cab1d1140c18933369071.zip | |
Auto merge of #2363 - emarteca:int-function-args-returns, r=oli-obk
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](https://github.com/maurer/miri/pull/1) -- thanks!
Diffstat (limited to 'tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.diff')
0 files changed, 0 insertions, 0 deletions
