Skip to content

Commit a492e35

Browse files
committed
fuzz all the things
1 parent a1dcec6 commit a492e35

File tree

10 files changed

+1167
-2
lines changed

10 files changed

+1167
-2
lines changed

.github/workflows/fuzz.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Smoke-Test Fuzz Targets
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
jobs:
10+
fuzz:
11+
runs-on: ${{ matrix.os }}
12+
13+
env:
14+
# The version of `cargo-fuzz` to install and use.
15+
CARGO_FUZZ_VERSION: 0.13.1
16+
17+
# The number of seconds to run the fuzz target. 300 seconds = 5 minutes.
18+
FUZZ_TIME: 300
19+
20+
# Use address sanitizer in the fuzzing.
21+
RUSTFLAGS: -Zsanitizer=address
22+
23+
strategy:
24+
matrix:
25+
os: ["ubuntu-24.04-arm", "ubuntu-latest"]
26+
include:
27+
- fuzz_target: ecmascript_atomics_api
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
# Install the nightly Rust channel.
33+
- run: rustup toolchain install nightly
34+
- run: rustup default nightly
35+
36+
# Install and cache `cargo-fuzz`.
37+
- uses: actions/cache@v4
38+
with:
39+
path: ${{ runner.tool_cache }}/cargo-fuzz
40+
key: cargo-fuzz-bin-${{ env.CARGO_FUZZ_VERSION }}
41+
- run: echo "${{ runner.tool_cache }}/cargo-fuzz/bin" >> $GITHUB_PATH
42+
- run: cargo install --root "${{ runner.tool_cache }}/cargo-fuzz" --version ${{ env.CARGO_FUZZ_VERSION }} cargo-fuzz --locked
43+
44+
# Build and then run the fuzz target.
45+
- run: cargo fuzz build ${{ matrix.fuzz_target }}
46+
- run: cargo fuzz run ${{ matrix.fuzz_target }} -- -max_total_time=${{ env.FUZZ_TIME }}
47+
48+
# Upload fuzzing artifacts on failure for post-mortem debugging.
49+
- uses: actions/upload-artifact@v4
50+
if: failure()
51+
with:
52+
name: fuzzing-artifacts-${{ matrix.fuzz_target }}-${{ github.sha }}
53+
path: fuzz/artifacts

Cargo.lock

Lines changed: 189 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = ["ecmascript_atomics", "gen_copy"]
3+
members = ["ecmascript_atomics", "fuzz", "gen_copy"]
44

55
[workspace.package]
66
edition = "2024"

ecmascript_atomics/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
[package]
22
name = "ecmascript_atomics"
3-
repository = "https://github.com/trynova/nova/tree/main/ecmascript_atomics"
3+
repository = "https://github.com/trynova/ecmascript_atomics/tree/main/ecmascript_atomics"
44
description = "ECMAScript and Java memory model racy atomics."
55
version.workspace = true
66
authors.workspace = true
77
edition.workspace = true
88
license.workspace = true
9+
readme.workspace = true
10+
keywords.workspace = true
11+
categories.workspace = true
912

1013
[lib]
1114
path = "lib.rs"

ecmascript_atomics/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,14 @@ pub fn atomic_pause() {
16811681
core::hint::spin_loop();
16821682
}
16831683

1684+
/// Size of a word (pointer) on this architecture.
1685+
pub const WORD_SIZE: usize = size_of::<usize>();
1686+
/// Number of words in a block (~cache line) on this architecture. Known to be
1687+
/// 8 on all supported architectures.
1688+
pub const WORDS_IN_BLOCK: usize = 8;
1689+
/// Size of a block (~cache line) on this architecture in bytes.
1690+
pub const BLOCK_SIZE: usize = WORD_SIZE * WORDS_IN_BLOCK;
1691+
16841692
#[inline(always)]
16851693
#[cfg(any(
16861694
target_arch = "x86",

fuzz/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
corpus
3+
artifacts
4+
coverage

fuzz/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "ecmascript_atomics_fuzz"
3+
version = "0.0.0"
4+
publish = false
5+
edition = "2024"
6+
7+
[package.metadata]
8+
cargo-fuzz = true
9+
10+
[dependencies]
11+
arbitrary = { version = "1.0", features = ["derive"] }
12+
ecmascript_atomics = { path = "../ecmascript_atomics" }
13+
libfuzzer-sys = "0.4"
14+
memmap2 = "0.9.8"
15+
proc-macro2 = "1.0"
16+
quote = "1.0"
17+
syn = { version = "2.0", features = ["full"] }
18+
19+
[[bin]]
20+
name = "ecmascript_atomics_api"
21+
path = "fuzz_targets/ecmascript_atomics_api.rs"
22+
test = false
23+
doc = false
24+
bench = false

0 commit comments

Comments
 (0)