Commit Graph

5143 Commits

Author SHA1 Message Date
Mara Bos
d5b3f54b46 Use force_ptr in futex implementation. 2020-10-02 21:59:11 +02:00
Mara Bos
422b5053a9
Add note about arguments in futex implementation.
Co-authored-by: Ralf Jung <post@ralfj.de>
2020-10-02 20:56:01 +02:00
Mara Bos
dabd980567 Update note about number of arguments to SYS_futex. 2020-10-02 20:53:31 +02:00
Mara Bos
ee3eb4b223 Add comments that document SYS_futex better. 2020-10-02 10:47:53 +02:00
Mara Bos
712e8006b3 Improve handling of the addr argument in SYS_futex. 2020-10-02 10:47:36 +02:00
Mara Bos
c2fa27c3b8 Check maximum amount of arguments to SYS_futex. 2020-10-02 10:46:57 +02:00
Mara Bos
1c582e7c96 Return correct value from futex_wait. 2020-10-02 01:49:20 +02:00
Mara Bos
69cea1dc92 Only check futex pointer in futex_wait and not in futex_wake.
futex_wake doesn't access the futex itself, so should accept pointers to
memory that's no longer there.
2020-10-01 22:57:27 +02:00
Mara Bos
6c2f36eb6b Erase tag from futex pointers. 2020-10-01 21:06:16 +02:00
Mara Bos
281a538226 Move futex syscall to its own file. 2020-10-01 21:03:36 +02:00
Mara Bos
1ffc5bb563 Implement futex_wait and futex_wake.
This does not support futex_wait with a timeout yet.
2020-10-01 20:55:54 +02:00
bors
266b75faec Auto merge of #1566 - RalfJung:backtrace, r=RalfJung
normalize backtrace stderr even more

The test previously failed on rustc CI with this diff:
```
 $DIR/backtrace-api.rs:21:59 (func_c)
 $DIR/backtrace-api.rs:20:53 (func_b)
 $DIR/backtrace-api.rs:19:50 (func_a)
 $DIR/backtrace-api.rs:25:18 (main)
-RUSTLIB/src/rust/library/core/src/ops/function.rs:LL:COL (<fn() as std::ops::FnOnce<()>>::call_once - shim(fn()))
-RUSTLIB/src/rust/library/std/src/sys_common/backtrace.rs:LL:COL (std::sys_common::backtrace::__rust_begin_short_backtrace)
-RUSTLIB/src/rust/library/std/src/rt.rs:LL:COL (std::rt::lang_start::{closure#0})
-RUSTLIB/src/rust/library/core/src/ops/function.rs:LL:COL (std::ops::function::impls::call_once)
-RUSTLIB/src/rust/library/std/src/panicking.rs:LL:COL (std::panicking::r#try::do_call)
-RUSTLIB/src/rust/library/std/src/panicking.rs:LL:COL (std::panicking::r#try)
-RUSTLIB/src/rust/library/std/src/panic.rs:LL:COL (std::panic::catch_unwind)
-RUSTLIB/src/rust/library/std/src/rt.rs:LL:COL (std::rt::lang_start_internal)
-RUSTLIB/src/rust/library/std/src/rt.rs:LL:COL (std::rt::lang_start)
+/checkout/library/core/src/ops/function.rs:227:5 (<fn() as std::ops::FnOnce<()>>::call_once - shim(fn()))
+/checkout/library/std/src/sys_common/backtrace.rs:137:18 (std::sys_common::backtrace::__rust_begin_short_backtrace)
+/checkout/library/std/src/rt.rs:66:18 (std::rt::lang_start::{closure#0})
+/checkout/library/core/src/ops/function.rs:259:13 (std::ops::function::impls::call_once)
+/checkout/library/std/src/panicking.rs:381:40 (std::panicking::r#try::do_call)
+/checkout/library/std/src/panicking.rs:345:19 (std::panicking::r#try)
+/checkout/library/std/src/panic.rs:382:14 (std::panic::catch_unwind)
+/checkout/library/std/src/rt.rs:51:25 (std::rt::lang_start_internal)
+/checkout/library/std/src/rt.rs:65:5 (std::rt::lang_start)
```
Cc `@Aaron1011`
2020-09-30 08:03:14 +00:00
Ralf Jung
17e16aad62 normalize backtrace stderr even more 2020-09-30 10:02:53 +02:00
bors
e046963ed6 Auto merge of #1565 - RalfJung:rustup, r=RalfJung
rustup; adjust for rustc_driver changes
2020-09-29 09:05:35 +00:00
Ralf Jung
eaf56c57e5 rustup; adjust for rustc_driver changes 2020-09-29 11:05:10 +02:00
bors
510e62c9ea Auto merge of #1559 - Aaron1011:new-miri-backtrace, r=RalfJung
Add API for capturing backtrace

This PR adds two new Miri-defined extern functions:
`miri_get_backtrace` and `miri_resolve_frame`, which are documented in
the README. Together, they allow obtaining a backtrace for the currently
executing program.

I've added a test showing how these APIs are used. I've also prepared a
companion PR `backtrace-rs`, which will allow
`backtrace::Backtrace::new()` to work automatically under Miri.

Once these two PRs are merged, we will be able to print backtraces from
the normal Rust panic hook (since libstd is now using backtrace-rs).

A few notes:
* Resolving the backtrace frames is *very* slow - you can actually see
  each line being printed out one at a time. Some local testing showed
  that this is not (primrary) caused by resolving a `Span` - it seems
  to be just Miri being slow.
* For the first time, we now interact directly with a user-defined
  struct (instead of just executing the user-provided MIR that
  manipulates the struct). To allow for future changes, I've added
  a 'version' parameter (currently required to be 0). This should allow
  us to change the `MiriFrame` struct should the need ever arise.
* I used the approach suggested by `@oli-obk` - a returned backtrace
  pointer consists of a base function allocation, with the 'offset'
  used to encode the `Span.lo`. This allows losslessly reconstructing
  the location information in `miri_resolve_frame`.
* There are a few quirks on the `backtrace-rs` side:
  * `backtrace-rs` calls `getcwd()` by default to try to simplify
    the filename. This results in an isolation error by default,
    which could be annoying when printing a backtrace from libstd.
  * `backtrace-rs` tries to remove 'internal' frames (everything between
     the call to `Backtrace::new()` and the internal API call made by
     backtrace-rs) by comparing the returned frame pointer value to
     a Rust function pointer. This doesn't work due to the way we
     construct the frame pointers passed to the caller. We could
     attempt to support this kind of comparison, or just add a
    `#[cfg(miri)]` and ignore the frames ourselves.
2020-09-28 19:16:50 +00:00
Aaron Hill
7fba3c2cf2
Normalize out generic arguments in backtrace-api stderr 2020-09-28 13:55:23 -04:00
Ralf Jung
b1837d0bc9
fix typo 2020-09-28 13:44:46 -04:00
Aaron Hill
5571bcfc4f
Require #[repr(C)] on MiriFrame 2020-09-28 13:44:46 -04:00
Aaron Hill
dba7f13549
Apply #[inline(never)] to functions that we want in the backtrace 2020-09-28 13:44:46 -04:00
Aaron Hill
11e2dbd51c
Update README 2020-09-28 13:44:45 -04:00
Aaron Hill
e1bce19ca9
Make some error messages lowercase 2020-09-28 13:44:45 -04:00
Aaron Hill
f756e3a93f
Explain encoding scheme 2020-09-28 13:44:45 -04:00
Aaron Hill
b89f6561e5
Move things around 2020-09-28 13:44:45 -04:00
Aaron Hill
9fc384fcf9
Print non-std frames to stdout in backtrace-api test 2020-09-28 13:44:45 -04:00
Aaron Hill
ef43c5a614
Use a 'flags' parameter instead of 'version' 2020-09-28 13:44:45 -04:00
Aaron Hill
ae18659d52
Normalize line and column numbers from the sysroot 2020-09-28 13:44:45 -04:00
Aaron Hill
22f1eb01ee
Add API for capturing backtrace
This PR adds two new Miri-defined extern functions:
`miri_get_backtrace` and `miri_resolve_frame`, which are documented in
the README. Together, they allow obtaining a backtrace for the currently
executing program.

I've added a test showing how these APIs are used. I've also prepared a
companion PR `backtrace-rs`, which will allow
`backtrace::Backtrace::new()` to work automatically under Miri.

Once these two PRs are merged, we will be able to print backtraces from
the normal Rust panic hook (since libstd is now using backtrace-rs).

A few notes:
* Resolving the backtrace frames is *very* slow - you can actually see
  each line being printed out one at a time. Some local testing showed
  that this is not (primrary) caused by resolving a `Span` - it seems
  to be just Miri being slow.
* For the first time, we now interact directly with a user-defined
  struct (instead of just executing the user-provided MIR that
  manipulates the struct). To allow for future changes, I've added
  a 'version' parameter (currently required to be 0). This should allow
  us to change the `MiriFrame` struct should the need ever arise.
* I used the approach suggested by @oli-obk - a returned backtrace
  pointer consists of a base function allocation, with the 'offset'
  used to encode the `Span.lo`. This allows losslessly reconstructing
  the location information in `miri_resolve_frame`.
* There are a few quirks on the `backtrace-rs` side:
  * `backtrace-rs` calls `getcwd()` by default to try to simplify
    the filename. This results in an isolation error by default,
    which could be annoying when printing a backtrace from libstd.
  * `backtrace-rs` tries to remove 'internal' frames (everything between
     the call to `Backtrace::new()` and the internal API call made by
     backtrace-rs) by comparing the returned frame pointer value to
     a Rust function pointer. This doesn't work due to the way we
     construct the frame pointers passed to the caller. We could
     attempt to support this kind of comparison, or just add a
    `#[cfg(miri)]` and ignore the frames ourselves.
2020-09-28 13:44:45 -04:00
bors
aa832c1133 Auto merge of #1555 - lzutao:upstream-assume-const, r=RalfJung
Remove assume intrinsic from EvalContextExt

Waiting for https://github.com/rust-lang/rust/pull/76973 merged.
2020-09-27 08:31:09 +00:00
Lzu Tao
56ea94dfa3 Remove assume intrinsic from EvalContextExt
It has been moved to rustc_mir.
2020-09-27 10:00:06 +07:00
bors
2f84bfc57d Auto merge of #1561 - RalfJung:rustup, r=RalfJung
rustup; fix tests
2020-09-24 07:19:39 +00:00
Ralf Jung
67c5067a2f rustup; fix tests 2020-09-24 09:19:03 +02:00
bors
462243ef5a Auto merge of #1560 - RalfJung:rustup, r=RalfJung
opt-level 3 is clean again :)
2020-09-23 20:13:59 +00:00
Ralf Jung
dae575c38f opt-level 3 is clean again :) 2020-09-23 22:13:13 +02:00
bors
639057e04e Auto merge of #1558 - RalfJung:serde_derive, r=RalfJung
test formerly broken serde_derive dependency

Adds a test for the issue fixed in https://github.com/rust-lang/miri/pull/1557
2020-09-21 13:48:15 +00:00
Ralf Jung
0c67ec2057 test formerly broken serde_derive dependency 2020-09-21 15:47:09 +02:00
bors
02a33d411d Auto merge of #1557 - RalfJung:cargo-miri, r=RalfJung
support non-rlib extern files

This came up in https://github.com/hsivonen/encoding_rs/pull/57.
2020-09-21 10:47:26 +00:00
Ralf Jung
4dda2ad5b4 support non-rlib extern files 2020-09-21 12:46:18 +02:00
bors
cbc7560ae2 Auto merge of #1556 - RalfJung:compat, r=RalfJung
also support old 'cargo miri run -- -- args' style

I forgot this in https://github.com/rust-lang/miri/pull/1540. Again this is just temporary, for backwards compatibility.
2020-09-21 07:11:37 +00:00
Ralf Jung
88b9c2173e also support old 'cargo miri run -- -- args' style 2020-09-21 09:10:04 +02:00
bors
5a15c8a6dd Auto merge of #1554 - RalfJung:rustup, r=RalfJung
rustup; support panic=abort on Windows

Fixes https://github.com/rust-lang/miri/issues/1058
2020-09-20 13:56:59 +00:00
Ralf Jung
4b5e78052a rustup; support panic=abort on Windows 2020-09-20 15:55:36 +02:00
bors
1f6ce43721 Auto merge of #1553 - RalfJung:rustup, r=RalfJung
rustup

Cc `@oli-obk`
2020-09-20 11:14:29 +00:00
Ralf Jung
b0baa151b2 rustup 2020-09-20 13:13:57 +02:00
bors
7942e7797b Auto merge of #1552 - RalfJung:rustup, r=RalfJung
rustup; make sure the generator moves even with smarter optimizations
2020-09-20 10:18:29 +00:00
Ralf Jung
08e076c658 account for mir-opts masking more errors 2020-09-20 12:18:02 +02:00
Ralf Jung
83a339e5a9 rustup; make sure the iterator moves even with smarter optimizations 2020-09-20 10:26:22 +02:00
bors
e086ae5d45 Auto merge of #1551 - RalfJung:readme, r=RalfJung
list two more aliasing problems we found in BTreeMap and VecDeque
2020-09-19 09:40:24 +00:00
Ralf Jung
5652052e23 list two more aliasing problems we found in BTreeMap and VecDeque 2020-09-19 11:39:13 +02:00
bors
84a4514254 Auto merge of #1549 - RalfJung:panic-abort, r=oli-obk
support panic=abort

This adds support for abort-on-panic (https://github.com/rust-lang/miri/issues/1058). To achieve this, we insert `cargo-miri` as `RUSTC` when building the standard library, and patch the rustc flags in a way similar to what bootstrap does.

However, this is currently not supported on Windows as the Windows code uses inline assembly to cause an abort (?!?). I'll submit a rustc PR with some `cffg(miri)` to make that work. (EDIT: that would be https://github.com/rust-lang/rust/pull/76871)

Cc `@Aaron1011` r? `@oli-obk`
2020-09-18 11:41:04 +00:00