1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 def RLBoxLibrary(name):
11 "/memory/mozalloc/mozalloc.cpp",
12 "/third_party/rlbox_wasm2c_sandbox/c_src/wasm2c_sandbox_wrapper.c",
15 SOURCES += [f"!{name}.wasm.c"]
16 SOURCES += ["/third_party/wasm2c/wasm2c/wasm-rt-impl.c"]
18 # Configuration for the wasm2c runtime used by RLBox
20 # Enable SIMD autovectorization
21 if CONFIG["WASM_CC_VERSION"] and int(CONFIG["WASM_CC_VERSION"].split(".")[0]) >= 11:
22 WASM_CXXFLAGS += ["-msimd128"]
24 # Use a mmap style allocation
25 DEFINES["WASM_RT_USE_MMAP"] = 1
27 # Don't use internal signal handler as Firefox already provides one
28 DEFINES["WASM_RT_SKIP_SIGNAL_RECOVERY"] = 1
30 # We provide a custom trap handler that calls MOZ_CRASH
31 DEFINES["WASM_RT_TRAP_HANDLER"] = "moz_wasm2c_trap_handler"
33 # Don't limit the nested call depth
34 DEFINES["WASM_RT_USE_STACK_DEPTH_COUNT"] = 0
36 # Configure the wasm runtime to invoke a callback when a Wasm memory growth
37 # fails inside the sandbox. This information is used to annotate crash reports.
38 DEFINES["WASM_RT_GROW_FAILED_HANDLER"] = "moz_wasm2c_memgrow_failed"
40 SOURCES[f"!{name}.wasm.c"].flags += [
44 WASM_DEFINES["MOZ_IN_WASM_SANDBOX"] = True
45 if CONFIG["ENABLE_CLANG_PLUGIN"]:
46 WASM_DEFINES["MOZ_CLANG_PLUGIN"] = True
48 SANDBOXED_WASM_LIBRARY_NAME = f"{name}.wasm"
50 # Ideally we'd also list {name}.wasm.h as an output, but that would put the
51 # generation in export rather than pre-compile, and we prefer the latter.
54 script="/config/wasm2c.py",
56 inputs=["!/dist/host/bin/wasm2c" + CONFIG["HOST_BIN_SUFFIX"], f"!{name}.wasm"],