Skip to content

Commit d498715

Browse files
authored
threads: fuzz shared-everything-threads (bytecodealliance#1756)
* threads: fuzz `shared-everything-threads` This adds initial support for fuzzing the WebAssembly side of the shared-everything-threads [proposal]. Eventual addition of the CM builtins will require extensions to this. [proposal]: https://github.com/WebAssembly/shared-everything-threads * Propagate shared function type into the code builder * Avoid shared function bodies for now Since it may take a while to implement all the "reverse validation" in wasm-smith's instruction generator, this effectively cordons off that bit of the fuzzer so that we can at least generate shared types in modules. Later, once the instruction generator is smarter, we will remove this filter and start generating shared function bodies. * Avoid shared const expressions for now Like shared function bodies, this can be cordoned off until later. * Allow `CodeBuilder::shared` to be unused for now * Check sharedness in `arbitrary_super_type_of_heap_type` * Actually filter `ref.func` const expressions In 2a2ddd5, I tried to avoid `ref.func` expressions entirely for shared types but unfortunately the other side could still occur: a `ref.func` on an unshared table that generates a shared funcref. This filters out the available types to match sharedness. * review: move feature-flipping to `Config::sanitize` * review: fuzz shared-everything at the same ratio as threads * fix: disable shared-everything if reference types is disabled * fix: disable shared-everything entirely for mutate fuzz target * review: invisibly propagate sharedness As @alexcrichton suggested, this holds a `must_share` flag on `Module` and carefully sets it and unsets it using `propagate_shared`. * fix: formatting * review: revert `arbitrary_ref_type` changes * review: add TODO to remove extra check * review: use `arbitrary_shared` more
1 parent 0c61dce commit d498715

File tree

6 files changed

+272
-111
lines changed

6 files changed

+272
-111
lines changed

crates/wasm-encoder/src/core/types.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ impl RefType {
293293
},
294294
};
295295

296+
/// Create a new abstract reference type.
297+
pub fn new_abstract(ty: AbstractHeapType, nullable: bool, shared: bool) -> Self {
298+
Self {
299+
nullable,
300+
heap_type: HeapType::Abstract { shared, ty },
301+
}
302+
}
303+
296304
/// Set the nullability of this reference type.
297305
pub fn nullable(mut self, nullable: bool) -> Self {
298306
self.nullable = nullable;

crates/wasm-smith/src/config.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,17 +551,30 @@ define_config! {
551551
/// Defaults to `true`.
552552
pub relaxed_simd_enabled: bool = true,
553553

554-
/// Determines whether the nontrapping-float-to-int-conversions propsal
555-
/// is enabled.
554+
/// Determines whether the non-trapping float-to-int conversions
555+
/// proposal is enabled.
556556
///
557557
/// Defaults to `true`.
558558
pub saturating_float_to_int_enabled: bool = true,
559559

560-
/// Determines whether the sign-extension-ops propsal is enabled.
560+
/// Determines whether the sign-extension-ops proposal is enabled.
561561
///
562562
/// Defaults to `true`.
563563
pub sign_extension_ops_enabled: bool = true,
564564

565+
/// Determines whether the shared-everything-threads proposal is
566+
/// enabled.
567+
///
568+
/// The [shared-everything-threads] proposal, among other things,
569+
/// extends `shared` attributes to all WebAssembly objects; it builds on
570+
/// the [threads] proposal.
571+
///
572+
/// [shared-everything-threads]: https://github.com/WebAssembly/shared-everything-threads
573+
/// [threads]: https://github.com/WebAssembly/threads
574+
///
575+
/// Defaults to `false`.
576+
pub shared_everything_threads_enabled: bool = false,
577+
565578
/// Determines whether the SIMD proposal is enabled for generating
566579
/// instructions.
567580
///
@@ -754,6 +767,7 @@ impl<'a> Arbitrary<'a> for Config {
754767
memory64_enabled: false,
755768
custom_page_sizes_enabled: false,
756769
wide_arithmetic_enabled: false,
770+
shared_everything_threads_enabled: false,
757771
};
758772
config.sanitize();
759773
Ok(config)
@@ -779,13 +793,20 @@ impl Config {
779793
if !self.reference_types_enabled {
780794
self.max_tables = self.max_tables.min(1);
781795
self.gc_enabled = false;
796+
self.shared_everything_threads_enabled = false;
782797
}
783798

784799
// If simd is disabled then disable all relaxed simd instructions as
785800
// well.
786801
if !self.simd_enabled {
787802
self.relaxed_simd_enabled = false;
788803
}
804+
805+
// It is impossible to use the shared-everything-threads proposal
806+
// without threads, which it is built on.
807+
if !self.threads_enabled {
808+
self.shared_everything_threads_enabled = false;
809+
}
789810
}
790811

791812
/// Returns the set of features that are necessary for validating against
@@ -821,6 +842,10 @@ impl Config {
821842
features.set(WasmFeatures::FUNCTION_REFERENCES, self.gc_enabled);
822843
features.set(WasmFeatures::GC, self.gc_enabled);
823844
features.set(WasmFeatures::THREADS, self.threads_enabled);
845+
features.set(
846+
WasmFeatures::SHARED_EVERYTHING_THREADS,
847+
self.shared_everything_threads_enabled,
848+
);
824849
features.set(
825850
WasmFeatures::CUSTOM_PAGE_SIZES,
826851
self.custom_page_sizes_enabled,

0 commit comments

Comments
 (0)