Bug 1758813 [wpt PR 33142] - Implement RP sign out, a=testonly
[gecko.git] / ipc / glue / LibrarySandboxPreload.cpp
blob0d7889d46158399a13261185d39c44fd7ed9742f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
7 #include "LibrarySandboxPreload.h"
8 #include "nsXPCOMPrivate.h" // for XPCOM_DLL
10 #include "BinaryPath.h"
11 #include "prlink.h"
13 namespace mozilla {
14 namespace ipc {
16 PathString GetSandboxedRLBoxPath() {
17 nsCOMPtr<nsIFile> libFile;
18 nsresult rv = mozilla::BinaryPath::GetFile(getter_AddRefs(libFile));
19 if (NS_FAILED(rv)) {
20 MOZ_CRASH("Library preload failure: Failed to get binary file\n");
23 rv = libFile->SetNativeLeafName(XPCOM_DLL ""_ns);
24 if (NS_FAILED(rv)) {
25 MOZ_CRASH("Library preload failure: Failed to get library file\n");
28 return libFile->NativePath();
31 PRLibrary* PreloadLibrary(const PathString& path) {
32 PRLibSpec libSpec;
33 #ifdef XP_WIN
34 libSpec.type = PR_LibSpec_PathnameU;
35 libSpec.value.pathname_u = path.get();
36 #else
37 libSpec.type = PR_LibSpec_Pathname;
38 libSpec.value.pathname = path.get();
39 #endif
40 PRLibrary* ret = PR_LoadLibraryWithFlags(libSpec, PR_LD_LAZY);
41 return ret;
44 } // namespace ipc
45 } // namespace mozilla