From a980e9cd4f5647dec22360da961a1a0efbbb72ff Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Mon, 25 Sep 2023 20:43:38 +0000 Subject: [PATCH] Bug 1853840 - Move sandboxed soundtouch out of libxul and reenable sandbox. r=firefox-build-system-reviewers,shravanrn,media-playback-reviewers,padenot,ahochheiden Differential Revision: https://phabricator.services.mozilla.com/D188648 --- .../rlbox_wasm2c_thread_locals.cpp | 8 +- config/recurse.mk | 7 +- dom/media/mediasink/moz.build | 2 +- dom/media/moz.build | 5 +- media/libsoundtouch/moz-libsoundtouch.patch | 24 +---- media/libsoundtouch/moz.yaml | 2 +- .../libsoundtouch/src}/RLBoxSoundTouch.cpp | 0 .../libsoundtouch/src}/RLBoxSoundTouch.h | 29 ++++- .../src/RLBoxSoundTouchFactory.h | 12 --- .../libsoundtouch/src}/RLBoxSoundTouchTypes.h | 0 media/libsoundtouch/src/STTypes.h | 10 -- media/libsoundtouch/src/SoundTouch.h | 2 +- media/libsoundtouch/src/SoundTouchFactory.cpp | 2 - media/libsoundtouch/src/SoundTouchFactory.h | 2 - media/libsoundtouch/src/moz.build | 100 ++++++++++++++---- media/libsoundtouch/src/sources.mozbuild | 26 ----- security/rlbox/moz.build | 74 +------------ security/rlbox/rlbox.mozbuild | 56 ++++++++++ toolkit/moz.configure | 2 +- 19 files changed, 186 insertions(+), 177 deletions(-) rename {dom/media => media/libsoundtouch/src}/RLBoxSoundTouch.cpp (100%) rename {dom/media => media/libsoundtouch/src}/RLBoxSoundTouch.h (74%) rename {dom/media => media/libsoundtouch/src}/RLBoxSoundTouchTypes.h (100%) delete mode 100644 media/libsoundtouch/src/sources.mozbuild create mode 100644 security/rlbox/rlbox.mozbuild diff --git a/config/external/rlbox_wasm2c_sandbox/rlbox_wasm2c_thread_locals.cpp b/config/external/rlbox_wasm2c_sandbox/rlbox_wasm2c_thread_locals.cpp index f37a86840652..0fadb5af40c5 100644 --- a/config/external/rlbox_wasm2c_sandbox/rlbox_wasm2c_thread_locals.cpp +++ b/config/external/rlbox_wasm2c_sandbox/rlbox_wasm2c_thread_locals.cpp @@ -15,7 +15,9 @@ # include "mozilla/rlbox/rlbox_wasm2c_tls.hpp" # include "wasm-rt.h" -# include "nsExceptionHandler.h" +# ifndef WASM_RT_GROW_FAILED_CRASH +# include "nsExceptionHandler.h" +# endif // The MingW compiler does not correctly handle static thread_local inline // members. We instead TLS storage via functions. This can be removed if the @@ -33,8 +35,12 @@ void moz_wasm2c_trap_handler(wasm_rt_trap_t code) { // The below function is called if a malloc in sandboxed code returns null // This indicates that the sandbox has run out of memory. void moz_wasm2c_memgrow_failed() { +# ifdef WASM_RT_GROW_FAILED_CRASH + MOZ_CRASH("wasm2c memory grow failed"); +# else CrashReporter::AnnotateCrashReport( CrashReporter::Annotation::WasmLibrarySandboxMallocFailed, true); +# endif } // This function is called when mozalloc_handle_oom is called from within diff --git a/config/recurse.mk b/config/recurse.mk index 01f577303061..f3a8759303fd 100644 --- a/config/recurse.mk +++ b/config/recurse.mk @@ -179,7 +179,7 @@ endif ifdef ENABLE_CLANG_PLUGIN # Only target rules use the clang plugin. -$(filter %/target %/target-objects,$(filter-out config/export config/host build/unix/stdc++compat/% build/clang-plugin/%,$(compile_targets))) security/rlbox/pre-compile: build/clang-plugin/host build/clang-plugin/tests/target-objects +$(filter %/target %/target-objects,$(filter-out config/export config/host build/unix/stdc++compat/% build/clang-plugin/%,$(compile_targets))) security/rlbox/pre-compile media/libsoundtouch/src/pre-compile: build/clang-plugin/host build/clang-plugin/tests/target-objects build/clang-plugin/tests/target-objects: build/clang-plugin/host # clang-plugin tests require js-confdefs.h on js standalone builds and mozilla-config.h on # other builds, because they are -include'd. @@ -216,8 +216,9 @@ $(filter %/target,$(compile_targets)): build/unix/elfhack/host build/unix/elfhac endif ifdef MOZ_USING_WASM_SANDBOXING -security/rlbox/pre-compile: config/external/wasm2c_sandbox_compiler/host -dom/media/ogg/target-objects extensions/spellcheck/hunspell/glue/target-objects gfx/thebes/target-objects parser/expat/target-objects parser/htmlparser/target-objects gfx/ots/src/target-objects dom/media/target-objects dom/media/mediasink/target-objects: security/rlbox/pre-compile +security/rlbox/pre-compile media/libsoundtouch/src/pre-compile: config/external/wasm2c_sandbox_compiler/host +dom/media/ogg/target-objects extensions/spellcheck/hunspell/glue/target-objects gfx/thebes/target-objects parser/expat/target-objects parser/htmlparser/target-objects gfx/ots/src/target-objects: security/rlbox/pre-compile +dom/media/target-objects dom/media/mediasink/target-objects: media/libsoundtouch/src/pre-compile endif # Most things are built during compile (target/host), but some things happen during export diff --git a/dom/media/mediasink/moz.build b/dom/media/mediasink/moz.build index 0dfa35357b90..e04bf24a25c5 100644 --- a/dom/media/mediasink/moz.build +++ b/dom/media/mediasink/moz.build @@ -17,7 +17,7 @@ EXPORTS += [ ] LOCAL_INCLUDES += [ - "!/security/rlbox", + "!/media/libsoundtouch/src", "/dom/media", ] diff --git a/dom/media/moz.build b/dom/media/moz.build index 7e24dc607b86..afa2f94bdccd 100644 --- a/dom/media/moz.build +++ b/dom/media/moz.build @@ -195,8 +195,6 @@ EXPORTS += [ "PrincipalHandle.h", "QueueObject.h", "ReaderProxy.h", - "RLBoxSoundTouch.h", - "RLBoxSoundTouchTypes.h", "SeekJob.h", "SeekTarget.h", "SelfRef.h", @@ -310,7 +308,6 @@ UNIFIED_SOURCES += [ "MemoryBlockCache.cpp", "QueueObject.cpp", "ReaderProxy.cpp", - "RLBoxSoundTouch.cpp", "SeekJob.cpp", "TimeUnits.cpp", "Tracing.cpp", @@ -358,7 +355,7 @@ EXTRA_JS_MODULES.media += [ ] LOCAL_INCLUDES += [ - "!/security/rlbox", + "!/media/libsoundtouch/src", "/caps", "/docshell/base", "/dom/base", diff --git a/media/libsoundtouch/moz-libsoundtouch.patch b/media/libsoundtouch/moz-libsoundtouch.patch index 02e8bd0d93db..d5607caed45d 100644 --- a/media/libsoundtouch/moz-libsoundtouch.patch +++ b/media/libsoundtouch/moz-libsoundtouch.patch @@ -76,7 +76,7 @@ diff -u /src/cpu_detect_x86.cpp /src/cpu_detect_x86.cpp diff -u /src/STTypes.h /src/STTypes.h --- /src/STTypes.h +++ /src/STTypes.h -@@ -54,12 +54,17 @@ +@@ -54,11 +54,7 @@ #define SOUNDTOUCH_ALIGN_POINTER_16(x) ( ( (ulongptr)(x) + 15 ) & ~(ulongptr)15 ) @@ -87,30 +87,8 @@ diff -u /src/STTypes.h /src/STTypes.h -#endif +#include "soundtouch_config.h" -+#if defined(WIN32) -+#if defined(BUILDING_SOUNDTOUCH) -+#define SOUNDTOUCH_API __declspec(dllexport) -+#else -+#define SOUNDTOUCH_API __declspec(dllimport) -+#endif -+#else -+#define SOUNDTOUCH_API -+#endif - namespace soundtouch { -diff -u /src/SoundTouch.h /src/SoundTouch.h ---- /src/SoundTouch.h -+++ /src/SoundTouch.h -@@ -141,7 +141,7 @@ - /// tempo/pitch/rate/samplerate settings. - #define SETTING_NOMINAL_OUTPUT_SEQUENCE 7 - --class SoundTouch : public FIFOProcessor -+class SOUNDTOUCH_API SoundTouch : public FIFOProcessor - { - private: - /// Rate transposer class instance diff -u /src/FIRFilter.cpp /src/FIRFilter.cpp --- /src/FIRFilter.cpp +++ /src/FIRFilter.cpp diff --git a/media/libsoundtouch/moz.yaml b/media/libsoundtouch/moz.yaml index be9751f22155..3bec78d270fd 100644 --- a/media/libsoundtouch/moz.yaml +++ b/media/libsoundtouch/moz.yaml @@ -69,7 +69,7 @@ vendoring: keep: - AUTHORS - clear-lf.sh - - src/RLBoxSoundTouchFactory.* + - src/RLBoxSoundTouch* - src/SoundTouchFactory.* - src/soundtouch_config.h - src/soundtouch_perms.h diff --git a/dom/media/RLBoxSoundTouch.cpp b/media/libsoundtouch/src/RLBoxSoundTouch.cpp similarity index 100% rename from dom/media/RLBoxSoundTouch.cpp rename to media/libsoundtouch/src/RLBoxSoundTouch.cpp diff --git a/dom/media/RLBoxSoundTouch.h b/media/libsoundtouch/src/RLBoxSoundTouch.h similarity index 74% rename from dom/media/RLBoxSoundTouch.h rename to media/libsoundtouch/src/RLBoxSoundTouch.h index 81406bccc545..7bee70b2eaea 100644 --- a/dom/media/RLBoxSoundTouch.h +++ b/media/libsoundtouch/src/RLBoxSoundTouch.h @@ -10,11 +10,13 @@ // Load general firefox configuration of RLBox #include "mozilla/rlbox/rlbox_config.h" +#undef RLBOX_WASM2C_MODULE_NAME +#define RLBOX_WASM2C_MODULE_NAME soundtouch #ifdef MOZ_WASM_SANDBOXING_SOUNDTOUCH // Include the generated header file so that we are able to resolve the symbols // in the wasm binary -# include "rlbox.wasm.h" +# include "soundtouch.wasm.h" # define RLBOX_USE_STATIC_CALLS() rlbox_wasm2c_sandbox_lookup_symbol # include "mozilla/rlbox/rlbox_wasm2c_sandbox.hpp" #else @@ -29,24 +31,48 @@ #define ST_NO_EXCEPTION_HANDLING 1 #include "soundtouch/SoundTouchFactory.h" +#if defined(WIN32) +#if defined(BUILDING_SOUNDTOUCH) +#define RLBOX_SOUNDTOUCH_API __declspec(dllexport) +#else +#define RLBOX_SOUNDTOUCH_API __declspec(dllimport) +#endif +#else +#define RLBOX_SOUNDTOUCH_API __attribute__((visibility("default"))) +#endif + namespace mozilla { class RLBoxSoundTouch { public: + RLBOX_SOUNDTOUCH_API RLBoxSoundTouch(); + RLBOX_SOUNDTOUCH_API ~RLBoxSoundTouch(); + RLBOX_SOUNDTOUCH_API void setSampleRate(uint aRate); + RLBOX_SOUNDTOUCH_API void setChannels(uint aChannels); + RLBOX_SOUNDTOUCH_API void setPitch(double aPitch); + RLBOX_SOUNDTOUCH_API void setSetting(int aSettingId, int aValue); + RLBOX_SOUNDTOUCH_API void setTempo(double aTempo); + RLBOX_SOUNDTOUCH_API uint numChannels(); + RLBOX_SOUNDTOUCH_API tainted_soundtouch numSamples(); + RLBOX_SOUNDTOUCH_API tainted_soundtouch numUnprocessedSamples(); + RLBOX_SOUNDTOUCH_API void setRate(double aRate); + RLBOX_SOUNDTOUCH_API void putSamples(const mozilla::AudioDataValue* aSamples, uint aNumSamples); + RLBOX_SOUNDTOUCH_API uint receiveSamples(mozilla::AudioDataValue* aOutput, uint aMaxSamples); + RLBOX_SOUNDTOUCH_API void flush(); private: @@ -56,6 +82,7 @@ class RLBoxSoundTouch { uint mSampleBufferSize{1}; tainted_soundtouch mTimeStretcher{nullptr}; + RLBOX_SOUNDTOUCH_API void resizeSampleBuffer(uint aNewSize); }; diff --git a/media/libsoundtouch/src/RLBoxSoundTouchFactory.h b/media/libsoundtouch/src/RLBoxSoundTouchFactory.h index 38dc186d6e07..5a19ef2fd8c4 100644 --- a/media/libsoundtouch/src/RLBoxSoundTouchFactory.h +++ b/media/libsoundtouch/src/RLBoxSoundTouchFactory.h @@ -10,31 +10,19 @@ extern "C" { -SOUNDTOUCH_API void SetSampleRate(soundtouch::SoundTouch* mTimeStretcher, uint srate); -SOUNDTOUCH_API void SetChannels(soundtouch::SoundTouch* mTimeStretcher, uint numChannels); -SOUNDTOUCH_API void SetPitch(soundtouch::SoundTouch* mTimeStretcher, double newPitch); -SOUNDTOUCH_API void SetSetting(soundtouch::SoundTouch* mTimeStretcher, int settingId, int value); -SOUNDTOUCH_API void SetTempo(soundtouch::SoundTouch* mTimeStretcher, double newTempo); -SOUNDTOUCH_API void SetRate(soundtouch::SoundTouch* mTimeStretcher, double newRate); -SOUNDTOUCH_API uint NumChannels(soundtouch::SoundTouch* mTimeStretcher); -SOUNDTOUCH_API uint NumSamples(soundtouch::SoundTouch* mTimeStretcher); -SOUNDTOUCH_API uint NumUnprocessedSamples(soundtouch::SoundTouch* mTimeStretcher); -SOUNDTOUCH_API void PutSamples(soundtouch::SoundTouch* mTimeStretcher, const soundtouch::SAMPLETYPE* samples, uint numSamples); -SOUNDTOUCH_API uint ReceiveSamples(soundtouch::SoundTouch* mTimeStretcher, soundtouch::SAMPLETYPE* output, uint maxSamples); -SOUNDTOUCH_API void Flush(soundtouch::SoundTouch* mTimeStretcher); } diff --git a/dom/media/RLBoxSoundTouchTypes.h b/media/libsoundtouch/src/RLBoxSoundTouchTypes.h similarity index 100% rename from dom/media/RLBoxSoundTouchTypes.h rename to media/libsoundtouch/src/RLBoxSoundTouchTypes.h diff --git a/media/libsoundtouch/src/STTypes.h b/media/libsoundtouch/src/STTypes.h index d80bc2899ef2..a70743dfe438 100644 --- a/media/libsoundtouch/src/STTypes.h +++ b/media/libsoundtouch/src/STTypes.h @@ -49,16 +49,6 @@ typedef unsigned long ulong; #include "soundtouch_config.h" -#if defined(WIN32) -#if defined(BUILDING_SOUNDTOUCH) -#define SOUNDTOUCH_API __declspec(dllexport) -#else -#define SOUNDTOUCH_API __declspec(dllimport) -#endif -#else -#define SOUNDTOUCH_API -#endif - namespace soundtouch { /// Max allowed number of channels diff --git a/media/libsoundtouch/src/SoundTouch.h b/media/libsoundtouch/src/SoundTouch.h index 19c161fed533..b68aba4d4456 100644 --- a/media/libsoundtouch/src/SoundTouch.h +++ b/media/libsoundtouch/src/SoundTouch.h @@ -165,7 +165,7 @@ namespace soundtouch #define SETTING_INITIAL_LATENCY 8 -class SOUNDTOUCH_API SoundTouch : public FIFOProcessor +class SoundTouch : public FIFOProcessor { private: /// Rate transposer class instance diff --git a/media/libsoundtouch/src/SoundTouchFactory.cpp b/media/libsoundtouch/src/SoundTouchFactory.cpp index 7c2831c43b65..1da3b88f36a6 100644 --- a/media/libsoundtouch/src/SoundTouchFactory.cpp +++ b/media/libsoundtouch/src/SoundTouchFactory.cpp @@ -9,14 +9,12 @@ extern "C" namespace soundtouch { -SOUNDTOUCH_API soundtouch::SoundTouch* createSoundTouchObj() { return new soundtouch::SoundTouch(); } -SOUNDTOUCH_API void destroySoundTouchObj(soundtouch::SoundTouch* aObj) { diff --git a/media/libsoundtouch/src/SoundTouchFactory.h b/media/libsoundtouch/src/SoundTouchFactory.h index fdeaafbaa423..2c6cea5b3ac1 100644 --- a/media/libsoundtouch/src/SoundTouchFactory.h +++ b/media/libsoundtouch/src/SoundTouchFactory.h @@ -13,11 +13,9 @@ extern "C" namespace soundtouch { -SOUNDTOUCH_API soundtouch::SoundTouch* createSoundTouchObj(); -SOUNDTOUCH_API void destroySoundTouchObj(soundtouch::SoundTouch* aObj); } diff --git a/media/libsoundtouch/src/moz.build b/media/libsoundtouch/src/moz.build index 828171b46745..979189ab97f8 100644 --- a/media/libsoundtouch/src/moz.build +++ b/media/libsoundtouch/src/moz.build @@ -4,7 +4,10 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -include("sources.mozbuild") +EXPORTS += [ + "RLBoxSoundTouch.h", + "RLBoxSoundTouchTypes.h", +] EXPORTS.soundtouch += [ 'FIFOSamplePipe.h', @@ -15,28 +18,89 @@ EXPORTS.soundtouch += [ 'STTypes.h', ] -UNIFIED_SOURCES += soundtouch_sources - LOCAL_INCLUDES += ["!/security/rlbox"] -if CONFIG['INTEL_ARCHITECTURE']: - if CONFIG['MOZ_SAMPLE_TYPE_FLOAT32']: - SOURCES += ['sse_optimized.cpp'] - SOURCES['sse_optimized.cpp'].flags += CONFIG['SSE2_FLAGS'] - else: - SOURCES += ['mmx_optimized.cpp'] - SOURCES['mmx_optimized.cpp'].flags += CONFIG['MMX_FLAGS'] +LOCAL_INCLUDES += [ + "/third_party/simde/", + "/third_party/wasm2c/wasm2c/", +] + +SOURCES += ["RLBoxSoundTouch.cpp"] +# Some xpcom things are #included indirectly (but not actually used), and +# it's simpler to set MOZILLA_INTERNAL_API to make it compile than to +# disentangle the whole thing. +SOURCES["RLBoxSoundTouch.cpp"].flags += ["-DMOZILLA_INTERNAL_API"] + +if CONFIG["MOZ_WASM_SANDBOXING_SOUNDTOUCH"]: + include("/security/rlbox/rlbox.mozbuild") + + RLBoxLibrary("soundtouch") + + DEFINES["WASM_RT_GROW_FAILED_CRASH"] = True + + SOURCES += [ + "/config/external/rlbox_wasm2c_sandbox/rlbox_wasm2c_thread_locals.cpp", + "/third_party/rlbox_wasm2c_sandbox/src/wasm2c_rt_mem.c", + "/third_party/rlbox_wasm2c_sandbox/src/wasm2c_rt_minwasi.c", + ] + if CONFIG['OS_ARCH'] != 'WINNT': + OS_LIBS += ["m"] + + if CONFIG["MOZ_SAMPLE_TYPE_FLOAT32"]: + WASM_DEFINES["MOZ_SAMPLE_TYPE_FLOAT32"] = 1 + + WASM_SOURCES += ['sse_optimized.cpp'] + + WASM_DEFINES["SOUNDTOUCH_ALLOW_SSE"] = 1 + WASM_DEFINES["SOUNDTOUCH_WASM_SIMD"] = 1 + WASM_DEFINES["SIMDE_ENABLE_NATIVE_ALIASES"] = 1 + + soundtouch_sources = WASM_SOURCES + soundtouch_defines = WASM_DEFINES -if CONFIG['OS_ARCH'] != 'WINNT': - # GCC/Clang require permissions to be explicitly set for the soundtouch - # header. - CXXFLAGS += ['-include', SRCDIR + '/soundtouch_perms.h'] else: - # Windows need alloca renamed to _alloca - DEFINES['alloca'] = '_alloca' + SOURCES += ["/config/external/rlbox/rlbox_thread_locals.cpp"] + if CONFIG['INTEL_ARCHITECTURE']: + if CONFIG['MOZ_SAMPLE_TYPE_FLOAT32']: + SOURCES += ['sse_optimized.cpp'] + SOURCES['sse_optimized.cpp'].flags += CONFIG['SSE2_FLAGS'] + else: + SOURCES += ['mmx_optimized.cpp'] + SOURCES['mmx_optimized.cpp'].flags += CONFIG['MMX_FLAGS'] + + if CONFIG['OS_ARCH'] != 'WINNT': + # GCC/Clang require permissions to be explicitly set for the soundtouch + # header. + CXXFLAGS += ['-include', SRCDIR + '/soundtouch_perms.h'] + else: + # Windows need alloca renamed to _alloca + DEFINES['alloca'] = '_alloca' + + soundtouch_sources = UNIFIED_SOURCES + soundtouch_defines = DEFINES + +soundtouch_sources += [ + 'AAFilter.cpp', + 'cpu_detect_x86.cpp', + 'FIFOSampleBuffer.cpp', + 'FIRFilter.cpp', + 'InterpolateCubic.cpp', + 'InterpolateLinear.cpp', + 'InterpolateShannon.cpp', + 'RateTransposer.cpp', + 'RLBoxSoundTouchFactory.cpp', + 'SoundTouch.cpp', + 'SoundTouchFactory.cpp', + 'TDStretch.cpp', +] + +for k, v in ( + ('BUILDING_SOUNDTOUCH', 1), + # Use abort() instead of exception in SoundTouch. + ('ST_NO_EXCEPTION_HANDLING', 1) +): + soundtouch_defines[k] = v -for k, v in soundtouch_defines: - DEFINES[k] = v # We allow warnings for third-party code that can be updated from upstream. AllowCompilerWarnings() diff --git a/media/libsoundtouch/src/sources.mozbuild b/media/libsoundtouch/src/sources.mozbuild deleted file mode 100644 index e5356fffc95a..000000000000 --- a/media/libsoundtouch/src/sources.mozbuild +++ /dev/null @@ -1,26 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -soundtouch_sources = [ - 'AAFilter.cpp', - 'cpu_detect_x86.cpp', - 'FIFOSampleBuffer.cpp', - 'FIRFilter.cpp', - 'InterpolateCubic.cpp', - 'InterpolateLinear.cpp', - 'InterpolateShannon.cpp', - 'RateTransposer.cpp', - 'RLBoxSoundTouchFactory.cpp', - 'SoundTouch.cpp', - 'SoundTouchFactory.cpp', - 'TDStretch.cpp', -] - -soundtouch_defines = [ - ('BUILDING_SOUNDTOUCH', 1), - # Use abort() instead of exception in SoundTouch. - ('ST_NO_EXCEPTION_HANDLING', 1) -] \ No newline at end of file diff --git a/security/rlbox/moz.build b/security/rlbox/moz.build index 85a5da2d052c..ed3efb03139d 100644 --- a/security/rlbox/moz.build +++ b/security/rlbox/moz.build @@ -4,10 +4,9 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -WASM_SOURCES += [ - "/memory/mozalloc/mozalloc.cpp", - "/third_party/rlbox_wasm2c_sandbox/c_src/wasm2c_sandbox_wrapper.c", -] +include("rlbox.mozbuild") + +RLBoxLibrary("rlbox") LOCAL_INCLUDES += [ "/third_party/simde/", @@ -18,50 +17,13 @@ EXPORTS += [ "/third_party/wasm2c/wasm2c/wasm-rt.h", ] -SOURCES += [ - "!rlbox.wasm.c", - "/third_party/wasm2c/wasm2c/wasm-rt-impl.c", -] - -# Configuration for the wasm2c runtime used by RLBox - -# Enable SIMD autovectorization -WASM_CXXFLAGS += ["-msimd128"] - -# Use a mmap style allocation -DEFINES["WASM_RT_USE_MMAP"] = 1 - -# Don't use internal signal handler as Firefox already provides one -DEFINES["WASM_RT_SKIP_SIGNAL_RECOVERY"] = 1 - -# We provide a custom trap handler that calls MOZ_CRASH -DEFINES["WASM_RT_TRAP_HANDLER"] = "moz_wasm2c_trap_handler" - -# Don't limit the nested call depth -DEFINES["WASM_RT_USE_STACK_DEPTH_COUNT"] = 0 - -# Configure the wasm runtime to invoke a callback when a Wasm memory growth -# fails inside the sandbox. This information is used to annotate crash reports. -DEFINES["WASM_RT_GROW_FAILED_HANDLER"] = "moz_wasm2c_memgrow_failed" - - FINAL_LIBRARY = "xul" # Allow compiler warnings both in wasm compiles (because they're third-party # libraries), and C compiles (because they're code generated by wasm2c). AllowCompilerWarnings() -SOURCES["!rlbox.wasm.c"].flags += [ - "-Wno-unused", -] - WASM_DEFINES["MOZILLA_CLIENT"] = True -WASM_DEFINES["_WASI_EMULATED_PROCESS_CLOCKS"] = True -WASM_DEFINES["MOZ_IN_WASM_SANDBOX"] = True -if CONFIG["ENABLE_CLANG_PLUGIN"]: - WASM_DEFINES["MOZ_CLANG_PLUGIN"] = True - -SANDBOXED_WASM_LIBRARY_NAME = "rlbox.wasm" if CONFIG["MOZ_WASM_SANDBOXING_HUNSPELL"]: include("/extensions/spellcheck/hunspell/src/sources.mozbuild") @@ -99,33 +61,3 @@ if CONFIG["MOZ_WASM_SANDBOXING_WOFF2"]: include("/modules/woff2/sources.mozbuild") WASM_SOURCES += ["/modules/woff2/" + s for s in woff2_sources] LOCAL_INCLUDES += ["/modules/woff2/include"] - -if CONFIG["MOZ_WASM_SANDBOXING_SOUNDTOUCH"]: - include("/media/libsoundtouch/src/sources.mozbuild") - WASM_SOURCES += ["/media/libsoundtouch/src/" + s for s in soundtouch_sources] - - # Only enable SIMD if Float32 is supported - if CONFIG["MOZ_SAMPLE_TYPE_FLOAT32"]: - WASM_DEFINES["MOZ_SAMPLE_TYPE_FLOAT32"] = 1 - - # Enable SoundTouch SSE optimized intrinsics - WASM_SOURCES += ["/media/libsoundtouch/src/sse_optimized.cpp"] - WASM_DEFINES["SOUNDTOUCH_ALLOW_SSE"] = 1 - - # Enables SIMD-everywhere to map SSE intrinsics to WASMSIMD intrinsics - WASM_DEFINES["SOUNDTOUCH_WASM_SIMD"] = 1 - WASM_DEFINES["SIMDE_ENABLE_NATIVE_ALIASES"] = 1 - - for k, v in soundtouch_defines: - WASM_DEFINES[k] = v - - LOCAL_INCLUDES += ["/media/libsoundtouch"] - -# Ideally we'd also list rlbox.wasm.h as an output, but that would put the -# generation in export rather than pre-compile, and we prefer the latter. -GeneratedFile( - "rlbox.wasm.c", - script="/config/wasm2c.py", - entry_point="wasm2c", - inputs=["!/dist/host/bin/wasm2c" + CONFIG["HOST_BIN_SUFFIX"], "!rlbox.wasm"], -) diff --git a/security/rlbox/rlbox.mozbuild b/security/rlbox/rlbox.mozbuild new file mode 100644 index 000000000000..ff7f0afea2b3 --- /dev/null +++ b/security/rlbox/rlbox.mozbuild @@ -0,0 +1,56 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +@template +def RLBoxLibrary(name): + WASM_SOURCES += [ + "/memory/mozalloc/mozalloc.cpp", + "/third_party/rlbox_wasm2c_sandbox/c_src/wasm2c_sandbox_wrapper.c", + ] + + SOURCES += [f"!{name}.wasm.c"] + SOURCES += ["/third_party/wasm2c/wasm2c/wasm-rt-impl.c"] + + # Configuration for the wasm2c runtime used by RLBox + + # Enable SIMD autovectorization + WASM_CXXFLAGS += ["-msimd128"] + + # Use a mmap style allocation + DEFINES["WASM_RT_USE_MMAP"] = 1 + + # Don't use internal signal handler as Firefox already provides one + DEFINES["WASM_RT_SKIP_SIGNAL_RECOVERY"] = 1 + + # We provide a custom trap handler that calls MOZ_CRASH + DEFINES["WASM_RT_TRAP_HANDLER"] = "moz_wasm2c_trap_handler" + + # Don't limit the nested call depth + DEFINES["WASM_RT_USE_STACK_DEPTH_COUNT"] = 0 + + # Configure the wasm runtime to invoke a callback when a Wasm memory growth + # fails inside the sandbox. This information is used to annotate crash reports. + DEFINES["WASM_RT_GROW_FAILED_HANDLER"] = "moz_wasm2c_memgrow_failed" + + SOURCES[f"!{name}.wasm.c"].flags += [ + "-Wno-unused", + ] + + WASM_DEFINES["_WASI_EMULATED_PROCESS_CLOCKS"] = True + WASM_DEFINES["MOZ_IN_WASM_SANDBOX"] = True + if CONFIG["ENABLE_CLANG_PLUGIN"]: + WASM_DEFINES["MOZ_CLANG_PLUGIN"] = True + + SANDBOXED_WASM_LIBRARY_NAME = f"{name}.wasm" + + # Ideally we'd also list {name}.wasm.h as an output, but that would put the + # generation in export rather than pre-compile, and we prefer the latter. + GeneratedFile( + f"{name}.wasm.c", + script="/config/wasm2c.py", + entry_point="wasm2c", + inputs=["!/dist/host/bin/wasm2c" + CONFIG["HOST_BIN_SUFFIX"], f"!{name}.wasm"], + ) diff --git a/toolkit/moz.configure b/toolkit/moz.configure index 98373842410d..26ab4e6a1297 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -2585,7 +2585,7 @@ def wasm_sandboxing_libraries(): @depends(dependable(wasm_sandboxing_libraries), build_project) def default_wasm_sandboxing_libraries(libraries, build_project): if build_project != "tools/rusttests": - non_default_libs = {"soundtouch"} + non_default_libs = {} return tuple(l for l in libraries if l not in non_default_libs)