зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 6 changesets (bug 1627075) for bustages on startupcache/StartupCache.cpp . CLOSED TREE
Backed out changeset 21605186687e (bug 1627075) Backed out changeset e29b15980da2 (bug 1627075) Backed out changeset eb5265addd5e (bug 1627075) Backed out changeset dfd71f4ecb81 (bug 1627075) Backed out changeset 13ecd68b3c0d (bug 1627075) Backed out changeset 333d035afe92 (bug 1627075)
This commit is contained in:
Родитель
f278cfa05f
Коммит
a182c015f5
|
@ -11,16 +11,6 @@
|
|||
#include "mozilla/dom/PWebGLChild.h"
|
||||
#include "mozilla/dom/IpdlQueue.h"
|
||||
|
||||
// This is a bit weird. Nothing directly in WebGLChild.h necessitates including
|
||||
// WebGLParent.h, but if we don't do this, we get compiler errors in the
|
||||
// generated code inside PWebGLChild.cpp. The error is due to a complex
|
||||
// dependency chain involving IpdlQueue, which I won't go into here. Including
|
||||
// WebGLParent.h inside WebGLChild.h is the simplest way we could think of to
|
||||
// avoid this issue. Including it in any of the code more directly involved in
|
||||
// the breaking dependency chain unfortunately introduces a cyclical dependency
|
||||
// between WebGLParent.h and PWebGLParent.h.
|
||||
#include "mozilla/dom/WebGLParent.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class ClientWebGLContext;
|
||||
|
|
|
@ -98,7 +98,6 @@
|
|||
#include "mozilla/plugins/PluginInstanceParent.h"
|
||||
#include "mozilla/plugins/PluginModuleParent.h"
|
||||
#include "mozilla/RemoteLazyInputStreamChild.h"
|
||||
#include "mozilla/scache/StartupCacheChild.h"
|
||||
#include "mozilla/widget/ScreenManager.h"
|
||||
#include "mozilla/widget/WidgetMessageUtils.h"
|
||||
#include "nsBaseDragService.h"
|
||||
|
@ -1921,23 +1920,6 @@ mozilla::ipc::IPCResult ContentChild::RecvPScriptCacheConstructor(
|
|||
return IPC_OK();
|
||||
}
|
||||
|
||||
scache::PStartupCacheChild* ContentChild::AllocPStartupCacheChild(
|
||||
const bool& wantCacheData) {
|
||||
return new scache::StartupCacheChild();
|
||||
}
|
||||
|
||||
bool ContentChild::DeallocPStartupCacheChild(
|
||||
scache::PStartupCacheChild* cache) {
|
||||
delete static_cast<scache::StartupCacheChild*>(cache);
|
||||
return true;
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult ContentChild::RecvPStartupCacheConstructor(
|
||||
scache::PStartupCacheChild* actor, const bool& wantCacheData) {
|
||||
static_cast<scache::StartupCacheChild*>(actor)->Init(wantCacheData);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
PNeckoChild* ContentChild::AllocPNeckoChild() { return new NeckoChild(); }
|
||||
|
||||
mozilla::ipc::IPCResult ContentChild::RecvNetworkLinkTypeChange(
|
||||
|
|
|
@ -238,13 +238,6 @@ class ContentChild final : public PContentChild,
|
|||
PScriptCacheChild*, const FileDescOrError& cacheFile,
|
||||
const bool& wantCacheData) override;
|
||||
|
||||
PStartupCacheChild* AllocPStartupCacheChild(const bool& wantCacheData);
|
||||
|
||||
bool DeallocPStartupCacheChild(PStartupCacheChild*);
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvPStartupCacheConstructor(
|
||||
PStartupCacheChild*, const bool& wantCacheData) override;
|
||||
|
||||
PNeckoChild* AllocPNeckoChild();
|
||||
|
||||
bool DeallocPNeckoChild(PNeckoChild*);
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
#include "mozilla/ProcessHangMonitorIPC.h"
|
||||
#include "mozilla/RDDProcessManager.h"
|
||||
#include "mozilla/ScopeExit.h"
|
||||
#include "mozilla/scache/StartupCache.h"
|
||||
#include "mozilla/ScriptPreloader.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/Sprintf.h"
|
||||
|
@ -156,7 +155,6 @@
|
|||
#include "mozilla/plugins/PluginBridge.h"
|
||||
#include "mozilla/RemoteLazyInputStreamParent.h"
|
||||
#include "mozilla/widget/ScreenManager.h"
|
||||
#include "mozilla/scache/StartupCacheParent.h"
|
||||
#include "nsAnonymousTemporaryFile.h"
|
||||
#include "nsAppRunner.h"
|
||||
#include "nsCExternalHandlerService.h"
|
||||
|
@ -2302,11 +2300,6 @@ bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) {
|
|||
}
|
||||
mPrefSerializer->AddSharedPrefCmdLineArgs(*mSubprocess, extraArgs);
|
||||
|
||||
auto startupCache = mozilla::scache::StartupCache::GetSingleton();
|
||||
if (startupCache) {
|
||||
startupCache->AddStartupCacheCmdLineArgs(*mSubprocess, extraArgs);
|
||||
}
|
||||
|
||||
// Register ContentParent as an observer for changes to any pref
|
||||
// whose prefix matches the empty string, i.e. all of them. The
|
||||
// observation starts here in order to capture pref updates that
|
||||
|
@ -2740,7 +2733,6 @@ bool ContentParent::InitInternal(ProcessPriority aInitialPriority) {
|
|||
Unused << SendRemoteType(mRemoteType);
|
||||
|
||||
ScriptPreloader::InitContentChild(*this);
|
||||
scache::StartupCache::InitContentChild(*this);
|
||||
|
||||
// Initialize the message manager (and load delayed scripts) now that we
|
||||
// have established communications with the child.
|
||||
|
@ -3837,16 +3829,6 @@ bool ContentParent::DeallocPScriptCacheParent(PScriptCacheParent* cache) {
|
|||
return true;
|
||||
}
|
||||
|
||||
PStartupCacheParent* ContentParent::AllocPStartupCacheParent(
|
||||
const bool& wantCacheData) {
|
||||
return new scache::StartupCacheParent(wantCacheData);
|
||||
}
|
||||
|
||||
bool ContentParent::DeallocPStartupCacheParent(PStartupCacheParent* cache) {
|
||||
delete static_cast<scache::StartupCacheParent*>(cache);
|
||||
return true;
|
||||
}
|
||||
|
||||
PNeckoParent* ContentParent::AllocPNeckoParent() { return new NeckoParent(); }
|
||||
|
||||
bool ContentParent::DeallocPNeckoParent(PNeckoParent* necko) {
|
||||
|
|
|
@ -86,7 +86,6 @@ class PreallocatedProcessManagerImpl;
|
|||
class BenchmarkStorageParent;
|
||||
|
||||
using mozilla::loader::PScriptCacheParent;
|
||||
using mozilla::scache::PStartupCacheParent;
|
||||
|
||||
namespace embedding {
|
||||
class PrintingParent;
|
||||
|
@ -927,10 +926,6 @@ class ContentParent final
|
|||
|
||||
bool DeallocPScriptCacheParent(PScriptCacheParent* shell);
|
||||
|
||||
PStartupCacheParent* AllocPStartupCacheParent(const bool& wantCacheData);
|
||||
|
||||
bool DeallocPStartupCacheParent(PStartupCacheParent* shell);
|
||||
|
||||
bool DeallocPNeckoParent(PNeckoParent* necko);
|
||||
|
||||
already_AddRefed<PExternalHelperAppParent> AllocPExternalHelperAppParent(
|
||||
|
|
|
@ -84,8 +84,6 @@ bool ContentProcess::Init(int aArgc, char* aArgv[]) {
|
|||
char* prefMapHandle = nullptr;
|
||||
char* prefsLen = nullptr;
|
||||
char* prefMapSize = nullptr;
|
||||
char* scacheHandle = nullptr;
|
||||
char* scacheSize = nullptr;
|
||||
#if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
|
||||
nsCOMPtr<nsIFile> profileDir;
|
||||
#endif
|
||||
|
@ -129,11 +127,6 @@ bool ContentProcess::Init(int aArgc, char* aArgv[]) {
|
|||
return false;
|
||||
}
|
||||
prefMapHandle = aArgv[i];
|
||||
} else if (strcmp(aArgv[i], "-scacheHandle") == 0) {
|
||||
if (++i == aArgc) {
|
||||
return false;
|
||||
}
|
||||
scacheHandle = aArgv[i];
|
||||
#endif
|
||||
|
||||
} else if (strcmp(aArgv[i], "-prefsLen") == 0) {
|
||||
|
@ -146,11 +139,6 @@ bool ContentProcess::Init(int aArgc, char* aArgv[]) {
|
|||
return false;
|
||||
}
|
||||
prefMapSize = aArgv[i];
|
||||
} else if (strcmp(aArgv[i], "-scacheSize") == 0) {
|
||||
if (++i == aArgc) {
|
||||
return false;
|
||||
}
|
||||
scacheSize = aArgv[i];
|
||||
} else if (strcmp(aArgv[i], "-safeMode") == 0) {
|
||||
gSafeMode = true;
|
||||
|
||||
|
@ -187,9 +175,6 @@ bool ContentProcess::Init(int aArgc, char* aArgv[]) {
|
|||
return false;
|
||||
}
|
||||
|
||||
Unused << mozilla::scache::StartupCache::InitChildSingleton(scacheHandle,
|
||||
scacheSize);
|
||||
|
||||
mContent.Init(IOThreadChild::message_loop(), ParentPid(), *parentBuildID,
|
||||
IOThreadChild::TakeChannel(), *childID, *isForBrowser);
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ include protocol PVRManager;
|
|||
include protocol PRemoteDecoderManager;
|
||||
include protocol PProfiler;
|
||||
include protocol PScriptCache;
|
||||
include protocol PStartupCache;
|
||||
include protocol PSessionStorageObserver;
|
||||
include protocol PBenchmarkStorage;
|
||||
include DOMTypes;
|
||||
|
@ -413,7 +412,6 @@ nested(upto inside_cpow) sync protocol PContent
|
|||
manages PURLClassifier;
|
||||
manages PURLClassifierLocal;
|
||||
manages PScriptCache;
|
||||
manages PStartupCache;
|
||||
manages PLoginReputation;
|
||||
manages PSessionStorageObserver;
|
||||
manages PBenchmarkStorage;
|
||||
|
@ -541,8 +539,6 @@ child:
|
|||
|
||||
async PScriptCache(FileDescOrError cacheFile, bool wantCacheData);
|
||||
|
||||
async PStartupCache(bool wantCacheData);
|
||||
|
||||
async RegisterChrome(ChromePackage[] packages, SubstitutionMapping[] substitutions,
|
||||
OverrideMapping[] overrides, nsCString locale, bool reset);
|
||||
async RegisterChromeItem(ChromeRegistryItem item);
|
||||
|
|
|
@ -95,14 +95,14 @@ already_AddRefed<SharedFTFace> FT2FontEntry::GetFTFace(bool aCommit) {
|
|||
// here would be memory allocation, in which case mFace remains null.
|
||||
RefPtr<SharedFTFace> face;
|
||||
if (mFilename[0] != '/') {
|
||||
RefPtr<CacheAwareZipReader> reader = Omnijar::GetReader(Omnijar::Type::GRE);
|
||||
RefPtr<nsZipArchive> reader = Omnijar::GetReader(Omnijar::Type::GRE);
|
||||
nsZipItem* item = reader->GetItem(mFilename.get());
|
||||
NS_ASSERTION(item, "failed to find zip entry");
|
||||
|
||||
uint32_t bufSize = item->RealSize();
|
||||
uint8_t* fontDataBuf = static_cast<uint8_t*>(malloc(bufSize));
|
||||
if (fontDataBuf) {
|
||||
CacheAwareZipCursor cursor(item, reader, fontDataBuf, bufSize);
|
||||
nsZipCursor cursor(item, reader, fontDataBuf, bufSize);
|
||||
cursor.Copy(&bufSize);
|
||||
NS_ASSERTION(bufSize == item->RealSize(), "error reading bundled font");
|
||||
RefPtr<FTUserFontData> ufd = new FTUserFontData(fontDataBuf, bufSize);
|
||||
|
@ -458,8 +458,7 @@ hb_blob_t* FT2FontEntry::GetFontTable(uint32_t aTableTag) {
|
|||
} else {
|
||||
// A relative path means an omnijar resource, which we may need to
|
||||
// decompress to a temporary buffer.
|
||||
RefPtr<CacheAwareZipReader> reader =
|
||||
Omnijar::GetReader(Omnijar::Type::GRE);
|
||||
RefPtr<nsZipArchive> reader = Omnijar::GetReader(Omnijar::Type::GRE);
|
||||
nsZipItem* item = reader->GetItem(mFilename.get());
|
||||
MOZ_ASSERT(item, "failed to find zip entry");
|
||||
if (item) {
|
||||
|
@ -470,7 +469,7 @@ hb_blob_t* FT2FontEntry::GetFontTable(uint32_t aTableTag) {
|
|||
uint32_t length = item->RealSize();
|
||||
uint8_t* buffer = static_cast<uint8_t*>(malloc(length));
|
||||
if (buffer) {
|
||||
CacheAwareZipCursor cursor(item, reader, buffer, length);
|
||||
nsZipCursor cursor(item, reader, buffer, length);
|
||||
cursor.Copy(&length);
|
||||
MOZ_ASSERT(length == item->RealSize(), "error reading font");
|
||||
if (length == item->RealSize()) {
|
||||
|
@ -1160,7 +1159,7 @@ void gfxFT2FontList::FindFontsInOmnijar(FontNameCache* aCache) {
|
|||
static const char* sJarSearchPaths[] = {
|
||||
"res/fonts/*.ttf$",
|
||||
};
|
||||
RefPtr<CacheAwareZipReader> reader = Omnijar::GetReader(Omnijar::Type::GRE);
|
||||
RefPtr<nsZipArchive> reader = Omnijar::GetReader(Omnijar::Type::GRE);
|
||||
for (unsigned i = 0; i < ArrayLength(sJarSearchPaths); i++) {
|
||||
nsZipFind* find;
|
||||
if (NS_SUCCEEDED(reader->FindInit(sJarSearchPaths[i], &find))) {
|
||||
|
@ -1275,7 +1274,7 @@ void gfxFT2FontList::AddFaceToList(const nsCString& aEntryName, uint32_t aIndex,
|
|||
}
|
||||
}
|
||||
|
||||
void gfxFT2FontList::AppendFacesFromOmnijarEntry(CacheAwareZipReader* aArchive,
|
||||
void gfxFT2FontList::AppendFacesFromOmnijarEntry(nsZipArchive* aArchive,
|
||||
const nsCString& aEntryName,
|
||||
FontNameCache* aCache,
|
||||
bool aJarChanged) {
|
||||
|
@ -1314,7 +1313,7 @@ void gfxFT2FontList::AppendFacesFromOmnijarEntry(CacheAwareZipReader* aArchive,
|
|||
return;
|
||||
}
|
||||
|
||||
CacheAwareZipCursor cursor(item, aArchive, (uint8_t*)buffer, bufSize);
|
||||
nsZipCursor cursor(item, aArchive, (uint8_t*)buffer, bufSize);
|
||||
uint8_t* data = cursor.Copy(&bufSize);
|
||||
MOZ_ASSERT(data && bufSize == item->RealSize(), "error reading bundled font");
|
||||
if (!data) {
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
#include "gfxPlatformFontList.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class CacheAwareZipReader;
|
||||
|
||||
namespace dom {
|
||||
class SystemFontListEntry;
|
||||
};
|
||||
|
@ -177,7 +174,7 @@ class gfxFT2FontList final : public gfxPlatformFontList {
|
|||
void AppendFacesFromFontFile(const nsCString& aFileName,
|
||||
FontNameCache* aCache, StandardFile aStdFile);
|
||||
|
||||
void AppendFacesFromOmnijarEntry(mozilla::CacheAwareZipReader* aArchive,
|
||||
void AppendFacesFromOmnijarEntry(nsZipArchive* aReader,
|
||||
const nsCString& aEntryName,
|
||||
FontNameCache* aCache, bool aJarChanged);
|
||||
|
||||
|
|
|
@ -228,7 +228,7 @@ void nsHyphenationManager::LoadPatternListFromOmnijar(Omnijar::Type aType) {
|
|||
return;
|
||||
}
|
||||
|
||||
RefPtr<CacheAwareZipReader> zip = Omnijar::GetReader(aType);
|
||||
RefPtr<nsZipArchive> zip = Omnijar::GetReader(aType);
|
||||
if (!zip) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -41,11 +41,20 @@ static const void* GetItemPtrFromJarURI(nsIJARURI* aJAR, uint32_t* aLength) {
|
|||
if (!file) {
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<CacheAwareZipReader> archive = Omnijar::GetReader(file);
|
||||
RefPtr<nsZipArchive> archive = Omnijar::GetReader(file);
|
||||
if (archive) {
|
||||
nsCString path;
|
||||
aJAR->GetJAREntry(path);
|
||||
return archive->GetData(path.get(), aLength);
|
||||
nsZipItem* item = archive->GetItem(path.get());
|
||||
if (item && item->Compression() == 0 && item->Size() > 0) {
|
||||
// We do NOT own this data, but it won't go away until the omnijar
|
||||
// file is closed during shutdown.
|
||||
const uint8_t* data = archive->GetData(item);
|
||||
if (data) {
|
||||
*aLength = item->Size();
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -295,14 +295,13 @@ bool LocaleService::IsServer() { return mIsServer; }
|
|||
|
||||
static bool GetGREFileContents(const char* aFilePath, nsCString* aOutString) {
|
||||
// Look for the requested file in omnijar.
|
||||
RefPtr<CacheAwareZipReader> zip = Omnijar::GetReader(Omnijar::GRE);
|
||||
RefPtr<nsZipArchive> zip = Omnijar::GetReader(Omnijar::GRE);
|
||||
if (zip) {
|
||||
uint32_t length;
|
||||
const uint8_t* data = zip->GetData(aFilePath, &length);
|
||||
if (!data) {
|
||||
nsZipItemPtr<char> item(zip, aFilePath);
|
||||
if (!item) {
|
||||
return false;
|
||||
}
|
||||
aOutString->Assign(reinterpret_cast<const char*>(data), length);
|
||||
aOutString->Assign(item.Buffer(), item.Length());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,82 +64,6 @@ class OutputBuffer {
|
|||
size_t cursor_ = 0;
|
||||
};
|
||||
|
||||
// This is similar to OutputBuffer, but with a fixed-size buffer, rather than
|
||||
// a dynamically growing one. This is currently used in order to share
|
||||
// StartupCache data across processes.
|
||||
class PreallocatedOutputBuffer {
|
||||
public:
|
||||
explicit PreallocatedOutputBuffer(Range<uint8_t>& buffer) : data(buffer) {}
|
||||
|
||||
uint8_t* write(size_t size) {
|
||||
MOZ_ASSERT(checkCapacity(size));
|
||||
|
||||
auto buf = &data[cursor_];
|
||||
cursor_ += size;
|
||||
return buf;
|
||||
}
|
||||
|
||||
bool codeUint8(const uint8_t& val) {
|
||||
if (checkCapacity(sizeof val)) {
|
||||
*write(sizeof val) = val;
|
||||
}
|
||||
return !error_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool codeUint8(const EnumSet<T>& val) {
|
||||
return codeUint8(val.serialize());
|
||||
}
|
||||
|
||||
bool codeUint16(const uint16_t& val) {
|
||||
if (checkCapacity(sizeof val)) {
|
||||
LittleEndian::writeUint16(write(sizeof val), val);
|
||||
}
|
||||
return !error_;
|
||||
}
|
||||
|
||||
bool codeUint32(const uint32_t& val) {
|
||||
if (checkCapacity(sizeof val)) {
|
||||
LittleEndian::writeUint32(write(sizeof val), val);
|
||||
}
|
||||
return !error_;
|
||||
}
|
||||
|
||||
bool codeString(const nsCString& str) {
|
||||
uint16_t len = CheckedUint16(str.Length()).value();
|
||||
if (codeUint16(len)) {
|
||||
if (checkCapacity(len)) {
|
||||
memcpy(write(len), str.get(), len);
|
||||
}
|
||||
}
|
||||
return !error_;
|
||||
}
|
||||
|
||||
bool error() { return error_; }
|
||||
|
||||
bool finished() { return error_ || !remainingCapacity(); }
|
||||
|
||||
size_t remainingCapacity() { return data.length() - cursor_; }
|
||||
|
||||
size_t cursor() const { return cursor_; }
|
||||
|
||||
const uint8_t* Get() const { return data.begin().get(); }
|
||||
|
||||
private:
|
||||
bool checkCapacity(size_t size) {
|
||||
if (size > remainingCapacity()) {
|
||||
error_ = true;
|
||||
}
|
||||
return !error_;
|
||||
}
|
||||
|
||||
bool error_ = false;
|
||||
|
||||
public:
|
||||
Range<uint8_t>& data;
|
||||
size_t cursor_ = 0;
|
||||
};
|
||||
|
||||
class InputBuffer {
|
||||
public:
|
||||
explicit InputBuffer(const Range<uint8_t>& buffer) : data(buffer) {}
|
||||
|
|
|
@ -322,7 +322,7 @@ void URLPreloader::BackgroundReadFiles() {
|
|||
mReaderThread = nullptr;
|
||||
});
|
||||
|
||||
Vector<CacheAwareZipCursor> cursors;
|
||||
Vector<nsZipCursor> cursors;
|
||||
LinkedList<URLEntry> pendingURLs;
|
||||
{
|
||||
MonitorAutoLock mal(mMonitor);
|
||||
|
@ -352,14 +352,14 @@ void URLPreloader::BackgroundReadFiles() {
|
|||
continue;
|
||||
}
|
||||
|
||||
RefPtr<CacheAwareZipReader> zip = entry->Archive();
|
||||
RefPtr<nsZipArchive> zip = entry->Archive();
|
||||
if (!zip) {
|
||||
MOZ_CRASH_UNSAFE_PRINTF(
|
||||
"Failed to get Omnijar %s archive for entry (path: \"%s\")",
|
||||
entry->TypeString(), entry->mPath.get());
|
||||
}
|
||||
|
||||
auto* item = zip->GetItem(entry->mPath.get());
|
||||
auto item = zip->GetItem(entry->mPath.get());
|
||||
if (!item) {
|
||||
entry->mResultCode = NS_ERROR_FILE_NOT_FOUND;
|
||||
continue;
|
||||
|
@ -495,25 +495,25 @@ Result<const nsCString, nsresult> URLPreloader::ReadURIInternal(
|
|||
}
|
||||
|
||||
/* static */ Result<const nsCString, nsresult> URLPreloader::ReadZip(
|
||||
CacheAwareZipReader* archive, const nsACString& path, ReadType readType) {
|
||||
nsZipArchive* zip, const nsACString& path, ReadType readType) {
|
||||
// If the zip archive belongs to an Omnijar location, map it to a cache
|
||||
// entry, and cache it as normal. Otherwise, simply read the entry
|
||||
// synchronously, since other JAR archives are currently unsupported by the
|
||||
// cache.
|
||||
RefPtr<CacheAwareZipReader> reader = Omnijar::GetReader(Omnijar::GRE);
|
||||
if (reader == archive) {
|
||||
RefPtr<nsZipArchive> reader = Omnijar::GetReader(Omnijar::GRE);
|
||||
if (zip == reader) {
|
||||
CacheKey key(CacheKey::TypeGREJar, path);
|
||||
return Read(key, readType);
|
||||
}
|
||||
|
||||
reader = Omnijar::GetReader(Omnijar::APP);
|
||||
if (reader == archive) {
|
||||
if (zip == reader) {
|
||||
CacheKey key(CacheKey::TypeAppJar, path);
|
||||
return Read(key, readType);
|
||||
}
|
||||
|
||||
// Not an Omnijar archive, so just read it directly.
|
||||
FileLocation location(archive, PromiseFlatCString(path).BeginReading());
|
||||
FileLocation location(zip, PromiseFlatCString(path).BeginReading());
|
||||
return URLEntry::ReadLocation(location);
|
||||
}
|
||||
|
||||
|
@ -581,7 +581,7 @@ Result<FileLocation, nsresult> URLPreloader::CacheKey::ToFileLocation() {
|
|||
return FileLocation(file);
|
||||
}
|
||||
|
||||
RefPtr<CacheAwareZipReader> zip = Archive();
|
||||
RefPtr<nsZipArchive> zip = Archive();
|
||||
return FileLocation(zip, mPath.get());
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "nsIThread.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
class nsZipArchive;
|
||||
|
||||
namespace mozilla {
|
||||
namespace loader {
|
||||
class InputBuffer;
|
||||
|
@ -75,7 +77,7 @@ class URLPreloader final : public nsIObserver, public nsIMemoryReporter {
|
|||
static Result<const nsCString, nsresult> ReadFile(nsIFile* file,
|
||||
ReadType readType = Forget);
|
||||
|
||||
static Result<const nsCString, nsresult> ReadZip(CacheAwareZipReader* archive,
|
||||
static Result<const nsCString, nsresult> ReadZip(nsZipArchive* archive,
|
||||
const nsACString& path,
|
||||
ReadType readType = Forget);
|
||||
|
||||
|
@ -196,7 +198,7 @@ class URLPreloader final : public nsIObserver, public nsIMemoryReporter {
|
|||
return "";
|
||||
}
|
||||
|
||||
already_AddRefed<CacheAwareZipReader> Archive() {
|
||||
already_AddRefed<nsZipArchive> Archive() {
|
||||
return Omnijar::GetReader(OmnijarType());
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
#include "mozilla/scache/StartupCacheUtils.h"
|
||||
#include "mozilla/MacroForEach.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Omnijar.h"
|
||||
#include "mozilla/ResultExtensions.h"
|
||||
#include "mozilla/ScriptPreloader.h"
|
||||
#include "mozilla/ScopeExit.h"
|
||||
|
@ -671,10 +670,6 @@ JSObject* mozJSComponentLoader::PrepareObjectForLocation(
|
|||
|
||||
static mozilla::Result<nsCString, nsresult> ReadScript(
|
||||
ComponentLoaderInfo& aInfo) {
|
||||
// We're going to cache the XDR encoded script data - suspend writes via the
|
||||
// CacheAwareZipReader, otherwise we'll end up redundantly caching scripts.
|
||||
AutoSuspendStartupCacheWrites suspendScache;
|
||||
|
||||
MOZ_TRY(aInfo.EnsureScriptChannel());
|
||||
|
||||
nsCOMPtr<nsIInputStream> scriptStream;
|
||||
|
@ -736,15 +731,7 @@ nsresult mozJSComponentLoader::ObjectForLocation(
|
|||
// to loading the script, since we can always slow-load.
|
||||
|
||||
bool writeToCache = false;
|
||||
|
||||
// Since we are intending to cache these buffers in the script preloader
|
||||
// already, caching them in the StartupCache tends to be redundant. This
|
||||
// ought to be addressed, but as in bug 1627075 we extended the
|
||||
// StartupCache to be multi-process, we just didn't want to propagate
|
||||
// this problem into yet more processes, so we pretend the StartupCache
|
||||
// doesn't exist if we're not the parent process.
|
||||
StartupCache* cache =
|
||||
XRE_IsParentProcess() ? StartupCache::GetSingleton() : nullptr;
|
||||
StartupCache* cache = StartupCache::GetSingleton();
|
||||
|
||||
aInfo.EnsureResolvedURI();
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include "mozilla/ContentPrincipal.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
#include "mozilla/Omnijar.h"
|
||||
#include "mozilla/ScriptPreloader.h"
|
||||
#include "mozilla/SystemPrincipal.h"
|
||||
#include "mozilla/scache/StartupCache.h"
|
||||
|
@ -249,10 +248,6 @@ bool mozJSSubScriptLoader::ReadScript(JS::MutableHandle<JSScript*> script,
|
|||
const char* uriStr, nsIIOService* serv,
|
||||
bool wantReturnValue,
|
||||
bool useCompilationScope) {
|
||||
// We're going to cache the XDR encoded script data - suspend writes via the
|
||||
// CacheAwareZipReader, otherwise we'll end up redundantly caching scripts.
|
||||
AutoSuspendStartupCacheWrites suspendScache;
|
||||
|
||||
// We create a channel and call SetContentType, to avoid expensive MIME type
|
||||
// lookups (bug 632490).
|
||||
nsCOMPtr<nsIChannel> chan;
|
||||
|
@ -455,15 +450,7 @@ nsresult mozJSSubScriptLoader::DoLoadSubScriptWithOptions(
|
|||
bool ignoreCache =
|
||||
options.ignoreCache || !isSystem || scheme.EqualsLiteral("blob");
|
||||
|
||||
// Since we are intending to cache these buffers in the script preloader
|
||||
// already, caching them in the StartupCache tends to be redundant. This
|
||||
// ought to be addressed, but as in bug 1627075 we extended the
|
||||
// StartupCache to be multi-process, we just didn't want to propagate
|
||||
// this problem into yet more processes, so we pretend the StartupCache
|
||||
// doesn't exist if we're not the parent process.
|
||||
StartupCache* cache = (ignoreCache || !XRE_IsParentProcess())
|
||||
? nullptr
|
||||
: StartupCache::GetSingleton();
|
||||
StartupCache* cache = ignoreCache ? nullptr : StartupCache::GetSingleton();
|
||||
|
||||
nsAutoCString cachePath;
|
||||
SubscriptCachePath(cx, uri, targetObj, cachePath);
|
||||
|
|
|
@ -26,7 +26,7 @@ using namespace mozilla;
|
|||
|
||||
// The following initialization makes a guess of 10 entries per jarfile.
|
||||
nsJAR::nsJAR()
|
||||
: mZip(nullptr),
|
||||
: mZip(new nsZipArchive()),
|
||||
mReleaseTime(PR_INTERVAL_NO_TIMEOUT),
|
||||
mCache(nullptr),
|
||||
mLock("nsJAR::mLock"),
|
||||
|
@ -87,13 +87,12 @@ nsJAR::Open(nsIFile* zipFile) {
|
|||
|
||||
// The omnijar is special, it is opened early on and closed late
|
||||
// this avoids reopening it
|
||||
RefPtr<CacheAwareZipReader> zip = mozilla::Omnijar::GetReader(zipFile);
|
||||
RefPtr<nsZipArchive> zip = mozilla::Omnijar::GetReader(zipFile);
|
||||
if (zip) {
|
||||
mZip = zip;
|
||||
mSkipArchiveClosing = true;
|
||||
return NS_OK;
|
||||
}
|
||||
mZip = new CacheAwareZipReader();
|
||||
return mZip->OpenArchive(zipFile);
|
||||
}
|
||||
|
||||
|
@ -103,7 +102,7 @@ nsJAR::OpenInner(nsIZipReader* aZipReader, const nsACString& aZipEntry) {
|
|||
if (mOpened) return NS_ERROR_FAILURE; // Already open!
|
||||
|
||||
nsJAR* outerJAR = static_cast<nsJAR*>(aZipReader);
|
||||
RefPtr<CacheAwareZipReader> innerZip =
|
||||
RefPtr<nsZipArchive> innerZip =
|
||||
mozilla::Omnijar::GetInnerReader(outerJAR->mZipFile, aZipEntry);
|
||||
if (innerZip) {
|
||||
mOpened = true;
|
||||
|
@ -125,12 +124,11 @@ nsJAR::OpenInner(nsIZipReader* aZipReader, const nsACString& aZipEntry) {
|
|||
mOuterZipEntry.Assign(aZipEntry);
|
||||
|
||||
RefPtr<nsZipHandle> handle;
|
||||
rv = nsZipHandle::Init(static_cast<nsJAR*>(aZipReader)->mZip->GetZipArchive(),
|
||||
rv = nsZipHandle::Init(static_cast<nsJAR*>(aZipReader)->mZip.get(),
|
||||
PromiseFlatCString(aZipEntry).get(),
|
||||
getter_AddRefs(handle));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mZip = new CacheAwareZipReader();
|
||||
return mZip->OpenArchive(handle);
|
||||
}
|
||||
|
||||
|
@ -146,7 +144,6 @@ nsJAR::OpenMemory(void* aData, uint32_t aLength) {
|
|||
getter_AddRefs(handle));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mZip = new CacheAwareZipReader();
|
||||
return mZip->OpenArchive(handle);
|
||||
}
|
||||
|
||||
|
@ -168,7 +165,7 @@ nsJAR::Close() {
|
|||
if (mSkipArchiveClosing) {
|
||||
// Reset state, but don't close the omnijar because we did not open it.
|
||||
mSkipArchiveClosing = false;
|
||||
mZip = nullptr;
|
||||
mZip = new nsZipArchive();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -304,7 +301,7 @@ nsresult nsJAR::GetNSPRFileDesc(PRFileDesc** aNSPRFileDesc) {
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
RefPtr<nsZipHandle> handle = mZip->GetZipArchive()->GetFD();
|
||||
RefPtr<nsZipHandle> handle = mZip->GetFD();
|
||||
if (!handle) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
|
@ -23,17 +23,13 @@
|
|||
#include "nsRefPtrHashtable.h"
|
||||
#include "nsTHashtable.h"
|
||||
#include "nsIZipReader.h"
|
||||
#include "nsZipArchive.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsZipArchive.h"
|
||||
|
||||
class nsZipReaderCache;
|
||||
|
||||
namespace mozilla {
|
||||
class CacheAwareZipReader;
|
||||
} // namespace mozilla
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Class nsJAR declaration.
|
||||
* nsJAR serves as an XPCOM wrapper for nsZipArchive with the addition of
|
||||
|
@ -76,9 +72,9 @@ class nsJAR final : public nsIZipReader {
|
|||
|
||||
protected:
|
||||
//-- Private data members
|
||||
nsCOMPtr<nsIFile> mZipFile; // The zip/jar file on disk
|
||||
nsCString mOuterZipEntry; // The entry in the zip this zip is reading from
|
||||
RefPtr<mozilla::CacheAwareZipReader> mZip; // The underlying zip archive
|
||||
nsCOMPtr<nsIFile> mZipFile; // The zip/jar file on disk
|
||||
nsCString mOuterZipEntry; // The entry in the zip this zip is reading from
|
||||
RefPtr<nsZipArchive> mZip; // The underlying zip archive
|
||||
PRIntervalTime mReleaseTime; // used by nsZipReaderCache for flushing entries
|
||||
nsZipReaderCache*
|
||||
mCache; // if cached, this points to the cache it's contained in
|
||||
|
|
|
@ -67,15 +67,8 @@ nsresult nsJARInputStream::InitFile(nsJAR* aJar, nsZipItem* item) {
|
|||
|
||||
// Must keep handle to filepointer and mmap structure as long as we need
|
||||
// access to the mmapped data
|
||||
rv = aJar->mZip->GetPersistentHandle(item, &mItemHandle,
|
||||
CacheAwareZipReader::DeferCaching);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
mZs.next_in =
|
||||
(Bytef*)aJar->mZip->GetData(item, CacheAwareZipReader::DeferCaching);
|
||||
|
||||
mFd = aJar->mZip->GetFD();
|
||||
mZs.next_in = (Bytef*)aJar->mZip->GetData(item);
|
||||
if (!mZs.next_in) {
|
||||
return NS_ERROR_FILE_CORRUPTED;
|
||||
}
|
||||
|
@ -199,7 +192,7 @@ nsJARInputStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aBytesRead) {
|
|||
*aBytesRead = 0;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
MMAP_FAULT_HANDLER_BEGIN_HANDLE(mItemHandle.UnderlyingFD())
|
||||
MMAP_FAULT_HANDLER_BEGIN_HANDLE(mFd)
|
||||
switch (mMode) {
|
||||
case MODE_NOTINITED:
|
||||
return NS_OK;
|
||||
|
@ -218,15 +211,15 @@ nsJARInputStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aBytesRead) {
|
|||
rv = ContinueInflate(aBuffer, aCount, aBytesRead);
|
||||
}
|
||||
// be aggressive about releasing the file!
|
||||
// note that sometimes, we will release mItemHandle before we've finished
|
||||
// note that sometimes, we will release mFd before we've finished
|
||||
// deflating - this is because zlib buffers the input
|
||||
if (mZs.avail_in == 0) {
|
||||
mItemHandle.ReleaseHandle();
|
||||
mFd = nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_COPY:
|
||||
if (mItemHandle) {
|
||||
if (mFd) {
|
||||
uint32_t count = std::min(aCount, mOutSize - uint32_t(mZs.total_out));
|
||||
if (count) {
|
||||
memcpy(aBuffer, mZs.next_in + mZs.total_out, count);
|
||||
|
@ -235,10 +228,9 @@ nsJARInputStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aBytesRead) {
|
|||
*aBytesRead = count;
|
||||
}
|
||||
// be aggressive about releasing the file!
|
||||
// note that sometimes, we will release mItemHandle before we've finished
|
||||
// copying.
|
||||
// note that sometimes, we will release mFd before we've finished copying.
|
||||
if (mZs.total_out >= mOutSize) {
|
||||
mItemHandle.ReleaseHandle();
|
||||
mFd = nullptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -270,7 +262,7 @@ nsJARInputStream::Close() {
|
|||
}
|
||||
#endif
|
||||
mMode = MODE_CLOSED;
|
||||
mItemHandle.ReleaseHandle();
|
||||
mFd = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "nsJAR.h"
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Omnijar.h"
|
||||
|
||||
#ifdef MOZ_JAR_BROTLI
|
||||
struct BrotliDecoderStateStruct;
|
||||
|
@ -52,11 +51,11 @@ class nsJARInputStream final : public nsIInputStream {
|
|||
private:
|
||||
~nsJARInputStream() { Close(); }
|
||||
|
||||
mozilla::CacheAwareZipHandle mItemHandle; // handle for reading
|
||||
uint32_t mOutSize; // inflated size
|
||||
uint32_t mInCrc; // CRC as provided by the zipentry
|
||||
uint32_t mOutCrc; // CRC as calculated by me
|
||||
z_stream mZs; // zip data structure
|
||||
RefPtr<nsZipHandle> mFd; // handle for reading
|
||||
uint32_t mOutSize; // inflated size
|
||||
uint32_t mInCrc; // CRC as provided by the zipentry
|
||||
uint32_t mOutCrc; // CRC as calculated by me
|
||||
z_stream mZs; // zip data structure
|
||||
#ifdef MOZ_JAR_BROTLI
|
||||
BrotliDecoderStateStruct* mBrotliState; // Brotli decoder state
|
||||
#endif
|
||||
|
|
|
@ -341,21 +341,11 @@ nsZipHandle::~nsZipHandle() {
|
|||
//---------------------------------------------
|
||||
// nsZipArchive::OpenArchive
|
||||
//---------------------------------------------
|
||||
nsresult nsZipArchive::OpenArchive(nsZipHandle* aZipHandle, PRFileDesc* aFd,
|
||||
Span<const uint8_t> aCachedCentral) {
|
||||
nsresult nsZipArchive::OpenArchive(nsZipHandle* aZipHandle, PRFileDesc* aFd) {
|
||||
mFd = aZipHandle;
|
||||
|
||||
//-- get table of contents for archive
|
||||
nsresult rv = NS_OK;
|
||||
if (!mBuiltFileList) {
|
||||
if (!aCachedCentral.IsEmpty()) {
|
||||
auto* start = aCachedCentral.Elements();
|
||||
auto* end = start + aCachedCentral.Length();
|
||||
rv = BuildFileListFromBuffer(start, end);
|
||||
} else {
|
||||
rv = BuildFileList(aFd);
|
||||
}
|
||||
}
|
||||
nsresult rv = BuildFileList(aFd);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (aZipHandle->mFile && XRE_IsParentProcess()) {
|
||||
static char* env = PR_GetEnv("MOZ_JAR_LOG_FILE");
|
||||
|
@ -409,8 +399,7 @@ nsresult nsZipArchive::OpenArchive(nsZipHandle* aZipHandle, PRFileDesc* aFd,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsZipArchive::OpenArchive(nsIFile* aFile,
|
||||
Span<const uint8_t> aCachedCentral) {
|
||||
nsresult nsZipArchive::OpenArchive(nsIFile* aFile) {
|
||||
RefPtr<nsZipHandle> handle;
|
||||
#if defined(XP_WIN)
|
||||
mozilla::AutoFDClose fd;
|
||||
|
@ -421,9 +410,9 @@ nsresult nsZipArchive::OpenArchive(nsIFile* aFile,
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
#if defined(XP_WIN)
|
||||
return OpenArchive(handle, fd.get(), aCachedCentral);
|
||||
return OpenArchive(handle, fd.get());
|
||||
#else
|
||||
return OpenArchive(handle, nullptr, aCachedCentral);
|
||||
return OpenArchive(handle);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -473,75 +462,13 @@ nsresult nsZipArchive::CloseArchive() {
|
|||
// Let us also cleanup the mFiles table for re-use on the next 'open' call
|
||||
memset(mFiles, 0, sizeof(mFiles));
|
||||
mBuiltSynthetics = false;
|
||||
|
||||
AutoWriteLock lock(mLazyOpenLock);
|
||||
mLazyOpenParams = Nothing();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsZipArchive::EnsureArchiveOpenedOnDisk() {
|
||||
{
|
||||
AutoReadLock lock(mLazyOpenLock);
|
||||
if (!mLazyOpenParams) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
AutoWriteLock lock(mLazyOpenLock);
|
||||
if (!mLazyOpenParams) {
|
||||
// Another thread beat us to opening the archive while we were waiting on
|
||||
// the mutex.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = OpenArchive(mLazyOpenParams->mFile);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
mLazyOpenParams = Nothing();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsZipArchive::EnsureFileListBuilt() {
|
||||
{
|
||||
AutoReadLock lock(mLazyOpenLock);
|
||||
if (!mLazyOpenParams || mBuiltFileList) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
AutoWriteLock lock(mLazyOpenLock);
|
||||
if (!mLazyOpenParams || mBuiltFileList) {
|
||||
// Another thread beat us to building the file list while we were waiting
|
||||
// on the mutex.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
if (!mLazyOpenParams->mCachedCentral.IsEmpty()) {
|
||||
auto* start = mLazyOpenParams->mCachedCentral.Elements();
|
||||
auto* end = start + mLazyOpenParams->mCachedCentral.Length();
|
||||
rv = BuildFileListFromBuffer(start, end);
|
||||
} else {
|
||||
rv = OpenArchive(mLazyOpenParams->mFile);
|
||||
mLazyOpenParams = Nothing();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
// nsZipArchive::GetItem
|
||||
//---------------------------------------------
|
||||
nsZipItem* nsZipArchive::GetItem(const char* aEntryName) {
|
||||
nsresult rv = EnsureFileListBuilt();
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (aEntryName) {
|
||||
uint32_t len = strlen(aEntryName);
|
||||
//-- If the request is for a directory, make sure that synthetic entries
|
||||
|
@ -625,12 +552,6 @@ nsresult nsZipArchive::ExtractFile(nsZipItem* item, nsIFile* outFile,
|
|||
nsresult nsZipArchive::FindInit(const char* aPattern, nsZipFind** aFind) {
|
||||
if (!aFind) return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
nsresult rv = EnsureFileListBuilt();
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// null out param in case an error happens
|
||||
*aFind = nullptr;
|
||||
|
||||
|
@ -638,7 +559,7 @@ nsresult nsZipArchive::FindInit(const char* aPattern, nsZipFind** aFind) {
|
|||
char* pattern = 0;
|
||||
|
||||
// Create synthetic directory entries on demand
|
||||
rv = BuildSynthetics();
|
||||
nsresult rv = BuildSynthetics();
|
||||
if (rv != NS_OK) return rv;
|
||||
|
||||
// validate the pattern
|
||||
|
@ -682,12 +603,7 @@ nsresult nsZipFind::FindNext(const char** aResult, uint16_t* aNameLen) {
|
|||
|
||||
*aResult = 0;
|
||||
*aNameLen = 0;
|
||||
|
||||
// NOTE: don't use GetFD here. if mFd is not null, then we need to have this
|
||||
// fault handler, as we may be reading from the memory mapped file. However
|
||||
// if it is null, then we can guarantee that we're reading here from a cached
|
||||
// buffer, which we assume is not mapped to a file.
|
||||
MMAP_FAULT_HANDLER_BEGIN_HANDLE(mArchive->mFd)
|
||||
MMAP_FAULT_HANDLER_BEGIN_HANDLE(mArchive->GetFD())
|
||||
// we start from last match, look for next
|
||||
while (mSlot < ZIP_TABSIZE) {
|
||||
// move to next in current chain, or move to new slot
|
||||
|
@ -733,13 +649,10 @@ nsZipItem* nsZipArchive::CreateZipItem() {
|
|||
// nsZipArchive::BuildFileList
|
||||
//---------------------------------------------
|
||||
nsresult nsZipArchive::BuildFileList(PRFileDesc* aFd) {
|
||||
mBuiltFileList = true;
|
||||
// Get archive size using end pos
|
||||
const uint8_t* buf;
|
||||
const uint8_t* startp = mFd->mFileData;
|
||||
const uint8_t* endp = startp + mFd->mLen;
|
||||
|
||||
nsresult rv;
|
||||
MMAP_FAULT_HANDLER_BEGIN_HANDLE(mFd)
|
||||
uint32_t centralOffset = 4;
|
||||
// Only perform readahead in the parent process. Children processes
|
||||
|
@ -764,63 +677,20 @@ nsresult nsZipArchive::BuildFileList(PRFileDesc* aFd) {
|
|||
return NS_ERROR_FILE_CORRUPTED;
|
||||
}
|
||||
|
||||
uintptr_t startpInt = reinterpret_cast<uintptr_t>(startp);
|
||||
if (startpInt + centralOffset < startpInt || centralOffset > mFd->mLen) {
|
||||
buf = startp + centralOffset;
|
||||
|
||||
// avoid overflow of startp + centralOffset.
|
||||
if (buf < startp) {
|
||||
return NS_ERROR_FILE_CORRUPTED;
|
||||
}
|
||||
|
||||
buf = startp + centralOffset;
|
||||
|
||||
mZipCentralOffset = centralOffset;
|
||||
rv = BuildFileListFromBuffer(buf, endp);
|
||||
|
||||
MMAP_FAULT_HANDLER_CATCH(NS_ERROR_FAILURE)
|
||||
return rv;
|
||||
}
|
||||
|
||||
UniquePtr<uint8_t[]> nsZipArchive::CopyCentralDirectoryBuffer(size_t* aSize) {
|
||||
*aSize = 0;
|
||||
|
||||
// mZipCentralOffset could in theory be 0. In practice though, we likely
|
||||
// won't ever see this. If the end result is that we can't cache the buffer
|
||||
// in these cases, that's fine.
|
||||
if (!mZipCentralOffset || !mZipCentralSize) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const uint8_t* buf;
|
||||
const uint8_t* startp = mFd->mFileData;
|
||||
buf = startp + mZipCentralOffset;
|
||||
|
||||
// Just a sanity check to make sure these values haven't overflowed the
|
||||
// buffer mapped to our file. Technically the pointer could overflow the max
|
||||
// pointer value, but that could only happen with this check succeeding if
|
||||
// mFd->mLen is incorrect, which we will here assume is impossible.
|
||||
if (mZipCentralOffset + mZipCentralSize > mFd->mLen) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto resultBuf = MakeUnique<uint8_t[]>(mZipCentralSize);
|
||||
|
||||
MMAP_FAULT_HANDLER_BEGIN_HANDLE(mFd)
|
||||
memcpy(resultBuf.get(), buf, mZipCentralSize);
|
||||
MMAP_FAULT_HANDLER_CATCH(nullptr)
|
||||
|
||||
*aSize = mZipCentralSize;
|
||||
return resultBuf;
|
||||
}
|
||||
|
||||
nsresult nsZipArchive::BuildFileListFromBuffer(const uint8_t* aBuf,
|
||||
const uint8_t* aEnd) {
|
||||
mBuiltFileList = true;
|
||||
const uint8_t* buf = aBuf;
|
||||
//-- Read the central directory headers
|
||||
uint32_t sig = 0;
|
||||
while ((buf + int32_t(sizeof(uint32_t)) > buf) &&
|
||||
(buf + int32_t(sizeof(uint32_t)) <= aEnd) &&
|
||||
(buf + int32_t(sizeof(uint32_t)) <= endp) &&
|
||||
((sig = xtolong(buf)) == CENTRALSIG)) {
|
||||
// Make sure there is enough data available.
|
||||
if ((buf > aEnd) || (aEnd - buf < ZIPCENTRAL_SIZE)) {
|
||||
if ((buf > endp) || (endp - buf < ZIPCENTRAL_SIZE)) {
|
||||
return NS_ERROR_FILE_CORRUPTED;
|
||||
}
|
||||
|
||||
|
@ -838,7 +708,7 @@ nsresult nsZipArchive::BuildFileListFromBuffer(const uint8_t* aBuf,
|
|||
return NS_ERROR_FILE_CORRUPTED;
|
||||
}
|
||||
if (buf >= buf + diff || // No overflow
|
||||
buf >= aEnd - diff) {
|
||||
buf >= endp - diff) {
|
||||
return NS_ERROR_FILE_CORRUPTED;
|
||||
}
|
||||
|
||||
|
@ -865,18 +735,18 @@ nsresult nsZipArchive::BuildFileListFromBuffer(const uint8_t* aBuf,
|
|||
}
|
||||
|
||||
// Make the comment available for consumers.
|
||||
if ((aEnd >= buf) && (aEnd - buf >= ZIPEND_SIZE)) {
|
||||
if ((endp >= buf) && (endp - buf >= ZIPEND_SIZE)) {
|
||||
ZipEnd* zipend = (ZipEnd*)buf;
|
||||
|
||||
buf += ZIPEND_SIZE;
|
||||
uint16_t commentlen = xtoint(zipend->commentfield_len);
|
||||
if (aEnd - buf >= commentlen) {
|
||||
mCommentPtr = (const char*)aBuf;
|
||||
if (endp - buf >= commentlen) {
|
||||
mCommentPtr = (const char*)buf;
|
||||
mCommentLen = commentlen;
|
||||
}
|
||||
}
|
||||
|
||||
mZipCentralSize = buf - aBuf;
|
||||
MMAP_FAULT_HANDLER_CATCH(NS_ERROR_FAILURE)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -946,64 +816,15 @@ nsresult nsZipArchive::BuildSynthetics() {
|
|||
}
|
||||
|
||||
nsZipHandle* nsZipArchive::GetFD() {
|
||||
nsresult rv = EnsureArchiveOpenedOnDisk();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!mFd) return nullptr;
|
||||
return mFd.get();
|
||||
}
|
||||
|
||||
void nsZipArchive::GetURIString(nsACString& result) {
|
||||
{
|
||||
AutoReadLock lock(mLazyOpenLock);
|
||||
if (!mLazyOpenParams) {
|
||||
mFd->mFile.GetURIString(result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
AutoReadLock lock(mLazyOpenLock);
|
||||
if (!mLazyOpenParams) {
|
||||
// Another thread consumed mLazyOpenParams while we were waiting.
|
||||
mFd->mFile.GetURIString(result);
|
||||
return;
|
||||
}
|
||||
|
||||
// This is a bit tricky - typically, we could just
|
||||
// NS_GetURLSpecFromActualFile from mLazyOpenParams->mFile or from
|
||||
// mFd->mFile.GetBaseFile(), depending on which we currently have. However,
|
||||
// this won't actually be correct if this zip archive is nested inside
|
||||
// another archive. However, at present, we know that mLazyOpenParams can
|
||||
// only be here if we were opened from a real underlying file, so we assume
|
||||
// that we're safe to do this. Any future code that breaks this assumption
|
||||
// will need to update things here.
|
||||
NS_GetURLSpecFromActualFile(mLazyOpenParams->mFile, result);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIFile> nsZipArchive::GetBaseFile() {
|
||||
{
|
||||
AutoReadLock lock(mLazyOpenLock);
|
||||
if (!mLazyOpenParams) {
|
||||
return mFd->mFile.GetBaseFile();
|
||||
}
|
||||
}
|
||||
AutoReadLock lock(mLazyOpenLock);
|
||||
if (!mLazyOpenParams) {
|
||||
// Another thread consumed mLazyOpenParams while we were waiting.
|
||||
return mFd->mFile.GetBaseFile();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> file = mLazyOpenParams->mFile;
|
||||
return file.forget();
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
// nsZipArchive::GetDataOffset
|
||||
//---------------------------------------------
|
||||
uint32_t nsZipArchive::GetDataOffset(nsZipItem* aItem) {
|
||||
MOZ_ASSERT(aItem);
|
||||
nsresult rv = EnsureArchiveOpenedOnDisk();
|
||||
MOZ_RELEASE_ASSERT(!NS_FAILED(rv),
|
||||
"Should have been able to open the zip archive");
|
||||
|
||||
uint32_t offset;
|
||||
MMAP_FAULT_HANDLER_BEGIN_HANDLE(mFd)
|
||||
|
@ -1034,10 +855,6 @@ uint32_t nsZipArchive::GetDataOffset(nsZipItem* aItem) {
|
|||
//---------------------------------------------
|
||||
const uint8_t* nsZipArchive::GetData(nsZipItem* aItem) {
|
||||
MOZ_ASSERT(aItem);
|
||||
nsresult rv = EnsureArchiveOpenedOnDisk();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t offset = GetDataOffset(aItem);
|
||||
|
||||
MMAP_FAULT_HANDLER_BEGIN_HANDLE(mFd)
|
||||
|
@ -1072,12 +889,8 @@ int64_t nsZipArchive::SizeOfMapping() { return mFd ? mFd->SizeOfMapping() : 0; }
|
|||
nsZipArchive::nsZipArchive()
|
||||
: mRefCnt(0),
|
||||
mCommentPtr(nullptr),
|
||||
mZipCentralOffset(0),
|
||||
mZipCentralSize(0),
|
||||
mCommentLen(0),
|
||||
mBuiltSynthetics(false),
|
||||
mBuiltFileList(false),
|
||||
mLazyOpenLock("nsZipArchive::mLazyOpenLock"),
|
||||
mUseZipLog(false) {
|
||||
// initialize the table to nullptr
|
||||
memset(mFiles, 0, sizeof(mFiles));
|
||||
|
@ -1385,14 +1198,12 @@ uint8_t* nsZipCursor::ReadOrCopy(uint32_t* aBytesRead, bool aCopy) {
|
|||
nsZipItemPtr_base::nsZipItemPtr_base(nsZipArchive* aZip, const char* aEntryName,
|
||||
bool doCRC)
|
||||
: mReturnBuf(nullptr), mReadlen(0) {
|
||||
nsZipItem* item = aZip->GetItem(aEntryName);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the ziparchive hangs around
|
||||
mZipHandle = aZip->GetFD();
|
||||
|
||||
nsZipItem* item = aZip->GetItem(aEntryName);
|
||||
if (!item) return;
|
||||
|
||||
uint32_t size = 0;
|
||||
bool compressed = (item->Compression() == DEFLATED);
|
||||
#ifdef MOZ_JAR_BROTLI
|
||||
|
|
|
@ -17,11 +17,9 @@
|
|||
#include "nsIFile.h"
|
||||
#include "nsISupportsImpl.h" // For mozilla::ThreadSafeAutoRefCnt
|
||||
#include "mozilla/ArenaAllocator.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "mozilla/FileLocation.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/RWLock.h"
|
||||
|
||||
class nsZipFind;
|
||||
struct PRFileDesc;
|
||||
|
@ -86,22 +84,6 @@ class nsZipArchive final {
|
|||
/** destructing the object closes the archive */
|
||||
~nsZipArchive();
|
||||
|
||||
/**
|
||||
* LazyOpenArchiveParams is a class which is used to store cached
|
||||
* contents of omnijars.
|
||||
*
|
||||
*/
|
||||
struct LazyOpenArchiveParams {
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
mozilla::Span<const uint8_t> mCachedCentral;
|
||||
|
||||
LazyOpenArchiveParams(nsIFile* aFile,
|
||||
mozilla::Span<const uint8_t> aCachedCentral)
|
||||
: mFile(nullptr), mCachedCentral(aCachedCentral) {
|
||||
aFile->Clone(getter_AddRefs(mFile));
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
static const char* sFileCorruptedReason;
|
||||
|
||||
|
@ -115,16 +97,11 @@ class nsZipArchive final {
|
|||
* object. If we were allowed to use exceptions this would have been
|
||||
* part of the constructor
|
||||
*
|
||||
* @param aZipHandle The nsZipHandle used to access the zip
|
||||
* @param aFd Optional PRFileDesc for Windows readahead
|
||||
optimization
|
||||
* @param aCachedCentral Optional cached buffer containing the zip central
|
||||
for this zip.
|
||||
* @param aZipHandle The nsZipHandle used to access the zip
|
||||
* @param aFd Optional PRFileDesc for Windows readahead optimization
|
||||
* @return status code
|
||||
*/
|
||||
nsresult OpenArchive(nsZipHandle* aZipHandle, PRFileDesc* aFd = nullptr,
|
||||
mozilla::Span<const uint8_t> aCachedCentral =
|
||||
mozilla::Span<const uint8_t>());
|
||||
nsresult OpenArchive(nsZipHandle* aZipHandle, PRFileDesc* aFd = nullptr);
|
||||
|
||||
/**
|
||||
* OpenArchive
|
||||
|
@ -132,46 +109,9 @@ class nsZipArchive final {
|
|||
* Convenience function that generates nsZipHandle
|
||||
*
|
||||
* @param aFile The file used to access the zip
|
||||
* @param aCachedCentral Optional cached buffer containing the zip central
|
||||
for this zip.
|
||||
* @return status code
|
||||
*/
|
||||
nsresult OpenArchive(nsIFile* aFile,
|
||||
mozilla::Span<const uint8_t> aCachedCentral =
|
||||
mozilla::Span<const uint8_t>());
|
||||
|
||||
/**
|
||||
* Ensures underlying archive is opened, if it was opened with
|
||||
* LazyOpenArchive.
|
||||
*
|
||||
* Convenience function that generates nsZipHandle
|
||||
*
|
||||
* @param aFile The file used to access the zip
|
||||
* @return status code
|
||||
*/
|
||||
nsresult EnsureArchiveOpenedOnDisk();
|
||||
|
||||
/**
|
||||
* OpenArchive
|
||||
*
|
||||
* Lazily opens the zip archive on the first request to get data from it.
|
||||
* NOTE: The buffer provided for aCachedCentral must outlive this
|
||||
* nsZipArchive. This is presently true for the StartupCache, as it ensures
|
||||
* that even past cache invalidation, all accessed buffers persist for the
|
||||
* lifetime of the application, but we will need to ensure that this remains
|
||||
* true.
|
||||
*
|
||||
* @param aFile The file used to access the zip
|
||||
* @param aCachedCentral Cached buffer containing the zip central
|
||||
for this zip.
|
||||
* @return status code
|
||||
*/
|
||||
nsresult LazyOpenArchive(nsIFile* aFile,
|
||||
mozilla::Span<const uint8_t> aCachedCentral) {
|
||||
mozilla::AutoWriteLock lock(mLazyOpenLock);
|
||||
mLazyOpenParams.emplace(aFile, aCachedCentral);
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult OpenArchive(nsIFile* aFile);
|
||||
|
||||
/**
|
||||
* Test the integrity of items in this archive by running
|
||||
|
@ -227,21 +167,6 @@ class nsZipArchive final {
|
|||
*/
|
||||
nsZipHandle* GetFD();
|
||||
|
||||
/*
|
||||
* Gets the URI string to the mapped file. One could get this URI string
|
||||
* in a roundabout way using GetFD, but GetFD requires opening the file for
|
||||
* read access, which can be expensive.
|
||||
*/
|
||||
void GetURIString(nsACString& result);
|
||||
|
||||
/*
|
||||
* Gets the underlying nsIFile pointer. Like GetURIString, this is to be
|
||||
* preferred over GetFD where possible, because it does not require opening
|
||||
* the file for read access, which can be expensive, and is to be avoided
|
||||
* when possible during application startup.
|
||||
*/
|
||||
already_AddRefed<nsIFile> GetBaseFile();
|
||||
|
||||
/**
|
||||
* Gets the data offset.
|
||||
* @param aItem Pointer to nsZipItem
|
||||
|
@ -256,17 +181,6 @@ class nsZipArchive final {
|
|||
*/
|
||||
const uint8_t* GetData(nsZipItem* aItem);
|
||||
|
||||
/**
|
||||
* Copies the contents of the zip central directory, and returns it to the
|
||||
* caller to take ownership. This is useful for caching the contents of the
|
||||
* central directory, which can be compressed and stored elsewhere, and
|
||||
* passed back into OpenArchive when this archive is opened in the future.
|
||||
*
|
||||
* @param aSize size_t pointer to be filled with the size of the
|
||||
returned buffer.
|
||||
*/
|
||||
mozilla::UniquePtr<uint8_t[]> CopyCentralDirectoryBuffer(size_t* aSize);
|
||||
|
||||
bool GetComment(nsACString& aComment);
|
||||
|
||||
/**
|
||||
|
@ -290,20 +204,14 @@ class nsZipArchive final {
|
|||
mozilla::ArenaAllocator<1024, sizeof(void*)> mArena;
|
||||
|
||||
const char* mCommentPtr;
|
||||
size_t mZipCentralOffset;
|
||||
size_t mZipCentralSize;
|
||||
uint16_t mCommentLen;
|
||||
|
||||
// Whether we synthesized the directory entries
|
||||
bool mBuiltSynthetics;
|
||||
bool mBuiltFileList;
|
||||
|
||||
// file handle
|
||||
RefPtr<nsZipHandle> mFd;
|
||||
|
||||
mozilla::Maybe<LazyOpenArchiveParams> mLazyOpenParams;
|
||||
mozilla::RWLock mLazyOpenLock;
|
||||
|
||||
// file URI, for logging
|
||||
nsCString mURI;
|
||||
|
||||
|
@ -315,9 +223,7 @@ class nsZipArchive final {
|
|||
//--- private methods ---
|
||||
nsZipItem* CreateZipItem();
|
||||
nsresult BuildFileList(PRFileDesc* aFd = nullptr);
|
||||
nsresult BuildFileListFromBuffer(const uint8_t* aBuf, const uint8_t* aEnd);
|
||||
nsresult BuildSynthetics();
|
||||
nsresult EnsureFileListBuilt();
|
||||
|
||||
nsZipArchive& operator=(const nsZipArchive& rhs) = delete;
|
||||
nsZipArchive(const nsZipArchive& rhs) = delete;
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
#include "nsXPCOMCID.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "nsZipArchive.h"
|
||||
#include "plbase64.h"
|
||||
#include "PLDHashTable.h"
|
||||
#include "plstr.h"
|
||||
|
@ -4311,7 +4312,7 @@ static nsresult pref_LoadPrefsInDir(nsIFile* aDir,
|
|||
return rv;
|
||||
}
|
||||
|
||||
static nsresult pref_ReadPrefFromJar(CacheAwareZipReader* aJarReader,
|
||||
static nsresult pref_ReadPrefFromJar(nsZipArchive* aJarReader,
|
||||
const char* aName) {
|
||||
TimeStamp startTime = TimeStamp::Now();
|
||||
|
||||
|
@ -4328,8 +4329,8 @@ static nsresult pref_ReadPrefFromJar(CacheAwareZipReader* aJarReader,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult pref_ReadDefaultPrefs(
|
||||
const RefPtr<CacheAwareZipReader>& jarReader, const char* path) {
|
||||
static nsresult pref_ReadDefaultPrefs(const RefPtr<nsZipArchive> jarReader,
|
||||
const char* path) {
|
||||
UniquePtr<nsZipFind> find;
|
||||
nsTArray<nsCString> prefEntries;
|
||||
const char* entryName;
|
||||
|
@ -4508,7 +4509,7 @@ nsresult Preferences::InitInitialObjects(bool aIsStartup) {
|
|||
const char* entryName;
|
||||
uint16_t entryNameLen;
|
||||
|
||||
RefPtr<CacheAwareZipReader> jarReader = Omnijar::GetReader(Omnijar::GRE);
|
||||
RefPtr<nsZipArchive> jarReader = Omnijar::GetReader(Omnijar::GRE);
|
||||
if (jarReader) {
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
// Try to load an architecture-specific greprefs.js first. This will be
|
||||
|
@ -4590,7 +4591,7 @@ nsresult Preferences::InitInitialObjects(bool aIsStartup) {
|
|||
|
||||
// Load jar:$app/omni.jar!/defaults/preferences/*.js
|
||||
// or jar:$gre/omni.jar!/defaults/preferences/*.js.
|
||||
RefPtr<CacheAwareZipReader> appJarReader = Omnijar::GetReader(Omnijar::APP);
|
||||
RefPtr<nsZipArchive> appJarReader = Omnijar::GetReader(Omnijar::APP);
|
||||
|
||||
// GetReader(Omnijar::APP) returns null when `$app == $gre`, in
|
||||
// which case we look for app-specific default preferences in $gre.
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
|
||||
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
include protocol PContent;
|
||||
|
||||
using class mozilla::TimeStamp from "mozilla/TimeStamp.h";
|
||||
using mozilla::void_t from "ipc/IPCMessageUtils.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace scache {
|
||||
|
||||
struct EntryData {
|
||||
nsCString key;
|
||||
// This will be an empty array if data is present in the previous
|
||||
// session's cache.
|
||||
uint8_t[] data;
|
||||
};
|
||||
|
||||
protocol PStartupCache
|
||||
{
|
||||
manager PContent;
|
||||
|
||||
parent:
|
||||
async __delete__(EntryData[] entries);
|
||||
};
|
||||
|
||||
} // namespace scache
|
||||
} // namespace mozilla
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -22,13 +22,10 @@
|
|||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/AutoMemMap.h"
|
||||
#include "mozilla/Compression.h"
|
||||
#include "mozilla/EnumSet.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/Omnijar.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/UniquePtrExtensions.h"
|
||||
|
||||
/**
|
||||
* The StartupCache is a persistent cache of simple key-value pairs,
|
||||
|
@ -81,153 +78,47 @@
|
|||
*/
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class ContentParent;
|
||||
}
|
||||
namespace ipc {
|
||||
class GeckoChildProcessHost;
|
||||
} // namespace ipc
|
||||
|
||||
namespace scache {
|
||||
|
||||
class StartupCacheChild;
|
||||
|
||||
#ifdef XP_UNIX
|
||||
|
||||
// Please see bug 1440207 about improving the problem of random fixed FDs,
|
||||
// which the addition of the below constant exacerbates.
|
||||
static const int kStartupCacheFd = 11;
|
||||
#endif
|
||||
|
||||
// We use INT_MAX here just to simplify the sorting - we want to push
|
||||
// unrequested entries to the back, and have requested entries in the order
|
||||
// they came in.
|
||||
static const int kStartupCacheEntryNotRequested = INT_MAX;
|
||||
static const int kStartupcacheEntryNotInSharedData = -1;
|
||||
|
||||
// StartupCache entries can be backed by a buffer which they allocate as
|
||||
// soon as they are requested, into which they decompress the contents out
|
||||
// of the memory mapped file, *or* they can be backed by a contiguous buffer
|
||||
// which we allocate up front and decompress into, in order to share it with
|
||||
// child processes. This class is a helper class to hold a buffer which the
|
||||
// entry itself may or may not own.
|
||||
//
|
||||
// Side note: it may be appropriate for StartupCache entries to never own
|
||||
// their underlying buffers. We explicitly work to ensure that anything the
|
||||
// StartupCache returns to a caller survives for the lifetime of the
|
||||
// application, so it may be preferable to have a set of large contiguous
|
||||
// buffers which we allocate on demand, and fill up with cache entry contents,
|
||||
// but at that point we're basically implementing our own hacky pseudo-malloc,
|
||||
// for relatively uncertain performance gains. For the time being, we just
|
||||
// keep the existing model unchanged.
|
||||
class MaybeOwnedCharPtr {
|
||||
public:
|
||||
char* mPtr;
|
||||
bool mOwned;
|
||||
|
||||
~MaybeOwnedCharPtr() {
|
||||
if (mOwned) {
|
||||
delete[] mPtr;
|
||||
}
|
||||
}
|
||||
|
||||
MaybeOwnedCharPtr(const MaybeOwnedCharPtr& other);
|
||||
MaybeOwnedCharPtr& operator=(const MaybeOwnedCharPtr& other);
|
||||
|
||||
MaybeOwnedCharPtr(MaybeOwnedCharPtr&& other)
|
||||
: mPtr(std::exchange(other.mPtr, nullptr)),
|
||||
mOwned(std::exchange(other.mOwned, false)) {}
|
||||
|
||||
MaybeOwnedCharPtr& operator=(MaybeOwnedCharPtr&& other) {
|
||||
std::swap(mPtr, other.mPtr);
|
||||
std::swap(mOwned, other.mOwned);
|
||||
return *this;
|
||||
}
|
||||
|
||||
MaybeOwnedCharPtr& operator=(decltype(nullptr)) {
|
||||
mPtr = nullptr;
|
||||
mOwned = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
explicit operator bool() const { return !!mPtr; }
|
||||
|
||||
char* get() { return mPtr; }
|
||||
|
||||
explicit MaybeOwnedCharPtr(char* aBytes) : mPtr(aBytes), mOwned(false) {}
|
||||
|
||||
explicit MaybeOwnedCharPtr(UniquePtr<char[]>&& aBytes)
|
||||
: mPtr(aBytes.release()), mOwned(true) {}
|
||||
|
||||
explicit MaybeOwnedCharPtr(size_t size)
|
||||
: mPtr(new char[size]), mOwned(true) {}
|
||||
};
|
||||
|
||||
enum class StartupCacheEntryFlags {
|
||||
Shared,
|
||||
RequestedByChild,
|
||||
AddedThisSession,
|
||||
};
|
||||
|
||||
struct StartupCacheEntry {
|
||||
MaybeOwnedCharPtr mData;
|
||||
UniquePtr<char[]> mData;
|
||||
uint32_t mOffset;
|
||||
uint32_t mCompressedSize;
|
||||
uint32_t mUncompressedSize;
|
||||
int32_t mSharedDataOffset;
|
||||
int32_t mHeaderOffsetInFile;
|
||||
int32_t mRequestedOrder;
|
||||
EnumSet<StartupCacheEntryFlags> mFlags;
|
||||
bool mRequested;
|
||||
|
||||
MOZ_IMPLICIT StartupCacheEntry(uint32_t aOffset, uint32_t aCompressedSize,
|
||||
uint32_t aUncompressedSize,
|
||||
EnumSet<StartupCacheEntryFlags> aFlags)
|
||||
uint32_t aUncompressedSize)
|
||||
: mData(nullptr),
|
||||
mOffset(aOffset),
|
||||
mCompressedSize(aCompressedSize),
|
||||
mUncompressedSize(aUncompressedSize),
|
||||
mSharedDataOffset(kStartupcacheEntryNotInSharedData),
|
||||
mHeaderOffsetInFile(0),
|
||||
mRequestedOrder(kStartupCacheEntryNotRequested),
|
||||
mFlags(aFlags) {}
|
||||
mRequestedOrder(0),
|
||||
mRequested(false) {}
|
||||
|
||||
StartupCacheEntry(UniquePtr<char[]> aData, size_t aLength,
|
||||
int32_t aRequestedOrder,
|
||||
EnumSet<StartupCacheEntryFlags> aFlags)
|
||||
int32_t aRequestedOrder)
|
||||
: mData(std::move(aData)),
|
||||
mOffset(0),
|
||||
mCompressedSize(0),
|
||||
mUncompressedSize(aLength),
|
||||
mSharedDataOffset(kStartupcacheEntryNotInSharedData),
|
||||
mHeaderOffsetInFile(0),
|
||||
mRequestedOrder(aRequestedOrder),
|
||||
mFlags(aFlags) {}
|
||||
mRequestedOrder(0),
|
||||
mRequested(true) {}
|
||||
|
||||
struct Comparator {
|
||||
using Value = std::pair<const nsCString*, StartupCacheEntry*>;
|
||||
|
||||
bool Equals(const Value& a, const Value& b) const {
|
||||
// This is a bit ugly. Here and below, just note that we want entries
|
||||
// with the RequestedByChild flag to be sorted before any other entries,
|
||||
// because we're going to want to decompress them and send them down to
|
||||
// child processes pretty early during startup.
|
||||
return a.second->mFlags.contains(
|
||||
StartupCacheEntryFlags::RequestedByChild) ==
|
||||
b.second->mFlags.contains(
|
||||
StartupCacheEntryFlags::RequestedByChild) &&
|
||||
a.second->mRequestedOrder == b.second->mRequestedOrder;
|
||||
return a.second->mRequestedOrder == b.second->mRequestedOrder;
|
||||
}
|
||||
|
||||
bool LessThan(const Value& a, const Value& b) const {
|
||||
bool requestedByChildA =
|
||||
a.second->mFlags.contains(StartupCacheEntryFlags::RequestedByChild);
|
||||
bool requestedByChildB =
|
||||
b.second->mFlags.contains(StartupCacheEntryFlags::RequestedByChild);
|
||||
if (requestedByChildA == requestedByChildB) {
|
||||
return a.second->mRequestedOrder < b.second->mRequestedOrder;
|
||||
} else {
|
||||
return requestedByChildA;
|
||||
}
|
||||
return a.second->mRequestedOrder < b.second->mRequestedOrder;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -240,26 +131,10 @@ class StartupCacheListener final : public nsIObserver {
|
|||
NS_DECL_NSIOBSERVER
|
||||
};
|
||||
|
||||
// This mirrors a bit of logic in the script preloader. Basically, there's
|
||||
// certainly some overhead in child processes sending us lists of requested
|
||||
// startup cache items, so we want to limit that. Accordingly, we only
|
||||
// request to be notified of requested cache items for the first occurrence
|
||||
// of each process type, enumerated below.
|
||||
enum class ProcessType : uint8_t {
|
||||
Uninitialized,
|
||||
Parent,
|
||||
Web,
|
||||
Extension,
|
||||
PrivilegedAbout,
|
||||
};
|
||||
|
||||
class StartupCache : public nsIMemoryReporter {
|
||||
friend class StartupCacheListener;
|
||||
friend class StartupCacheChild;
|
||||
|
||||
public:
|
||||
using Table = HashMap<nsCString, StartupCacheEntry>;
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIMEMORYREPORTER
|
||||
|
||||
|
@ -272,10 +147,11 @@ class StartupCache : public nsIMemoryReporter {
|
|||
nsresult GetBuffer(const char* id, const char** outbuf, uint32_t* length);
|
||||
|
||||
// Stores a buffer. Caller yields ownership.
|
||||
nsresult PutBuffer(const char* id, UniquePtr<char[]>&& inbuf, uint32_t length,
|
||||
bool isFromChildProcess = false);
|
||||
nsresult PutBuffer(const char* id, UniquePtr<char[]>&& inbuf,
|
||||
uint32_t length);
|
||||
|
||||
void InvalidateCache();
|
||||
// Removes the cache file.
|
||||
void InvalidateCache(bool memoryOnly = false);
|
||||
|
||||
// For use during shutdown - this will write the startupcache's data
|
||||
// to disk if the timer hasn't already gone off.
|
||||
|
@ -293,35 +169,16 @@ class StartupCache : public nsIMemoryReporter {
|
|||
nsresult GetDebugObjectOutputStream(nsIObjectOutputStream* aStream,
|
||||
nsIObjectOutputStream** outStream);
|
||||
|
||||
static ProcessType GetChildProcessType(const nsAString& remoteType);
|
||||
static StartupCache* GetSingletonNoInit();
|
||||
static StartupCache* GetSingleton();
|
||||
|
||||
// This will get the StartupCache up and running to get cached entries, but
|
||||
// it won't init some of the deferred things which require later services
|
||||
// to be up and running.
|
||||
static nsresult PartialInitSingleton(nsIFile* aProfileLocalDir);
|
||||
|
||||
// If the startup cache singleton exists (initialized via
|
||||
// PartialInitSingleton), this will ensure that all of the ancillary
|
||||
// requirements of the startup cache are met.
|
||||
static nsresult FullyInitSingleton();
|
||||
|
||||
static nsresult InitChildSingleton(char* aScacheHandleStr,
|
||||
char* aScacheSizeStr);
|
||||
|
||||
static void DeleteSingleton();
|
||||
static void InitContentChild(dom::ContentParent& parent);
|
||||
|
||||
void AddStartupCacheCmdLineArgs(ipc::GeckoChildProcessHost& procHost,
|
||||
std::vector<std::string>& aExtraOpts);
|
||||
nsresult ParseStartupCacheCmdLineArgs(char* aScacheHandleStr,
|
||||
char* aScacheSizeStr);
|
||||
|
||||
// This measures all the heap memory used by the StartupCache, i.e. it
|
||||
// excludes the mapping.
|
||||
size_t HeapSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
||||
|
||||
bool ShouldCompactCache();
|
||||
nsresult ResetStartupWriteTimerCheckingReadCount();
|
||||
nsresult ResetStartupWriteTimer();
|
||||
bool StartupWriteComplete();
|
||||
|
||||
|
@ -332,15 +189,7 @@ class StartupCache : public nsIMemoryReporter {
|
|||
friend class StartupCacheInfo;
|
||||
|
||||
Result<Ok, nsresult> LoadArchive();
|
||||
nsresult PartialInit(nsIFile* aProfileLocalDir);
|
||||
nsresult FullyInit();
|
||||
nsresult InitChild(StartupCacheChild* cacheChild);
|
||||
|
||||
// Removes the cache file.
|
||||
void InvalidateCacheImpl(bool memoryOnly = false);
|
||||
|
||||
nsresult ResetStartupWriteTimerCheckingReadCount();
|
||||
nsresult ResetStartupWriteTimerImpl();
|
||||
nsresult Init();
|
||||
|
||||
// Returns a file pointer for the cache file with the given name in the
|
||||
// current profile.
|
||||
|
@ -352,69 +201,37 @@ class StartupCache : public nsIMemoryReporter {
|
|||
// Writes the cache to disk
|
||||
Result<Ok, nsresult> WriteToDisk();
|
||||
|
||||
Result<Ok, nsresult> DecompressEntry(StartupCacheEntry& aEntry);
|
||||
|
||||
Result<Ok, nsresult> LoadEntriesOffDisk();
|
||||
|
||||
Result<Ok, nsresult> LoadEntriesFromSharedMemory();
|
||||
|
||||
void WaitOnPrefetchThread();
|
||||
void StartPrefetchMemoryThread();
|
||||
|
||||
static nsresult InitSingleton();
|
||||
static void WriteTimeout(nsITimer* aTimer, void* aClosure);
|
||||
static void SendEntriesTimeout(nsITimer* aTimer, void* aClosure);
|
||||
void MaybeWriteOffMainThread();
|
||||
static void ThreadedPrefetch(void* aClosure);
|
||||
|
||||
EnumSet<ProcessType> mInitializedProcesses{};
|
||||
nsCString mContentStartupFinishedTopic;
|
||||
|
||||
Table mTable;
|
||||
HashMap<nsCString, StartupCacheEntry> mTable;
|
||||
// owns references to the contents of tables which have been invalidated.
|
||||
// In theory grows forever if the cache is continually filled and then
|
||||
// invalidated, but this should not happen in practice.
|
||||
nsTArray<decltype(mTable)> mOldTables;
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
loader::AutoMemMap mCacheData;
|
||||
loader::AutoMemMap mSharedData;
|
||||
UniqueFileHandle mSharedDataHandle;
|
||||
|
||||
// This lock must protect a few members of the StartupCache. Essentially,
|
||||
// we want to protect everything accessed by GetBuffer and PutBuffer. This
|
||||
// includes:
|
||||
// - mTable
|
||||
// - mCacheData
|
||||
// - mDecompressionContext
|
||||
// - mCurTableReferenced
|
||||
// - mOldTables
|
||||
// - mWrittenOnce
|
||||
// - gIgnoreDiskCache
|
||||
// - mFile
|
||||
// - mWriteTimer
|
||||
// - mStartupWriteInitiated
|
||||
mutable Mutex mLock;
|
||||
Mutex mTableLock;
|
||||
|
||||
nsCOMPtr<nsIObserverService> mObserverService;
|
||||
RefPtr<StartupCacheListener> mListener;
|
||||
nsCOMPtr<nsITimer> mWriteTimer;
|
||||
nsCOMPtr<nsITimer> mSendEntriesTimer;
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
|
||||
Atomic<bool> mDirty;
|
||||
Atomic<bool> mWrittenOnce;
|
||||
bool mCurTableReferenced;
|
||||
bool mLoaded;
|
||||
bool mFullyInitialized;
|
||||
uint32_t mRequestedCount;
|
||||
uint32_t mPrefetchSize;
|
||||
uint32_t mSharedDataSize;
|
||||
size_t mCacheEntriesBaseOffset;
|
||||
|
||||
static StaticRefPtr<StartupCache> gStartupCache;
|
||||
static bool gShutdownInitiated;
|
||||
static bool gIgnoreDiskCache;
|
||||
static bool gFoundDiskCacheOnInit;
|
||||
|
||||
Atomic<StartupCacheChild*> mChildActor;
|
||||
PRThread* mPrefetchThread;
|
||||
UniquePtr<Compression::LZ4FrameDecompressionContext> mDecompressionContext;
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/scache/StartupCacheChild.h"
|
||||
|
||||
#include "mozilla/scache/StartupCache.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace scache {
|
||||
|
||||
void StartupCacheChild::Init(bool wantCacheData) {
|
||||
mWantCacheData = wantCacheData;
|
||||
|
||||
auto* cache = StartupCache::GetSingleton();
|
||||
if (cache) {
|
||||
Unused << cache->InitChild(wantCacheData ? this : nullptr);
|
||||
}
|
||||
|
||||
if (!wantCacheData) {
|
||||
// If the parent process isn't expecting any cache data from us, we're
|
||||
// done.
|
||||
Send__delete__(this, AutoTArray<EntryData, 0>());
|
||||
}
|
||||
}
|
||||
|
||||
void StartupCacheChild::SendEntriesAndFinalize(StartupCache::Table& entries) {
|
||||
MOZ_RELEASE_ASSERT(mWantCacheData);
|
||||
nsTArray<EntryData> dataArray;
|
||||
for (auto iter = entries.iter(); !iter.done(); iter.next()) {
|
||||
const auto& key = iter.get().key();
|
||||
auto& value = iter.get().value();
|
||||
|
||||
if (!value.mData ||
|
||||
value.mRequestedOrder == kStartupCacheEntryNotRequested) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto data = dataArray.AppendElement();
|
||||
|
||||
data->key() = key;
|
||||
if (value.mFlags.contains(StartupCacheEntryFlags::AddedThisSession)) {
|
||||
data->data().AppendElements(
|
||||
reinterpret_cast<const uint8_t*>(value.mData.get()),
|
||||
value.mUncompressedSize);
|
||||
}
|
||||
}
|
||||
|
||||
mWantCacheData = false;
|
||||
Send__delete__(this, dataArray);
|
||||
}
|
||||
|
||||
void StartupCacheChild::ActorDestroy(ActorDestroyReason aWhy) {
|
||||
auto* cache = StartupCache::GetSingleton();
|
||||
if (cache) {
|
||||
cache->mChildActor = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace scache
|
||||
} // namespace mozilla
|
|
@ -1,43 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef StartupCacheChild_h
|
||||
#define StartupCacheChild_h
|
||||
|
||||
#include "mozilla/scache/StartupCache.h"
|
||||
#include "mozilla/scache/PStartupCacheChild.h"
|
||||
#include "mozilla/scache/PStartupCacheParent.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
class FileDescriptor;
|
||||
}
|
||||
|
||||
namespace scache {
|
||||
|
||||
using mozilla::ipc::FileDescriptor;
|
||||
|
||||
class StartupCacheChild final : public PStartupCacheChild {
|
||||
friend class mozilla::scache::StartupCache;
|
||||
friend class mozilla::scache::StartupCacheListener;
|
||||
|
||||
public:
|
||||
StartupCacheChild() = default;
|
||||
|
||||
void Init(bool wantCacheData);
|
||||
|
||||
protected:
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
void SendEntriesAndFinalize(StartupCache::Table& entries);
|
||||
|
||||
private:
|
||||
bool mWantCacheData = false;
|
||||
};
|
||||
|
||||
} // namespace scache
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // StartupCacheChild_h
|
|
@ -1,38 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/scache/StartupCacheParent.h"
|
||||
|
||||
#include "mozilla/scache/StartupCache.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace scache {
|
||||
|
||||
IPCResult StartupCacheParent::Recv__delete__(nsTArray<EntryData>&& entries) {
|
||||
if (!mWantCacheData && entries.Length()) {
|
||||
return IPC_FAIL(this, "UnexpectedScriptData");
|
||||
}
|
||||
|
||||
mWantCacheData = false;
|
||||
|
||||
if (entries.Length()) {
|
||||
auto* cache = StartupCache::GetSingleton();
|
||||
for (auto& entry : entries) {
|
||||
auto buffer = MakeUnique<char[]>(entry.data().Length());
|
||||
memcpy(buffer.get(), entry.data().Elements(), entry.data().Length());
|
||||
cache->PutBuffer(entry.key().get(), std::move(buffer),
|
||||
entry.data().Length(), /* isFromChildProcess:*/ true);
|
||||
}
|
||||
}
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
void StartupCacheParent::ActorDestroy(ActorDestroyReason aWhy) {}
|
||||
|
||||
} // namespace scache
|
||||
} // namespace mozilla
|
|
@ -1,37 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef StartupCacheParent_h
|
||||
#define StartupCacheParent_h
|
||||
|
||||
#include "mozilla/scache/StartupCache.h"
|
||||
#include "mozilla/scache/PStartupCacheParent.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace scache {
|
||||
|
||||
using mozilla::ipc::IPCResult;
|
||||
|
||||
class StartupCacheParent final : public PStartupCacheParent {
|
||||
friend class PStartupCacheParent;
|
||||
|
||||
public:
|
||||
explicit StartupCacheParent(bool wantCacheData)
|
||||
: mWantCacheData(wantCacheData) {}
|
||||
|
||||
protected:
|
||||
IPCResult Recv__delete__(nsTArray<EntryData>&& entries);
|
||||
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
private:
|
||||
bool mWantCacheData;
|
||||
};
|
||||
|
||||
} // namespace scache
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // StartupCacheParent_h
|
|
@ -12,16 +12,12 @@ BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
|
|||
|
||||
EXPORTS.mozilla.scache += [
|
||||
'StartupCache.h',
|
||||
'StartupCacheChild.h',
|
||||
'StartupCacheParent.h',
|
||||
'StartupCacheUtils.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'StartupCache.cpp',
|
||||
'StartupCacheChild.cpp',
|
||||
'StartupCacheInfo.cpp',
|
||||
'StartupCacheParent.cpp',
|
||||
'StartupCacheUtils.cpp',
|
||||
]
|
||||
|
||||
|
@ -35,10 +31,4 @@ XPIDL_SOURCES += [
|
|||
'nsIStartupCacheInfo.idl',
|
||||
]
|
||||
|
||||
IPDL_SOURCES += [
|
||||
'PStartupCache.ipdl',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
|
|
@ -66,11 +66,6 @@ TestStartupCache::TestStartupCache() {
|
|||
// We intentionally leak `env` here because it is required by PR_SetEnv
|
||||
MOZ_LSAN_INTENTIONALLY_LEAK_OBJECT(env);
|
||||
#endif
|
||||
|
||||
if (!StartupCache::GetSingleton()) {
|
||||
StartupCache::PartialInitSingleton(nullptr);
|
||||
StartupCache::FullyInitSingleton();
|
||||
}
|
||||
StartupCache::GetSingleton()->InvalidateCache();
|
||||
}
|
||||
TestStartupCache::~TestStartupCache() {
|
||||
|
|
|
@ -4234,10 +4234,7 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {
|
|||
mAppData->directory, gSafeMode || !startupCacheValid);
|
||||
}
|
||||
|
||||
if (!startupCacheValid) {
|
||||
StartupCache::IgnoreDiskCache();
|
||||
}
|
||||
StartupCache::PartialInitSingleton(mProfLD);
|
||||
if (!startupCacheValid) StartupCache::IgnoreDiskCache();
|
||||
|
||||
if (flagFile) {
|
||||
flagFile->Remove(true);
|
||||
|
|
|
@ -142,7 +142,7 @@ void AppShutdown::Init(AppShutdownMode aMode) {
|
|||
|
||||
// Very early shutdowns can happen before the startup cache is even
|
||||
// initialized; don't bother initializing it during shutdown.
|
||||
if (auto* cache = scache::StartupCache::GetSingleton()) {
|
||||
if (auto* cache = scache::StartupCache::GetSingletonNoInit()) {
|
||||
cache->MaybeInitShutdownWrite();
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ void AppShutdown::MaybeFastShutdown(ShutdownPhase aPhase) {
|
|||
// the late write checking code. Anything that writes to disk and which
|
||||
// we don't want to skip should be listed out explicitly in this section.
|
||||
if (aPhase == sFastShutdownPhase || aPhase == sLateWriteChecksPhase) {
|
||||
if (auto* cache = scache::StartupCache::GetSingleton()) {
|
||||
if (auto* cache = scache::StartupCache::GetSingletonNoInit()) {
|
||||
cache->EnsureShutdownWriteComplete();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "FileLocation.h"
|
||||
#include "nsZipArchive.h"
|
||||
#include "nsURLHelper.h"
|
||||
#include "mozilla/Omnijar.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -17,12 +16,12 @@ FileLocation::~FileLocation() = default;
|
|||
|
||||
FileLocation::FileLocation(nsIFile* aFile) { Init(aFile); }
|
||||
|
||||
FileLocation::FileLocation(CacheAwareZipReader* aZip, const char* aPath) {
|
||||
Init(aZip, aPath);
|
||||
FileLocation::FileLocation(nsIFile* aFile, const char* aPath) {
|
||||
Init(aFile, aPath);
|
||||
}
|
||||
|
||||
FileLocation::FileLocation(nsZipArchive* aZip, const char* aPath) {
|
||||
Init(new CacheAwareZipReader(aZip, nullptr), aPath);
|
||||
Init(aZip, aPath);
|
||||
}
|
||||
|
||||
FileLocation::FileLocation(const FileLocation& aOther)
|
||||
|
@ -89,14 +88,8 @@ void FileLocation::Init(nsIFile* aFile, const char* aPath) {
|
|||
mPath = aPath;
|
||||
}
|
||||
|
||||
void FileLocation::Init(CacheAwareZipReader* aZip, const char* aPath) {
|
||||
mBaseZip = aZip;
|
||||
mBaseFile = nullptr;
|
||||
mPath = aPath;
|
||||
}
|
||||
|
||||
void FileLocation::Init(nsZipArchive* aZip, const char* aPath) {
|
||||
mBaseZip = new CacheAwareZipReader(aZip, nullptr);
|
||||
mBaseZip = aZip;
|
||||
mBaseFile = nullptr;
|
||||
mPath = aPath;
|
||||
}
|
||||
|
@ -105,7 +98,8 @@ void FileLocation::GetURIString(nsACString& aResult) const {
|
|||
if (mBaseFile) {
|
||||
net_GetURLSpecFromActualFile(mBaseFile, aResult);
|
||||
} else if (mBaseZip) {
|
||||
mBaseZip->GetURIString(aResult);
|
||||
RefPtr<nsZipHandle> handler = mBaseZip->GetFD();
|
||||
handler->mFile.GetURIString(aResult);
|
||||
}
|
||||
if (IsZip()) {
|
||||
aResult.InsertLiteral("jar:", 0);
|
||||
|
@ -116,7 +110,11 @@ void FileLocation::GetURIString(nsACString& aResult) const {
|
|||
|
||||
already_AddRefed<nsIFile> FileLocation::GetBaseFile() {
|
||||
if (IsZip() && mBaseZip) {
|
||||
return mBaseZip->GetBaseFile();
|
||||
RefPtr<nsZipHandle> handler = mBaseZip->GetFD();
|
||||
if (handler) {
|
||||
return handler->mFile.GetBaseFile();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> file = mBaseFile;
|
||||
|
@ -128,17 +126,23 @@ bool FileLocation::Equals(const FileLocation& aFile) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> a = mBaseFile;
|
||||
nsCOMPtr<nsIFile> b = aFile.mBaseFile;
|
||||
if (!mBaseFile && mBaseZip) {
|
||||
a = mBaseZip->GetBaseFile();
|
||||
}
|
||||
if (!aFile.mBaseFile && aFile.mBaseZip) {
|
||||
b = mBaseZip->GetBaseFile();
|
||||
if (mBaseFile && aFile.mBaseFile) {
|
||||
bool eq;
|
||||
return NS_SUCCEEDED(mBaseFile->Equals(aFile.mBaseFile, &eq)) && eq;
|
||||
}
|
||||
|
||||
bool eq;
|
||||
return NS_SUCCEEDED(a->Equals(b, &eq)) && eq;
|
||||
const FileLocation* a = this;
|
||||
const FileLocation* b = &aFile;
|
||||
if (a->mBaseZip) {
|
||||
RefPtr<nsZipHandle> handler = a->mBaseZip->GetFD();
|
||||
a = &handler->mFile;
|
||||
}
|
||||
if (b->mBaseZip) {
|
||||
RefPtr<nsZipHandle> handler = b->mBaseZip->GetFD();
|
||||
b = &handler->mFile;
|
||||
}
|
||||
|
||||
return a->Equals(*b);
|
||||
}
|
||||
|
||||
nsresult FileLocation::GetData(Data& aData) {
|
||||
|
@ -147,7 +151,7 @@ nsresult FileLocation::GetData(Data& aData) {
|
|||
}
|
||||
aData.mZip = mBaseZip;
|
||||
if (!aData.mZip) {
|
||||
aData.mZip = new CacheAwareZipReader();
|
||||
aData.mZip = new nsZipArchive();
|
||||
aData.mZip->OpenArchive(mBaseFile);
|
||||
}
|
||||
aData.mItem = aData.mZip->GetItem(mPath.get());
|
||||
|
@ -191,8 +195,8 @@ nsresult FileLocation::Data::Copy(char* aBuf, uint32_t aLen) {
|
|||
return NS_OK;
|
||||
}
|
||||
if (mItem) {
|
||||
CacheAwareZipCursor cursor(mItem, mZip, reinterpret_cast<uint8_t*>(aBuf),
|
||||
aLen, true);
|
||||
nsZipCursor cursor(mItem, mZip, reinterpret_cast<uint8_t*>(aBuf), aLen,
|
||||
true);
|
||||
uint32_t readLen;
|
||||
cursor.Copy(&readLen);
|
||||
if (readLen != aLen) {
|
||||
|
|
|
@ -17,8 +17,6 @@ class nsZipItem;
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
class CacheAwareZipReader;
|
||||
|
||||
class FileLocation {
|
||||
public:
|
||||
/**
|
||||
|
@ -29,7 +27,7 @@ class FileLocation {
|
|||
* - in archives within archives
|
||||
* As such, it stores a path within an archive, as well as the archive
|
||||
* path itself, or the complete file path alone when on a filesystem.
|
||||
* When the archive is in an archive, an CacheAwareZipReader is stored instead
|
||||
* When the archive is in an archive, an nsZipArchive is stored instead
|
||||
* of a file path.
|
||||
*/
|
||||
FileLocation();
|
||||
|
@ -47,14 +45,9 @@ class FileLocation {
|
|||
|
||||
/**
|
||||
* Constructors for path within an archive. The archive can be given either
|
||||
* as nsIFile or CacheAwareZipReader.
|
||||
* as nsIFile or nsZipArchive.
|
||||
*/
|
||||
FileLocation(nsIFile* aFile, const char* aPath);
|
||||
|
||||
/**
|
||||
* Constructors for path within a zip archive.
|
||||
*/
|
||||
FileLocation(CacheAwareZipReader* aZip, const char* aPath);
|
||||
FileLocation(nsIFile* aZip, const char* aPath);
|
||||
|
||||
FileLocation(nsZipArchive* aZip, const char* aPath);
|
||||
|
||||
|
@ -68,12 +61,10 @@ class FileLocation {
|
|||
*/
|
||||
void Init(nsIFile* aFile);
|
||||
|
||||
void Init(nsIFile* aFile, const char* aPath);
|
||||
void Init(nsIFile* aZip, const char* aPath);
|
||||
|
||||
void Init(nsZipArchive* aZip, const char* aPath);
|
||||
|
||||
void Init(CacheAwareZipReader* aZip, const char* aPath);
|
||||
|
||||
/**
|
||||
* Returns an URI string corresponding to the file location
|
||||
*/
|
||||
|
@ -87,7 +78,7 @@ class FileLocation {
|
|||
*/
|
||||
already_AddRefed<nsIFile> GetBaseFile();
|
||||
|
||||
CacheAwareZipReader* GetBaseZip() { return mBaseZip; }
|
||||
nsZipArchive* GetBaseZip() { return mBaseZip; }
|
||||
|
||||
/**
|
||||
* Returns whether the "base file" (see GetBaseFile) is an archive
|
||||
|
@ -128,7 +119,7 @@ class FileLocation {
|
|||
protected:
|
||||
friend class FileLocation;
|
||||
nsZipItem* mItem;
|
||||
RefPtr<CacheAwareZipReader> mZip;
|
||||
RefPtr<nsZipArchive> mZip;
|
||||
mozilla::AutoFDClose mFd;
|
||||
};
|
||||
|
||||
|
@ -140,7 +131,7 @@ class FileLocation {
|
|||
|
||||
private:
|
||||
nsCOMPtr<nsIFile> mBaseFile;
|
||||
RefPtr<CacheAwareZipReader> mBaseZip;
|
||||
RefPtr<nsZipArchive> mBaseZip;
|
||||
nsCString mPath;
|
||||
}; /* class FileLocation */
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*/
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
|
@ -12,28 +11,16 @@
|
|||
#include "nsIFile.h"
|
||||
#include "nsZipArchive.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "mozilla/scache/StartupCache.h"
|
||||
#include "mozilla/MmapFaultHandler.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
StaticRefPtr<nsIFile> Omnijar::sPath[2];
|
||||
StaticRefPtr<CacheAwareZipReader> Omnijar::sReader[2];
|
||||
StaticRefPtr<CacheAwareZipReader> Omnijar::sOuterReader[2];
|
||||
StaticRefPtr<nsZipArchive> Omnijar::sReader[2];
|
||||
StaticRefPtr<nsZipArchive> Omnijar::sOuterReader[2];
|
||||
bool Omnijar::sInitialized = false;
|
||||
bool Omnijar::sIsUnified = false;
|
||||
|
||||
static MOZ_THREAD_LOCAL(int) tlsSuspendStartupCacheWrites;
|
||||
|
||||
bool SuspendingStartupCacheWritesForCurrentThread() {
|
||||
if (!tlsSuspendStartupCacheWrites.init()) {
|
||||
return true;
|
||||
}
|
||||
return tlsSuspendStartupCacheWrites.get() > 0;
|
||||
}
|
||||
|
||||
static const char* sProp[2] = {NS_GRE_DIR, NS_XPCOM_CURRENT_PROCESS_DIR};
|
||||
static const char* sCachePrefixes[2] = {"GreOmnijar:", "AppOmnijar:"};
|
||||
|
||||
#define SPROP(Type) ((Type == mozilla::Omnijar::GRE) ? sProp[GRE] : sProp[APP])
|
||||
|
||||
|
@ -91,41 +78,8 @@ void Omnijar::InitOne(nsIFile* aPath, Type aType) {
|
|||
}
|
||||
|
||||
RefPtr<nsZipArchive> zipReader = new nsZipArchive();
|
||||
auto* cache = scache::StartupCache::GetSingleton();
|
||||
const uint8_t* centralBuf = nullptr;
|
||||
uint32_t centralBufLength = 0;
|
||||
nsCString startupCacheKey =
|
||||
nsPrintfCString("::%s:OmnijarCentral", sCachePrefixes[aType]);
|
||||
if (cache) {
|
||||
nsresult rv = cache->GetBuffer(startupCacheKey.get(),
|
||||
reinterpret_cast<const char**>(¢ralBuf),
|
||||
¢ralBufLength);
|
||||
if (NS_FAILED(rv)) {
|
||||
centralBuf = nullptr;
|
||||
centralBufLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!centralBuf) {
|
||||
if (NS_FAILED(zipReader->OpenArchive(file))) {
|
||||
return;
|
||||
}
|
||||
if (cache) {
|
||||
size_t bufSize;
|
||||
// Annoyingly, nsZipArchive and the startupcache use different types to
|
||||
// represent bytes (uint8_t vs char), so we have to do a little dance to
|
||||
// convert the UniquePtr over.
|
||||
UniquePtr<char[]> centralBuf(reinterpret_cast<char*>(
|
||||
zipReader->CopyCentralDirectoryBuffer(&bufSize).release()));
|
||||
if (centralBuf) {
|
||||
cache->PutBuffer(startupCacheKey.get(), std::move(centralBuf), bufSize);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (NS_FAILED(zipReader->LazyOpenArchive(
|
||||
file, MakeSpan(centralBuf, centralBufLength)))) {
|
||||
return;
|
||||
}
|
||||
if (NS_FAILED(zipReader->OpenArchive(file))) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<nsZipArchive> outerReader;
|
||||
|
@ -140,9 +94,8 @@ void Omnijar::InitOne(nsIFile* aPath, Type aType) {
|
|||
}
|
||||
|
||||
CleanUpOne(aType);
|
||||
sReader[aType] = new CacheAwareZipReader(zipReader, sCachePrefixes[aType]);
|
||||
sOuterReader[aType] =
|
||||
outerReader ? new CacheAwareZipReader(outerReader, nullptr) : nullptr;
|
||||
sReader[aType] = zipReader;
|
||||
sOuterReader[aType] = outerReader;
|
||||
sPath[aType] = file;
|
||||
}
|
||||
|
||||
|
@ -158,7 +111,7 @@ void Omnijar::CleanUp() {
|
|||
sInitialized = false;
|
||||
}
|
||||
|
||||
already_AddRefed<CacheAwareZipReader> Omnijar::GetReader(nsIFile* aPath) {
|
||||
already_AddRefed<nsZipArchive> Omnijar::GetReader(nsIFile* aPath) {
|
||||
MOZ_ASSERT(IsInitialized(), "Omnijar not initialized");
|
||||
|
||||
bool equals;
|
||||
|
@ -179,7 +132,7 @@ already_AddRefed<CacheAwareZipReader> Omnijar::GetReader(nsIFile* aPath) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
already_AddRefed<CacheAwareZipReader> Omnijar::GetInnerReader(
|
||||
already_AddRefed<nsZipArchive> Omnijar::GetInnerReader(
|
||||
nsIFile* aPath, const nsACString& aEntry) {
|
||||
MOZ_ASSERT(IsInitialized(), "Omnijar not initialized");
|
||||
|
||||
|
@ -244,226 +197,4 @@ nsresult Omnijar::GetURIString(Type aType, nsACString& aResult) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
CacheAwareZipReader::CacheAwareZipReader(nsZipArchive* aZip,
|
||||
const char* aCacheKeyPrefix)
|
||||
: mZip(aZip), mCacheKeyPrefix(aCacheKeyPrefix) {}
|
||||
|
||||
nsresult CacheAwareZipReader::FindInit(const char* aPattern,
|
||||
nsZipFind** aFind) {
|
||||
return mZip->FindInit(aPattern, aFind);
|
||||
}
|
||||
|
||||
const uint8_t* CacheAwareZipReader::GetData(
|
||||
nsZipItem* aItem, CacheAwareZipReader::Caching aCaching) {
|
||||
nsAutoCString cacheKey;
|
||||
uint32_t size;
|
||||
const uint8_t* cached =
|
||||
GetCachedBuffer(aItem->Name(), aItem->nameLength, &size, cacheKey);
|
||||
if (cached) {
|
||||
MOZ_ASSERT(size == aItem->RealSize());
|
||||
return cached;
|
||||
}
|
||||
|
||||
const uint8_t* zipItemData = mZip->GetData(aItem);
|
||||
|
||||
// If the data is compressed, it is somewhat silly to store it in the startup
|
||||
// cache, as the startup cache will try to double compress it.
|
||||
if (aCaching == Default && aItem->Compression() == STORED &&
|
||||
!cacheKey.IsEmpty()) {
|
||||
MOZ_ASSERT(aItem->RealSize() == aItem->Size());
|
||||
PutBufferIntoCache(cacheKey, zipItemData, aItem->Size());
|
||||
}
|
||||
|
||||
return zipItemData;
|
||||
}
|
||||
|
||||
const uint8_t* CacheAwareZipReader::GetData(
|
||||
const char* aEntryName, uint32_t* aResultSize,
|
||||
CacheAwareZipReader::Caching aCaching) {
|
||||
nsAutoCString cacheKey;
|
||||
const uint8_t* cached =
|
||||
GetCachedBuffer(aEntryName, strlen(aEntryName), aResultSize, cacheKey);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
nsZipItem* zipItem = mZip->GetItem(aEntryName);
|
||||
if (!zipItem) {
|
||||
*aResultSize = 0;
|
||||
return nullptr;
|
||||
}
|
||||
const uint8_t* zipItemData = mZip->GetData(zipItem);
|
||||
*aResultSize = zipItem->Size();
|
||||
|
||||
// If the data is compressed, it is somewhat silly to store it in the startup
|
||||
// cache, as the startup cache will try to double compress it.
|
||||
if (aCaching == Default && zipItem->Compression() == STORED &&
|
||||
!cacheKey.IsEmpty()) {
|
||||
MOZ_ASSERT(zipItem->RealSize() == *aResultSize);
|
||||
PutBufferIntoCache(cacheKey, zipItemData, *aResultSize);
|
||||
}
|
||||
|
||||
return zipItemData;
|
||||
}
|
||||
|
||||
nsZipItem* CacheAwareZipReader::GetItem(const char* aEntryName) {
|
||||
return mZip->GetItem(aEntryName);
|
||||
}
|
||||
|
||||
nsresult CacheAwareZipReader::CloseArchive() { return mZip->CloseArchive(); }
|
||||
|
||||
CacheAwareZipCursor::CacheAwareZipCursor(nsZipItem* aItem,
|
||||
CacheAwareZipReader* aReader,
|
||||
uint8_t* aBuf, uint32_t aBufSize,
|
||||
bool aDoCRC)
|
||||
: mItem(aItem),
|
||||
mReader(aReader),
|
||||
mBuf(aBuf),
|
||||
mBufSize(aBufSize),
|
||||
mDoCRC(aDoCRC) {}
|
||||
|
||||
uint8_t* CacheAwareZipCursor::ReadOrCopy(uint32_t* aBytesRead, bool aCopy) {
|
||||
nsCString cacheKey;
|
||||
const uint8_t* cached = mReader->GetCachedBuffer(
|
||||
mItem->Name(), mItem->nameLength, aBytesRead, cacheKey);
|
||||
if (cached && *aBytesRead <= mBufSize) {
|
||||
if (aCopy) {
|
||||
memcpy(mBuf, cached, *aBytesRead);
|
||||
return mBuf;
|
||||
}
|
||||
|
||||
// The const cast is unfortunate, but it matches existing consumers'
|
||||
// uses. We ought to file a bug to make Read return a const uint8_t*
|
||||
return const_cast<uint8_t*>(cached);
|
||||
}
|
||||
|
||||
nsZipCursor cursor(mItem, mReader->mZip, mBuf, mBufSize, mDoCRC);
|
||||
uint8_t* buf = nullptr;
|
||||
if (aCopy) {
|
||||
cursor.Copy(aBytesRead);
|
||||
buf = mBuf;
|
||||
} else {
|
||||
buf = cursor.Read(aBytesRead);
|
||||
}
|
||||
|
||||
if (!cacheKey.IsEmpty() && *aBytesRead == mItem->RealSize()) {
|
||||
CacheAwareZipReader::PutBufferIntoCache(cacheKey, buf, *aBytesRead);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
nsresult CacheAwareZipReader::GetPersistentHandle(
|
||||
nsZipItem* aItem, CacheAwareZipHandle* aHandle,
|
||||
CacheAwareZipReader::Caching aCaching) {
|
||||
nsCString cacheKey;
|
||||
if (!mCacheKeyPrefix.IsEmpty() && aItem->Compression() == STORED) {
|
||||
auto* cache = scache::StartupCache::GetSingleton();
|
||||
if (cache) {
|
||||
cacheKey.Append(mCacheKeyPrefix);
|
||||
cacheKey.Append(aItem->Name(), aItem->nameLength);
|
||||
|
||||
if (cache->HasEntry(cacheKey.get())) {
|
||||
aHandle->mDataIsCached = true;
|
||||
aHandle->mFd = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
if (aCaching == DeferCaching) {
|
||||
aHandle->mDeferredCachingKey = std::move(cacheKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult rv = mZip->EnsureArchiveOpenedOnDisk();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
aHandle->mDataIsCached = false;
|
||||
aHandle->mFd = mZip->GetFD();
|
||||
|
||||
if (!aHandle->mDeferredCachingKey.IsEmpty() &&
|
||||
aItem->Compression() == STORED) {
|
||||
MOZ_ASSERT(aItem->RealSize() == aItem->Size());
|
||||
aHandle->mDataToCache = MakeSpan(mZip->GetData(aItem), aItem->Size());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const uint8_t* CacheAwareZipReader::GetCachedBuffer(const char* aEntryName,
|
||||
uint32_t aEntryNameLength,
|
||||
uint32_t* aResultSize,
|
||||
nsCString& aCacheKey) {
|
||||
*aResultSize = 0;
|
||||
if (mCacheKeyPrefix.IsEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
auto* cache = scache::StartupCache::GetSingleton();
|
||||
if (!cache) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
aCacheKey.Append(mCacheKeyPrefix);
|
||||
aCacheKey.Append(aEntryName, aEntryNameLength);
|
||||
|
||||
const char* cached;
|
||||
nsresult rv = cache->GetBuffer(aCacheKey.get(), &cached, aResultSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return reinterpret_cast<const uint8_t*>(cached);
|
||||
}
|
||||
|
||||
void CacheAwareZipReader::PutBufferIntoCache(const nsCString& aCacheKey,
|
||||
const uint8_t* aBuffer,
|
||||
uint32_t aSize) {
|
||||
if (SuspendingStartupCacheWritesForCurrentThread() || aSize == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* cache = scache::StartupCache::GetSingleton();
|
||||
auto dataCopy = MakeUnique<char[]>(aSize);
|
||||
|
||||
MMAP_FAULT_HANDLER_BEGIN_BUFFER(aBuffer, aSize)
|
||||
memcpy(dataCopy.get(), aBuffer, aSize);
|
||||
MMAP_FAULT_HANDLER_CATCH()
|
||||
Unused << cache->PutBuffer(aCacheKey.get(), std::move(dataCopy), aSize);
|
||||
}
|
||||
|
||||
void CacheAwareZipReader::PushSuspendStartupCacheWrites() {
|
||||
if (!tlsSuspendStartupCacheWrites.init()) {
|
||||
return;
|
||||
}
|
||||
tlsSuspendStartupCacheWrites.set(tlsSuspendStartupCacheWrites.get() + 1);
|
||||
}
|
||||
|
||||
void CacheAwareZipReader::PopSuspendStartupCacheWrites() {
|
||||
if (!tlsSuspendStartupCacheWrites.init()) {
|
||||
return;
|
||||
}
|
||||
int current = tlsSuspendStartupCacheWrites.get();
|
||||
MOZ_ASSERT(current > 0);
|
||||
tlsSuspendStartupCacheWrites.set(current - 1);
|
||||
}
|
||||
|
||||
void CacheAwareZipHandle::ReleaseHandle() {
|
||||
if (!mDataToCache.IsEmpty()) {
|
||||
MOZ_ASSERT(mFd);
|
||||
MOZ_ASSERT(!mDeferredCachingKey.IsEmpty());
|
||||
MOZ_ASSERT(!mDataIsCached);
|
||||
|
||||
auto* cache = scache::StartupCache::GetSingleton();
|
||||
MOZ_ASSERT(cache);
|
||||
if (cache) {
|
||||
CacheAwareZipReader::PutBufferIntoCache(
|
||||
mDeferredCachingKey, mDataToCache.Elements(), mDataToCache.Length());
|
||||
mDataToCache = Span<const uint8_t>();
|
||||
}
|
||||
}
|
||||
|
||||
mFd = nullptr;
|
||||
}
|
||||
|
||||
} /* namespace mozilla */
|
||||
|
|
|
@ -13,14 +13,10 @@
|
|||
#include "nsIFile.h"
|
||||
#include "nsZipArchive.h"
|
||||
|
||||
#include "mozilla/Span.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class CacheAwareZipReader;
|
||||
|
||||
class Omnijar {
|
||||
private:
|
||||
/**
|
||||
|
@ -32,15 +28,15 @@ class Omnijar {
|
|||
static StaticRefPtr<nsIFile> sPath[2];
|
||||
|
||||
/**
|
||||
* Cached CacheAwareZipReaders for the corresponding sPath
|
||||
* Cached nsZipArchives for the corresponding sPath
|
||||
*/
|
||||
static StaticRefPtr<CacheAwareZipReader> sReader[2];
|
||||
static StaticRefPtr<nsZipArchive> sReader[2];
|
||||
|
||||
/**
|
||||
* Cached CacheAwareZipReaders for the outer jar, when using nested jars.
|
||||
* Cached nsZipArchives for the outer jar, when using nested jars.
|
||||
* Otherwise nullptr.
|
||||
*/
|
||||
static StaticRefPtr<CacheAwareZipReader> sOuterReader[2];
|
||||
static StaticRefPtr<nsZipArchive> sOuterReader[2];
|
||||
|
||||
/**
|
||||
* Has Omnijar::Init() been called?
|
||||
|
@ -65,14 +61,13 @@ class Omnijar {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an CacheAwareZipReader pointer for the outer jar file when using
|
||||
* nested jars. Returns nullptr in the same cases GetPath() would, or if not
|
||||
* using nested jars.
|
||||
* Returns a nsZipArchive pointer for the outer jar file when using nested
|
||||
* jars. Returns nullptr in the same cases GetPath() would, or if not using
|
||||
* nested jars.
|
||||
*/
|
||||
static inline already_AddRefed<CacheAwareZipReader> GetOuterReader(
|
||||
Type aType) {
|
||||
static inline already_AddRefed<nsZipArchive> GetOuterReader(Type aType) {
|
||||
MOZ_ASSERT(IsInitialized(), "Omnijar not initialized");
|
||||
RefPtr<CacheAwareZipReader> reader = sOuterReader[aType].get();
|
||||
RefPtr<nsZipArchive> reader = sOuterReader[aType].get();
|
||||
return reader.forget();
|
||||
}
|
||||
|
||||
|
@ -118,20 +113,20 @@ class Omnijar {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an CacheAwareZipReader pointer for the omni.jar file for GRE or
|
||||
* Returns a nsZipArchive pointer for the omni.jar file for GRE or
|
||||
* APP. Returns nullptr in the same cases GetPath() would.
|
||||
*/
|
||||
static inline already_AddRefed<CacheAwareZipReader> GetReader(Type aType) {
|
||||
static inline already_AddRefed<nsZipArchive> GetReader(Type aType) {
|
||||
MOZ_ASSERT(IsInitialized(), "Omnijar not initialized");
|
||||
RefPtr<CacheAwareZipReader> reader = sReader[aType].get();
|
||||
RefPtr<nsZipArchive> reader = sReader[aType].get();
|
||||
return reader.forget();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an CacheAwareZipReader pointer for the given path IAOI the given
|
||||
* Returns a nsZipArchive pointer for the given path IAOI the given
|
||||
* path is the omni.jar for either GRE or APP.
|
||||
*/
|
||||
static already_AddRefed<CacheAwareZipReader> GetReader(nsIFile* aPath);
|
||||
static already_AddRefed<nsZipArchive> GetReader(nsIFile* aPath);
|
||||
|
||||
/**
|
||||
* In the case of a nested omnijar, this returns the inner reader for the
|
||||
|
@ -141,7 +136,7 @@ class Omnijar {
|
|||
* GetReader("path/to.apk") returns the outer reader and GetInnerReader(
|
||||
* "path/to.apk", "assets/omni.ja") returns the inner reader.
|
||||
*/
|
||||
static already_AddRefed<CacheAwareZipReader> GetInnerReader(
|
||||
static already_AddRefed<nsZipArchive> GetInnerReader(
|
||||
nsIFile* aPath, const nsACString& aEntry);
|
||||
|
||||
/**
|
||||
|
@ -161,132 +156,6 @@ class Omnijar {
|
|||
static void CleanUpOne(Type aType);
|
||||
}; /* class Omnijar */
|
||||
|
||||
class CacheAwareZipCursor {
|
||||
public:
|
||||
CacheAwareZipCursor(nsZipItem* aItem, CacheAwareZipReader* aReader,
|
||||
uint8_t* aBuf = nullptr, uint32_t aBufSize = 0,
|
||||
bool aDoCRC = false);
|
||||
|
||||
uint8_t* Read(uint32_t* aBytesRead) { return ReadOrCopy(aBytesRead, false); }
|
||||
uint8_t* Copy(uint32_t* aBytesRead) { return ReadOrCopy(aBytesRead, true); }
|
||||
|
||||
private:
|
||||
/* Actual implementation for both Read and Copy above */
|
||||
uint8_t* ReadOrCopy(uint32_t* aBytesRead, bool aCopy);
|
||||
|
||||
nsZipItem* mItem;
|
||||
CacheAwareZipReader* mReader;
|
||||
|
||||
uint8_t* mBuf;
|
||||
uint32_t mBufSize;
|
||||
|
||||
bool mDoCRC;
|
||||
};
|
||||
|
||||
// This class wraps an nsZipHandle, which may be null, if the data is
|
||||
// cached
|
||||
class CacheAwareZipHandle {
|
||||
friend class CacheAwareZipReader;
|
||||
|
||||
public:
|
||||
CacheAwareZipHandle() : mFd(nullptr), mDataIsCached(false) {}
|
||||
~CacheAwareZipHandle() { ReleaseHandle(); }
|
||||
|
||||
nsZipHandle* UnderlyingFD() { return mFd; }
|
||||
void ReleaseHandle();
|
||||
|
||||
explicit operator bool() const { return mDataIsCached || mFd; }
|
||||
|
||||
private:
|
||||
RefPtr<nsZipHandle> mFd;
|
||||
nsCString mDeferredCachingKey;
|
||||
Span<const uint8_t> mDataToCache;
|
||||
bool mDataIsCached;
|
||||
};
|
||||
|
||||
class CacheAwareZipReader {
|
||||
friend class CacheAwareZipCursor;
|
||||
friend class CacheAwareZipHandle;
|
||||
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheAwareZipReader)
|
||||
|
||||
enum Caching {
|
||||
Default,
|
||||
DeferCaching,
|
||||
};
|
||||
|
||||
// Constructor for CacheAwareZipReader. aCacheKeyPrefix will be a prefix
|
||||
// which the wrapper will prepend to any requested entries prior to
|
||||
// requesting the entry from the StartupCache. However, if aCacheKeyPrefix
|
||||
// is null, we will simply pass through to the underlying zip archive
|
||||
// without caching.
|
||||
explicit CacheAwareZipReader(nsZipArchive* aZip, const char* aCacheKeyPrefix);
|
||||
|
||||
// The default constructor should be used for an nsZipArchive which doesn't
|
||||
// want to cache any entries. Consumers will need to call `OpenArchive`
|
||||
// explicitly after constructing.
|
||||
CacheAwareZipReader() : mZip(new nsZipArchive()) {}
|
||||
|
||||
nsresult OpenArchive(nsIFile* aFile) { return mZip->OpenArchive(aFile); }
|
||||
nsresult OpenArchive(nsZipHandle* aHandle) {
|
||||
return mZip->OpenArchive(aHandle);
|
||||
}
|
||||
|
||||
const uint8_t* GetData(const char* aEntryName, uint32_t* aResultSize,
|
||||
Caching aCaching = Default);
|
||||
const uint8_t* GetData(nsZipItem* aItem, Caching aCaching = Default);
|
||||
|
||||
nsresult GetPersistentHandle(nsZipItem* aItem, CacheAwareZipHandle* aHandle,
|
||||
Caching aCaching);
|
||||
|
||||
already_AddRefed<nsIFile> GetBaseFile() { return mZip->GetBaseFile(); }
|
||||
|
||||
void GetURIString(nsACString& result) { mZip->GetURIString(result); }
|
||||
|
||||
nsZipArchive* GetZipArchive() { return mZip; }
|
||||
|
||||
nsresult FindInit(const char* aPattern, nsZipFind** aFind);
|
||||
bool IsForZip(nsZipArchive* aArchive) { return aArchive == mZip; }
|
||||
nsZipItem* GetItem(const char* aEntryName);
|
||||
|
||||
nsresult CloseArchive();
|
||||
|
||||
nsresult Test(const char* aEntryName) { return mZip->Test(aEntryName); }
|
||||
|
||||
nsresult ExtractFile(nsZipItem* zipEntry, nsIFile* outFile,
|
||||
PRFileDesc* outFD) {
|
||||
return mZip->ExtractFile(zipEntry, outFile, outFD);
|
||||
}
|
||||
|
||||
static void PushSuspendStartupCacheWrites();
|
||||
static void PopSuspendStartupCacheWrites();
|
||||
|
||||
protected:
|
||||
~CacheAwareZipReader() = default;
|
||||
|
||||
private:
|
||||
const uint8_t* GetCachedBuffer(const char* aEntryName,
|
||||
uint32_t aEntryNameLength,
|
||||
uint32_t* aResultSize, nsCString& aCacheKey);
|
||||
static void PutBufferIntoCache(const nsCString& aCacheKey,
|
||||
const uint8_t* aBuffer, uint32_t aSize);
|
||||
|
||||
RefPtr<nsZipArchive> mZip;
|
||||
nsCString mCacheKeyPrefix;
|
||||
};
|
||||
|
||||
class MOZ_RAII AutoSuspendStartupCacheWrites {
|
||||
public:
|
||||
AutoSuspendStartupCacheWrites() {
|
||||
CacheAwareZipReader::PushSuspendStartupCacheWrites();
|
||||
}
|
||||
|
||||
~AutoSuspendStartupCacheWrites() {
|
||||
CacheAwareZipReader::PopSuspendStartupCacheWrites();
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace mozilla */
|
||||
|
||||
#endif /* mozilla_Omnijar_h */
|
||||
|
|
|
@ -462,7 +462,7 @@ NS_InitXPCOM(nsIServiceManager** aResult, nsIFile* aBinDirectory,
|
|||
// Init mozilla::SharedThreadPool (which needs the service manager).
|
||||
mozilla::SharedThreadPool::InitStatics();
|
||||
|
||||
mozilla::scache::StartupCache::FullyInitSingleton();
|
||||
mozilla::scache::StartupCache::GetSingleton();
|
||||
mozilla::AvailableMemoryTracker::Init();
|
||||
|
||||
// Notify observers of xpcom autoregistration start
|
||||
|
|
|
@ -491,7 +491,7 @@ nsresult nsComponentManagerImpl::Init() {
|
|||
InitializeModuleLocations();
|
||||
ComponentLocation* cl = sModuleLocations->AppendElement();
|
||||
cl->type = NS_APP_LOCATION;
|
||||
RefPtr<CacheAwareZipReader> greOmnijar =
|
||||
RefPtr<nsZipArchive> greOmnijar =
|
||||
mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE);
|
||||
if (greOmnijar) {
|
||||
cl->location.Init(greOmnijar, "chrome.manifest");
|
||||
|
@ -500,7 +500,7 @@ nsresult nsComponentManagerImpl::Init() {
|
|||
cl->location.Init(lf);
|
||||
}
|
||||
|
||||
RefPtr<CacheAwareZipReader> appOmnijar =
|
||||
RefPtr<nsZipArchive> appOmnijar =
|
||||
mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
|
||||
if (appOmnijar) {
|
||||
cl = sModuleLocations->AppendElement();
|
||||
|
|
Загрузка…
Ссылка в новой задаче