Commit graph

302 commits

Author SHA1 Message Date
Jason White
73dbb7dc41 Don't use include_str on the README
Summary:
This causes problems with creating a Nix package for Reverie since it is pulling the readme from a parent directory while nix is trying to isolate each package in the workspace.

Fixes https://github.com/facebookexperimental/reverie/issues/17.

Reviewed By: rrnewton

Differential Revision: D42466480

fbshipit-source-id: 8a7eef961a4477ca31b53c39cb72b57bad07f0ad
2023-01-20 10:19:06 -08:00
Richard Barnes
567988736d Remove unused variables in hermetic_infra/reverie/tests/c_tests/forkMany-blockSigchld.c
Summary:
LLVM-15 has a warning `-Wunused-but-set-variable` which we treat as an error because it's so often diagnostic of a code issue. Unused variables can compromise readability or, worse, performance.

This diff either (a) removes an unused variable and, possibly, it's associated code, or (b) qualifies the variable with `[[maybe_unused]]`, mostly in cases where the variable _is_ used, but, eg, in an `assert` statement that isn't present in production code.

 - If you approve of this diff, please use the "Accept & Ship" button :-)

Reviewed By: luciang

Differential Revision: D42465117

fbshipit-source-id: 64e7dec0eecaa4e3c50d4fea5ffd1c57cd8b58d7
2023-01-11 16:31:31 -08:00
Richard Barnes
894ce0fd86 Remove unused variables in hermetic_infra/reverie/tests/c_tests/forkMany.c
Summary:
LLVM-15 has a warning `-Wunused-but-set-variable` which we treat as an error because it's so often diagnostic of a code issue. Unused variables can compromise readability or, worse, performance.

This diff either (a) removes an unused variable and, possibly, it's associated code, or (b) qualifies the variable with `[[maybe_unused]]`, mostly in cases where the variable _is_ used, but, eg, in an `assert` statement that isn't present in production code.

 - If you approve of this diff, please use the "Accept & Ship" button :-)

Reviewed By: luciang

Differential Revision: D42465119

fbshipit-source-id: 02ad87bf0d56b6ced76912bd1d866a192dbbcbda
2023-01-11 16:27:54 -08:00
Jack Wrenn
346da4a53b Fix import in reverie_memory::LocalMemory::new doctest. (#18)
Summary:
When dba0b5b9b7 moved `LocalMemory` into the standalone `reverie-memory` crate, a doctest import was not updated.

Pull Request resolved: https://github.com/facebookexperimental/reverie/pull/18

Reviewed By: VladimirMakaev

Differential Revision: D42330995

Pulled By: jasonwhite

fbshipit-source-id: 54b4d6770a1b156f09f9feb014730dcec80f32c5
2023-01-09 10:08:24 -08:00
Jason White
dba0b5b9b7 Extract MemoryAccess into separate crate
Summary: This removes the need for `safeptrace` to depend on `reverie-syscalls`, which is a somewhat heavyweight library.

Reviewed By: VladimirMakaev

Differential Revision: D41751372

fbshipit-source-id: 36f601c7f441b070cd3a0678621649c4fb12b28e
2022-12-07 18:06:56 -08:00
Jason White
9515dfe3c2 Only compile for Linux
Summary:
Everything in Reverie is super Linux-specific, so we should just skip compilation if we're not targetting Linux.

This is helpful for consumers of the library when it gets published to crates.io. With this, they don't need to have a special case for this in the `[dependencies]` section of `Cargo.toml`.

Reviewed By: VladimirMakaev

Differential Revision: D41824410

fbshipit-source-id: be1e0a887e35ed151cfad27af8107246df30c2e5
2022-12-07 18:05:11 -08:00
Jason White
5590fdacb2 Remove unused dotslash files
Reviewed By: VladimirMakaev

Differential Revision: D41821643

fbshipit-source-id: 36dbd6c26c6986e8acb771b5825a1e09c2255340
2022-12-07 16:47:04 -08:00
Jason White
bcce15d17d safeptrace: Remove unnecessary copying of registers
Summary: Might lead to a minor speed up, but probably not due to the magic of compiler optimizations. I noticed this a while back and meant to fix it before publishing the `safeptrace` crate (so this won't be a breaking change later).

Reviewed By: VladimirMakaev

Differential Revision: D41699769

fbshipit-source-id: ef3e5f24468ddb4b69b8628e28b1da8cfdcbce7b
2022-12-07 07:38:13 -08:00
Ryan Newton
866529e6e8 refactor: move pedgree from reverie-util to detcore-model
Summary:
We want to use this in detcore, and reverie-util is slated to go away.
Detcore-model is meant to be widely depended on anyway, so this is a fine place for it.

Reviewed By: jasonwhite

Differential Revision: D41627508

fbshipit-source-id: bb477909217231d8fb6a7bafbfca1fb72a578ec2
2022-12-06 07:09:49 -08:00
Jason White
68cb6d5f3a Remove unused pedigree example
Summary: Removing this to remove another dependency on `reverie-util`, so we can eventually get rid of it.

Reviewed By: rrnewton

Differential Revision: D41629842

fbshipit-source-id: bf6d518db6e5ff9f4149936a7dabc0e912133886
2022-12-05 10:20:52 -08:00
Will Hughes
7ff30097d7 Demangle pretty stack frame by default
Summary:
We output the pretty backtrace as JSON, but demangling of symbol names only happens when a symbol is debug printed, which therefore doesn't apply to the JSON.

Instead, demangle pretty backtraces by default so this demangling applies to the output JSON

Reviewed By: jasonwhite

Differential Revision: D41687077

fbshipit-source-id: ee5919597a37664dfb8a66c4fdeda86379d024a9
2022-12-05 04:04:53 -08:00
Jason White
d9a2b94410 reverie-syscalls: Add io_uring support
Reviewed By: rrnewton

Differential Revision: D41699755

fbshipit-source-id: a16e262d5f66e7af373dea93e1e4bd349db4f841
2022-12-03 12:19:30 -08:00
Jason White
487f7b6d8b Add Guest::has_cpuid_interception
Summary: This is useful for knowing if we're able to intercept CPUID or not.

Reviewed By: rrnewton

Differential Revision: D41599743

fbshipit-source-id: 56b1ca16f028ad070ecdf4e8489b6e318e386e65
2022-11-30 11:14:39 -08:00
Will Hughes
6ac4e49ab3 Output structured report data instead of strings
Summary:
Currently the hermit analyze report json has:
1. Header, a string containing some text
2. A formatted stack trace as string for both events

Change this to a structured JSON report, with data only, so non-human consumers can decide how to render it.

Reviewed By: rrnewton

Differential Revision: D41523428

fbshipit-source-id: af689bfb04885775ed7cb60e103a3103da875849
2022-11-30 04:02:22 -08:00
Jason White
5995e04dde reverie-syscalls: Fix Sendfile missing from aarch64
Summary: `sendfile` is available on aarch64, so this was a mistake.

Differential Revision: D41590782

fbshipit-source-id: 6e704bc0c3358c232768a5382c7b5435445c3976
2022-11-29 15:58:23 -08:00
Jason White
495ffad867 Fix README commands being treated as Rust code
Summary:
Fixes the following errors:
```
---- src/lib.rs - (line 55) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `apt`
 --> src/lib.rs:56:6
  |
3 | sudo apt install pkg-config libunwind-devel
  |      ^^^ expected one of 8 possible tokens

error: aborting due to previous error

Couldn't compile the test.
---- src/lib.rs - (line 61) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `test`
 --> src/lib.rs:62:7
  |
3 | cargo test -- --test-threads=1
  |       ^^^^ expected one of 8 possible tokens

error: aborting due to previous error

Couldn't compile the test.
---- src/lib.rs - (line 66) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `reverie`
 --> src/lib.rs:67:4
  |
4 | cd reverie-examples
  |    ^^^^^^^ expected one of 8 possible tokens

error: aborting due to previous error
```

Reviewed By: rrnewton

Differential Revision: D41588323

fbshipit-source-id: 46d55e81f741ac3b36a25e21291b00849600b7f1
2022-11-29 15:56:13 -08:00
Jason White
7b7c638449 Fix broken doc links
Summary: Fixes broken doc links so that `cargo doc` succeeds again.

Reviewed By: rrnewton

Differential Revision: D41588324

fbshipit-source-id: ed539bef5ea2a91562ec7d03a756ea4cc3f9000a
2022-11-29 13:53:16 -08:00
Jason White
0037ec860d Remove usage of 'never_type' nightly feature
Summary: It doesn't look like the never type is going to be stabilized anytime soon, so lets just use the `never-say-never` crate instead.

Reviewed By: dtolnay

Differential Revision: D41459064

fbshipit-source-id: 6bc82377242b31171251b2393a534f76c7f3d97a
2022-11-29 12:40:44 -08:00
Jason White
8058dd4803 reverie-process: Fix remaining unnecessary usage of unsafe
Summary: Missed these in a previous diff.

Reviewed By: rrnewton

Differential Revision: D41567346

fbshipit-source-id: eba0b738a66da1823312803ed91fdc5eeaf90c57
2022-11-29 08:26:39 -08:00
Jason White
42a87f915e Add retries to early syscall injection
Summary: Our early injected syscalls could get interrupted by a signal (like `SIGWINCH`), so we should always be sure to retry them.

Reviewed By: rrnewton

Differential Revision: D41568242

fbshipit-source-id: e3026bd162619795e776198b7bf05d3e33753c05
2022-11-29 08:26:39 -08:00
Jason White
ab518fb892 Handle CPUID faulting failures gracefully
Summary: We inject a call to `arch_prctl(ARCH_SET_CPUID, 0)` to enable faulting on CPUID. This isn't supported on virtual machines, so we should gracefully handle any errors.

Reviewed By: rrnewton

Differential Revision: D41567919

fbshipit-source-id: 9623f2852d9b2e8cad0de447214c798c5b9dcb0b
2022-11-29 04:04:22 -08:00
Jason White
5478e47a25 Fix VDSO patching of small entries
Summary:
On Ubuntu 22.04, this is the disassembly of `gettimeofday` and `clock_gettime`:
```
0000000000000bd0 <__vdso_gettimeofday@LINUX_2.6>:
 bd0:   e9 4b fe ff ff          jmp    a20 <LINUX_2.6@LINUX_2.6+0xa20>
 bd5:   66 66 2e 0f 1f 84 00    data16 cs nopw 0x0(%rax,%rax,1)
 bdc:   00 00 00 00

0000000000000c10 <__vdso_clock_gettime@LINUX_2.6>:
 c10:   e9 9b fb ff ff          jmp    7b0 <LINUX_2.6@LINUX_2.6+0x7b0>
 c15:   66 66 2e 0f 1f 84 00    data16 cs nopw 0x0(%rax,%rax,1)
 c1c:   00 00 00 00
```

These implementations just `jmp` to another internal function. The dynamic symbol table reports that these functions are 5 bytes in size, but we can see that they are aligned up to 16 bytes and they are still safe to patch. Thus, our patcher should take this padding and alignment into account.

Fixes https://github.com/facebookexperimental/hermit/issues/16.

Differential Revision: D41565913

fbshipit-source-id: 164aca876abf92642e7ebf4ce96d0860b276647b
2022-11-28 16:28:02 -08:00
Jason White
fa44c91a66 Add script to dump the VDSO
Summary: Helper script for debugging https://github.com/facebookexperimental/hermit/issues/16.

Differential Revision: D41565407

fbshipit-source-id: 01cd3121dde671a563a8d2674cc42bfa6bce1226
2022-11-28 16:28:02 -08:00
Jason White
8909065ec3 Add build/test instructions to the README
Differential Revision: D41562403

fbshipit-source-id: 4478d4cfca9d487f03fdf3b60b2805bc65d4bca4
2022-11-28 16:28:02 -08:00
Jason White
5ff7f23e25 Remove file descriptor niche optimization
Summary: This size optimization relies on a nightly feature that will likely never be stabilized. All it did was make `Option<Fd>` equal to 4 bytes instead of 8 bytes.

Reviewed By: rrnewton

Differential Revision: D41506685

fbshipit-source-id: 15aa75b01200ff7f179373b07e14f542590aa24d
2022-11-28 12:21:33 -08:00
Jason White
c448d10586 Reduce size of getcpu vdso
Summary: The `getcpu` VDSO was just returning 0 unconditionally. This was an old hack to determinize the getcpu syscall, but we don't need this anymore because we just intercept it and determinize it instead. Reducing the size of this vdso function will make it more compatible with various VDSO implementations.

Reviewed By: wkhughes

Differential Revision: D41506684

fbshipit-source-id: 3dacad93971ecc7969d725f8b7e984a189a0ebb4
2022-11-23 13:55:56 -08:00
Jason White
debce82715 Remove unnecessary padding on vdso replacements
Summary: If the VDSO replacements are too large, they will overwrite too much memory if the real VDSO functions are smaller than the replacement. This fixes https://github.com/facebookexperimental/hermit/issues/16.

Reviewed By: wkhughes

Differential Revision: D41506686

fbshipit-source-id: 7c33e68ae9cccb440b820245e4d37184e156d03b
2022-11-23 13:55:56 -08:00
Ryan Johnson
6f03658469 Remove call to trace_start_init
Summary:
`trace_start_init` relies on the deprecated/removed symbol `initForTraceStart`,
and it's not critical, so this diff removes it.

Reviewed By: jasonwhite

Differential Revision: D41447262

fbshipit-source-id: a291b822d7e6c620f15182374d8923bc18ad2ec8
2022-11-21 17:16:10 -08:00
Jason White
2a73bdeb1c Move set_output_capture behind the nightly feature flag
Summary: `std::io::set_output_capture()` is only available in nightly. In order to publish this crate, we can't use unstable features.

Reviewed By: rrnewton

Differential Revision: D41394375

fbshipit-source-id: d4b6e9310cd6d6925aa9d7b0cd5c4558d6ef7d4c
2022-11-21 11:07:23 -08:00
Jason White
3a0494e2bc Remove need for never_type unstable feature
Summary: Refactors `do_exec` a little bit so that it no longer needs the `never_type` feature. This doesn't affect correctness at all.

Reviewed By: rrnewton

Differential Revision: D41394377

fbshipit-source-id: 30e8793557d12d9aef1c5641eb782b170f86512b
2022-11-21 11:07:23 -08:00
Jason White
5ca441ea60 Make rustc_attrs unstable feature optional
Summary: The usage of `rustc_attrs` is completely optional and only serves as a size optimization for the `Fd` type.

Reviewed By: rrnewton

Differential Revision: D41394376

fbshipit-source-id: 2f4898b872dc32c517df99e0b5f4a82fad5bda77
2022-11-21 11:07:23 -08:00
Jason White
100dd3ec3a Add "nightly" crate feature
Summary:
This adds the "nightly" crate feature to `reverie-process` so that it can use nightly features if they are enabled.

This *should* let it still get uploaded to crates.io, but some fancy optional nightly features will be hidden behind this feature flag. Then, we can still use these features internally.

Reviewed By: rrnewton

Differential Revision: D41394572

fbshipit-source-id: 6f5eaccd070f85c839089d3d5e5994471948afd4
2022-11-21 11:07:23 -08:00
Jason White
230d1421a2 Fix doc-test
Summary: The OSS CI build is currently failing because of this.

Reviewed By: rrnewton

Differential Revision: D41414284

fbshipit-source-id: ba9cb5b46f552e76d7a8ebd5ff94d949105339b6
2022-11-18 16:28:31 -08:00
Jason White
b9e3f0c0e7 Remove associated_type_defaults unstable feature
Summary: Removes the `associated_type_defaults` unstable feature. This brings us one step closer to removing all usage of unstable nightly features, which will allow publishing the crate on https://crates.io.

Reviewed By: rrnewton

Differential Revision: D41389496

fbshipit-source-id: f80d9dd960196ce4fb61c886796836a79e12962b
2022-11-18 12:36:51 -08:00
Jason White
9a942d055f Remove dependencies on associated_type_defaults unstable feature
Summary: Removes usage of the `associated_type_defaults` unstable feature, but does not actually disable the feature yet. This brings us one step closer to removing all usage of unstable nightly features, which will allow publishing a crate on https://crates.io.

Reviewed By: rrnewton

Differential Revision: D41388745

fbshipit-source-id: f347a577857a713fe3088a556cbf37ffe92e5553
2022-11-18 12:36:51 -08:00
Jason White
58bc1cce8b Remove unused bench_black_box unstable feature
Summary: Removes usage of the `bench_black_box` unstable feature. This brings us one step closer to removing all usage of unstable nightly features, which will allow publishing a crate on https://crates.io.

Reviewed By: rrnewton

Differential Revision: D41387686

fbshipit-source-id: 98bfcf053cd320137dbf62f4ef24beb835e1f0df
2022-11-18 12:36:51 -08:00
Jason White
0f5f62c1dd Remove need for map_first_last unstable feature
Summary: Removes usage of the `map_first_last` unstable feature. This brings us one step closer to removing all usage of unstable nightly features, which will allow publishing a crate on https://crates.io.

Reviewed By: rrnewton

Differential Revision: D41387687

fbshipit-source-id: 05184220a6d6cd5ec03339845741b46e9557ca83
2022-11-18 12:36:51 -08:00
Jason White
ee616643a4 Remove need for async_closure unstable feature
Summary: Removes usage of the `async_closure` unstable feature. This brings us one step closer to removing all usage of unstable nightly features, which will allow publishing a crate on https://crates.io.

Reviewed By: rrnewton

Differential Revision: D41387688

fbshipit-source-id: 136c5c8d19876e732d18dca195e87e3bc2ab7661
2022-11-18 12:36:51 -08:00
Jason White
b9bd4ec901 Fix broken backtraces
Summary:
This contains a couple of big fixes for stack traces:
 1. Fixes missing symbols for executables.
 2. Fixes missing file and line numbers for libraries that use the `gnu_debuglink` feature (where the actual debug information is in a separate file).

Reviewed By: wkhughes

Differential Revision: D41366208

fbshipit-source-id: dd9bb8099ecdab4668846acc67c3b56a04cc96cf
2022-11-17 08:52:33 -08:00
Jason White
97677924e9 third-party/rust: Upgrade addr2line and object crates
Summary: Updates `addr2line` and `object` to the latest versions.

Reviewed By: wkhughes

Differential Revision: D41327264

fbshipit-source-id: 90f600257b7176ee35b243cb7ab72afbc06762b5
2022-11-17 08:52:33 -08:00
generatedunixname89002005287564
c462336e3d Daily common/rust/cargo_from_buck/bin/autocargo
Reviewed By: krallin

Differential Revision: D41368646

fbshipit-source-id: 5f15114f141028c7dcd38c96cd853f29dfe91696
2022-11-17 00:26:13 -08:00
Vladimir Makaev
4820afb142 implement set_timer_precise(rbc, instr)
Summary: We want to allow precise timers with an instruction offset. While single stepping we have target and current value of the counter and once we match branches we only increment instructions

Reviewed By: jasonwhite

Differential Revision: D41269879

fbshipit-source-id: 46b3307249663de10607513dc59d8436ca907f78
2022-11-16 14:01:41 -08:00
Ryan Newton
d7e9901f53 use RunOpts more uniformly
Summary: These previous launch_* functions can be simplified by using RunOpts to contain all the relevant information about a run, plus everything needed to print a reproducer command.

Reviewed By: VladimirMakaev

Differential Revision: D41329114

fbshipit-source-id: 5bab08dfbf28e1cee7fd244178e03ba2cdc1ba34
2022-11-16 07:01:14 -08:00
generatedunixname89002005294178
81ca16a694 Update traceviz component on FBS:master
Differential Revision: D41332214

fbshipit-source-id: 3b6a7e09e124d11a9501c2aa03b0c3cbce39b89f
2022-11-15 23:30:37 -08:00
Jason White
69367b5408 Partially fix symbol resolution
Summary: `libunwind` isn't able to resolve symbols from the symbol table. There seems to be a regression preventing this from working. This partially fixes symbol lookup for stack frames by using the `object` crate for looking up symbols in the symbol table. This is a partial fix because symbol lookup does not seem to work yet for executables (only shared libraries).

Reviewed By: VladimirMakaev

Differential Revision: D41290099

fbshipit-source-id: 5d4ad1173f6ab1ca6c2995369c2dedb4a9f30e86
2022-11-15 09:58:51 -08:00
generatedunixname89002005294178
6bea3e3f73 Update traceviz component on FBS:master
Differential Revision: D41297952

fbshipit-source-id: 0deb4885917aa482cfa4a0cb790775c9a486b8cc
2022-11-14 23:25:53 -08:00
generatedunixname89002005294178
775308ee49 Update traceviz component on FBS:master
Differential Revision: D41259923

fbshipit-source-id: dbf84d6130a30547fb1579ddbd3f54cdb2bdab7f
2022-11-13 23:25:20 -08:00
Jason White
de3a571bb9 Fix dotslash paths
Summary: Fixes the paths after moving `reverie/fb-only/` to `reverie/experimental/`.

Reviewed By: VladimirMakaev

Differential Revision: D41240531

fbshipit-source-id: bba17fa598c2bb53f2765f9e6edddd59b7543048
2022-11-11 17:43:40 -08:00
Jason White
316b36650c Add ReadFamily
Summary: Adds `ReadFamily` to make it easier to handle all `read` syscall variants.

Reviewed By: igorsugak

Differential Revision: D41239542

fbshipit-source-id: 2c847e421b38281aa5243d8dfc00a8d1de0c075a
2022-11-11 16:52:21 -08:00
Jason White
df05ba9e83 Remove Addr::as_ref and AddrMut::as_ref
Summary: These operations are misleading and should never be called. Since the address could be a remote address, dereferencing it like this is wildly wrong. Not quite sure how they got there in the first place.

Reviewed By: igorsugak

Differential Revision: D41193389

fbshipit-source-id: 143c491df81125b319f7d5d88049021a81981795
2022-11-10 15:26:59 -08:00