Bug 1726474 - Preload rlbox library on all platforms. r=nika

Notably, on Windows, the sequences of loading/unloading in child processes trigger https://searchfox.org/mozilla-central/rev/d3683dbb252506400c71256ef3994cdbdfb71ada/toolkit/xre/dllservices/UntrustedModulesData.cpp#324

Differential Revision: https://phabricator.services.mozilla.com/D123039
This commit is contained in:
Mike Hommey 2021-08-24 01:01:38 +00:00
parent 5c13a00393
commit 2829072aeb

View File

@ -27,10 +27,15 @@ PathString GetSandboxedRLBoxPath() {
return libFile->NativePath();
}
PRLibrary* PreloadLibrary(const nsCString& path) {
PRLibrary* PreloadLibrary(const PathString& path) {
PRLibSpec libSpec;
#ifdef XP_WIN
libSpec.type = PR_LibSpec_PathnameU;
libSpec.value.pathname_u = path.get();
#else
libSpec.type = PR_LibSpec_Pathname;
libSpec.value.pathname = path.get();
#endif
PRLibrary* ret = PR_LoadLibraryWithFlags(libSpec, PR_LD_LAZY);
return ret;
}
@ -38,9 +43,9 @@ PRLibrary* PreloadLibrary(const nsCString& path) {
void PreloadSandboxedDynamicLibrary() {
// The process level sandbox does not allow loading of dynamic libraries.
// This preloads wasm sandboxed libraries before the process level sandbox is
// enabled. Currently, this is only needed for Linux as Mac allows loading
// libraries from the package file.
#if defined(XP_LINUX) && defined(MOZ_USING_WASM_SANDBOXING)
// enabled. Technically, this is only needed for Linux, but also allows to
// avoid loading/unloading the library repeatedly on other platforms.
#if defined(MOZ_USING_WASM_SANDBOXING)
if (!PreloadLibrary(GetSandboxedRLBoxPath())) {
MOZ_CRASH("Library preload failure: Failed to load librlbox\n");
}