Commit Graph

5062 Commits

Author SHA1 Message Date
bors
3fafb835ea Auto merge of #1570 - RalfJung:syscalls, r=RalfJung
check that all syscall arguments are scalars

`@m-ou-se` do you think this check makes sense?

The `abi` of a layout contains everything needed for the calling convention (as far as I know), so this should ensure that all the ignored arguments are passed like integers and do not otherwise mess up argument passing.

The one thing I am not sure about is what happens when more arguments are passed than fit in registers. The `syscall` man page says that all calling conventions support at least 6 arguments, except for "mips/o32" where it says that
```
       [1] The mips/o32 system call convention passes arguments 5 through 8 on the user stack.
```
If we assume that passing these extra arguments to futex is legal even with that calling convention, that would mean that those user stack arguments are just silently ignored as well, which seems plausible to me -- but I know very little about calling conventions.
2020-10-03 15:49:15 +00:00
Ralf Jung
2b2a3a0cc1 check that all syscall arguments are scalars 2020-10-03 16:01:53 +02:00
bors
5620ad015d Auto merge of #1569 - RalfJung:rustup, r=RalfJung
bump Rust version and a bit of cleanup
2020-10-03 13:28:37 +00:00
Ralf Jung
a4cbbddc8e merge parking test into general synchronization test 2020-10-03 15:27:23 +02:00
Ralf Jung
b350c80a31 add backtics back in isolation error message 2020-10-03 15:25:30 +02:00
Ralf Jung
044c9ca206 rustup 2020-10-03 15:19:57 +02:00
bors
b0e02f0218 Auto merge of #1568 - fusion-engineering-forks:futex, r=RalfJung
Implement futex_wait and futex_wake.

Fixes https://github.com/rust-lang/rust/issues/77406 and fixes #1562.

This makes std's park(), park_timeout(), and unpark() work. That means std::sync::Once is usable again and the test pass again with the latest rustc.

This also makes parking_lot work.
2020-10-03 12:36:03 +00:00
Mara Bos
68776d2921
Add FIXME about type of addr in futex implementation.
Co-authored-by: Ralf Jung <post@ralfj.de>
2020-10-03 14:32:30 +02:00
Mara Bos
c268ee2bcb
Add note about use of force_ptr in futex implementation.
Co-authored-by: Ralf Jung <post@ralfj.de>
2020-10-03 14:21:37 +02:00
Mara Bos
dfcb46a4e0 Update syscall FIXME to include note about 'wrong' types. 2020-10-03 13:39:16 +02:00
Mara Bos
dc36988f38 Add test for futex syscall. 2020-10-03 13:34:49 +02:00
Mara Bos
9d764c5750 Add FIXME note about variadic syscall(). 2020-10-03 12:18:38 +02:00
Mara Bos
6df54c47a7 Use read_scalar_at_offset in futex_wait instead of memory.get_raw. 2020-10-03 12:11:24 +02:00
Mara Bos
5880e7d809 Update expected error messages in tests. 2020-10-03 12:00:29 +02:00
Mara Bos
66282754ff Remove backtics from isolation error.
Otherwise `FUTEX_WAIT with timeout` will look weird.
2020-10-03 11:38:16 +02:00
Mara Bos
924fd56944 Only allow FUTEX_WAIT with timeout when isoloation is disabled. 2020-10-03 11:35:13 +02:00
Mara Bos
c9627b25fb Use correct return type for syscall(SYS_futex). 2020-10-03 00:40:53 +02:00
Mara Bos
81138825b3 Add park/park_timeout/unpark test. 2020-10-02 23:35:00 +02:00
Mara Bos
e64ead2f46 Implement timeouts for FUTEX_WAIT. 2020-10-02 23:34:14 +02:00
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