Bug 1538279 - Only readahead DLLs in parent process r=glandium

There shouldn't be any need to do this for content processes as
the DLL should already be in the system file cache.

Differential Revision: https://phabricator.services.mozilla.com/D26017

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Doug Thayer 2019-04-12 02:17:48 +00:00
parent 358b289ecc
commit 13a4a8518f
4 changed files with 34 additions and 17 deletions

View File

@ -212,14 +212,14 @@ static int do_main(int argc, char* argv[], char* envp[]) {
return gBootstrap->XRE_main(argc, argv, config);
}
static nsresult InitXPCOMGlue() {
static nsresult InitXPCOMGlue(LibLoadingStrategy aLibLoadingStrategy) {
UniqueFreePtr<char> exePath = BinaryPath::Get();
if (!exePath) {
Output("Couldn't find the application directory.\n");
return NS_ERROR_FAILURE;
}
gBootstrap = mozilla::GetBootstrap(exePath.get());
gBootstrap = mozilla::GetBootstrap(exePath.get(), aLibLoadingStrategy);
if (!gBootstrap) {
Output("Couldn't load XPCOM.\n");
return NS_ERROR_FAILURE;
@ -255,7 +255,10 @@ int main(int argc, char* argv[], char* envp[]) {
}
# endif
nsresult rv = InitXPCOMGlue();
// Don't bother doing a ReadAhead if we're not in the parent process.
// What we need from the library should already be in the system file
// cache.
nsresult rv = InitXPCOMGlue(LibLoadingStrategy::NoReadAhead);
if (NS_FAILED(rv)) {
return 255;
}
@ -277,7 +280,7 @@ int main(int argc, char* argv[], char* envp[]) {
DllBlocklist_Initialize(gBlocklistInitFlags);
#endif
nsresult rv = InitXPCOMGlue();
nsresult rv = InitXPCOMGlue(LibLoadingStrategy::ReadAhead);
if (NS_FAILED(rv)) {
return 255;
}

View File

@ -196,7 +196,8 @@ static mozglueresult loadGeckoLibs() {
getrusage(RUSAGE_THREAD, &usage1_thread);
getrusage(RUSAGE_SELF, &usage1);
gBootstrap = GetBootstrap(getUnpackedLibraryName("libxul.so").get());
gBootstrap = GetBootstrap(getUnpackedLibraryName("libxul.so").get(),
LibLoadingStrategy::ReadAhead);
if (!gBootstrap) {
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad",
"Couldn't get a handle to libxul!");

View File

@ -128,6 +128,11 @@ class Bootstrap {
#endif
};
enum class LibLoadingStrategy {
NoReadAhead,
ReadAhead,
};
/**
* Creates and returns the singleton instnace of the bootstrap object.
* @param `b` is an outparam. We use a parameter and not a return value
@ -137,12 +142,15 @@ class Bootstrap {
*/
#ifdef XPCOM_GLUE
typedef void (*GetBootstrapType)(Bootstrap::UniquePtr&);
Bootstrap::UniquePtr GetBootstrap(const char* aXPCOMFile = nullptr);
Bootstrap::UniquePtr GetBootstrap(
const char* aXPCOMFile = nullptr,
LibLoadingStrategy aLibLoadingStrategy = LibLoadingStrategy::NoReadAhead);
#else
extern "C" NS_EXPORT void NS_FROZENCALL
XRE_GetBootstrap(Bootstrap::UniquePtr& b);
inline Bootstrap::UniquePtr GetBootstrap(const char* aXPCOMFile = nullptr) {
inline Bootstrap::UniquePtr GetBootstrap(
const char* aXPCOMFile = nullptr) {
Bootstrap::UniquePtr bootstrap;
XRE_GetBootstrap(bootstrap);
return bootstrap;

View File

@ -123,10 +123,12 @@ static void AppendDependentLib(LibHandleType aLibHandle) {
sTop = d;
}
static bool ReadDependentCB(pathstr_t aDependentLib) {
static bool ReadDependentCB(pathstr_t aDependentLib,
LibLoadingStrategy aLibLoadingStrategy) {
#ifndef MOZ_LINKER
// We do this unconditionally because of data in bug 771745
ReadAheadLib(aDependentLib);
if (aLibLoadingStrategy == LibLoadingStrategy::ReadAhead) {
ReadAheadLib(aDependentLib);
}
#endif
LibHandleType libHandle = GetLibHandle(aDependentLib);
if (libHandle) {
@ -137,11 +139,12 @@ static bool ReadDependentCB(pathstr_t aDependentLib) {
}
#ifdef XP_WIN
static bool ReadDependentCB(const char* aDependentLib) {
static bool ReadDependentCB(const char* aDependentLib,
LibLoadingStrategy aLibLoadingStrategy) {
wchar_t wideDependentLib[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, aDependentLib, -1, wideDependentLib,
MAX_PATH);
return ReadDependentCB(wideDependentLib);
return ReadDependentCB(wideDependentLib, aLibLoadingStrategy);
}
inline FILE* TS_tfopen(const char* path, const wchar_t* mode) {
@ -198,9 +201,10 @@ static const char* ns_strrpbrk(const char* string, const char* strCharSet) {
}
#endif
static nsresult XPCOMGlueLoad(const char* aXPCOMFile) {
static nsresult XPCOMGlueLoad(const char* aXPCOMFile,
LibLoadingStrategy aLibLoadingStrategy) {
#ifdef MOZ_LINKER
if (!ReadDependentCB(aXPCOMFile)) {
if (!ReadDependentCB(aXPCOMFile, aLibLoadingStrategy)) {
return NS_ERROR_FAILURE;
}
#else
@ -296,7 +300,7 @@ static nsresult XPCOMGlueLoad(const char* aXPCOMFile) {
}
strcpy(cursor, buffer);
if (!ReadDependentCB(xpcomDir)) {
if (!ReadDependentCB(xpcomDir, aLibLoadingStrategy)) {
XPCOMGlueUnload();
return NS_ERROR_FAILURE;
}
@ -342,7 +346,8 @@ class GSliceInit {
namespace mozilla {
Bootstrap::UniquePtr GetBootstrap(const char* aXPCOMFile) {
Bootstrap::UniquePtr GetBootstrap(const char* aXPCOMFile,
LibLoadingStrategy aLibLoadingStrategy) {
#ifdef MOZ_GSLICE_INIT
GSliceInit gSliceInit;
#endif
@ -363,7 +368,7 @@ Bootstrap::UniquePtr GetBootstrap(const char* aXPCOMFile) {
memcpy(file.get(), aXPCOMFile, base_len);
memcpy(file.get() + base_len, XPCOM_DLL, sizeof(XPCOM_DLL));
if (NS_FAILED(XPCOMGlueLoad(file.get()))) {
if (NS_FAILED(XPCOMGlueLoad(file.get(), aLibLoadingStrategy))) {
return nullptr;
}