Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.wasm32-unknown-unknown]
runner = "wasmtime run"
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git*
target/

*.lock
*.md
*.txt
.dockerignore
Dockerfile*
10 changes: 10 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM rustlang/rust:nightly

RUN rustup target add wasm32-unknown-unknown && \
cargo install wasmtime-cli

WORKDIR /app
COPY . .

RUN cargo test
RUN cargo test --target wasm32-unknown-unknown
9 changes: 9 additions & 0 deletions src/barriers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
#[inline(always)]
pub fn optimization_barrier_u8(mut value: u8) -> u8 {
unsafe {
#[cfg(not(target_arch = "wasm32"))]
std::arch::asm!(
// Rust requires us to use every register defined, so we use it inside of a comment.
"/* optimization_barrier_u8 {unused} */",
Expand All @@ -169,6 +170,14 @@ pub fn optimization_barrier_u8(mut value: u8) -> u8 {
// Since the assembly block is a no-op, we easily uphold all of these invariants.
options(pure, nomem, nostack, preserves_flags)
);

// WebAssembly only supports local class
#[cfg(target_arch = "wasm32")]
std::arch::asm!(
"/* optimization_barrier_u8 {unused} */",
unused = inout(local) value,
options(pure, nomem, nostack, preserves_flags)
);
}

value
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//! page](https://www.chosenplaintext.ca/open-source/rust-timing-shield/getting-started) for more
//! information.

#![cfg_attr(target_arch = "wasm32", feature(asm_experimental_arch))]
#[cfg(test)]
extern crate quickcheck;

Expand Down