Skip to content

Commit

Permalink
Add ptr auth feature
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-fink committed Apr 30, 2024
1 parent c840e6e commit 6dd417f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/wasm-shrink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ impl ShrinkRun {
floats: true,
memory_control: true,
mem_safety: true,
ptr_auth: true,
});

validator.validate_all(wasm)?;
Expand Down
16 changes: 13 additions & 3 deletions crates/wasm-smith/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,18 @@ pub trait Config: 'static + std::fmt::Debug {

/// Determines whether the mem_safety proposal is enabled.
///
/// The [mem_safety proposal] involves shared linear memory, new atomic
/// instructions, and new `wait` and `notify` instructions.
///
/// Defaults to `false`.
fn mem_safety_enabled(&self) -> bool {
false
}

/// Determines whether the ptr_auth proposal is enabled.
///
/// Defaults to `false`.
fn ptr_auth_enabled(&self) -> bool {
false
}

/// Returns whether we should avoid generating code that will possibly trap.
///
/// For some trapping instructions, this will emit extra instructions to
Expand Down Expand Up @@ -560,6 +564,7 @@ pub struct SwarmConfig {
pub simd_enabled: bool,
pub threads_enabled: bool,
pub mem_safety_enabled: bool,
pub ptr_auth_enabled: bool,
pub allowed_instructions: InstructionKinds,
pub max_table_elements: u32,
pub table_max_size_required: bool,
Expand Down Expand Up @@ -637,6 +642,7 @@ impl<'a> Arbitrary<'a> for SwarmConfig {
available_imports: None,
threads_enabled: false,
mem_safety_enabled: false,
ptr_auth_enabled: false,
export_everything: false,
disallow_traps: false,
tail_call_enabled: false,
Expand Down Expand Up @@ -835,6 +841,10 @@ impl Config for SwarmConfig {
self.mem_safety_enabled
}

fn ptr_auth_enabled(&self) -> bool {
self.ptr_auth_enabled
}

fn allowed_instructions(&self) -> InstructionKinds {
self.allowed_instructions
}
Expand Down
6 changes: 3 additions & 3 deletions crates/wasmparser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,9 @@ macro_rules! for_each_operator {
@mem_safety SegmentNew { memarg: $crate::MemArg } => visit_segment_new
@mem_safety SegmentSetTag { memarg: $crate::MemArg } => visit_segment_set_tag
@mem_safety SegmentFree { memarg: $crate::MemArg } => visit_segment_free
@mem_safety PointerSign => visit_pointer_sign
@mem_safety PointerAuth => visit_pointer_auth
@mem_safety PointerStrip => visit_pointer_strip
@ptr_auth PointerSign => visit_pointer_sign
@ptr_auth PointerAuth => visit_pointer_auth
@ptr_auth PointerStrip => visit_pointer_strip
}
};
}
Expand Down
4 changes: 4 additions & 0 deletions crates/wasmparser/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ pub struct WasmFeatures {
pub component_model_values: bool,
/// The WebAssembly memory safety proposal
pub mem_safety: bool,
/// The WebAssembly ptr auth proposal
pub ptr_auth: bool,
}

impl WasmFeatures {
Expand Down Expand Up @@ -278,6 +280,7 @@ impl WasmFeatures {
gc: true,
component_model_values: true,
mem_safety: true,
ptr_auth: true,
}
}

Expand Down Expand Up @@ -366,6 +369,7 @@ impl Default for WasmFeatures {
gc: false,
component_model_values: false,
mem_safety: false,
ptr_auth: false,

// On-by-default features (phase 4 or greater).
mutable_global: true,
Expand Down
1 change: 1 addition & 0 deletions crates/wasmparser/src/validator/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ macro_rules! validate_proposal {
(desc memory_control) => ("memory control");
(desc gc) => ("gc");
(desc mem_safety) => ("memory safety");
(desc ptr_auth) => ("pointer authentication");
}

impl<'a, T> VisitOperator<'a> for WasmProposalValidator<'_, '_, T>
Expand Down
4 changes: 4 additions & 0 deletions src/bin/wasm-tools/smith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ struct Config {
#[clap(long = "mem-safety")]
#[serde(rename = "mem-safety")]
mem_safety_enabled: Option<bool>,
#[clap(long = "ptr-auth")]
#[serde(rename = "ptr-auth")]
ptr_auth_enabled: Option<bool>,
}

impl Opts {
Expand Down Expand Up @@ -322,6 +325,7 @@ impl wasm_smith::Config for CliAndJsonConfig {
(generate_custom_sections, bool, false),
(threads_enabled, bool, false),
(mem_safety_enabled, bool, false),
(ptr_auth_enabled, bool, false),
}

fn max_memory_pages(&self, _is_64: bool) -> u64 {
Expand Down
1 change: 1 addition & 0 deletions src/bin/wasm-tools/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ fn parse_features(arg: &str) -> Result<WasmFeatures> {
("relaxed-simd", |f| &mut f.relaxed_simd),
("gc", |f| &mut f.gc),
("mem-safety", |f| &mut f.mem_safety),
("ptr-auth", |f| &mut f.ptr_auth),
];

for part in arg.split(',').map(|s| s.trim()).filter(|s| !s.is_empty()) {
Expand Down

0 comments on commit 6dd417f

Please sign in to comment.