Bug 1829050 - Enable STL wrapping (and thus infallible new) for wasm-sandboxed code. r=firefox-build-system-reviewers,shravanrn,andi

Differential Revision: https://phabricator.services.mozilla.com/D175981
This commit is contained in:
Mike Hommey 2023-05-08 21:10:19 +00:00
parent 1669ae5659
commit e120474d55
6 changed files with 48 additions and 24 deletions

View File

@ -8,6 +8,8 @@
// For MOZ_CRASH_UNSAFE_PRINTF
# include "mozilla/Assertions.h"
# include "mozilla/mozalloc_oom.h"
// Load general firefox configuration of RLBox
# include "mozilla/rlbox/rlbox_config.h"
# include "mozilla/rlbox/rlbox_wasm2c_tls.hpp"
@ -34,6 +36,13 @@ void moz_wasm2c_memgrow_failed() {
CrashReporter::AnnotateCrashReport(
CrashReporter::Annotation::WasmLibrarySandboxMallocFailed, true);
}
// This function is called when mozalloc_handle_oom is called from within
// the sandbox. We redirect to that function, ignoring the ctx argument, which
// is the sandbox itself.
void w2c_env_mozalloc_handle_oom(void* ctx, uint32_t size) {
mozalloc_handle_oom(size);
}
}
#endif

View File

@ -103,6 +103,7 @@ void* moz_xmemdup(const void* ptr, size_t size) {
return newPtr;
}
#ifndef __wasm__
# ifndef HAVE_MEMALIGN
// We always have a definition of memalign, but system headers don't
// necessarily come with a declaration.
@ -118,6 +119,7 @@ void* moz_xmemalign(size_t boundary, size_t size) {
// non-NULL ptr or errno == EINVAL
return ptr;
}
#endif
size_t moz_malloc_usable_size(void* ptr) {
if (!ptr) return 0;

View File

@ -14,7 +14,12 @@
* Called when memory is critically low. Returns iff it was able to
* remedy the critical memory situation; if not, it will abort().
*/
MFBT_API void mozalloc_handle_oom(size_t requestedSize);
#ifdef __wasm__
__attribute__((import_module("env")))
__attribute__((import_name("mozalloc_handle_oom")))
#endif
MFBT_API void
mozalloc_handle_oom(size_t requestedSize);
extern MFBT_DATA size_t gOOMAllocationSize;

View File

@ -8,6 +8,8 @@
#ifndef mozilla_throw_gcc_h
#define mozilla_throw_gcc_h
#ifndef __wasm__
# include "mozilla/Attributes.h"
# include <stdio.h> // snprintf
@ -145,4 +147,6 @@ MOZ_THROW_NORETURN MOZ_EXPORT MOZ_ALWAYS_INLINE void __throw_regex_error(
# undef MOZ_THROW_NORETURN
# undef MOZ_THROW_INLINE
#endif
#endif // mozilla_throw_gcc_h

View File

@ -767,6 +767,7 @@ class WasmFlags(TargetCompileFlags):
context.config.substs.get("MOZ_FILE_PREFIX_MAP_FLAGS"),
("WASM_CFLAGS", "WASM_CXXFLAGS"),
),
("STL", context.config.substs.get("STL_FLAGS"), ("WASM_CXXFLAGS",)),
)
TargetCompileFlags.__init__(self, context)

View File

@ -5,6 +5,7 @@
# 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",
]
@ -47,6 +48,8 @@ AllowCompilerWarnings()
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"