Commit Graph

1270 Commits

Author SHA1 Message Date
Mara Bos
5880e7d809 Update expected error messages in tests. 2020-10-03 12:00:29 +02:00
Mara Bos
81138825b3 Add park/park_timeout/unpark test. 2020-10-02 23:35:00 +02:00
Ralf Jung
17e16aad62 normalize backtrace stderr even more 2020-09-30 10:02:53 +02:00
Aaron Hill
7fba3c2cf2
Normalize out generic arguments in backtrace-api stderr 2020-09-28 13:55:23 -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
e1bce19ca9
Make some error messages lowercase 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
Ralf Jung
67c5067a2f rustup; fix tests 2020-09-24 09:19:03 +02:00
Ralf Jung
4b5e78052a rustup; support panic=abort on Windows 2020-09-20 15:55:36 +02: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
Ralf Jung
32cdb7131b support panic=abort 2020-09-18 13:10:18 +02:00
Ralf Jung
9a9988a4b0 update docs, and also use MIRIFLAGS for the test suite 2020-09-17 17:29:19 +02:00
Ralf Jung
bc548d3004 test BTreeMap::drain_filter for leaks 2020-09-11 12:20:08 +02:00
Ralf Jung
e61be0b8b8 expand collection tests 2020-09-10 08:44:27 +02:00
Samrat Man Singh
563fb8e43d Implement dup and close for stdin/stdout/stderr
Support F_DUPFD on stdin/stdout/stderr

Enable `close`-ing stdin/stdout/stderr

For `dup`, check if FD is `File` first

If not, clone the appropriate standard IO stream

Merge POSIX `close` and `dup` tests into same module

Also, add assertion that `write` on a closed FD returns an error.

Add `dup` as FileDescriptor trait fn

Also:
- Fix `close` so it drops `self` instead of reference to it
- Remove FD clamping in insert_fd_with_min_fd, since FDs 0-2 can be
closed

Fix fs_libc tests

Make error message when closing stdin/out/err more specific

Return io::Result from `FileDescriptor::dup`

Change error message when closing stdin/out/err

Refactor `FileDescriptor::dup` impl for `FileHandle`

Remove empty line
2020-09-09 23:26:33 +05:30
bors
604a674ea3 Auto merge of #1536 - divergentdave:nanosleep, r=RalfJung
Nanosleep

This PR adds a shim for `libc::nanosleep`, (available under -Zmiri-disable-isolation only) which backs `thread::sleep` on Linux and macOS. I started off by extracting the `timespec` parsing from the `pthread_cond_timedwait` shim into a helper method, and adding checks for invalid values. The second commit adds the new shim and a small test. The shim blocks the current thread, and registers a timeout callback to unblock the thread again, using the same method as `pthread_cond_timedwait` does.
2020-09-08 08:26:33 +00:00
David Cook
06aaea1d6b Update comment 2020-09-07 15:05:26 -05:00
David Cook
33e928c9ca Review comments 2020-09-07 10:54:39 -05:00
Ralf Jung
3fdbc0fd3f fix referenced issue 2020-09-07 13:10:31 +02:00
Ralf Jung
3ba1035d27 use standard black_box function 2020-09-07 11:29:47 +02:00
Ralf Jung
029c851d7c another optimization work-around 2020-09-07 11:23:09 +02:00
Ralf Jung
088af66f85
better optimization suppression
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
2020-09-07 11:16:16 +02:00
Ralf Jung
d9bc19a7b0 test opt-level 2 2020-09-07 10:43:49 +02:00
Ralf Jung
210f18d6c7 work around rustc optimizations becoming too smart 2020-09-07 10:24:38 +02:00
David Cook
417ac2939a Implement libc::nanosleep shim 2020-09-06 18:07:17 -05:00
David Cook
6d323e1032 Refactor timespec parsing, improve error handling 2020-09-06 18:07:14 -05:00
bors
c28a8eeb74 Auto merge of #1532 - divergentdave:thread-panic-payload, r=RalfJung
Move panic payload state from Machine to Thread

This PR moves the panic payload storage from the `Machine` state to per-thread state. Prior to this change, if one thread panicked while another was still unwinding, Miri would fail with `thread 'rustc' panicked at 'the panic runtime should avoid double-panics', src/shims/panic.rs:51:9`. I ran into this issue while prototyping a round-robin scheduler, but it's also reachable with the current scheduler and contrived programs that use blocking API calls to cause thread switching during unwinding. I wrote a test case along those lines for this change.
2020-09-03 10:09:34 +00:00
David Cook
7a2c6812b9 Per-thread errno storage 2020-09-02 20:57:20 -05:00
Ralf Jung
3466462306 rustup, fix test 2020-09-01 10:55:09 +02:00
David Cook
da2f268443 Review comments 2020-08-31 19:32:14 -05:00
David Cook
3ba7f46058 Move panic payload state from Machine to Thread 2020-08-29 21:38:37 -05:00
Ralf Jung
39e6baeb91 rustup 2020-08-27 09:27:58 +02:00
Ralf Jung
2f9de18f88 rustup; account for ptr_offset_from stabilization 2020-08-24 10:06:44 +02:00
Ralf Jung
df9b2127ce fix a test for big-endian targets 2020-08-22 18:07:43 +02:00
Ralf Jung
237bea2c17 avoid promotion in alignment test to get different alignment on each try 2020-08-20 10:14:13 +02:00
Ralf Jung
d5b15297ac forgot to add alignment test loop in one test 2020-08-18 10:19:29 +02:00
Ralf Jung
5b1bc4ba94 make another test more robust against random alignment 2020-08-17 18:22:46 +02:00
Ralf Jung
0913653e06 make sure we test panic of interpreter-impelemted align_offset 2020-08-16 18:31:48 +02:00
Ralf Jung
d4e5943259 use real align_offset unless we symbolic alignment check is enabled 2020-08-16 18:26:04 +02:00
Ralf Jung
cb985670c1 make alignment check integer-based by default, and add an option to make it symbolic 2020-08-16 17:08:38 +02:00
Ralf Jung
80929e17ae add test for unused ill-formed constant
also use better span in TopFrameInfo
2020-08-13 08:33:36 +02:00
Ralf Jung
da2260db44 make sure opening a file fails with isolation enabled 2020-08-10 10:10:08 +02:00
Ralf Jung
5657f08bea fs: move isolation handling to inside trait 2020-08-08 15:24:30 +02:00
bors
cf633d0e89 Auto merge of #1498 - RalfJung:rustup, r=RalfJung
rustup

The allocator API changed *again*, adjust our test.
2020-08-05 11:39:07 +00:00