Commit ed0bb19d authored by Shravan Narayan's avatar Shravan Narayan
Browse files

Bug 1827704 - Migrate to the upstream wasm2c for RLBox sandboxing r=glandium

parent 4d6ebc05
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -21,4 +21,10 @@
// fixed.
#define RLBOX_EMBEDDER_PROVIDES_TLS_STATIC_VARIABLES

// When instantiating a wasm sandbox, rlbox requires the name of the wasm module
// being instantiated. LLVM and wasm2c use the module name by choosing the name
// used to generate the wasm file. In Firefox this is a static library called
// rlbox
#define RLBOX_WASM2C_MODULE_NAME rlbox

#endif
+12 −1
Original line number Diff line number Diff line
@@ -6,8 +6,19 @@

EXPORTS.mozilla.rlbox += [
    "/third_party/rlbox_wasm2c_sandbox/include/rlbox_wasm2c_sandbox.hpp",
    "/third_party/rlbox_wasm2c_sandbox/include/rlbox_wasm2c_tls.hpp",
]
EXPORTS += [
    "/third_party/rlbox_wasm2c_sandbox/include/wasm2c_rt_mem.h",
    "/third_party/rlbox_wasm2c_sandbox/include/wasm2c_rt_minwasi.h",
]

SOURCES += [
    "/third_party/rlbox_wasm2c_sandbox/src/wasm2c_rt_mem.c",
    "/third_party/rlbox_wasm2c_sandbox/src/wasm2c_rt_minwasi.c",
    "rlbox_wasm2c_thread_locals.cpp",
]

SOURCES += ["rlbox_wasm2c_thread_locals.cpp"]
LOCAL_INCLUDES += ["/third_party/wasm2c/wasm2c/"]

FINAL_LIBRARY = "xul"
+3 −5
Original line number Diff line number Diff line
@@ -7,10 +7,10 @@ bugzilla:
origin:
  name: rlbox_wasm2c_sandbox
  description: rlbox integration for the wasm2c sandboxed code
  url: https://github.com/PLSysSec/rlbox_wasm2c_sandbox
  url: https://github.com/PLSysSec/rlbox_wasm2c_sandbox/tree/upstream-wasm2c

  release: commit 54e8469095e7929c66aeecdc26f23f502b986218 (2021-12-08T08:12:13Z).
  revision: 54e8469095e7929c66aeecdc26f23f502b986218
  release: 7e4ff0ebca2c7644a297bfe51a53b9904f0999b2 (2023-04-13T05:07:28Z).
  revision: 7e4ff0ebca2c7644a297bfe51a53b9904f0999b2

  license: MIT
  license-file: LICENSE
@@ -32,5 +32,3 @@ vendoring:
    - CMakeLists.txt
    - LibrarySandbox.md
    - README.md

+5 −10
Original line number Diff line number Diff line
@@ -10,10 +10,8 @@

// Load general firefox configuration of RLBox
#  include "mozilla/rlbox/rlbox_config.h"

#  include "mozilla/rlbox/rlbox_wasm2c_sandbox.hpp"

#  include "mozilla/rlbox/rlbox.hpp"
#  include "mozilla/rlbox/rlbox_wasm2c_tls.hpp"
#  include "wasm-rt.h"

#  include "nsExceptionHandler.h"

@@ -26,16 +24,13 @@ extern "C" {

// Any error encountered by the wasm2c runtime or wasm sandboxed library code
// is configured to call the below trap handler.
void moz_wasm2c_trap_handler(const char* msg) {
  MOZ_CRASH_UNSAFE_PRINTF("wasm2c crash: %s", msg);
void moz_wasm2c_trap_handler(wasm_rt_trap_t code) {
  MOZ_CRASH_UNSAFE_PRINTF("wasm2c crash: %s", wasm_rt_strerror(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_malloc_failed(uint32_t size) {
  // We don't use the allocation size information for now
  (void)size;

void moz_wasm2c_memgrow_failed() {
  CrashReporter::AnnotateCrashReport(
      CrashReporter::Annotation::WasmLibrarySandboxMallocFailed, true);
}
+13 −4
Original line number Diff line number Diff line
@@ -4,10 +4,13 @@
# 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/.

LOCAL_INCLUDES += ["/third_party/wasm2c/"]
LOCAL_INCLUDES += [
    "/third_party/picosha2/",
    "/third_party/wasm2c/include/",
]

GeneratedFile(
    "config.h",
    "wabt/config.h",
    script="preprocess_wasm2c_config.py",
    entry_point="generate_config",
    inputs=["/third_party/wasm2c/src/config.h.in"],
@@ -18,6 +21,8 @@ HOST_SOURCES += [
    "/third_party/wasm2c/src/apply-names.cc",
    "/third_party/wasm2c/src/binary-reader-ir.cc",
    "/third_party/wasm2c/src/binary-reader-logging.cc",
    "/third_party/wasm2c/src/binary-reader-objdump.cc",
    "/third_party/wasm2c/src/binary-reader-opcnt.cc",
    "/third_party/wasm2c/src/binary-reader.cc",
    "/third_party/wasm2c/src/binary-writer-spec.cc",
    "/third_party/wasm2c/src/binary-writer.cc",
@@ -27,12 +32,12 @@ HOST_SOURCES += [
    "/third_party/wasm2c/src/common.cc",
    "/third_party/wasm2c/src/config.cc",
    "/third_party/wasm2c/src/decompiler.cc",
    "/third_party/wasm2c/src/emscripten-helpers.cc",
    "/third_party/wasm2c/src/error-formatter.cc",
    "/third_party/wasm2c/src/expr-visitor.cc",
    "/third_party/wasm2c/src/feature.cc",
    "/third_party/wasm2c/src/filenames.cc",
    "/third_party/wasm2c/src/generate-names.cc",
    "/third_party/wasm2c/src/hash-util.cc",
    "/third_party/wasm2c/src/ir-util.cc",
    "/third_party/wasm2c/src/ir.cc",
    "/third_party/wasm2c/src/leb128.cc",
@@ -43,9 +48,9 @@ HOST_SOURCES += [
    "/third_party/wasm2c/src/opcode.cc",
    "/third_party/wasm2c/src/option-parser.cc",
    "/third_party/wasm2c/src/resolve-names.cc",
    "/third_party/wasm2c/src/sha256.cc",
    "/third_party/wasm2c/src/shared-validator.cc",
    "/third_party/wasm2c/src/stream.cc",
    "/third_party/wasm2c/src/string-view.cc",
    "/third_party/wasm2c/src/token.cc",
    "/third_party/wasm2c/src/tracing.cc",
    "/third_party/wasm2c/src/type-checker.cc",
@@ -59,6 +64,10 @@ HOST_SOURCES += [
# wasm2c sources
HOST_SOURCES += [
    "/third_party/wasm2c/src/c-writer.cc",
    "/third_party/wasm2c/src/prebuilt/wasm2c_header_bottom.cc",
    "/third_party/wasm2c/src/prebuilt/wasm2c_header_top.cc",
    "/third_party/wasm2c/src/prebuilt/wasm2c_source_declarations.cc",
    "/third_party/wasm2c/src/prebuilt/wasm2c_source_includes.cc",
    "/third_party/wasm2c/src/tools/wasm2c.cc",
]

Loading