Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp
Warning:line 2316, column 7
Value stored to 'rv' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_netwerk_cache20.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/netwerk/cache2 -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/netwerk/cache2 -resource-dir /usr/lib/llvm-19/lib/clang/19 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2 -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/netwerk/cache2 -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/base -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-09-22-115206-3586786-1 -x c++ Unified_cpp_netwerk_cache20.cpp
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#include <limits>
6#include "CacheLog.h"
7#include "CacheFileIOManager.h"
8
9#include "CacheHashUtils.h"
10#include "CacheStorageService.h"
11#include "CacheIndex.h"
12#include "CacheFileUtils.h"
13#include "nsError.h"
14#include "nsThreadUtils.h"
15#include "CacheFile.h"
16#include "CacheObserver.h"
17#include "nsIFile.h"
18#include "CacheFileContextEvictor.h"
19#include "nsITimer.h"
20#include "nsIDirectoryEnumerator.h"
21#include "nsEffectiveTLDService.h"
22#include "nsIObserverService.h"
23#include "nsISizeOf.h"
24#include "mozilla/net/MozURL.h"
25#include "mozilla/Telemetry.h"
26#include "mozilla/DebugOnly.h"
27#include "mozilla/Services.h"
28#include "mozilla/SpinEventLoopUntil.h"
29#include "mozilla/StaticPrefs_network.h"
30#include "mozilla/StoragePrincipalHelper.h"
31#include "nsDirectoryServiceUtils.h"
32#include "nsAppDirectoryServiceDefs.h"
33#include "private/pprio.h"
34#include "mozilla/IntegerPrintfMacros.h"
35#include "mozilla/Preferences.h"
36#include "nsNetUtil.h"
37#include "mozilla/glean/GleanMetrics.h"
38
39#ifdef MOZ_BACKGROUNDTASKS1
40# include "mozilla/BackgroundTasksRunner.h"
41# include "nsIBackgroundTasks.h"
42#endif
43
44// include files for ftruncate (or equivalent)
45#if defined(XP_UNIX1)
46# include <unistd.h>
47#elif defined(XP_WIN)
48# include <windows.h>
49# undef CreateFile
50# undef CREATE_NEW
51#else
52// XXX add necessary include file for ftruncate (or equivalent)
53#endif
54
55namespace mozilla::net {
56
57#define kOpenHandlesLimit128 128
58#define kMetadataWriteDelay5000 5000
59#define kRemoveTrashStartDelay60000 60000 // in milliseconds
60#define kSmartSizeUpdateInterval60000 60000 // in milliseconds
61
62#ifdef ANDROID
63const uint32_t kMaxCacheSizeKB = 512 * 1024; // 512 MB
64#else
65const uint32_t kMaxCacheSizeKB = 1024 * 1024; // 1 GB
66#endif
67const uint32_t kMaxClearOnShutdownCacheSizeKB = 150 * 1024; // 150 MB
68const auto kPurgeExtension = ".purge.bg_rm"_ns;
69
70bool CacheFileHandle::DispatchRelease() {
71 if (CacheFileIOManager::IsOnIOThreadOrCeased()) {
72 return false;
73 }
74
75 nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget();
76 if (!ioTarget) {
77 return false;
78 }
79
80 nsresult rv = ioTarget->Dispatch(
81 NewNonOwningRunnableMethod("net::CacheFileHandle::Release", this,
82 &CacheFileHandle::Release),
83 nsIEventTarget::DISPATCH_NORMAL);
84 return NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)));
85}
86
87NS_IMPL_ADDREF(CacheFileHandle)MozExternalRefCountType CacheFileHandle::AddRef(void) { static_assert
(!std::is_destructible_v<CacheFileHandle>, "Reference-counted class "
"CacheFileHandle" " should not have a public destructor. " "Make this class's destructor non-public"
); do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 87); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
87; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CacheFileHandle" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CacheFileHandle" != nullptr
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"\"CacheFileHandle\" != nullptr" " (" "Must specify a name" ")"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 87); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CacheFileHandle\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 87; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("CacheFileHandle" " not thread-safe"); nsrefcnt count = ++mRefCnt
; NS_LogAddRef((this), (count), ("CacheFileHandle"), (uint32_t
)(sizeof(*this))); return count; }
88NS_IMETHODIMP_(MozExternalRefCountType)MozExternalRefCountType
89CacheFileHandle::Release() {
90 nsrefcnt count = mRefCnt - 1;
91 if (DispatchRelease()) {
92 // Redispatched to the IO thread.
93 return count;
94 }
95
96 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 96); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 96; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
97
98 LOG(("CacheFileHandle::Release() [this=%p, refcnt=%" PRIuPTR "]", this,do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Release() [this=%p, refcnt=%"
"l" "u" "]", this, mRefCnt.get()); } } while (0)
99 mRefCnt.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Release() [this=%p, refcnt=%"
"l" "u" "]", this, mRefCnt.get()); } } while (0)
;
100 MOZ_ASSERT(0 != mRefCnt, "dup release")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(0 != mRefCnt)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(0 != mRefCnt))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("0 != mRefCnt" " ("
"dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 100); AnnotateMozCrashReason("MOZ_ASSERT" "(" "0 != mRefCnt"
") (" "dup release" ")"); do { *((volatile int*)__null) = 100
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
101 count = --mRefCnt;
102 NS_LOG_RELEASE(this, count, "CacheFileHandle")NS_LogRelease((this), (count), ("CacheFileHandle"));
103
104 if (0 == count) {
105 mRefCnt = 1;
106 delete (this);
107 return 0;
108 }
109
110 return count;
111}
112
113NS_INTERFACE_MAP_BEGIN(CacheFileHandle)nsresult CacheFileHandle::QueryInterface(const nsIID& aIID
, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 113); MOZ_PretendNoReturn(); } } while (0); nsISupports* foundInterface
;
114 NS_INTERFACE_MAP_ENTRY(nsISupports)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t
<decltype(*this)>, nsISupports>)) foundInterface = static_cast
<nsISupports*>(this); else
115NS_INTERFACE_MAP_ENDfoundInterface = 0; nsresult status; if (!foundInterface) { do
{ static_assert( mozilla::detail::AssertionConditionType<
decltype(!aIID.Equals((nsISupports::COMTypeInfo<nsISupports
, void>::kIID)))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aIID.Equals((nsISupports::COMTypeInfo
<nsISupports, void>::kIID))))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("!aIID.Equals((nsISupports::COMTypeInfo<nsISupports, void>::kIID))"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 115); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIID.Equals((nsISupports::COMTypeInfo<nsISupports, void>::kIID))"
")"); do { *((volatile int*)__null) = 115; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); status = NS_NOINTERFACE
; } else { (foundInterface)->AddRef(); status = NS_OK; } *
aInstancePtr = foundInterface; return status; }
116
117CacheFileHandle::CacheFileHandle(const SHA1Sum::Hash* aHash, bool aPriority,
118 PinningStatus aPinning)
119 : mHash(aHash),
120 mIsDoomed(false),
121 mClosed(false),
122 mPriority(aPriority),
123 mSpecialFile(false),
124 mInvalid(false),
125 mFileExists(false),
126 mDoomWhenFoundPinned(false),
127 mDoomWhenFoundNonPinned(false),
128 mKilled(false),
129 mPinning(aPinning),
130 mFileSize(-1),
131 mFD(nullptr) {
132 // If we initialize mDoomed in the initialization list, that initialization is
133 // not guaranteeded to be atomic. Whereas this assignment here is guaranteed
134 // to be atomic. TSan will see this (atomic) assignment and be satisfied
135 // that cross-thread accesses to mIsDoomed are properly synchronized.
136 mIsDoomed = false;
137 LOG((do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::CacheFileHandle() [this=%p, hash=%08x%08x%08x%08x%08x]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[4])); } } while (0)
138 "CacheFileHandle::CacheFileHandle() [this=%p, hash=%08x%08x%08x%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::CacheFileHandle() [this=%p, hash=%08x%08x%08x%08x%08x]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[4])); } } while (0)
139 this, LOGSHA1(aHash)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::CacheFileHandle() [this=%p, hash=%08x%08x%08x%08x%08x]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[4])); } } while (0)
;
140}
141
142CacheFileHandle::CacheFileHandle(const nsACString& aKey, bool aPriority,
143 PinningStatus aPinning)
144 : mHash(nullptr),
145 mIsDoomed(false),
146 mClosed(false),
147 mPriority(aPriority),
148 mSpecialFile(true),
149 mInvalid(false),
150 mFileExists(false),
151 mDoomWhenFoundPinned(false),
152 mDoomWhenFoundNonPinned(false),
153 mKilled(false),
154 mPinning(aPinning),
155 mFileSize(-1),
156 mFD(nullptr),
157 mKey(aKey) {
158 // See comment above about the initialization of mIsDoomed.
159 mIsDoomed = false;
160 LOG(("CacheFileHandle::CacheFileHandle() [this=%p, key=%s]", this,do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::CacheFileHandle() [this=%p, key=%s]"
, this, TPromiseFlatString<char>(aKey).get()); } } while
(0)
161 PromiseFlatCString(aKey).get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::CacheFileHandle() [this=%p, key=%s]"
, this, TPromiseFlatString<char>(aKey).get()); } } while
(0)
;
162}
163
164CacheFileHandle::~CacheFileHandle() {
165 LOG(("CacheFileHandle::~CacheFileHandle() [this=%p]", this))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::~CacheFileHandle() [this=%p]"
, this); } } while (0)
;
166
167 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 167); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 167; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
168
169 RefPtr<CacheFileIOManager> ioMan = CacheFileIOManager::gInstance;
170 if (!IsClosed() && ioMan) {
171 ioMan->CloseHandleInternal(this);
172 }
173}
174
175void CacheFileHandle::Log() {
176 nsAutoCString leafName;
177 if (mFile) {
178 mFile->GetNativeLeafName(leafName);
179 }
180
181 if (mSpecialFile) {
182 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
183 ("CacheFileHandle::Log() - special file [this=%p, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
184 "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
185 "pinning=%" PRIu32 ", fileExists=%d, fileSize=%" PRId64do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
186 ", leafName=%s, key=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
187 this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool(mInvalid),do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
188 static_cast<uint32_t>(mPinning), bool(mFileExists), int64_t(mFileSize),do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
189 leafName.get(), mKey.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
;
190 } else {
191 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
192 ("CacheFileHandle::Log() - entry file [this=%p, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
193 "hash=%08x%08x%08x%08x%08x, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
194 "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
195 "pinning=%" PRIu32 ", fileExists=%d, fileSize=%" PRId64do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
196 ", leafName=%s, key=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
197 this, LOGSHA1(mHash), bool(mIsDoomed), bool(mPriority), bool(mClosed),do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
198 bool(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists),do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
199 int64_t(mFileSize), leafName.get(), mKey.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
;
200 }
201}
202
203uint32_t CacheFileHandle::FileSizeInK() const {
204 MOZ_ASSERT(mFileSize != -1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mFileSize != -1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mFileSize != -1))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("mFileSize != -1"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 204); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mFileSize != -1"
")"); do { *((volatile int*)__null) = 204; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
205 uint64_t size64 = mFileSize;
206
207 size64 += 0x3FF;
208 size64 >>= 10;
209
210 uint32_t size;
211 if (size64 >> 32) {
212 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileHandle::FileSizeInK() - FileSize is too large, "
"truncating to PR_UINT32_MAX", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 214)
213 "CacheFileHandle::FileSizeInK() - FileSize is too large, "NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileHandle::FileSizeInK() - FileSize is too large, "
"truncating to PR_UINT32_MAX", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 214)
214 "truncating to PR_UINT32_MAX")NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileHandle::FileSizeInK() - FileSize is too large, "
"truncating to PR_UINT32_MAX", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 214)
;
215 size = PR_UINT32_MAX4294967295U;
216 } else {
217 size = static_cast<uint32_t>(size64);
218 }
219
220 return size;
221}
222
223bool CacheFileHandle::SetPinned(bool aPinned) {
224 LOG(("CacheFileHandle::SetPinned [this=%p, pinned=%d]", this, aPinned))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::SetPinned [this=%p, pinned=%d]"
, this, aPinned); } } while (0)
;
225
226 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 226); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 226; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
227
228 mPinning = aPinned ? PinningStatus::PINNED : PinningStatus::NON_PINNED;
229
230 if ((MOZ_UNLIKELY(mDoomWhenFoundPinned)(__builtin_expect(!!(mDoomWhenFoundPinned), 0)) && aPinned) ||
231 (MOZ_UNLIKELY(mDoomWhenFoundNonPinned)(__builtin_expect(!!(mDoomWhenFoundNonPinned), 0)) && !aPinned)) {
232 LOG((" dooming, when: pinned=%d, non-pinned=%d, found: pinned=%d",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " dooming, when: pinned=%d, non-pinned=%d, found: pinned=%d"
, bool(mDoomWhenFoundPinned), bool(mDoomWhenFoundNonPinned), aPinned
); } } while (0)
233 bool(mDoomWhenFoundPinned), bool(mDoomWhenFoundNonPinned), aPinned))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " dooming, when: pinned=%d, non-pinned=%d, found: pinned=%d"
, bool(mDoomWhenFoundPinned), bool(mDoomWhenFoundNonPinned), aPinned
); } } while (0)
;
234
235 mDoomWhenFoundPinned = false;
236 mDoomWhenFoundNonPinned = false;
237
238 return false;
239 }
240
241 return true;
242}
243
244// Memory reporting
245
246size_t CacheFileHandle::SizeOfExcludingThis(
247 mozilla::MallocSizeOf mallocSizeOf) const {
248 size_t n = 0;
249 nsCOMPtr<nsISizeOf> sizeOf;
250
251 sizeOf = do_QueryInterface(mFile);
252 if (sizeOf) {
253 n += sizeOf->SizeOfIncludingThis(mallocSizeOf);
254 }
255
256 n += mallocSizeOf(mFD);
257 n += mKey.SizeOfExcludingThisIfUnshared(mallocSizeOf);
258 return n;
259}
260
261size_t CacheFileHandle::SizeOfIncludingThis(
262 mozilla::MallocSizeOf mallocSizeOf) const {
263 return mallocSizeOf(this) + SizeOfExcludingThis(mallocSizeOf);
264}
265
266/******************************************************************************
267 * CacheFileHandles::HandleHashKey
268 *****************************************************************************/
269
270void CacheFileHandles::HandleHashKey::AddHandle(CacheFileHandle* aHandle) {
271 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 271); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 271; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
272
273 mHandles.InsertElementAt(0, aHandle);
274}
275
276void CacheFileHandles::HandleHashKey::RemoveHandle(CacheFileHandle* aHandle) {
277 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 277); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 277; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
278
279 DebugOnly<bool> found{};
280 found = mHandles.RemoveElement(aHandle);
281 MOZ_ASSERT(found)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(found)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(found))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("found", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 281); AnnotateMozCrashReason("MOZ_ASSERT" "(" "found" ")");
do { *((volatile int*)__null) = 281; __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
282}
283
284already_AddRefed<CacheFileHandle>
285CacheFileHandles::HandleHashKey::GetNewestHandle() {
286 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 286); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 286; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
287
288 RefPtr<CacheFileHandle> handle;
289 if (mHandles.Length()) {
290 handle = mHandles[0];
291 }
292
293 return handle.forget();
294}
295
296void CacheFileHandles::HandleHashKey::GetHandles(
297 nsTArray<RefPtr<CacheFileHandle>>& aResult) {
298 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 298); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 298; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
299
300 for (uint32_t i = 0; i < mHandles.Length(); ++i) {
301 CacheFileHandle* handle = mHandles[i];
302 aResult.AppendElement(handle);
303 }
304}
305
306#ifdef DEBUG1
307
308void CacheFileHandles::HandleHashKey::AssertHandlesState() {
309 for (uint32_t i = 0; i < mHandles.Length(); ++i) {
310 CacheFileHandle* handle = mHandles[i];
311 MOZ_ASSERT(handle->IsDoomed())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(handle->IsDoomed())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(handle->IsDoomed()))), 0)
)) { do { } while (false); MOZ_ReportAssertionFailure("handle->IsDoomed()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 311); AnnotateMozCrashReason("MOZ_ASSERT" "(" "handle->IsDoomed()"
")"); do { *((volatile int*)__null) = 311; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
312 }
313}
314
315#endif
316
317size_t CacheFileHandles::HandleHashKey::SizeOfExcludingThis(
318 mozilla::MallocSizeOf mallocSizeOf) const {
319 MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("CacheFileIOManager::IsOnIOThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 319); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { *((volatile int*)__null) = 319; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
320
321 size_t n = 0;
322 n += mallocSizeOf(mHash.get());
323 for (uint32_t i = 0; i < mHandles.Length(); ++i) {
324 n += mHandles[i]->SizeOfIncludingThis(mallocSizeOf);
325 }
326
327 return n;
328}
329
330/******************************************************************************
331 * CacheFileHandles
332 *****************************************************************************/
333
334CacheFileHandles::CacheFileHandles() {
335 LOG(("CacheFileHandles::CacheFileHandles() [this=%p]", this))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::CacheFileHandles() [this=%p]"
, this); } } while (0)
;
336 MOZ_COUNT_CTOR(CacheFileHandles)do { static_assert(std::is_class_v<CacheFileHandles>, "Token '"
"CacheFileHandles" "' is not a class type."); static_assert(
!std::is_base_of<nsISupports, CacheFileHandles>::value,
"nsISupports classes don't need to call MOZ_COUNT_CTOR or " "MOZ_COUNT_DTOR"
);; NS_LogCtor((void*)this, "CacheFileHandles", sizeof(*this)
); } while (0)
;
337}
338
339CacheFileHandles::~CacheFileHandles() {
340 LOG(("CacheFileHandles::~CacheFileHandles() [this=%p]", this))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::~CacheFileHandles() [this=%p]"
, this); } } while (0)
;
341 MOZ_COUNT_DTOR(CacheFileHandles)do { static_assert(std::is_class_v<CacheFileHandles>, "Token '"
"CacheFileHandles" "' is not a class type."); static_assert(
!std::is_base_of<nsISupports, CacheFileHandles>::value,
"nsISupports classes don't need to call MOZ_COUNT_CTOR or " "MOZ_COUNT_DTOR"
);; NS_LogDtor((void*)this, "CacheFileHandles", sizeof(*this)
); } while (0)
;
342}
343
344nsresult CacheFileHandles::GetHandle(const SHA1Sum::Hash* aHash,
345 CacheFileHandle** _retval) {
346 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 346); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 346; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
347 MOZ_ASSERT(aHash)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHash)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(aHash))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("aHash", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 347); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHash" ")");
do { *((volatile int*)__null) = 347; __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
348
349#ifdef DEBUG_HANDLES
350 LOG(("CacheFileHandles::GetHandle() [hash=%08x%08x%08x%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() [hash=%08x%08x%08x%08x%08x]"
, PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0
]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))
[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[4])); } } while (0)
351 LOGSHA1(aHash)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() [hash=%08x%08x%08x%08x%08x]"
, PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0
]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))
[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[4])); } } while (0)
;
352#endif
353
354 // find hash entry for key
355 HandleHashKey* entry = mTable.GetEntry(*aHash);
356 if (!entry) {
357 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle entries found", PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[4])); } } while (0)
358 ("CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle entries found", PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[4])); } } while (0)
359 "no handle entries found",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle entries found", PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[4])); } } while (0)
360 LOGSHA1(aHash)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle entries found", PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[4])); } } while (0)
;
361 return NS_ERROR_NOT_AVAILABLE;
362 }
363
364#ifdef DEBUG_HANDLES
365 Log(entry);
366#endif
367
368 // Check if the entry is doomed
369 RefPtr<CacheFileHandle> handle = entry->GetNewestHandle();
370 if (!handle) {
371 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle found %p, entry %p", PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[4]), handle.get(), entry); } } while
(0)
372 ("CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle found %p, entry %p", PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[4]), handle.get(), entry); } } while
(0)
373 "no handle found %p, entry %p",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle found %p, entry %p", PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[4]), handle.get(), entry); } } while
(0)
374 LOGSHA1(aHash), handle.get(), entry))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle found %p, entry %p", PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHash))[4]), handle.get(), entry); } } while
(0)
;
375 return NS_ERROR_NOT_AVAILABLE;
376 }
377
378 if (handle->IsDoomed()) {
379 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found doomed handle %p, entry %p", PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[4]), handle.get(), entry); } }
while (0)
380 ("CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found doomed handle %p, entry %p", PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[4]), handle.get(), entry); } }
while (0)
381 "found doomed handle %p, entry %p",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found doomed handle %p, entry %p", PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[4]), handle.get(), entry); } }
while (0)
382 LOGSHA1(aHash), handle.get(), entry))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found doomed handle %p, entry %p", PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[4]), handle.get(), entry); } }
while (0)
;
383 return NS_ERROR_NOT_AVAILABLE;
384 }
385
386 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found handle %p, entry %p", PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[4]), handle.get(), entry); } } while (
0)
387 ("CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found handle %p, entry %p", PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[4]), handle.get(), entry); } } while (
0)
388 "found handle %p, entry %p",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found handle %p, entry %p", PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[4]), handle.get(), entry); } } while (
0)
389 LOGSHA1(aHash), handle.get(), entry))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found handle %p, entry %p", PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHash))[4]), handle.get(), entry); } } while (
0)
;
390
391 handle.forget(_retval);
392 return NS_OK;
393}
394
395already_AddRefed<CacheFileHandle> CacheFileHandles::NewHandle(
396 const SHA1Sum::Hash* aHash, bool aPriority,
397 CacheFileHandle::PinningStatus aPinning) {
398 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 398); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 398; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
399 MOZ_ASSERT(aHash)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHash)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(aHash))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("aHash", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 399); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHash" ")");
do { *((volatile int*)__null) = 399; __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
400
401#ifdef DEBUG_HANDLES
402 LOG(("CacheFileHandles::NewHandle() [hash=%08x%08x%08x%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::NewHandle() [hash=%08x%08x%08x%08x%08x]"
, PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0
]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))
[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[4])); } } while (0)
403 LOGSHA1(aHash)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::NewHandle() [hash=%08x%08x%08x%08x%08x]"
, PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0
]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))
[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[4])); } } while (0)
;
404#endif
405
406 // find hash entry for key
407 HandleHashKey* entry = mTable.PutEntry(*aHash);
408
409#ifdef DEBUG_HANDLES
410 Log(entry);
411#endif
412
413#ifdef DEBUG1
414 entry->AssertHandlesState();
415#endif
416
417 RefPtr<CacheFileHandle> handle =
418 new CacheFileHandle(entry->Hash(), aPriority, aPinning);
419 entry->AddHandle(handle);
420
421 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::NewHandle() hash=%08x%08x%08x%08x%08x "
"created new handle %p, entry=%p", PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[4]), handle.get(), entry); } }
while (0)
422 ("CacheFileHandles::NewHandle() hash=%08x%08x%08x%08x%08x "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::NewHandle() hash=%08x%08x%08x%08x%08x "
"created new handle %p, entry=%p", PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[4]), handle.get(), entry); } }
while (0)
423 "created new handle %p, entry=%p",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::NewHandle() hash=%08x%08x%08x%08x%08x "
"created new handle %p, entry=%p", PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[4]), handle.get(), entry); } }
while (0)
424 LOGSHA1(aHash), handle.get(), entry))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::NewHandle() hash=%08x%08x%08x%08x%08x "
"created new handle %p, entry=%p", PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHash))[4]), handle.get(), entry); } }
while (0)
;
425 return handle.forget();
426}
427
428void CacheFileHandles::RemoveHandle(CacheFileHandle* aHandle) {
429 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 429); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 429; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
430 MOZ_ASSERT(aHandle)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHandle)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aHandle))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aHandle", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 430); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHandle" ")"
); do { *((volatile int*)__null) = 430; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
431
432 if (!aHandle) {
433 return;
434 }
435
436#ifdef DEBUG_HANDLES
437 LOG((do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() [handle=%p, hash=%08x%08x%08x%08x%08x]"
, aHandle, PR_htonl((reinterpret_cast<const uint32_t*>(
aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
438 "CacheFileHandles::RemoveHandle() [handle=%p, hash=%08x%08x%08x%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() [handle=%p, hash=%08x%08x%08x%08x%08x]"
, aHandle, PR_htonl((reinterpret_cast<const uint32_t*>(
aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
439 aHandle, LOGSHA1(aHandle->Hash())))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() [handle=%p, hash=%08x%08x%08x%08x%08x]"
, aHandle, PR_htonl((reinterpret_cast<const uint32_t*>(
aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
;
440#endif
441
442 // find hash entry for key
443 HandleHashKey* entry = mTable.GetEntry(*aHandle->Hash());
444 if (!entry) {
445 MOZ_ASSERT(CacheFileIOManager::IsShutdown(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsShutdown())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsShutdown
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("CacheFileIOManager::IsShutdown()" " (" "Should find entry when removing a handle before shutdown"
")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 446); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsShutdown()"
") (" "Should find entry when removing a handle before shutdown"
")"); do { *((volatile int*)__null) = 446; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
446 "Should find entry when removing a handle before shutdown")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsShutdown())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsShutdown
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("CacheFileIOManager::IsShutdown()" " (" "Should find entry when removing a handle before shutdown"
")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 446); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsShutdown()"
") (" "Should find entry when removing a handle before shutdown"
")"); do { *((volatile int*)__null) = 446; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
447
448 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"no entries found", PR_htonl((reinterpret_cast<const uint32_t
*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
449 ("CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"no entries found", PR_htonl((reinterpret_cast<const uint32_t
*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
450 "no entries found",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"no entries found", PR_htonl((reinterpret_cast<const uint32_t
*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
451 LOGSHA1(aHandle->Hash())))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"no entries found", PR_htonl((reinterpret_cast<const uint32_t
*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
;
452 return;
453 }
454
455#ifdef DEBUG_HANDLES
456 Log(entry);
457#endif
458
459 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"removing handle %p", PR_htonl((reinterpret_cast<const uint32_t
*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[4]), aHandle); } }
while (0)
460 ("CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"removing handle %p", PR_htonl((reinterpret_cast<const uint32_t
*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[4]), aHandle); } }
while (0)
461 "removing handle %p",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"removing handle %p", PR_htonl((reinterpret_cast<const uint32_t
*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[4]), aHandle); } }
while (0)
462 LOGSHA1(entry->Hash()), aHandle))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"removing handle %p", PR_htonl((reinterpret_cast<const uint32_t
*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[4]), aHandle); } }
while (0)
;
463 entry->RemoveHandle(aHandle);
464
465 if (entry->IsEmpty()) {
466 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"list is empty, removing entry %p", PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[4]), entry); } } while
(0)
467 ("CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"list is empty, removing entry %p", PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[4]), entry); } } while
(0)
468 "list is empty, removing entry %p",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"list is empty, removing entry %p", PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[4]), entry); } } while
(0)
469 LOGSHA1(entry->Hash()), entry))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"list is empty, removing entry %p", PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(entry->Hash()))[4]), entry); } } while
(0)
;
470 mTable.RemoveEntry(entry);
471 }
472}
473
474void CacheFileHandles::GetAllHandles(
475 nsTArray<RefPtr<CacheFileHandle>>* _retval) {
476 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 476); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 476; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
477 for (auto iter = mTable.Iter(); !iter.Done(); iter.Next()) {
478 iter.Get()->GetHandles(*_retval);
479 }
480}
481
482void CacheFileHandles::GetActiveHandles(
483 nsTArray<RefPtr<CacheFileHandle>>* _retval) {
484 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 484); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 484; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
485 for (auto iter = mTable.Iter(); !iter.Done(); iter.Next()) {
486 RefPtr<CacheFileHandle> handle = iter.Get()->GetNewestHandle();
487 MOZ_ASSERT(handle)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(handle)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(handle))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("handle", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 487); AnnotateMozCrashReason("MOZ_ASSERT" "(" "handle" ")")
; do { *((volatile int*)__null) = 487; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
488
489 if (!handle->IsDoomed()) {
490 _retval->AppendElement(handle);
491 }
492 }
493}
494
495void CacheFileHandles::ClearAll() {
496 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 496); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 496; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
497 mTable.Clear();
498}
499
500uint32_t CacheFileHandles::HandleCount() { return mTable.Count(); }
501
502#ifdef DEBUG_HANDLES
503void CacheFileHandles::Log(CacheFileHandlesEntry* entry) {
504 LOG(("CacheFileHandles::Log() BEGIN [entry=%p]", entry))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::Log() BEGIN [entry=%p]"
, entry); } } while (0)
;
505
506 nsTArray<RefPtr<CacheFileHandle>> array;
507 aEntry->GetHandles(array);
508
509 for (uint32_t i = 0; i < array.Length(); ++i) {
510 CacheFileHandle* handle = array[i];
511 handle->Log();
512 }
513
514 LOG(("CacheFileHandles::Log() END [entry=%p]", entry))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::Log() END [entry=%p]"
, entry); } } while (0)
;
515}
516#endif
517
518// Memory reporting
519
520size_t CacheFileHandles::SizeOfExcludingThis(
521 mozilla::MallocSizeOf mallocSizeOf) const {
522 MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("CacheFileIOManager::IsOnIOThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 522); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { *((volatile int*)__null) = 522; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
523
524 return mTable.SizeOfExcludingThis(mallocSizeOf);
525}
526
527// Events
528
529class ShutdownEvent : public Runnable, nsITimerCallback {
530 NS_DECL_ISUPPORTS_INHERITEDpublic: virtual nsresult QueryInterface(const nsIID& aIID
, void** aInstancePtr) override; virtual MozExternalRefCountType
AddRef(void) override; virtual MozExternalRefCountType Release
(void) override;
531 public:
532 ShutdownEvent() : Runnable("net::ShutdownEvent") {}
533
534 protected:
535 ~ShutdownEvent() = default;
536
537 public:
538 NS_IMETHODvirtual nsresult Run() override {
539 CacheFileIOManager::gInstance->ShutdownInternal();
540
541 mNotified = true;
542
543 NS_DispatchToMainThread(
544 NS_NewRunnableFunction("CacheFileIOManager::ShutdownEvent::Run", []() {
545 // This empty runnable is dispatched just in case the MT event loop
546 // becomes empty - we need to process a task to break out of
547 // SpinEventLoopUntil.
548 }));
549
550 return NS_OK;
551 }
552
553 NS_IMETHODvirtual nsresult Notify(nsITimer* timer) override {
554 if (mNotified) {
555 return NS_OK;
556 }
557
558 // If there is any IO blocking on the IO thread, this will
559 // try to cancel it.
560 CacheFileIOManager::gInstance->mIOThread->CancelBlockingIO();
561
562 // After this runs the first time, the browser_cache_max_shutdown_io_lag
563 // time has elapsed. The CacheIO thread may pick up more blocking IO tasks
564 // so we want to block those too if necessary.
565 mTimer->SetDelay(
566 StaticPrefs::browser_cache_shutdown_io_time_between_cancellations_ms());
567 return NS_OK;
568 }
569
570 void PostAndWait() {
571 nsresult rv = CacheFileIOManager::gInstance->mIOThread->Dispatch(
572 this,
573 CacheIOThread::WRITE); // When writes and closing of handles is done
574 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 574); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 574; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
575
576 // If we failed to post the even there's no reason to go into the loop
577 // because mNotified will never be set to true.
578 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
579 NS_WARNING("Posting ShutdownEvent task failed")NS_DebugBreak(NS_DEBUG_WARNING, "Posting ShutdownEvent task failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 579)
;
580 return;
581 }
582
583 rv = NS_NewTimerWithCallback(
584 getter_AddRefs(mTimer), this,
585 StaticPrefs::browser_cache_max_shutdown_io_lag() * 1000,
586 nsITimer::TYPE_REPEATING_SLACK);
587 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 587); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 587; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
588
589 mozilla::SpinEventLoopUntil("CacheFileIOManager::ShutdownEvent"_ns,
590 [&]() { return bool(mNotified); });
591
592 if (mTimer) {
593 mTimer->Cancel();
594 mTimer = nullptr;
595 }
596 }
597
598 protected:
599 Atomic<bool> mNotified{false};
600 nsCOMPtr<nsITimer> mTimer;
601};
602
603NS_IMPL_ISUPPORTS_INHERITED(ShutdownEvent, Runnable, nsITimerCallback)nsresult ShutdownEvent::QueryInterface(const nsIID& aIID,
void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 603); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE_INHERITED"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<ShutdownEvent, nsITimerCallback>, int32_t
( reinterpret_cast<char*>(static_cast<nsITimerCallback
*>((ShutdownEvent*)0x1000)) - reinterpret_cast<char*>
((ShutdownEvent*)0x1000))}, { nullptr, 0 } } ; static_assert(
(sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface"
); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID
, aInstancePtr, table); if (((bool)(__builtin_expect(!!(!NS_FAILED_impl
(rv)), 1)))) return rv; return Runnable::QueryInterface(aIID,
aInstancePtr); } MozExternalRefCountType ShutdownEvent::AddRef
(void) { static_assert(!std::is_destructible_v<ShutdownEvent
>, "Reference-counted class " "ShutdownEvent" " should not have a public destructor. "
"Make this class's destructor non-public"); nsrefcnt r = Runnable
::AddRef(); if constexpr (::mozilla::detail::ShouldLogInheritedRefcnt
<ShutdownEvent>) { NS_LogAddRef((this), (r), ("ShutdownEvent"
), (uint32_t)(sizeof(*this))); } return r; } MozExternalRefCountType
ShutdownEvent::Release(void) { nsrefcnt r = Runnable::Release
(); if constexpr (::mozilla::detail::ShouldLogInheritedRefcnt
<ShutdownEvent>) { NS_LogRelease((this), (r), ("ShutdownEvent"
)); } return r; }
604
605// Class responsible for reporting IO performance stats
606class IOPerfReportEvent {
607 public:
608 explicit IOPerfReportEvent(CacheFileUtils::CachePerfStats::EDataType aType)
609 : mType(aType), mEventCounter(0) {}
610
611 void Start(CacheIOThread* aIOThread) {
612 mStartTime = TimeStamp::Now();
613 mEventCounter = aIOThread->EventCounter();
614 }
615
616 void Report(CacheIOThread* aIOThread) {
617 if (mStartTime.IsNull()) {
618 return;
619 }
620
621 // Single IO operations can take less than 1ms. So we use microseconds to
622 // keep a good resolution of data.
623 uint32_t duration = (TimeStamp::Now() - mStartTime).ToMicroseconds();
624
625 // This is a simple prefiltering of values that might differ a lot from the
626 // average value. Do not add the value to the filtered stats when the event
627 // had to wait in a long queue.
628 uint32_t eventCounter = aIOThread->EventCounter();
629 bool shortOnly = eventCounter - mEventCounter >= 5;
630
631 CacheFileUtils::CachePerfStats::AddValue(mType, duration, shortOnly);
632 }
633
634 protected:
635 CacheFileUtils::CachePerfStats::EDataType mType;
636 TimeStamp mStartTime;
637 uint32_t mEventCounter;
638};
639
640class OpenFileEvent : public Runnable, public IOPerfReportEvent {
641 public:
642 OpenFileEvent(const nsACString& aKey, uint32_t aFlags,
643 CacheFileIOListener* aCallback)
644 : Runnable("net::OpenFileEvent"),
645 IOPerfReportEvent(CacheFileUtils::CachePerfStats::IO_OPEN),
646 mFlags(aFlags),
647 mCallback(aCallback),
648 mKey(aKey) {
649 mIOMan = CacheFileIOManager::gInstance;
650 if (!(mFlags & CacheFileIOManager::SPECIAL_FILE)) {
651 Start(mIOMan->mIOThread);
652 }
653 }
654
655 protected:
656 ~OpenFileEvent() = default;
657
658 public:
659 NS_IMETHODvirtual nsresult Run() override {
660 nsresult rv = NS_OK;
661
662 if (!(mFlags & CacheFileIOManager::SPECIAL_FILE)) {
663 SHA1Sum sum;
664 sum.update(mKey.BeginReading(), mKey.Length());
665 sum.finish(mHash);
666 }
667
668 if (!mIOMan) {
669 rv = NS_ERROR_NOT_INITIALIZED;
670 } else {
671 if (mFlags & CacheFileIOManager::SPECIAL_FILE) {
672 rv = mIOMan->OpenSpecialFileInternal(mKey, mFlags,
673 getter_AddRefs(mHandle));
674 } else {
675 rv = mIOMan->OpenFileInternal(&mHash, mKey, mFlags,
676 getter_AddRefs(mHandle));
677 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
678 Report(mIOMan->mIOThread);
679 }
680 }
681 mIOMan = nullptr;
682 if (mHandle) {
683 if (mHandle->Key().IsEmpty()) {
684 mHandle->Key() = mKey;
685 }
686 }
687 }
688
689 mCallback->OnFileOpened(mHandle, rv);
690 return NS_OK;
691 }
692
693 protected:
694 SHA1Sum::Hash mHash{};
695 uint32_t mFlags;
696 nsCOMPtr<CacheFileIOListener> mCallback;
697 RefPtr<CacheFileIOManager> mIOMan;
698 RefPtr<CacheFileHandle> mHandle;
699 nsCString mKey;
700};
701
702class ReadEvent : public Runnable, public IOPerfReportEvent {
703 public:
704 ReadEvent(CacheFileHandle* aHandle, int64_t aOffset, char* aBuf,
705 int32_t aCount, CacheFileIOListener* aCallback)
706 : Runnable("net::ReadEvent"),
707 IOPerfReportEvent(CacheFileUtils::CachePerfStats::IO_READ),
708 mHandle(aHandle),
709 mOffset(aOffset),
710 mBuf(aBuf),
711 mCount(aCount),
712 mCallback(aCallback) {
713 if (!mHandle->IsSpecialFile()) {
714 Start(CacheFileIOManager::gInstance->mIOThread);
715 }
716 }
717
718 protected:
719 ~ReadEvent() = default;
720
721 public:
722 NS_IMETHODvirtual nsresult Run() override {
723 nsresult rv;
724
725 if (mHandle->IsClosed() || (mCallback && mCallback->IsKilled())) {
726 rv = NS_ERROR_NOT_INITIALIZED;
727 } else {
728 rv = CacheFileIOManager::gInstance->ReadInternal(mHandle, mOffset, mBuf,
729 mCount);
730 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
731 Report(CacheFileIOManager::gInstance->mIOThread);
732 }
733 }
734
735 mCallback->OnDataRead(mHandle, mBuf, rv);
736 return NS_OK;
737 }
738
739 protected:
740 RefPtr<CacheFileHandle> mHandle;
741 int64_t mOffset;
742 char* mBuf;
743 int32_t mCount;
744 nsCOMPtr<CacheFileIOListener> mCallback;
745};
746
747class WriteEvent : public Runnable, public IOPerfReportEvent {
748 public:
749 WriteEvent(CacheFileHandle* aHandle, int64_t aOffset, const char* aBuf,
750 int32_t aCount, bool aValidate, bool aTruncate,
751 CacheFileIOListener* aCallback)
752 : Runnable("net::WriteEvent"),
753 IOPerfReportEvent(CacheFileUtils::CachePerfStats::IO_WRITE),
754 mHandle(aHandle),
755 mOffset(aOffset),
756 mBuf(aBuf),
757 mCount(aCount),
758 mValidate(aValidate),
759 mTruncate(aTruncate),
760 mCallback(aCallback) {
761 if (!mHandle->IsSpecialFile()) {
762 Start(CacheFileIOManager::gInstance->mIOThread);
763 }
764 }
765
766 protected:
767 ~WriteEvent() {
768 if (!mCallback && mBuf) {
769 free(const_cast<char*>(mBuf));
770 }
771 }
772
773 public:
774 NS_IMETHODvirtual nsresult Run() override {
775 nsresult rv;
776
777 if (mHandle->IsClosed() || (mCallback && mCallback->IsKilled())) {
778 // We usually get here only after the internal shutdown
779 // (i.e. mShuttingDown == true). Pretend write has succeeded
780 // to avoid any past-shutdown file dooming.
781 rv = (CacheObserver::IsPastShutdownIOLag() ||
782 CacheFileIOManager::gInstance->mShuttingDown)
783 ? NS_OK
784 : NS_ERROR_NOT_INITIALIZED;
785 } else {
786 rv = CacheFileIOManager::gInstance->WriteInternal(
787 mHandle, mOffset, mBuf, mCount, mValidate, mTruncate);
788 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
789 Report(CacheFileIOManager::gInstance->mIOThread);
790 }
791 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && !mCallback) {
792 // No listener is going to handle the error, doom the file
793 CacheFileIOManager::gInstance->DoomFileInternal(mHandle);
794 }
795 }
796 if (mCallback) {
797 mCallback->OnDataWritten(mHandle, mBuf, rv);
798 } else {
799 free(const_cast<char*>(mBuf));
800 mBuf = nullptr;
801 }
802
803 return NS_OK;
804 }
805
806 protected:
807 RefPtr<CacheFileHandle> mHandle;
808 int64_t mOffset;
809 const char* mBuf;
810 int32_t mCount;
811 bool mValidate : 1;
812 bool mTruncate : 1;
813 nsCOMPtr<CacheFileIOListener> mCallback;
814};
815
816class DoomFileEvent : public Runnable {
817 public:
818 DoomFileEvent(CacheFileHandle* aHandle, CacheFileIOListener* aCallback)
819 : Runnable("net::DoomFileEvent"),
820 mCallback(aCallback),
821 mHandle(aHandle) {}
822
823 protected:
824 ~DoomFileEvent() = default;
825
826 public:
827 NS_IMETHODvirtual nsresult Run() override {
828 nsresult rv;
829
830 if (mHandle->IsClosed()) {
831 rv = NS_ERROR_NOT_INITIALIZED;
832 } else {
833 rv = CacheFileIOManager::gInstance->DoomFileInternal(mHandle);
834 }
835
836 if (mCallback) {
837 mCallback->OnFileDoomed(mHandle, rv);
838 }
839
840 return NS_OK;
841 }
842
843 protected:
844 nsCOMPtr<CacheFileIOListener> mCallback;
845 nsCOMPtr<nsIEventTarget> mTarget;
846 RefPtr<CacheFileHandle> mHandle;
847};
848
849class DoomFileByKeyEvent : public Runnable {
850 public:
851 DoomFileByKeyEvent(const nsACString& aKey, CacheFileIOListener* aCallback)
852 : Runnable("net::DoomFileByKeyEvent"), mCallback(aCallback) {
853 SHA1Sum sum;
854 sum.update(aKey.BeginReading(), aKey.Length());
855 sum.finish(mHash);
856
857 mIOMan = CacheFileIOManager::gInstance;
858 }
859
860 protected:
861 ~DoomFileByKeyEvent() = default;
862
863 public:
864 NS_IMETHODvirtual nsresult Run() override {
865 nsresult rv;
866
867 if (!mIOMan) {
868 rv = NS_ERROR_NOT_INITIALIZED;
869 } else {
870 rv = mIOMan->DoomFileByKeyInternal(&mHash);
871 mIOMan = nullptr;
872 }
873
874 if (mCallback) {
875 mCallback->OnFileDoomed(nullptr, rv);
876 }
877
878 return NS_OK;
879 }
880
881 protected:
882 SHA1Sum::Hash mHash{};
883 nsCOMPtr<CacheFileIOListener> mCallback;
884 RefPtr<CacheFileIOManager> mIOMan;
885};
886
887class ReleaseNSPRHandleEvent : public Runnable {
888 public:
889 explicit ReleaseNSPRHandleEvent(CacheFileHandle* aHandle)
890 : Runnable("net::ReleaseNSPRHandleEvent"), mHandle(aHandle) {}
891
892 protected:
893 ~ReleaseNSPRHandleEvent() = default;
894
895 public:
896 NS_IMETHODvirtual nsresult Run() override {
897 if (!mHandle->IsClosed()) {
898 CacheFileIOManager::gInstance->MaybeReleaseNSPRHandleInternal(mHandle);
899 }
900
901 return NS_OK;
902 }
903
904 protected:
905 RefPtr<CacheFileHandle> mHandle;
906};
907
908class TruncateSeekSetEOFEvent : public Runnable {
909 public:
910 TruncateSeekSetEOFEvent(CacheFileHandle* aHandle, int64_t aTruncatePos,
911 int64_t aEOFPos, CacheFileIOListener* aCallback)
912 : Runnable("net::TruncateSeekSetEOFEvent"),
913 mHandle(aHandle),
914 mTruncatePos(aTruncatePos),
915 mEOFPos(aEOFPos),
916 mCallback(aCallback) {}
917
918 protected:
919 ~TruncateSeekSetEOFEvent() = default;
920
921 public:
922 NS_IMETHODvirtual nsresult Run() override {
923 nsresult rv;
924
925 if (mHandle->IsClosed() || (mCallback && mCallback->IsKilled())) {
926 rv = NS_ERROR_NOT_INITIALIZED;
927 } else {
928 rv = CacheFileIOManager::gInstance->TruncateSeekSetEOFInternal(
929 mHandle, mTruncatePos, mEOFPos);
930 }
931
932 if (mCallback) {
933 mCallback->OnEOFSet(mHandle, rv);
934 }
935
936 return NS_OK;
937 }
938
939 protected:
940 RefPtr<CacheFileHandle> mHandle;
941 int64_t mTruncatePos;
942 int64_t mEOFPos;
943 nsCOMPtr<CacheFileIOListener> mCallback;
944};
945
946class RenameFileEvent : public Runnable {
947 public:
948 RenameFileEvent(CacheFileHandle* aHandle, const nsACString& aNewName,
949 CacheFileIOListener* aCallback)
950 : Runnable("net::RenameFileEvent"),
951 mHandle(aHandle),
952 mNewName(aNewName),
953 mCallback(aCallback) {}
954
955 protected:
956 ~RenameFileEvent() = default;
957
958 public:
959 NS_IMETHODvirtual nsresult Run() override {
960 nsresult rv;
961
962 if (mHandle->IsClosed()) {
963 rv = NS_ERROR_NOT_INITIALIZED;
964 } else {
965 rv = CacheFileIOManager::gInstance->RenameFileInternal(mHandle, mNewName);
966 }
967
968 if (mCallback) {
969 mCallback->OnFileRenamed(mHandle, rv);
970 }
971
972 return NS_OK;
973 }
974
975 protected:
976 RefPtr<CacheFileHandle> mHandle;
977 nsCString mNewName;
978 nsCOMPtr<CacheFileIOListener> mCallback;
979};
980
981class InitIndexEntryEvent : public Runnable {
982 public:
983 InitIndexEntryEvent(CacheFileHandle* aHandle,
984 OriginAttrsHash aOriginAttrsHash, bool aAnonymous,
985 bool aPinning)
986 : Runnable("net::InitIndexEntryEvent"),
987 mHandle(aHandle),
988 mOriginAttrsHash(aOriginAttrsHash),
989 mAnonymous(aAnonymous),
990 mPinning(aPinning) {}
991
992 protected:
993 ~InitIndexEntryEvent() = default;
994
995 public:
996 NS_IMETHODvirtual nsresult Run() override {
997 if (mHandle->IsClosed() || mHandle->IsDoomed()) {
998 return NS_OK;
999 }
1000
1001 CacheIndex::InitEntry(mHandle->Hash(), mOriginAttrsHash, mAnonymous,
1002 mPinning);
1003
1004 // We cannot set the filesize before we init the entry. If we're opening
1005 // an existing entry file, frecency will be set after parsing the entry
1006 // file, but we must set the filesize here since nobody is going to set it
1007 // if there is no write to the file.
1008 uint32_t sizeInK = mHandle->FileSizeInK();
1009 CacheIndex::UpdateEntry(mHandle->Hash(), nullptr, nullptr, nullptr, nullptr,
1010 nullptr, &sizeInK);
1011
1012 return NS_OK;
1013 }
1014
1015 protected:
1016 RefPtr<CacheFileHandle> mHandle;
1017 OriginAttrsHash mOriginAttrsHash;
1018 bool mAnonymous;
1019 bool mPinning;
1020};
1021
1022class UpdateIndexEntryEvent : public Runnable {
1023 public:
1024 UpdateIndexEntryEvent(CacheFileHandle* aHandle, const uint32_t* aFrecency,
1025 const bool* aHasAltData, const uint16_t* aOnStartTime,
1026 const uint16_t* aOnStopTime,
1027 const uint8_t* aContentType)
1028 : Runnable("net::UpdateIndexEntryEvent"),
1029 mHandle(aHandle),
1030 mHasFrecency(false),
1031 mHasHasAltData(false),
1032 mHasOnStartTime(false),
1033 mHasOnStopTime(false),
1034 mHasContentType(false),
1035 mFrecency(0),
1036 mHasAltData(false),
1037 mOnStartTime(0),
1038 mOnStopTime(0),
1039 mContentType(nsICacheEntry::CONTENT_TYPE_UNKNOWN) {
1040 if (aFrecency) {
1041 mHasFrecency = true;
1042 mFrecency = *aFrecency;
1043 }
1044 if (aHasAltData) {
1045 mHasHasAltData = true;
1046 mHasAltData = *aHasAltData;
1047 }
1048 if (aOnStartTime) {
1049 mHasOnStartTime = true;
1050 mOnStartTime = *aOnStartTime;
1051 }
1052 if (aOnStopTime) {
1053 mHasOnStopTime = true;
1054 mOnStopTime = *aOnStopTime;
1055 }
1056 if (aContentType) {
1057 mHasContentType = true;
1058 mContentType = *aContentType;
1059 }
1060 }
1061
1062 protected:
1063 ~UpdateIndexEntryEvent() = default;
1064
1065 public:
1066 NS_IMETHODvirtual nsresult Run() override {
1067 if (mHandle->IsClosed() || mHandle->IsDoomed()) {
1068 return NS_OK;
1069 }
1070
1071 CacheIndex::UpdateEntry(mHandle->Hash(),
1072 mHasFrecency ? &mFrecency : nullptr,
1073 mHasHasAltData ? &mHasAltData : nullptr,
1074 mHasOnStartTime ? &mOnStartTime : nullptr,
1075 mHasOnStopTime ? &mOnStopTime : nullptr,
1076 mHasContentType ? &mContentType : nullptr, nullptr);
1077 return NS_OK;
1078 }
1079
1080 protected:
1081 RefPtr<CacheFileHandle> mHandle;
1082
1083 bool mHasFrecency;
1084 bool mHasHasAltData;
1085 bool mHasOnStartTime;
1086 bool mHasOnStopTime;
1087 bool mHasContentType;
1088
1089 uint32_t mFrecency;
1090 bool mHasAltData;
1091 uint16_t mOnStartTime;
1092 uint16_t mOnStopTime;
1093 uint8_t mContentType;
1094};
1095
1096class MetadataWriteScheduleEvent : public Runnable {
1097 public:
1098 enum EMode { SCHEDULE, UNSCHEDULE, SHUTDOWN } mMode;
1099
1100 RefPtr<CacheFile> mFile;
1101 RefPtr<CacheFileIOManager> mIOMan;
1102
1103 MetadataWriteScheduleEvent(CacheFileIOManager* aManager, CacheFile* aFile,
1104 EMode aMode)
1105 : Runnable("net::MetadataWriteScheduleEvent"),
1106 mMode(aMode),
1107 mFile(aFile),
1108 mIOMan(aManager) {}
1109
1110 virtual ~MetadataWriteScheduleEvent() = default;
1111
1112 NS_IMETHODvirtual nsresult Run() override {
1113 RefPtr<CacheFileIOManager> ioMan = CacheFileIOManager::gInstance;
1114 if (!ioMan) {
1115 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager already gone in "
"MetadataWriteScheduleEvent::Run()", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1117)
1116 "CacheFileIOManager already gone in "NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager already gone in "
"MetadataWriteScheduleEvent::Run()", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1117)
1117 "MetadataWriteScheduleEvent::Run()")NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager already gone in "
"MetadataWriteScheduleEvent::Run()", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1117)
;
1118 return NS_OK;
1119 }
1120
1121 switch (mMode) {
1122 case SCHEDULE:
1123 ioMan->ScheduleMetadataWriteInternal(mFile);
1124 break;
1125 case UNSCHEDULE:
1126 ioMan->UnscheduleMetadataWriteInternal(mFile);
1127 break;
1128 case SHUTDOWN:
1129 ioMan->ShutdownMetadataWriteSchedulingInternal();
1130 break;
1131 }
1132 return NS_OK;
1133 }
1134};
1135
1136StaticRefPtr<CacheFileIOManager> CacheFileIOManager::gInstance;
1137
1138NS_IMPL_ISUPPORTS(CacheFileIOManager, nsITimerCallback, nsINamed)MozExternalRefCountType CacheFileIOManager::AddRef(void) { static_assert
(!std::is_destructible_v<CacheFileIOManager>, "Reference-counted class "
"CacheFileIOManager" " should not have a public destructor. "
"Make this class's destructor non-public"); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(int32_t
(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1138); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
1138; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CacheFileIOManager" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CacheFileIOManager" != nullptr
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"\"CacheFileIOManager\" != nullptr" " (" "Must specify a name"
")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1138); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CacheFileIOManager\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 1138; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("CacheFileIOManager" " not thread-safe"); nsrefcnt
count = ++mRefCnt; NS_LogAddRef((this), (count), ("CacheFileIOManager"
), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType
CacheFileIOManager::Release(void) { do { static_assert( mozilla
::detail::AssertionConditionType<decltype(int32_t(mRefCnt)
> 0)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(int32_t(mRefCnt) > 0))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release"
")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1138); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 1138
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CacheFileIOManager" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CacheFileIOManager" != nullptr
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"\"CacheFileIOManager\" != nullptr" " (" "Must specify a name"
")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1138); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CacheFileIOManager\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 1138; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("CacheFileIOManager" " not thread-safe"); const
char* const nametmp = "CacheFileIOManager"; nsrefcnt count =
--mRefCnt; NS_LogRelease((this), (count), (nametmp)); if (count
== 0) { mRefCnt = 1; delete (this); return 0; } return count
; } nsresult CacheFileIOManager::QueryInterface(const nsIID&
aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1138); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(2 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<CacheFileIOManager, nsITimerCallback>
, int32_t( reinterpret_cast<char*>(static_cast<nsITimerCallback
*>((CacheFileIOManager*)0x1000)) - reinterpret_cast<char
*>((CacheFileIOManager*)0x1000))}, {&mozilla::detail::
kImplementedIID<CacheFileIOManager, nsINamed>, int32_t(
reinterpret_cast<char*>(static_cast<nsINamed*>((
CacheFileIOManager*)0x1000)) - reinterpret_cast<char*>(
(CacheFileIOManager*)0x1000))}, {&mozilla::detail::kImplementedIID
<CacheFileIOManager, nsISupports>, int32_t(reinterpret_cast
<char*>(static_cast<nsISupports*>( static_cast<
nsITimerCallback*>((CacheFileIOManager*)0x1000))) - reinterpret_cast
<char*>((CacheFileIOManager*)0x1000))}, { nullptr, 0 } }
; static_assert((sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface"
); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID
, aInstancePtr, table); return rv; }
1139
1140CacheFileIOManager::CacheFileIOManager()
1141
1142{
1143 LOG(("CacheFileIOManager::CacheFileIOManager [this=%p]", this))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::CacheFileIOManager [this=%p]"
, this); } } while (0)
;
1144 MOZ_ASSERT(!gInstance, "multiple CacheFileIOManager instances!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!gInstance)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!gInstance))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!gInstance" " (" "multiple CacheFileIOManager instances!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1144); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!gInstance"
") (" "multiple CacheFileIOManager instances!" ")"); do { *(
(volatile int*)__null) = 1144; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
1145}
1146
1147CacheFileIOManager::~CacheFileIOManager() {
1148 LOG(("CacheFileIOManager::~CacheFileIOManager [this=%p]", this))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::~CacheFileIOManager [this=%p]"
, this); } } while (0)
;
1149}
1150
1151// static
1152nsresult CacheFileIOManager::Init() {
1153 LOG(("CacheFileIOManager::Init()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::Init()"
); } } while (0)
;
1154
1155 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1155); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1155; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1156
1157 if (gInstance) {
1158 return NS_ERROR_ALREADY_INITIALIZED;
1159 }
1160
1161 RefPtr<CacheFileIOManager> ioMan = new CacheFileIOManager();
1162
1163 nsresult rv = ioMan->InitInternal();
1164 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1164); return rv; } } while (false)
;
1165
1166 gInstance = std::move(ioMan);
1167 return NS_OK;
1168}
1169
1170nsresult CacheFileIOManager::InitInternal() {
1171 nsresult rv;
1172
1173 mIOThread = new CacheIOThread();
1174
1175 rv = mIOThread->Init();
1176 MOZ_ASSERT(NS_SUCCEEDED(rv), "Can't create background thread")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" " ("
"Can't create background thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1176); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
") (" "Can't create background thread" ")"); do { *((volatile
int*)__null) = 1176; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
1177 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1177); return rv; } } while (false)
;
1178
1179 mStartTime = TimeStamp::NowLoRes();
1180
1181 return NS_OK;
1182}
1183
1184// static
1185nsresult CacheFileIOManager::Shutdown() {
1186 LOG(("CacheFileIOManager::Shutdown() [gInstance=%p]", gInstance.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::Shutdown() [gInstance=%p]"
, gInstance.get()); } } while (0)
;
1187
1188 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1188); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 1188; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1189
1190 if (!gInstance) {
1191 return NS_ERROR_NOT_INITIALIZED;
1192 }
1193
1194 Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_SHUTDOWN_V2> shutdownTimer;
1195
1196 CacheIndex::PreShutdown();
1197
1198 ShutdownMetadataWriteScheduling();
1199
1200 RefPtr<ShutdownEvent> ev = new ShutdownEvent();
1201 ev->PostAndWait();
1202
1203 MOZ_ASSERT(gInstance->mHandles.HandleCount() == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(gInstance->mHandles.HandleCount() == 0)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(gInstance->mHandles.HandleCount() == 0))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("gInstance->mHandles.HandleCount() == 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1203); AnnotateMozCrashReason("MOZ_ASSERT" "(" "gInstance->mHandles.HandleCount() == 0"
")"); do { *((volatile int*)__null) = 1203; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1204 MOZ_ASSERT(gInstance->mHandlesByLastUsed.Length() == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(gInstance->mHandlesByLastUsed.Length() == 0)>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(gInstance->mHandlesByLastUsed.Length() == 0))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("gInstance->mHandlesByLastUsed.Length() == 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1204); AnnotateMozCrashReason("MOZ_ASSERT" "(" "gInstance->mHandlesByLastUsed.Length() == 0"
")"); do { *((volatile int*)__null) = 1204; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1205
1206 if (gInstance->mIOThread) {
1207 gInstance->mIOThread->Shutdown();
1208 }
1209
1210 CacheIndex::Shutdown();
1211
1212 if (CacheObserver::ClearCacheOnShutdown()) {
1213 Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE2_SHUTDOWN_CLEAR_PRIVATE>
1214 totalTimer;
1215 gInstance->SyncRemoveAllCacheFiles();
1216 }
1217
1218 gInstance = nullptr;
1219
1220 return NS_OK;
1221}
1222
1223void CacheFileIOManager::ShutdownInternal() {
1224 LOG(("CacheFileIOManager::ShutdownInternal() [this=%p]", this))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ShutdownInternal() [this=%p]"
, this); } } while (0)
;
1225
1226 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1226); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 1226; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1227
1228 // No new handles can be created after this flag is set
1229 mShuttingDown = true;
1230
1231 if (mTrashTimer) {
1232 mTrashTimer->Cancel();
1233 mTrashTimer = nullptr;
1234 }
1235
1236 // close all handles and delete all associated files
1237 nsTArray<RefPtr<CacheFileHandle>> handles;
1238 mHandles.GetAllHandles(&handles);
1239 handles.AppendElements(mSpecialHandles);
1240
1241 for (uint32_t i = 0; i < handles.Length(); i++) {
1242 CacheFileHandle* h = handles[i];
1243 h->mClosed = true;
1244
1245 h->Log();
1246
1247 // Close completely written files.
1248 MaybeReleaseNSPRHandleInternal(h);
1249 // Don't bother removing invalid and/or doomed files to improve
1250 // shutdown perfomrance.
1251 // Doomed files are already in the doomed directory from which
1252 // we never reuse files and delete the dir on next session startup.
1253 // Invalid files don't have metadata and thus won't load anyway
1254 // (hashes won't match).
1255
1256 if (!h->IsSpecialFile() && !h->mIsDoomed && !h->mFileExists) {
1257 CacheIndex::RemoveEntry(h->Hash());
1258 }
1259
1260 // Remove the handle from mHandles/mSpecialHandles
1261 if (h->IsSpecialFile()) {
1262 mSpecialHandles.RemoveElement(h);
1263 } else {
1264 mHandles.RemoveHandle(h);
1265 }
1266
1267 // Pointer to the hash is no longer valid once the last handle with the
1268 // given hash is released. Null out the pointer so that we crash if there
1269 // is a bug in this code and we dereference the pointer after this point.
1270 if (!h->IsSpecialFile()) {
1271 h->mHash = nullptr;
1272 }
1273 }
1274
1275 // Assert the table is empty. When we are here, no new handles can be added
1276 // and handles will no longer remove them self from this table and we don't
1277 // want to keep invalid handles here. Also, there is no lookup after this
1278 // point to happen.
1279 MOZ_ASSERT(mHandles.HandleCount() == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mHandles.HandleCount() == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mHandles.HandleCount() == 0)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mHandles.HandleCount() == 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1279); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mHandles.HandleCount() == 0"
")"); do { *((volatile int*)__null) = 1279; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1280
1281 // Release trash directory enumerator
1282 if (mTrashDirEnumerator) {
1283 mTrashDirEnumerator->Close();
1284 mTrashDirEnumerator = nullptr;
1285 }
1286
1287 if (mContextEvictor) {
1288 mContextEvictor->Shutdown();
1289 mContextEvictor = nullptr;
1290 }
1291}
1292
1293// static
1294nsresult CacheFileIOManager::OnProfile() {
1295 LOG(("CacheFileIOManager::OnProfile() [gInstance=%p]", gInstance.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OnProfile() [gInstance=%p]"
, gInstance.get()); } } while (0)
;
1296
1297 RefPtr<CacheFileIOManager> ioMan = gInstance;
1298 if (!ioMan) {
1299 // CacheFileIOManager::Init() failed, probably could not create the IO
1300 // thread, just go with it...
1301 return NS_ERROR_NOT_INITIALIZED;
1302 }
1303
1304 nsresult rv;
1305
1306 nsCOMPtr<nsIFile> directory;
1307
1308 CacheObserver::ParentDirOverride(getter_AddRefs(directory));
1309
1310#if defined(MOZ_WIDGET_ANDROID)
1311 nsCOMPtr<nsIFile> profilelessDirectory;
1312 char* cachePath = getenv("CACHE_DIRECTORY");
1313 if (!directory && cachePath && *cachePath) {
1314 rv = NS_NewNativeLocalFile(nsDependentCString(cachePath), true,
1315 getter_AddRefs(directory));
1316 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1317 // Save this directory as the profileless path.
1318 rv = directory->Clone(getter_AddRefs(profilelessDirectory));
1319 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1319); return rv; } } while (false)
;
1320
1321 // Add profile leaf name to the directory name to distinguish
1322 // multiple profiles Fennec supports.
1323 nsCOMPtr<nsIFile> profD;
1324 rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR"ProfD",
1325 getter_AddRefs(profD));
1326
1327 nsAutoCString leafName;
1328 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1329 rv = profD->GetNativeLeafName(leafName);
1330 }
1331 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1332 rv = directory->AppendNative(leafName);
1333 }
1334 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1335 directory = nullptr;
1336 }
1337 }
1338 }
1339#endif
1340
1341 if (!directory) {
1342 rv = NS_GetSpecialDirectory(NS_APP_CACHE_PARENT_DIR"cachePDir",
1343 getter_AddRefs(directory));
1344 }
1345
1346 if (!directory) {
1347 rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_LOCAL_50_DIR"ProfLD",
1348 getter_AddRefs(directory));
1349 }
1350
1351 if (directory) {
1352 rv = directory->Append(u"cache2"_ns);
1353 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1353); return rv; } } while (false)
;
1354 }
1355
1356 // All functions return a clone.
1357 ioMan->mCacheDirectory.swap(directory);
1358
1359#if defined(MOZ_WIDGET_ANDROID)
1360 if (profilelessDirectory) {
1361 rv = profilelessDirectory->Append(u"cache2"_ns);
1362 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1362); return rv; } } while (false)
;
1363 }
1364
1365 ioMan->mCacheProfilelessDirectory.swap(profilelessDirectory);
1366#endif
1367
1368 if (ioMan->mCacheDirectory) {
1369 CacheIndex::Init(ioMan->mCacheDirectory);
1370 }
1371
1372 return NS_OK;
1373}
1374
1375static bool inBackgroundTask() {
1376 MOZ_ASSERT(NS_IsMainThread(), "backgroundtasks are main thread only")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
" (" "backgroundtasks are main thread only" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1376); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
") (" "backgroundtasks are main thread only" ")"); do { *((volatile
int*)__null) = 1376; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
1377#if defined(MOZ_BACKGROUNDTASKS1)
1378 nsCOMPtr<nsIBackgroundTasks> backgroundTaskService =
1379 do_GetService("@mozilla.org/backgroundtasks;1");
1380 if (!backgroundTaskService) {
1381 return false;
1382 }
1383 bool isBackgroundTask = false;
1384 backgroundTaskService->GetIsBackgroundTaskMode(&isBackgroundTask);
1385 return isBackgroundTask;
1386#else
1387 return false;
1388#endif
1389}
1390
1391// static
1392nsresult CacheFileIOManager::OnDelayedStartupFinished() {
1393 // If we don't clear the cache at shutdown, or we don't use a
1394 // background task then there's no need to dispatch a cleanup task
1395 // at startup
1396 if (!CacheObserver::ClearCacheOnShutdown()) {
1397 return NS_OK;
1398 }
1399 if (!StaticPrefs::network_cache_shutdown_purge_in_background_task()) {
1400 return NS_OK;
1401 }
1402
1403 // If this is a background task already, there's no need to
1404 // dispatch another one.
1405 if (inBackgroundTask()) {
1406 return NS_OK;
1407 }
1408
1409 RefPtr<CacheFileIOManager> ioMan = gInstance;
1410 nsCOMPtr<nsIEventTarget> target = IOTarget();
1411 if (NS_WARN_IF(!ioMan || !target)NS_warn_if_impl(!ioMan || !target, "!ioMan || !target", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1411)
) {
1412 return NS_ERROR_NOT_AVAILABLE;
1413 }
1414
1415 return target->Dispatch(
1416 NS_NewRunnableFunction("CacheFileIOManager::OnDelayedStartupFinished",
1417 [ioMan = std::move(ioMan)] {
1418 ioMan->DispatchPurgeTask(""_ns, "0"_ns,
1419 kPurgeExtension);
1420 }),
1421 nsIEventTarget::DISPATCH_NORMAL);
1422}
1423
1424// static
1425nsresult CacheFileIOManager::OnIdleDaily() {
1426 // In case the background task process fails for some reason (bug 1848542)
1427 // We will remove the directories in the main process on a daily idle.
1428 if (!CacheObserver::ClearCacheOnShutdown()) {
1429 return NS_OK;
1430 }
1431 if (!StaticPrefs::network_cache_shutdown_purge_in_background_task()) {
1432 return NS_OK;
1433 }
1434
1435 RefPtr<CacheFileIOManager> ioMan = gInstance;
1436 nsCOMPtr<nsIFile> parentDir;
1437 nsresult rv = ioMan->mCacheDirectory->GetParent(getter_AddRefs(parentDir));
1438 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || !parentDir) {
1439 return NS_OK;
1440 }
1441
1442 NS_DispatchBackgroundTask(
1443 NS_NewRunnableFunction(
1444 "CacheFileIOManager::CheckLeftoverFolders",
1445 [dir = std::move(parentDir)] {
1446 nsCOMPtr<nsIDirectoryEnumerator> directories;
1447 nsresult rv = dir->GetDirectoryEntries(getter_AddRefs(directories));
1448 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1449 return;
1450 }
1451 bool hasMoreElements = false;
1452 while (
1453 NS_SUCCEEDED(directories->HasMoreElements(&hasMoreElements))((bool)(__builtin_expect(!!(!NS_FAILED_impl(directories->HasMoreElements
(&hasMoreElements))), 1)))
&&
1454 hasMoreElements) {
1455 nsCOMPtr<nsIFile> subdir;
1456 rv = directories->GetNextFile(getter_AddRefs(subdir));
1457 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || !subdir) {
1458 break;
1459 }
1460 nsAutoCString leafName;
1461 rv = subdir->GetNativeLeafName(leafName);
1462 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1463 continue;
1464 }
1465 if (leafName.Find(kPurgeExtension) != kNotFound) {
1466 mozilla::glean::networking::residual_cache_folder_count.Add(1);
1467 rv = subdir->Remove(true);
1468 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1469 mozilla::glean::networking::residual_cache_folder_removal
1470 .Get("success"_ns)
1471 .Add(1);
1472 } else {
1473 mozilla::glean::networking::residual_cache_folder_removal
1474 .Get("failure"_ns)
1475 .Add(1);
1476 }
1477 }
1478 }
1479
1480 return;
1481 }),
1482 NS_DISPATCH_EVENT_MAY_BLOCKnsIEventTarget::DISPATCH_EVENT_MAY_BLOCK);
1483
1484 return NS_OK;
1485}
1486
1487// static
1488already_AddRefed<nsIEventTarget> CacheFileIOManager::IOTarget() {
1489 nsCOMPtr<nsIEventTarget> target;
1490 if (gInstance && gInstance->mIOThread) {
1491 target = gInstance->mIOThread->Target();
1492 }
1493
1494 return target.forget();
1495}
1496
1497// static
1498already_AddRefed<CacheIOThread> CacheFileIOManager::IOThread() {
1499 RefPtr<CacheIOThread> thread;
1500 if (gInstance) {
1501 thread = gInstance->mIOThread;
1502 }
1503
1504 return thread.forget();
1505}
1506
1507// static
1508bool CacheFileIOManager::IsOnIOThread() {
1509 RefPtr<CacheFileIOManager> ioMan = gInstance;
1510 if (ioMan && ioMan->mIOThread) {
1511 return ioMan->mIOThread->IsCurrentThread();
1512 }
1513
1514 return false;
1515}
1516
1517// static
1518bool CacheFileIOManager::IsOnIOThreadOrCeased() {
1519 RefPtr<CacheFileIOManager> ioMan = gInstance;
1520 if (ioMan && ioMan->mIOThread) {
1521 return ioMan->mIOThread->IsCurrentThread();
1522 }
1523
1524 // Ceased...
1525 return true;
1526}
1527
1528// static
1529bool CacheFileIOManager::IsShutdown() {
1530 if (!gInstance) {
1531 return true;
1532 }
1533 return gInstance->mShuttingDown;
1534}
1535
1536// static
1537nsresult CacheFileIOManager::ScheduleMetadataWrite(CacheFile* aFile) {
1538 RefPtr<CacheFileIOManager> ioMan = gInstance;
1539 NS_ENSURE_TRUE(ioMan, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(ioMan)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "ioMan" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1539); return NS_ERROR_NOT_INITIALIZED; } } while (false)
;
1540
1541 NS_ENSURE_TRUE(!ioMan->mShuttingDown, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(!ioMan->mShuttingDown)), 0
))) { NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "!ioMan->mShuttingDown"
") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1541); return NS_ERROR_NOT_INITIALIZED; } } while (false)
;
1542
1543 RefPtr<MetadataWriteScheduleEvent> event = new MetadataWriteScheduleEvent(
1544 ioMan, aFile, MetadataWriteScheduleEvent::SCHEDULE);
1545 nsCOMPtr<nsIEventTarget> target = ioMan->IOTarget();
1546 NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(target)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "target" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1546); return NS_ERROR_UNEXPECTED; } } while (false)
;
1547 return target->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
1548}
1549
1550nsresult CacheFileIOManager::ScheduleMetadataWriteInternal(CacheFile* aFile) {
1551 MOZ_ASSERT(IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsOnIOThreadOrCeased())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsOnIOThreadOrCeased()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1551); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 1551; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1552
1553 nsresult rv;
1554
1555 if (!mMetadataWritesTimer) {
1556 rv = NS_NewTimerWithCallback(getter_AddRefs(mMetadataWritesTimer), this,
1557 kMetadataWriteDelay5000, nsITimer::TYPE_ONE_SHOT);
1558 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1558); return rv; } } while (false)
;
1559 }
1560
1561 if (mScheduledMetadataWrites.IndexOf(aFile) !=
1562 nsTArray<RefPtr<mozilla::net::CacheFile>>::NoIndex) {
1563 return NS_OK;
1564 }
1565
1566 mScheduledMetadataWrites.AppendElement(aFile);
1567
1568 return NS_OK;
1569}
1570
1571// static
1572nsresult CacheFileIOManager::UnscheduleMetadataWrite(CacheFile* aFile) {
1573 RefPtr<CacheFileIOManager> ioMan = gInstance;
1574 NS_ENSURE_TRUE(ioMan, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(ioMan)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "ioMan" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1574); return NS_ERROR_NOT_INITIALIZED; } } while (false)
;
1575
1576 NS_ENSURE_TRUE(!ioMan->mShuttingDown, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(!ioMan->mShuttingDown)), 0
))) { NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "!ioMan->mShuttingDown"
") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1576); return NS_ERROR_NOT_INITIALIZED; } } while (false)
;
1577
1578 RefPtr<MetadataWriteScheduleEvent> event = new MetadataWriteScheduleEvent(
1579 ioMan, aFile, MetadataWriteScheduleEvent::UNSCHEDULE);
1580 nsCOMPtr<nsIEventTarget> target = ioMan->IOTarget();
1581 NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(target)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "target" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1581); return NS_ERROR_UNEXPECTED; } } while (false)
;
1582 return target->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
1583}
1584
1585void CacheFileIOManager::UnscheduleMetadataWriteInternal(CacheFile* aFile) {
1586 MOZ_ASSERT(IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsOnIOThreadOrCeased())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsOnIOThreadOrCeased()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1586); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 1586; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1587
1588 mScheduledMetadataWrites.RemoveElement(aFile);
1589
1590 if (mScheduledMetadataWrites.Length() == 0 && mMetadataWritesTimer) {
1591 mMetadataWritesTimer->Cancel();
1592 mMetadataWritesTimer = nullptr;
1593 }
1594}
1595
1596// static
1597nsresult CacheFileIOManager::ShutdownMetadataWriteScheduling() {
1598 RefPtr<CacheFileIOManager> ioMan = gInstance;
1599 NS_ENSURE_TRUE(ioMan, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(ioMan)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "ioMan" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1599); return NS_ERROR_NOT_INITIALIZED; } } while (false)
;
1600
1601 RefPtr<MetadataWriteScheduleEvent> event = new MetadataWriteScheduleEvent(
1602 ioMan, nullptr, MetadataWriteScheduleEvent::SHUTDOWN);
1603 nsCOMPtr<nsIEventTarget> target = ioMan->IOTarget();
1604 NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(target)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "target" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1604); return NS_ERROR_UNEXPECTED; } } while (false)
;
1605 return target->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
1606}
1607
1608void CacheFileIOManager::ShutdownMetadataWriteSchedulingInternal() {
1609 MOZ_ASSERT(IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsOnIOThreadOrCeased())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsOnIOThreadOrCeased()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1609); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 1609; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1610
1611 nsTArray<RefPtr<CacheFile>> files = std::move(mScheduledMetadataWrites);
1612 for (uint32_t i = 0; i < files.Length(); ++i) {
1613 CacheFile* file = files[i];
1614 file->WriteMetadataIfNeeded();
1615 }
1616
1617 if (mMetadataWritesTimer) {
1618 mMetadataWritesTimer->Cancel();
1619 mMetadataWritesTimer = nullptr;
1620 }
1621}
1622
1623NS_IMETHODIMPnsresult
1624CacheFileIOManager::Notify(nsITimer* aTimer) {
1625 MOZ_ASSERT(IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsOnIOThreadOrCeased())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsOnIOThreadOrCeased()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1625); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 1625; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1626 MOZ_ASSERT(mMetadataWritesTimer == aTimer)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mMetadataWritesTimer == aTimer)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mMetadataWritesTimer == aTimer
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mMetadataWritesTimer == aTimer", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1626); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mMetadataWritesTimer == aTimer"
")"); do { *((volatile int*)__null) = 1626; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1627
1628 mMetadataWritesTimer = nullptr;
1629
1630 nsTArray<RefPtr<CacheFile>> files = std::move(mScheduledMetadataWrites);
1631 for (uint32_t i = 0; i < files.Length(); ++i) {
1632 CacheFile* file = files[i];
1633 file->WriteMetadataIfNeeded();
1634 }
1635
1636 return NS_OK;
1637}
1638
1639NS_IMETHODIMPnsresult
1640CacheFileIOManager::GetName(nsACString& aName) {
1641 aName.AssignLiteral("CacheFileIOManager");
1642 return NS_OK;
1643}
1644
1645// static
1646nsresult CacheFileIOManager::OpenFile(const nsACString& aKey, uint32_t aFlags,
1647 CacheFileIOListener* aCallback) {
1648 LOG(("CacheFileIOManager::OpenFile() [key=%s, flags=%d, listener=%p]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFile() [key=%s, flags=%d, listener=%p]"
, TPromiseFlatString<char>(aKey).get(), aFlags, aCallback
); } } while (0)
1649 PromiseFlatCString(aKey).get(), aFlags, aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFile() [key=%s, flags=%d, listener=%p]"
, TPromiseFlatString<char>(aKey).get(), aFlags, aCallback
); } } while (0)
;
1650
1651 nsresult rv;
1652 RefPtr<CacheFileIOManager> ioMan = gInstance;
1653
1654 if (!ioMan) {
1655 return NS_ERROR_NOT_INITIALIZED;
1656 }
1657
1658 bool priority = aFlags & CacheFileIOManager::PRIORITY;
1659 RefPtr<OpenFileEvent> ev = new OpenFileEvent(aKey, aFlags, aCallback);
1660 rv = ioMan->mIOThread->Dispatch(
1661 ev, priority ? CacheIOThread::OPEN_PRIORITY : CacheIOThread::OPEN);
1662 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1662); return rv; } } while (false)
;
1663
1664 return NS_OK;
1665}
1666
1667nsresult CacheFileIOManager::OpenFileInternal(const SHA1Sum::Hash* aHash,
1668 const nsACString& aKey,
1669 uint32_t aFlags,
1670 CacheFileHandle** _retval) {
1671 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() [hash=%08x%08x%08x%08x%08x, "
"key=%s, flags=%d]", PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[4]), TPromiseFlatString<char>(aKey).get()
, aFlags); } } while (0)
1672 ("CacheFileIOManager::OpenFileInternal() [hash=%08x%08x%08x%08x%08x, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() [hash=%08x%08x%08x%08x%08x, "
"key=%s, flags=%d]", PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[4]), TPromiseFlatString<char>(aKey).get()
, aFlags); } } while (0)
1673 "key=%s, flags=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() [hash=%08x%08x%08x%08x%08x, "
"key=%s, flags=%d]", PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[4]), TPromiseFlatString<char>(aKey).get()
, aFlags); } } while (0)
1674 LOGSHA1(aHash), PromiseFlatCString(aKey).get(), aFlags))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() [hash=%08x%08x%08x%08x%08x, "
"key=%s, flags=%d]", PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t
*>(aHash))[4]), TPromiseFlatString<char>(aKey).get()
, aFlags); } } while (0)
;
1675
1676 MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("CacheFileIOManager::IsOnIOThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1676); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { *((volatile int*)__null) = 1676; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1677
1678 nsresult rv;
1679
1680 if (mShuttingDown) {
1681 return NS_ERROR_NOT_INITIALIZED;
1682 }
1683
1684 CacheIOThread::Cancelable cancelable(
1685 true /* never called for special handles */);
1686
1687 if (!mTreeCreated) {
1688 rv = CreateCacheTree();
1689 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1690 }
1691
1692 CacheFileHandle::PinningStatus pinning =
1693 aFlags & PINNED ? CacheFileHandle::PinningStatus::PINNED
1694 : CacheFileHandle::PinningStatus::NON_PINNED;
1695
1696 nsCOMPtr<nsIFile> file;
1697 rv = GetFile(aHash, getter_AddRefs(file));
1698 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1698); return rv; } } while (false)
;
1699
1700 RefPtr<CacheFileHandle> handle;
1701 mHandles.GetHandle(aHash, getter_AddRefs(handle));
1702
1703 if ((aFlags & (OPEN | CREATE | CREATE_NEW)) == CREATE_NEW) {
1704 if (handle) {
1705 rv = DoomFileInternal(handle);
1706 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1706); return rv; } } while (false)
;
1707 handle = nullptr;
1708 }
1709
1710 handle = mHandles.NewHandle(aHash, aFlags & PRIORITY, pinning);
1711
1712 bool exists;
1713 rv = file->Exists(&exists);
1714 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1714); return rv; } } while (false)
;
1715
1716 if (exists) {
1717 CacheIndex::RemoveEntry(aHash);
1718
1719 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() - Removing old file from "
"disk"); } } while (0)
1720 ("CacheFileIOManager::OpenFileInternal() - Removing old file from "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() - Removing old file from "
"disk"); } } while (0)
1721 "disk"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() - Removing old file from "
"disk"); } } while (0)
;
1722 rv = file->Remove(false);
1723 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1724 NS_WARNING("Cannot remove old entry from the disk")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot remove old entry from the disk"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1724)
;
1725 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
1726 ("CacheFileIOManager::OpenFileInternal() - Removing old file failed"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
1727 ". [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
1728 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
;
1729 }
1730 }
1731
1732 CacheIndex::AddEntry(aHash);
1733 handle->mFile.swap(file);
1734 handle->mFileSize = 0;
1735 }
1736
1737 if (handle) {
1738 handle.swap(*_retval);
1739 return NS_OK;
1740 }
1741
1742 bool exists, evictedAsPinned = false, evictedAsNonPinned = false;
1743 rv = file->Exists(&exists);
1744 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1744); return rv; } } while (false)
;
1745
1746 if (exists && mContextEvictor) {
1747 if (mContextEvictor->ContextsCount() == 0) {
1748 mContextEvictor = nullptr;
1749 } else {
1750 mContextEvictor->WasEvicted(aKey, file, &evictedAsPinned,
1751 &evictedAsNonPinned);
1752 }
1753 }
1754
1755 if (!exists && (aFlags & (OPEN | CREATE | CREATE_NEW)) == OPEN) {
1756 return NS_ERROR_NOT_AVAILABLE;
1757 }
1758
1759 if (exists) {
1760 // For existing files we determine the pinning status later, after the
1761 // metadata gets parsed.
1762 pinning = CacheFileHandle::PinningStatus::UNKNOWN;
1763 }
1764
1765 handle = mHandles.NewHandle(aHash, aFlags & PRIORITY, pinning);
1766 if (exists) {
1767 // If this file has been found evicted through the context file evictor
1768 // above for any of pinned or non-pinned state, these calls ensure we doom
1769 // the handle ASAP we know the real pinning state after metadta has been
1770 // parsed. DoomFileInternal on the |handle| doesn't doom right now, since
1771 // the pinning state is unknown and we pass down a pinning restriction.
1772 if (evictedAsPinned) {
1773 rv = DoomFileInternal(handle, DOOM_WHEN_PINNED);
1774 MOZ_ASSERT(!handle->IsDoomed() && NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!handle->IsDoomed() && ((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!handle->IsDoomed() &&
((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!handle->IsDoomed() && ((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1774); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!handle->IsDoomed() && ((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1774; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1775 }
1776 if (evictedAsNonPinned) {
1777 rv = DoomFileInternal(handle, DOOM_WHEN_NON_PINNED);
1778 MOZ_ASSERT(!handle->IsDoomed() && NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!handle->IsDoomed() && ((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!handle->IsDoomed() &&
((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!handle->IsDoomed() && ((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1778); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!handle->IsDoomed() && ((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1778; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1779 }
1780
1781 int64_t fileSize = -1;
1782 rv = file->GetFileSize(&fileSize);
1783 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1783); return rv; } } while (false)
;
1784
1785 handle->mFileSize = fileSize;
1786 handle->mFileExists = true;
1787
1788 CacheIndex::EnsureEntryExists(aHash);
1789 } else {
1790 handle->mFileSize = 0;
1791
1792 CacheIndex::AddEntry(aHash);
1793 }
1794
1795 handle->mFile.swap(file);
1796 handle.swap(*_retval);
1797 return NS_OK;
1798}
1799
1800nsresult CacheFileIOManager::OpenSpecialFileInternal(
1801 const nsACString& aKey, uint32_t aFlags, CacheFileHandle** _retval) {
1802 LOG(("CacheFileIOManager::OpenSpecialFileInternal() [key=%s, flags=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() [key=%s, flags=%d]"
, TPromiseFlatString<char>(aKey).get(), aFlags); } } while
(0)
1803 PromiseFlatCString(aKey).get(), aFlags))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() [key=%s, flags=%d]"
, TPromiseFlatString<char>(aKey).get(), aFlags); } } while
(0)
;
1804
1805 MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("CacheFileIOManager::IsOnIOThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1805); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { *((volatile int*)__null) = 1805; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1806
1807 nsresult rv;
1808
1809 if (mShuttingDown) {
1810 return NS_ERROR_NOT_INITIALIZED;
1811 }
1812
1813 if (!mTreeCreated) {
1814 rv = CreateCacheTree();
1815 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1816 }
1817
1818 nsCOMPtr<nsIFile> file;
1819 rv = GetSpecialFile(aKey, getter_AddRefs(file));
1820 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1820); return rv; } } while (false)
;
1821
1822 RefPtr<CacheFileHandle> handle;
1823 for (uint32_t i = 0; i < mSpecialHandles.Length(); i++) {
1824 if (!mSpecialHandles[i]->IsDoomed() && mSpecialHandles[i]->Key() == aKey) {
1825 handle = mSpecialHandles[i];
1826 break;
1827 }
1828 }
1829
1830 if ((aFlags & (OPEN | CREATE | CREATE_NEW)) == CREATE_NEW) {
1831 if (handle) {
1832 rv = DoomFileInternal(handle);
1833 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1833); return rv; } } while (false)
;
1834 handle = nullptr;
1835 }
1836
1837 handle = new CacheFileHandle(aKey, aFlags & PRIORITY,
1838 CacheFileHandle::PinningStatus::NON_PINNED);
1839 mSpecialHandles.AppendElement(handle);
1840
1841 bool exists;
1842 rv = file->Exists(&exists);
1843 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1843); return rv; } } while (false)
;
1844
1845 if (exists) {
1846 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file from "
"disk"); } } while (0)
1847 ("CacheFileIOManager::OpenSpecialFileInternal() - Removing file from "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file from "
"disk"); } } while (0)
1848 "disk"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file from "
"disk"); } } while (0)
;
1849 rv = file->Remove(false);
1850 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1851 NS_WARNING("Cannot remove old entry from the disk")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot remove old entry from the disk"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1851)
;
1852 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file "
"failed. [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
1853 ("CacheFileIOManager::OpenSpecialFileInternal() - Removing file "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file "
"failed. [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
1854 "failed. [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file "
"failed. [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
1855 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file "
"failed. [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
;
1856 }
1857 }
1858
1859 handle->mFile.swap(file);
1860 handle->mFileSize = 0;
1861 }
1862
1863 if (handle) {
1864 handle.swap(*_retval);
1865 return NS_OK;
1866 }
1867
1868 bool exists;
1869 rv = file->Exists(&exists);
1870 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1870); return rv; } } while (false)
;
1871
1872 if (!exists && (aFlags & (OPEN | CREATE | CREATE_NEW)) == OPEN) {
1873 return NS_ERROR_NOT_AVAILABLE;
1874 }
1875
1876 handle = new CacheFileHandle(aKey, aFlags & PRIORITY,
1877 CacheFileHandle::PinningStatus::NON_PINNED);
1878 mSpecialHandles.AppendElement(handle);
1879
1880 if (exists) {
1881 int64_t fileSize = -1;
1882 rv = file->GetFileSize(&fileSize);
1883 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1883); return rv; } } while (false)
;
1884
1885 handle->mFileSize = fileSize;
1886 handle->mFileExists = true;
1887 } else {
1888 handle->mFileSize = 0;
1889 }
1890
1891 handle->mFile.swap(file);
1892 handle.swap(*_retval);
1893 return NS_OK;
1894}
1895
1896void CacheFileIOManager::CloseHandleInternal(CacheFileHandle* aHandle) {
1897 nsresult rv;
1898 LOG(("CacheFileIOManager::CloseHandleInternal() [handle=%p]", aHandle))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::CloseHandleInternal() [handle=%p]"
, aHandle); } } while (0)
;
1899
1900 MOZ_ASSERT(!aHandle->IsClosed())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aHandle->IsClosed())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aHandle->IsClosed()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!aHandle->IsClosed()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1900); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aHandle->IsClosed()"
")"); do { *((volatile int*)__null) = 1900; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1901
1902 aHandle->Log();
1903
1904 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1904); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 1904; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1905
1906 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
1907
1908 // Maybe close file handle (can be legally bypassed after shutdown)
1909 rv = MaybeReleaseNSPRHandleInternal(aHandle);
1910
1911 // Delete the file if the entry was doomed or invalid and
1912 // filedesc properly closed
1913 if ((aHandle->mIsDoomed || aHandle->mInvalid) && aHandle->mFileExists &&
1914 NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1915 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::CloseHandleInternal() - Removing file from "
"disk"); } } while (0)
1916 ("CacheFileIOManager::CloseHandleInternal() - Removing file from "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::CloseHandleInternal() - Removing file from "
"disk"); } } while (0)
1917 "disk"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::CloseHandleInternal() - Removing file from "
"disk"); } } while (0)
;
1918
1919 rv = aHandle->mFile->Remove(false);
1920 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1921 aHandle->mFileExists = false;
1922 } else {
1923 LOG((" failed to remove the file [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " failed to remove the file [rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
1924 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " failed to remove the file [rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
;
1925 }
1926 }
1927
1928 if (!aHandle->IsSpecialFile() && !aHandle->mIsDoomed &&
1929 (aHandle->mInvalid || !aHandle->mFileExists)) {
1930 CacheIndex::RemoveEntry(aHandle->Hash());
1931 }
1932
1933 // Don't remove handles after shutdown
1934 if (!mShuttingDown) {
1935 if (aHandle->IsSpecialFile()) {
1936 mSpecialHandles.RemoveElement(aHandle);
1937 } else {
1938 mHandles.RemoveHandle(aHandle);
1939 }
1940 }
1941}
1942
1943// static
1944nsresult CacheFileIOManager::Read(CacheFileHandle* aHandle, int64_t aOffset,
1945 char* aBuf, int32_t aCount,
1946 CacheFileIOListener* aCallback) {
1947 LOG(("CacheFileIOManager::Read() [handle=%p, offset=%" PRId64 ", count=%d, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::Read() [handle=%p, offset=%"
"l" "d" ", count=%d, " "listener=%p]", aHandle, aOffset, aCount
, aCallback); } } while (0)
1948 "listener=%p]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::Read() [handle=%p, offset=%"
"l" "d" ", count=%d, " "listener=%p]", aHandle, aOffset, aCount
, aCallback); } } while (0)
1949 aHandle, aOffset, aCount, aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::Read() [handle=%p, offset=%"
"l" "d" ", count=%d, " "listener=%p]", aHandle, aOffset, aCount
, aCallback); } } while (0)
;
1950
1951 if (CacheObserver::ShuttingDown()) {
1952 LOG((" no reads after shutdown"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " no reads after shutdown"
); } } while (0)
;
1953 return NS_ERROR_NOT_INITIALIZED;
1954 }
1955
1956 nsresult rv;
1957 RefPtr<CacheFileIOManager> ioMan = gInstance;
1958
1959 if (aHandle->IsClosed() || !ioMan) {
1960 return NS_ERROR_NOT_INITIALIZED;
1961 }
1962
1963 RefPtr<ReadEvent> ev =
1964 new ReadEvent(aHandle, aOffset, aBuf, aCount, aCallback);
1965 rv = ioMan->mIOThread->Dispatch(ev, aHandle->IsPriority()
1966 ? CacheIOThread::READ_PRIORITY
1967 : CacheIOThread::READ);
1968 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1968); return rv; } } while (false)
;
1969
1970 return NS_OK;
1971}
1972
1973nsresult CacheFileIOManager::ReadInternal(CacheFileHandle* aHandle,
1974 int64_t aOffset, char* aBuf,
1975 int32_t aCount) {
1976 LOG(("CacheFileIOManager::ReadInternal() [handle=%p, offset=%" PRId64do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ReadInternal() [handle=%p, offset=%"
"l" "d" ", count=%d]", aHandle, aOffset, aCount); } } while (
0)
1977 ", count=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ReadInternal() [handle=%p, offset=%"
"l" "d" ", count=%d]", aHandle, aOffset, aCount); } } while (
0)
1978 aHandle, aOffset, aCount))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ReadInternal() [handle=%p, offset=%"
"l" "d" ", count=%d]", aHandle, aOffset, aCount); } } while (
0)
;
1979
1980 nsresult rv;
1981
1982 if (CacheObserver::ShuttingDown()) {
1983 LOG((" no reads after shutdown"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " no reads after shutdown"
); } } while (0)
;
1984 return NS_ERROR_NOT_INITIALIZED;
1985 }
1986
1987 if (!aHandle->mFileExists) {
1988 NS_WARNING("Trying to read from non-existent file")NS_DebugBreak(NS_DEBUG_WARNING, "Trying to read from non-existent file"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1988)
;
1989 return NS_ERROR_NOT_AVAILABLE;
1990 }
1991
1992 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
1993
1994 if (!aHandle->mFD) {
1995 rv = OpenNSPRHandle(aHandle);
1996 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 1996); return rv; } } while (false)
;
1997 } else {
1998 NSPRHandleUsed(aHandle);
1999 }
2000
2001 // Check again, OpenNSPRHandle could figure out the file was gone.
2002 if (!aHandle->mFileExists) {
2003 NS_WARNING("Trying to read from non-existent file")NS_DebugBreak(NS_DEBUG_WARNING, "Trying to read from non-existent file"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2003)
;
2004 return NS_ERROR_NOT_AVAILABLE;
2005 }
2006
2007 int64_t offset = PR_Seek64(aHandle->mFD, aOffset, PR_SEEK_SET);
2008 if (offset == -1) {
2009 return NS_ERROR_FAILURE;
2010 }
2011
2012 int32_t bytesRead = PR_Read(aHandle->mFD, aBuf, aCount);
2013 if (bytesRead != aCount) {
2014 return NS_ERROR_FAILURE;
2015 }
2016
2017 return NS_OK;
2018}
2019
2020// static
2021nsresult CacheFileIOManager::Write(CacheFileHandle* aHandle, int64_t aOffset,
2022 const char* aBuf, int32_t aCount,
2023 bool aValidate, bool aTruncate,
2024 CacheFileIOListener* aCallback) {
2025 LOG(("CacheFileIOManager::Write() [handle=%p, offset=%" PRId64 ", count=%d, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::Write() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d, listener=%p]"
, aHandle, aOffset, aCount, aValidate, aTruncate, aCallback);
} } while (0)
2026 "validate=%d, truncate=%d, listener=%p]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::Write() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d, listener=%p]"
, aHandle, aOffset, aCount, aValidate, aTruncate, aCallback);
} } while (0)
2027 aHandle, aOffset, aCount, aValidate, aTruncate, aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::Write() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d, listener=%p]"
, aHandle, aOffset, aCount, aValidate, aTruncate, aCallback);
} } while (0)
;
2028
2029 MOZ_ASSERT(aCallback)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aCallback)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aCallback))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aCallback", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2029); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCallback" ")"
); do { *((volatile int*)__null) = 2029; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2030
2031 RefPtr<CacheFileIOManager> ioMan = gInstance;
2032
2033 if (aHandle->IsClosed() || aCallback->IsKilled() || !ioMan) {
2034 return NS_ERROR_NOT_INITIALIZED;
2035 }
2036
2037 RefPtr<WriteEvent> ev = new WriteEvent(aHandle, aOffset, aBuf, aCount,
2038 aValidate, aTruncate, aCallback);
2039 return ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
2040 ? CacheIOThread::WRITE_PRIORITY
2041 : CacheIOThread::WRITE);
2042}
2043
2044// static
2045nsresult CacheFileIOManager::WriteWithoutCallback(CacheFileHandle* aHandle,
2046 int64_t aOffset, char* aBuf,
2047 int32_t aCount,
2048 bool aValidate,
2049 bool aTruncate) {
2050 LOG(("CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%" PRId64do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2051 ", count=%d, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2052 "validate=%d, truncate=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2053 aHandle, aOffset, aCount, aValidate, aTruncate))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
;
2054
2055 RefPtr<CacheFileIOManager> ioMan = gInstance;
2056
2057 if (aHandle->IsClosed() || !ioMan) {
2058 // When no callback is provided, CacheFileIOManager is responsible for
2059 // releasing the buffer. We must release it even in case of failure.
2060 free(aBuf);
2061 return NS_ERROR_NOT_INITIALIZED;
2062 }
2063
2064 RefPtr<WriteEvent> ev = new WriteEvent(aHandle, aOffset, aBuf, aCount,
2065 aValidate, aTruncate, nullptr);
2066 return ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
2067 ? CacheIOThread::WRITE_PRIORITY
2068 : CacheIOThread::WRITE);
2069}
2070
2071static nsresult TruncFile(PRFileDesc* aFD, int64_t aEOF) {
2072#if defined(XP_UNIX1)
2073 if (ftruncate(PR_FileDesc2NativeHandle(aFD), aEOF) != 0) {
2074 NS_ERROR("ftruncate failed")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "ftruncate failed", "Error"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2074); MOZ_PretendNoReturn(); } while (0)
;
2075 return NS_ERROR_FAILURE;
2076 }
2077#elif defined(XP_WIN)
2078 int64_t cnt = PR_Seek64(aFD, aEOF, PR_SEEK_SET);
2079 if (cnt == -1) {
2080 return NS_ERROR_FAILURE;
2081 }
2082 if (!SetEndOfFile((HANDLE)PR_FileDesc2NativeHandle(aFD))) {
2083 NS_ERROR("SetEndOfFile failed")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "SetEndOfFile failed",
"Error", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2083); MOZ_PretendNoReturn(); } while (0)
;
2084 return NS_ERROR_FAILURE;
2085 }
2086#else
2087 MOZ_ASSERT(false, "Not implemented!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Not implemented!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2087); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Not implemented!" ")"); do { *((volatile int*)__null) = 2087
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
2088 return NS_ERROR_NOT_IMPLEMENTED;
2089#endif
2090
2091 return NS_OK;
2092}
2093
2094nsresult CacheFileIOManager::WriteInternal(CacheFileHandle* aHandle,
2095 int64_t aOffset, const char* aBuf,
2096 int32_t aCount, bool aValidate,
2097 bool aTruncate) {
2098 LOG(("CacheFileIOManager::WriteInternal() [handle=%p, offset=%" PRId64do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2099 ", count=%d, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2100 "validate=%d, truncate=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2101 aHandle, aOffset, aCount, aValidate, aTruncate))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
;
2102
2103 nsresult rv;
2104
2105 if (aHandle->mKilled) {
2106 LOG((" handle already killed, nothing written"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " handle already killed, nothing written"
); } } while (0)
;
2107 return NS_OK;
2108 }
2109
2110 if (CacheObserver::ShuttingDown() && (!aValidate || !aHandle->mFD)) {
2111 aHandle->mKilled = true;
2112 LOG((" killing the handle, nothing written"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " killing the handle, nothing written"
); } } while (0)
;
2113 return NS_OK;
2114 }
2115
2116 if (CacheObserver::IsPastShutdownIOLag()) {
2117 LOG((" past the shutdown I/O lag, nothing written"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " past the shutdown I/O lag, nothing written"
); } } while (0)
;
2118 // Pretend the write has succeeded, otherwise upper layers will doom
2119 // the file and we end up with I/O anyway.
2120 return NS_OK;
2121 }
2122
2123 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
2124
2125 if (!aHandle->mFileExists) {
2126 rv = CreateFile(aHandle);
2127 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2127); return rv; } } while (false)
;
2128 }
2129
2130 if (!aHandle->mFD) {
2131 rv = OpenNSPRHandle(aHandle);
2132 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2132); return rv; } } while (false)
;
2133 } else {
2134 NSPRHandleUsed(aHandle);
2135 }
2136
2137 // Check again, OpenNSPRHandle could figure out the file was gone.
2138 if (!aHandle->mFileExists) {
2139 return NS_ERROR_NOT_AVAILABLE;
2140 }
2141
2142 // When this operation would increase cache size, check whether the cache size
2143 // reached the hard limit and whether it would cause critical low disk space.
2144 if (aHandle->mFileSize < aOffset + aCount) {
2145 if (mOverLimitEvicting && mCacheSizeOnHardLimit) {
2146 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - failing because cache size "
"reached hard limit!"); } } while (0)
2147 ("CacheFileIOManager::WriteInternal() - failing because cache size "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - failing because cache size "
"reached hard limit!"); } } while (0)
2148 "reached hard limit!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - failing because cache size "
"reached hard limit!"); } } while (0)
;
2149 return NS_ERROR_FILE_NO_DEVICE_SPACE;
2150 }
2151
2152 int64_t freeSpace;
2153 rv = mCacheDirectory->GetDiskSpaceAvailable(&freeSpace);
2154 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2154)
) {
2155 freeSpace = -1;
2156 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - GetDiskSpaceAvailable() "
"failed! [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
2157 ("CacheFileIOManager::WriteInternal() - GetDiskSpaceAvailable() "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - GetDiskSpaceAvailable() "
"failed! [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
2158 "failed! [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - GetDiskSpaceAvailable() "
"failed! [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
2159 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - GetDiskSpaceAvailable() "
"failed! [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
;
2160 } else {
2161 freeSpace >>= 10; // bytes to kilobytes
2162 uint32_t limit = CacheObserver::DiskFreeSpaceHardLimit();
2163 if (freeSpace - aOffset - aCount + aHandle->mFileSize < limit) {
2164 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - Low free space, refusing "
"to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]", freeSpace
, limit); } } while (0)
2165 ("CacheFileIOManager::WriteInternal() - Low free space, refusing "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - Low free space, refusing "
"to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]", freeSpace
, limit); } } while (0)
2166 "to write! [freeSpace=%" PRId64 "kB, limit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - Low free space, refusing "
"to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]", freeSpace
, limit); } } while (0)
2167 freeSpace, limit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - Low free space, refusing "
"to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]", freeSpace
, limit); } } while (0)
;
2168 return NS_ERROR_FILE_NO_DEVICE_SPACE;
2169 }
2170 }
2171 }
2172
2173 // Write invalidates the entry by default
2174 aHandle->mInvalid = true;
2175
2176 int64_t offset = PR_Seek64(aHandle->mFD, aOffset, PR_SEEK_SET);
2177 if (offset == -1) {
2178 return NS_ERROR_FAILURE;
2179 }
2180
2181 int32_t bytesWritten = PR_Write(aHandle->mFD, aBuf, aCount);
2182
2183 if (bytesWritten != -1) {
2184 uint32_t oldSizeInK = aHandle->FileSizeInK();
2185 int64_t writeEnd = aOffset + bytesWritten;
2186
2187 if (aTruncate) {
2188 rv = TruncFile(aHandle->mFD, writeEnd);
2189 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2189); return rv; } } while (false)
;
2190
2191 aHandle->mFileSize = writeEnd;
2192 } else {
2193 if (aHandle->mFileSize < writeEnd) {
2194 aHandle->mFileSize = writeEnd;
2195 }
2196 }
2197
2198 uint32_t newSizeInK = aHandle->FileSizeInK();
2199
2200 if (oldSizeInK != newSizeInK && !aHandle->IsDoomed() &&
2201 !aHandle->IsSpecialFile()) {
2202 CacheIndex::UpdateEntry(aHandle->Hash(), nullptr, nullptr, nullptr,
2203 nullptr, nullptr, &newSizeInK);
2204
2205 if (oldSizeInK < newSizeInK) {
2206 EvictIfOverLimitInternal();
2207 }
2208 }
2209
2210 CacheIndex::UpdateTotalBytesWritten(bytesWritten);
2211 }
2212
2213 if (bytesWritten != aCount) {
2214 return NS_ERROR_FAILURE;
2215 }
2216
2217 // Write was successful and this write validates the entry (i.e. metadata)
2218 if (aValidate) {
2219 aHandle->mInvalid = false;
2220 }
2221
2222 return NS_OK;
2223}
2224
2225// static
2226nsresult CacheFileIOManager::DoomFile(CacheFileHandle* aHandle,
2227 CacheFileIOListener* aCallback) {
2228 LOG(("CacheFileIOManager::DoomFile() [handle=%p, listener=%p]", aHandle,do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFile() [handle=%p, listener=%p]"
, aHandle, aCallback); } } while (0)
2229 aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFile() [handle=%p, listener=%p]"
, aHandle, aCallback); } } while (0)
;
2230
2231 nsresult rv;
2232 RefPtr<CacheFileIOManager> ioMan = gInstance;
2233
2234 if (aHandle->IsClosed() || !ioMan) {
2235 return NS_ERROR_NOT_INITIALIZED;
2236 }
2237
2238 RefPtr<DoomFileEvent> ev = new DoomFileEvent(aHandle, aCallback);
2239 rv = ioMan->mIOThread->Dispatch(ev, aHandle->IsPriority()
2240 ? CacheIOThread::OPEN_PRIORITY
2241 : CacheIOThread::OPEN);
2242 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2242); return rv; } } while (false)
;
2243
2244 return NS_OK;
2245}
2246
2247nsresult CacheFileIOManager::DoomFileInternal(
2248 CacheFileHandle* aHandle, PinningDoomRestriction aPinningDoomRestriction) {
2249 LOG(("CacheFileIOManager::DoomFileInternal() [handle=%p]", aHandle))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileInternal() [handle=%p]"
, aHandle); } } while (0)
;
2250 aHandle->Log();
2251
2252 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2252); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 2252; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2253
2254 nsresult rv;
2255
2256 if (aHandle->IsDoomed()) {
2257 return NS_OK;
2258 }
2259
2260 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
2261
2262 if (aPinningDoomRestriction > NO_RESTRICTION) {
2263 switch (aHandle->mPinning) {
2264 case CacheFileHandle::PinningStatus::NON_PINNED:
2265 if (MOZ_LIKELY(aPinningDoomRestriction != DOOM_WHEN_NON_PINNED)(__builtin_expect(!!(aPinningDoomRestriction != DOOM_WHEN_NON_PINNED
), 1))
) {
2266 LOG((" not dooming, it's a non-pinned handle"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " not dooming, it's a non-pinned handle"
); } } while (0)
;
2267 return NS_OK;
2268 }
2269 // Doom now
2270 break;
2271
2272 case CacheFileHandle::PinningStatus::PINNED:
2273 if (MOZ_UNLIKELY(aPinningDoomRestriction != DOOM_WHEN_PINNED)(__builtin_expect(!!(aPinningDoomRestriction != DOOM_WHEN_PINNED
), 0))
) {
2274 LOG((" not dooming, it's a pinned handle"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " not dooming, it's a pinned handle"
); } } while (0)
;
2275 return NS_OK;
2276 }
2277 // Doom now
2278 break;
2279
2280 case CacheFileHandle::PinningStatus::UNKNOWN:
2281 if (MOZ_LIKELY(aPinningDoomRestriction == DOOM_WHEN_NON_PINNED)(__builtin_expect(!!(aPinningDoomRestriction == DOOM_WHEN_NON_PINNED
), 1))
) {
2282 LOG((" doom when non-pinned set"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " doom when non-pinned set"
); } } while (0)
;
2283 aHandle->mDoomWhenFoundNonPinned = true;
2284 } else if (MOZ_UNLIKELY(aPinningDoomRestriction == DOOM_WHEN_PINNED)(__builtin_expect(!!(aPinningDoomRestriction == DOOM_WHEN_PINNED
), 0))
) {
2285 LOG((" doom when pinned set"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " doom when pinned set"
); } } while (0)
;
2286 aHandle->mDoomWhenFoundPinned = true;
2287 }
2288
2289 LOG((" pinning status not known, deferring doom decision"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " pinning status not known, deferring doom decision"
); } } while (0)
;
2290 return NS_OK;
2291 }
2292 }
2293
2294 if (aHandle->mFileExists) {
2295 // we need to move the current file to the doomed directory
2296 rv = MaybeReleaseNSPRHandleInternal(aHandle, true);
2297 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2297); return rv; } } while (false)
;
2298
2299 // find unused filename
2300 nsCOMPtr<nsIFile> file;
2301 rv = GetDoomedFile(getter_AddRefs(file));
2302 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2302); return rv; } } while (false)
;
2303
2304 nsCOMPtr<nsIFile> parentDir;
2305 rv = file->GetParent(getter_AddRefs(parentDir));
2306 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2306); return rv; } } while (false)
;
2307
2308 nsAutoCString leafName;
2309 rv = file->GetNativeLeafName(leafName);
2310 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2310); return rv; } } while (false)
;
2311
2312 rv = aHandle->mFile->MoveToNative(parentDir, leafName);
2313 if (NS_ERROR_FILE_NOT_FOUND == rv) {
2314 LOG((" file already removed under our hands"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " file already removed under our hands"
); } } while (0)
;
2315 aHandle->mFileExists = false;
2316 rv = NS_OK;
Value stored to 'rv' is never read
2317 } else {
2318 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2318); return rv; } } while (false)
;
2319 aHandle->mFile.swap(file);
2320 }
2321 }
2322
2323 if (!aHandle->IsSpecialFile()) {
2324 CacheIndex::RemoveEntry(aHandle->Hash());
2325 }
2326
2327 aHandle->mIsDoomed = true;
2328
2329 if (!aHandle->IsSpecialFile()) {
2330 RefPtr<CacheStorageService> storageService = CacheStorageService::Self();
2331 if (storageService) {
2332 nsAutoCString idExtension, url;
2333 nsCOMPtr<nsILoadContextInfo> info =
2334 CacheFileUtils::ParseKey(aHandle->Key(), &idExtension, &url);
2335 MOZ_ASSERT(info)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(info)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(info))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("info", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2335); AnnotateMozCrashReason("MOZ_ASSERT" "(" "info" ")");
do { *((volatile int*)__null) = 2335; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2336 if (info) {
2337 storageService->CacheFileDoomed(info, idExtension, url);
2338 }
2339 }
2340 }
2341
2342 return NS_OK;
2343}
2344
2345// static
2346nsresult CacheFileIOManager::DoomFileByKey(const nsACString& aKey,
2347 CacheFileIOListener* aCallback) {
2348 LOG(("CacheFileIOManager::DoomFileByKey() [key=%s, listener=%p]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKey() [key=%s, listener=%p]"
, TPromiseFlatString<char>(aKey).get(), aCallback); } }
while (0)
2349 PromiseFlatCString(aKey).get(), aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKey() [key=%s, listener=%p]"
, TPromiseFlatString<char>(aKey).get(), aCallback); } }
while (0)
;
2350
2351 nsresult rv;
2352 RefPtr<CacheFileIOManager> ioMan = gInstance;
2353
2354 if (!ioMan) {
2355 return NS_ERROR_NOT_INITIALIZED;
2356 }
2357
2358 RefPtr<DoomFileByKeyEvent> ev = new DoomFileByKeyEvent(aKey, aCallback);
2359 rv = ioMan->mIOThread->DispatchAfterPendingOpens(ev);
2360 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2360); return rv; } } while (false)
;
2361
2362 return NS_OK;
2363}
2364
2365nsresult CacheFileIOManager::DoomFileByKeyInternal(const SHA1Sum::Hash* aHash) {
2366 LOG((do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() [hash=%08x%08x%08x%08x%08x]"
, PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0
]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))
[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[4])); } } while (0)
2367 "CacheFileIOManager::DoomFileByKeyInternal() [hash=%08x%08x%08x%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() [hash=%08x%08x%08x%08x%08x]"
, PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0
]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))
[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[4])); } } while (0)
2368 LOGSHA1(aHash)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() [hash=%08x%08x%08x%08x%08x]"
, PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0
]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))
[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash
))[4])); } } while (0)
;
2369
2370 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2370); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 2370; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2371
2372 nsresult rv;
2373
2374 if (mShuttingDown) {
2375 return NS_ERROR_NOT_INITIALIZED;
2376 }
2377
2378 if (!mCacheDirectory) {
2379 return NS_ERROR_FILE_INVALID_PATH;
2380 }
2381
2382 // Find active handle
2383 RefPtr<CacheFileHandle> handle;
2384 mHandles.GetHandle(aHash, getter_AddRefs(handle));
2385
2386 if (handle) {
2387 handle->Log();
2388
2389 return DoomFileInternal(handle);
2390 }
2391
2392 CacheIOThread::Cancelable cancelable(true);
2393
2394 // There is no handle for this file, delete the file if exists
2395 nsCOMPtr<nsIFile> file;
2396 rv = GetFile(aHash, getter_AddRefs(file));
2397 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2397); return rv; } } while (false)
;
2398
2399 bool exists;
2400 rv = file->Exists(&exists);
2401 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2401); return rv; } } while (false)
;
2402
2403 if (!exists) {
2404 return NS_ERROR_NOT_AVAILABLE;
2405 }
2406
2407 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file from "
"disk"); } } while (0)
2408 ("CacheFileIOManager::DoomFileByKeyInternal() - Removing file from "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file from "
"disk"); } } while (0)
2409 "disk"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file from "
"disk"); } } while (0)
;
2410 rv = file->Remove(false);
2411 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2412 NS_WARNING("Cannot remove old entry from the disk")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot remove old entry from the disk"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2412)
;
2413 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file failed. "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
2414 ("CacheFileIOManager::DoomFileByKeyInternal() - Removing file failed. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file failed. "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
2415 "[rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file failed. "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
2416 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file failed. "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
;
2417 }
2418
2419 CacheIndex::RemoveEntry(aHash);
2420
2421 return NS_OK;
2422}
2423
2424// static
2425nsresult CacheFileIOManager::ReleaseNSPRHandle(CacheFileHandle* aHandle) {
2426 LOG(("CacheFileIOManager::ReleaseNSPRHandle() [handle=%p]", aHandle))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ReleaseNSPRHandle() [handle=%p]"
, aHandle); } } while (0)
;
2427
2428 nsresult rv;
2429 RefPtr<CacheFileIOManager> ioMan = gInstance;
2430
2431 if (aHandle->IsClosed() || !ioMan) {
2432 return NS_ERROR_NOT_INITIALIZED;
2433 }
2434
2435 RefPtr<ReleaseNSPRHandleEvent> ev = new ReleaseNSPRHandleEvent(aHandle);
2436 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
2437 ? CacheIOThread::WRITE_PRIORITY
2438 : CacheIOThread::WRITE);
2439 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2439); return rv; } } while (false)
;
2440
2441 return NS_OK;
2442}
2443
2444nsresult CacheFileIOManager::MaybeReleaseNSPRHandleInternal(
2445 CacheFileHandle* aHandle, bool aIgnoreShutdownLag) {
2446 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() [handle=%p, "
"ignore shutdown=%d]", aHandle, aIgnoreShutdownLag); } } while
(0)
2447 ("CacheFileIOManager::MaybeReleaseNSPRHandleInternal() [handle=%p, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() [handle=%p, "
"ignore shutdown=%d]", aHandle, aIgnoreShutdownLag); } } while
(0)
2448 "ignore shutdown=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() [handle=%p, "
"ignore shutdown=%d]", aHandle, aIgnoreShutdownLag); } } while
(0)
2449 aHandle, aIgnoreShutdownLag))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() [handle=%p, "
"ignore shutdown=%d]", aHandle, aIgnoreShutdownLag); } } while
(0)
;
2450
2451 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2451); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 2451; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2452
2453 if (aHandle->mFD) {
2454 DebugOnly<bool> found{};
2455 found = mHandlesByLastUsed.RemoveElement(aHandle);
2456 MOZ_ASSERT(found)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(found)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(found))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("found", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2456); AnnotateMozCrashReason("MOZ_ASSERT" "(" "found" ")")
; do { *((volatile int*)__null) = 2456; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2457 }
2458
2459 PRFileDesc* fd = aHandle->mFD;
2460 aHandle->mFD = nullptr;
2461
2462 // Leak invalid (w/o metadata) and doomed handles immediately after shutdown.
2463 // Leak other handles when past the shutdown time maximum lag.
2464 if (
2465#ifndef DEBUG1
2466 ((aHandle->mInvalid || aHandle->mIsDoomed) &&
2467 MOZ_UNLIKELY(CacheObserver::ShuttingDown())(__builtin_expect(!!(CacheObserver::ShuttingDown()), 0))) ||
2468#endif
2469 MOZ_UNLIKELY(!aIgnoreShutdownLag &&(__builtin_expect(!!(!aIgnoreShutdownLag && CacheObserver
::IsPastShutdownIOLag()), 0))
2470 CacheObserver::IsPastShutdownIOLag())(__builtin_expect(!!(!aIgnoreShutdownLag && CacheObserver
::IsPastShutdownIOLag()), 0))
) {
2471 // Don't bother closing this file. Return a failure code from here will
2472 // cause any following IO operation on the file (mainly removal) to be
2473 // bypassed, which is what we want.
2474 // For mInvalid == true the entry will never be used, since it doesn't
2475 // have correct metadata, thus we don't need to worry about removing it.
2476 // For mIsDoomed == true the file is already in the doomed sub-dir and
2477 // will be removed on next session start.
2478 LOG((" past the shutdown I/O lag, leaking file handle"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " past the shutdown I/O lag, leaking file handle"
); } } while (0)
;
2479 return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
2480 }
2481
2482 if (!fd) {
2483 // The filedesc has already been closed before, just let go.
2484 return NS_OK;
2485 }
2486
2487 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
2488
2489 PRStatus status = PR_Close(fd);
2490 if (status != PR_SUCCESS) {
2491 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() "
"failed to close [handle=%p, status=%u]", aHandle, status); }
} while (0)
2492 ("CacheFileIOManager::MaybeReleaseNSPRHandleInternal() "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() "
"failed to close [handle=%p, status=%u]", aHandle, status); }
} while (0)
2493 "failed to close [handle=%p, status=%u]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() "
"failed to close [handle=%p, status=%u]", aHandle, status); }
} while (0)
2494 aHandle, status))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() "
"failed to close [handle=%p, status=%u]", aHandle, status); }
} while (0)
;
2495 return NS_ERROR_FAILURE;
2496 }
2497
2498 LOG(("CacheFileIOManager::MaybeReleaseNSPRHandleInternal() DONE"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() DONE"
); } } while (0)
;
2499
2500 return NS_OK;
2501}
2502
2503// static
2504nsresult CacheFileIOManager::TruncateSeekSetEOF(
2505 CacheFileHandle* aHandle, int64_t aTruncatePos, int64_t aEOFPos,
2506 CacheFileIOListener* aCallback) {
2507 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "
"truncatePos=%" "l" "d" ", " "EOFPos=%" "l" "d" ", listener=%p]"
, aHandle, aTruncatePos, aEOFPos, aCallback); } } while (0)
2508 ("CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "
"truncatePos=%" "l" "d" ", " "EOFPos=%" "l" "d" ", listener=%p]"
, aHandle, aTruncatePos, aEOFPos, aCallback); } } while (0)
2509 "truncatePos=%" PRId64 ", "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "
"truncatePos=%" "l" "d" ", " "EOFPos=%" "l" "d" ", listener=%p]"
, aHandle, aTruncatePos, aEOFPos, aCallback); } } while (0)
2510 "EOFPos=%" PRId64 ", listener=%p]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "
"truncatePos=%" "l" "d" ", " "EOFPos=%" "l" "d" ", listener=%p]"
, aHandle, aTruncatePos, aEOFPos, aCallback); } } while (0)
2511 aHandle, aTruncatePos, aEOFPos, aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "
"truncatePos=%" "l" "d" ", " "EOFPos=%" "l" "d" ", listener=%p]"
, aHandle, aTruncatePos, aEOFPos, aCallback); } } while (0)
;
2512
2513 nsresult rv;
2514 RefPtr<CacheFileIOManager> ioMan = gInstance;
2515
2516 if (aHandle->IsClosed() || (aCallback && aCallback->IsKilled()) || !ioMan) {
2517 return NS_ERROR_NOT_INITIALIZED;
2518 }
2519
2520 RefPtr<TruncateSeekSetEOFEvent> ev =
2521 new TruncateSeekSetEOFEvent(aHandle, aTruncatePos, aEOFPos, aCallback);
2522 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
2523 ? CacheIOThread::WRITE_PRIORITY
2524 : CacheIOThread::WRITE);
2525 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2525); return rv; } } while (false)
;
2526
2527 return NS_OK;
2528}
2529
2530// static
2531void CacheFileIOManager::GetCacheDirectory(nsIFile** result) {
2532 *result = nullptr;
2533
2534 RefPtr<CacheFileIOManager> ioMan = gInstance;
2535 if (!ioMan || !ioMan->mCacheDirectory) {
2536 return;
2537 }
2538
2539 ioMan->mCacheDirectory->Clone(result);
2540}
2541
2542#if defined(MOZ_WIDGET_ANDROID)
2543
2544// static
2545void CacheFileIOManager::GetProfilelessCacheDirectory(nsIFile** result) {
2546 *result = nullptr;
2547
2548 RefPtr<CacheFileIOManager> ioMan = gInstance;
2549 if (!ioMan || !ioMan->mCacheProfilelessDirectory) {
2550 return;
2551 }
2552
2553 ioMan->mCacheProfilelessDirectory->Clone(result);
2554}
2555
2556#endif
2557
2558// static
2559nsresult CacheFileIOManager::GetEntryInfo(
2560 const SHA1Sum::Hash* aHash,
2561 CacheStorageService::EntryInfoCallback* aCallback) {
2562 MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("CacheFileIOManager::IsOnIOThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2562); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { *((volatile int*)__null) = 2562; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2563
2564 nsresult rv;
2565
2566 RefPtr<CacheFileIOManager> ioMan = gInstance;
2567 if (!ioMan) {
2568 return NS_ERROR_NOT_INITIALIZED;
2569 }
2570
2571 nsAutoCString enhanceId;
2572 nsAutoCString uriSpec;
2573
2574 RefPtr<CacheFileHandle> handle;
2575 ioMan->mHandles.GetHandle(aHash, getter_AddRefs(handle));
2576 if (handle) {
2577 RefPtr<nsILoadContextInfo> info =
2578 CacheFileUtils::ParseKey(handle->Key(), &enhanceId, &uriSpec);
2579
2580 MOZ_ASSERT(info)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(info)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(info))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("info", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2580); AnnotateMozCrashReason("MOZ_ASSERT" "(" "info" ")");
do { *((volatile int*)__null) = 2580; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2581 if (!info) {
2582 return NS_OK; // ignore
2583 }
2584
2585 RefPtr<CacheStorageService> service = CacheStorageService::Self();
2586 if (!service) {
2587 return NS_ERROR_NOT_INITIALIZED;
2588 }
2589
2590 // Invokes OnCacheEntryInfo when an existing entry is found
2591 if (service->GetCacheEntryInfo(info, enhanceId, uriSpec, aCallback)) {
2592 return NS_OK;
2593 }
2594
2595 // When we are here, there is no existing entry and we need
2596 // to synchrnously load metadata from a disk file.
2597 }
2598
2599 // Locate the actual file
2600 nsCOMPtr<nsIFile> file;
2601 ioMan->GetFile(aHash, getter_AddRefs(file));
2602
2603 // Read metadata from the file synchronously
2604 RefPtr<CacheFileMetadata> metadata = new CacheFileMetadata();
2605 rv = metadata->SyncReadMetadata(file);
2606 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2607 return NS_OK;
2608 }
2609
2610 // Now get the context + enhance id + URL from the key.
2611 RefPtr<nsILoadContextInfo> info =
2612 CacheFileUtils::ParseKey(metadata->GetKey(), &enhanceId, &uriSpec);
2613 MOZ_ASSERT(info)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(info)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(info))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("info", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2613); AnnotateMozCrashReason("MOZ_ASSERT" "(" "info" ")");
do { *((volatile int*)__null) = 2613; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2614 if (!info) {
2615 return NS_OK;
2616 }
2617
2618 // Pick all data to pass to the callback.
2619 int64_t dataSize = metadata->Offset();
2620 int64_t altDataSize = 0;
2621 uint32_t fetchCount = metadata->GetFetchCount();
2622 uint32_t expirationTime = metadata->GetExpirationTime();
2623 uint32_t lastModified = metadata->GetLastModified();
2624
2625 const char* altDataElement =
2626 metadata->GetElement(CacheFileUtils::kAltDataKey);
2627 if (altDataElement) {
2628 int64_t altDataOffset = std::numeric_limits<int64_t>::max();
2629 if (NS_SUCCEEDED(CacheFileUtils::ParseAlternativeDataInfo(((bool)(__builtin_expect(!!(!NS_FAILED_impl(CacheFileUtils::ParseAlternativeDataInfo
( altDataElement, &altDataOffset, nullptr))), 1)))
2630 altDataElement, &altDataOffset, nullptr))((bool)(__builtin_expect(!!(!NS_FAILED_impl(CacheFileUtils::ParseAlternativeDataInfo
( altDataElement, &altDataOffset, nullptr))), 1)))
&&
2631 altDataOffset < dataSize) {
2632 dataSize = altDataOffset;
2633 altDataSize = metadata->Offset() - altDataOffset;
2634 } else {
2635 LOG(("CacheFileIOManager::GetEntryInfo() invalid alternative data info"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::GetEntryInfo() invalid alternative data info"
); } } while (0)
;
2636 return NS_OK;
2637 }
2638 }
2639
2640 // Call directly on the callback.
2641 aCallback->OnEntryInfo(uriSpec, enhanceId, dataSize, altDataSize, fetchCount,
2642 lastModified, expirationTime, metadata->Pinned(),
2643 info);
2644
2645 return NS_OK;
2646}
2647
2648nsresult CacheFileIOManager::TruncateSeekSetEOFInternal(
2649 CacheFileHandle* aHandle, int64_t aTruncatePos, int64_t aEOFPos) {
2650 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() [handle=%p, "
"truncatePos=%" "l" "d" ", EOFPos=%" "l" "d" "]", aHandle, aTruncatePos
, aEOFPos); } } while (0)
2651 ("CacheFileIOManager::TruncateSeekSetEOFInternal() [handle=%p, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() [handle=%p, "
"truncatePos=%" "l" "d" ", EOFPos=%" "l" "d" "]", aHandle, aTruncatePos
, aEOFPos); } } while (0)
2652 "truncatePos=%" PRId64 ", EOFPos=%" PRId64 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() [handle=%p, "
"truncatePos=%" "l" "d" ", EOFPos=%" "l" "d" "]", aHandle, aTruncatePos
, aEOFPos); } } while (0)
2653 aHandle, aTruncatePos, aEOFPos))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() [handle=%p, "
"truncatePos=%" "l" "d" ", EOFPos=%" "l" "d" "]", aHandle, aTruncatePos
, aEOFPos); } } while (0)
;
2654
2655 nsresult rv;
2656
2657 if (aHandle->mKilled) {
2658 LOG((" handle already killed, file not truncated"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " handle already killed, file not truncated"
); } } while (0)
;
2659 return NS_OK;
2660 }
2661
2662 if (CacheObserver::ShuttingDown() && !aHandle->mFD) {
2663 aHandle->mKilled = true;
2664 LOG((" killing the handle, file not truncated"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " killing the handle, file not truncated"
); } } while (0)
;
2665 return NS_OK;
2666 }
2667
2668 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
2669
2670 if (!aHandle->mFileExists) {
2671 rv = CreateFile(aHandle);
2672 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2672); return rv; } } while (false)
;
2673 }
2674
2675 if (!aHandle->mFD) {
2676 rv = OpenNSPRHandle(aHandle);
2677 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2677); return rv; } } while (false)
;
2678 } else {
2679 NSPRHandleUsed(aHandle);
2680 }
2681
2682 // Check again, OpenNSPRHandle could figure out the file was gone.
2683 if (!aHandle->mFileExists) {
2684 return NS_ERROR_NOT_AVAILABLE;
2685 }
2686
2687 // When this operation would increase cache size, check whether the cache size
2688 // reached the hard limit and whether it would cause critical low disk space.
2689 if (aHandle->mFileSize < aEOFPos) {
2690 if (mOverLimitEvicting && mCacheSizeOnHardLimit) {
2691 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - failing because "
"cache size reached hard limit!"); } } while (0)
2692 ("CacheFileIOManager::TruncateSeekSetEOFInternal() - failing because "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - failing because "
"cache size reached hard limit!"); } } while (0)
2693 "cache size reached hard limit!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - failing because "
"cache size reached hard limit!"); } } while (0)
;
2694 return NS_ERROR_FILE_NO_DEVICE_SPACE;
2695 }
2696
2697 int64_t freeSpace;
2698 rv = mCacheDirectory->GetDiskSpaceAvailable(&freeSpace);
2699 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2699)
) {
2700 freeSpace = -1;
2701 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2702 ("CacheFileIOManager::TruncateSeekSetEOFInternal() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2703 "GetDiskSpaceAvailable() failed! [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2704 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
;
2705 } else {
2706 freeSpace >>= 10; // bytes to kilobytes
2707 uint32_t limit = CacheObserver::DiskFreeSpaceHardLimit();
2708 if (freeSpace - aEOFPos + aHandle->mFileSize < limit) {
2709 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - Low free space"
", refusing to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]"
, freeSpace, limit); } } while (0)
2710 ("CacheFileIOManager::TruncateSeekSetEOFInternal() - Low free space"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - Low free space"
", refusing to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]"
, freeSpace, limit); } } while (0)
2711 ", refusing to write! [freeSpace=%" PRId64 "kB, limit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - Low free space"
", refusing to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]"
, freeSpace, limit); } } while (0)
2712 freeSpace, limit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - Low free space"
", refusing to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]"
, freeSpace, limit); } } while (0)
;
2713 return NS_ERROR_FILE_NO_DEVICE_SPACE;
2714 }
2715 }
2716 }
2717
2718 // This operation always invalidates the entry
2719 aHandle->mInvalid = true;
2720
2721 rv = TruncFile(aHandle->mFD, aTruncatePos);
2722 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2722); return rv; } } while (false)
;
2723
2724 if (aTruncatePos != aEOFPos) {
2725 rv = TruncFile(aHandle->mFD, aEOFPos);
2726 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2726); return rv; } } while (false)
;
2727 }
2728
2729 uint32_t oldSizeInK = aHandle->FileSizeInK();
2730 aHandle->mFileSize = aEOFPos;
2731 uint32_t newSizeInK = aHandle->FileSizeInK();
2732
2733 if (oldSizeInK != newSizeInK && !aHandle->IsDoomed() &&
2734 !aHandle->IsSpecialFile()) {
2735 CacheIndex::UpdateEntry(aHandle->Hash(), nullptr, nullptr, nullptr, nullptr,
2736 nullptr, &newSizeInK);
2737
2738 if (oldSizeInK < newSizeInK) {
2739 EvictIfOverLimitInternal();
2740 }
2741 }
2742
2743 return NS_OK;
2744}
2745
2746// static
2747nsresult CacheFileIOManager::RenameFile(CacheFileHandle* aHandle,
2748 const nsACString& aNewName,
2749 CacheFileIOListener* aCallback) {
2750 LOG(("CacheFileIOManager::RenameFile() [handle=%p, newName=%s, listener=%p]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFile() [handle=%p, newName=%s, listener=%p]"
, aHandle, TPromiseFlatString<char>(aNewName).get(), aCallback
); } } while (0)
2751 aHandle, PromiseFlatCString(aNewName).get(), aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFile() [handle=%p, newName=%s, listener=%p]"
, aHandle, TPromiseFlatString<char>(aNewName).get(), aCallback
); } } while (0)
;
2752
2753 nsresult rv;
2754 RefPtr<CacheFileIOManager> ioMan = gInstance;
2755
2756 if (aHandle->IsClosed() || !ioMan) {
2757 return NS_ERROR_NOT_INITIALIZED;
2758 }
2759
2760 if (!aHandle->IsSpecialFile()) {
2761 return NS_ERROR_UNEXPECTED;
2762 }
2763
2764 RefPtr<RenameFileEvent> ev =
2765 new RenameFileEvent(aHandle, aNewName, aCallback);
2766 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
2767 ? CacheIOThread::WRITE_PRIORITY
2768 : CacheIOThread::WRITE);
2769 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2769); return rv; } } while (false)
;
2770
2771 return NS_OK;
2772}
2773
2774nsresult CacheFileIOManager::RenameFileInternal(CacheFileHandle* aHandle,
2775 const nsACString& aNewName) {
2776 LOG(("CacheFileIOManager::RenameFileInternal() [handle=%p, newName=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFileInternal() [handle=%p, newName=%s]"
, aHandle, TPromiseFlatString<char>(aNewName).get()); }
} while (0)
2777 aHandle, PromiseFlatCString(aNewName).get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFileInternal() [handle=%p, newName=%s]"
, aHandle, TPromiseFlatString<char>(aNewName).get()); }
} while (0)
;
2778
2779 nsresult rv;
2780
2781 MOZ_ASSERT(aHandle->IsSpecialFile())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHandle->IsSpecialFile())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aHandle->IsSpecialFile())
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aHandle->IsSpecialFile()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2781); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHandle->IsSpecialFile()"
")"); do { *((volatile int*)__null) = 2781; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2782
2783 if (aHandle->IsDoomed()) {
2784 return NS_ERROR_NOT_AVAILABLE;
2785 }
2786
2787 // Doom old handle if it exists and is not doomed
2788 for (uint32_t i = 0; i < mSpecialHandles.Length(); i++) {
2789 if (!mSpecialHandles[i]->IsDoomed() &&
2790 mSpecialHandles[i]->Key() == aNewName) {
2791 MOZ_ASSERT(aHandle != mSpecialHandles[i])do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHandle != mSpecialHandles[i])>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aHandle != mSpecialHandles[i
]))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aHandle != mSpecialHandles[i]", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2791); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHandle != mSpecialHandles[i]"
")"); do { *((volatile int*)__null) = 2791; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2792 rv = DoomFileInternal(mSpecialHandles[i]);
2793 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2793); return rv; } } while (false)
;
2794 break;
2795 }
2796 }
2797
2798 nsCOMPtr<nsIFile> file;
2799 rv = GetSpecialFile(aNewName, getter_AddRefs(file));
2800 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2800); return rv; } } while (false)
;
2801
2802 bool exists;
2803 rv = file->Exists(&exists);
2804 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2804); return rv; } } while (false)
;
2805
2806 if (exists) {
2807 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFileInternal() - Removing old file from "
"disk"); } } while (0)
2808 ("CacheFileIOManager::RenameFileInternal() - Removing old file from "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFileInternal() - Removing old file from "
"disk"); } } while (0)
2809 "disk"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFileInternal() - Removing old file from "
"disk"); } } while (0)
;
2810 rv = file->Remove(false);
2811 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2812 NS_WARNING("Cannot remove file from the disk")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot remove file from the disk"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2812)
;
2813 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
2814 ("CacheFileIOManager::RenameFileInternal() - Removing old file failed"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
2815 ". [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
2816 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
;
2817 }
2818 }
2819
2820 if (!aHandle->FileExists()) {
2821 aHandle->mKey = aNewName;
2822 return NS_OK;
2823 }
2824
2825 rv = MaybeReleaseNSPRHandleInternal(aHandle, true);
2826 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2826); return rv; } } while (false)
;
2827
2828 rv = aHandle->mFile->MoveToNative(nullptr, aNewName);
2829 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2829); return rv; } } while (false)
;
2830
2831 aHandle->mKey = aNewName;
2832 return NS_OK;
2833}
2834
2835// static
2836nsresult CacheFileIOManager::EvictIfOverLimit() {
2837 LOG(("CacheFileIOManager::EvictIfOverLimit()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimit()"
); } } while (0)
;
2838
2839 nsresult rv;
2840 RefPtr<CacheFileIOManager> ioMan = gInstance;
2841
2842 if (!ioMan) {
2843 return NS_ERROR_NOT_INITIALIZED;
2844 }
2845
2846 nsCOMPtr<nsIRunnable> ev;
2847 ev = NewRunnableMethod("net::CacheFileIOManager::EvictIfOverLimitInternal",
2848 ioMan, &CacheFileIOManager::EvictIfOverLimitInternal);
2849
2850 rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::EVICT);
2851 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2851); return rv; } } while (false)
;
2852
2853 return NS_OK;
2854}
2855
2856nsresult CacheFileIOManager::EvictIfOverLimitInternal() {
2857 LOG(("CacheFileIOManager::EvictIfOverLimitInternal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal()"
); } } while (0)
;
2858
2859 nsresult rv;
2860
2861 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2861); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 2861; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2862
2863 if (mShuttingDown) {
2864 return NS_ERROR_NOT_INITIALIZED;
2865 }
2866
2867 if (mOverLimitEvicting) {
2868 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Eviction already "
"running."); } } while (0)
2869 ("CacheFileIOManager::EvictIfOverLimitInternal() - Eviction already "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Eviction already "
"running."); } } while (0)
2870 "running."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Eviction already "
"running."); } } while (0)
;
2871 return NS_OK;
2872 }
2873
2874 CacheIOThread::Cancelable cancelable(true);
2875
2876 int64_t freeSpace;
2877 rv = mCacheDirectory->GetDiskSpaceAvailable(&freeSpace);
2878 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2878)
) {
2879 freeSpace = -1;
2880
2881 // Do not change smart size.
2882 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2883 ("CacheFileIOManager::EvictIfOverLimitInternal() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2884 "GetDiskSpaceAvailable() failed! [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2885 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
;
2886 } else {
2887 freeSpace >>= 10; // bytes to kilobytes
2888 UpdateSmartCacheSize(freeSpace);
2889 }
2890
2891 uint32_t cacheUsage;
2892 rv = CacheIndex::GetCacheSize(&cacheUsage);
2893 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2893); return rv; } } while (false)
;
2894
2895 uint32_t cacheLimit = CacheObserver::DiskCacheCapacity();
2896 uint32_t freeSpaceLimit = CacheObserver::DiskFreeSpaceSoftLimit();
2897
2898 if (cacheUsage <= cacheLimit &&
2899 (freeSpace == -1 || freeSpace >= freeSpaceLimit)) {
2900 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "
"space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, " "freeSpace=%"
"l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage, cacheLimit, freeSpace
, freeSpaceLimit); } } while (0)
2901 ("CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "
"space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, " "freeSpace=%"
"l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage, cacheLimit, freeSpace
, freeSpaceLimit); } } while (0)
2902 "space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "
"space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, " "freeSpace=%"
"l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage, cacheLimit, freeSpace
, freeSpaceLimit); } } while (0)
2903 "freeSpace=%" PRId64 "kB, freeSpaceLimit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "
"space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, " "freeSpace=%"
"l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage, cacheLimit, freeSpace
, freeSpaceLimit); } } while (0)
2904 cacheUsage, cacheLimit, freeSpace, freeSpaceLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "
"space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, " "freeSpace=%"
"l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage, cacheLimit, freeSpace
, freeSpaceLimit); } } while (0)
;
2905 return NS_OK;
2906 }
2907
2908 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size exceeded "
"limit. Starting overlimit eviction. [cacheSize=%ukB, limit=%ukB]"
, cacheUsage, cacheLimit); } } while (0)
2909 ("CacheFileIOManager::EvictIfOverLimitInternal() - Cache size exceeded "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size exceeded "
"limit. Starting overlimit eviction. [cacheSize=%ukB, limit=%ukB]"
, cacheUsage, cacheLimit); } } while (0)
2910 "limit. Starting overlimit eviction. [cacheSize=%ukB, limit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size exceeded "
"limit. Starting overlimit eviction. [cacheSize=%ukB, limit=%ukB]"
, cacheUsage, cacheLimit); } } while (0)
2911 cacheUsage, cacheLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size exceeded "
"limit. Starting overlimit eviction. [cacheSize=%ukB, limit=%ukB]"
, cacheUsage, cacheLimit); } } while (0)
;
2912
2913 nsCOMPtr<nsIRunnable> ev;
2914 ev = NewRunnableMethod("net::CacheFileIOManager::OverLimitEvictionInternal",
2915 this, &CacheFileIOManager::OverLimitEvictionInternal);
2916
2917 rv = mIOThread->Dispatch(ev, CacheIOThread::EVICT);
2918 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2918); return rv; } } while (false)
;
2919
2920 mOverLimitEvicting = true;
2921 return NS_OK;
2922}
2923
2924nsresult CacheFileIOManager::OverLimitEvictionInternal() {
2925 LOG(("CacheFileIOManager::OverLimitEvictionInternal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal()"
); } } while (0)
;
2926
2927 nsresult rv;
2928
2929 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2929); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 2929; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2930
2931 // mOverLimitEvicting is accessed only on IO thread, so we can set it to false
2932 // here and set it to true again once we dispatch another event that will
2933 // continue with the eviction. The reason why we do so is that we can fail
2934 // early anywhere in this method and the variable will contain a correct
2935 // value. Otherwise we would need to set it to false on every failing place.
2936 mOverLimitEvicting = false;
2937
2938 if (mShuttingDown) {
2939 return NS_ERROR_NOT_INITIALIZED;
2940 }
2941
2942 while (true) {
2943 int64_t freeSpace;
2944 rv = mCacheDirectory->GetDiskSpaceAvailable(&freeSpace);
2945 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2945)
) {
2946 freeSpace = -1;
2947
2948 // Do not change smart size.
2949 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2950 ("CacheFileIOManager::EvictIfOverLimitInternal() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2951 "GetDiskSpaceAvailable() failed! [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2952 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
;
2953 } else {
2954 freeSpace >>= 10; // bytes to kilobytes
2955 UpdateSmartCacheSize(freeSpace);
2956 }
2957
2958 uint32_t cacheUsage;
2959 rv = CacheIndex::GetCacheSize(&cacheUsage);
2960 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 2960); return rv; } } while (false)
;
2961
2962 uint32_t cacheLimit = CacheObserver::DiskCacheCapacity();
2963 uint32_t freeSpaceLimit = CacheObserver::DiskFreeSpaceSoftLimit();
2964
2965 if (cacheUsage > cacheLimit) {
2966 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size over "
"limit. [cacheSize=%ukB, limit=%ukB]", cacheUsage, cacheLimit
); } } while (0)
2967 ("CacheFileIOManager::OverLimitEvictionInternal() - Cache size over "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size over "
"limit. [cacheSize=%ukB, limit=%ukB]", cacheUsage, cacheLimit
); } } while (0)
2968 "limit. [cacheSize=%ukB, limit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size over "
"limit. [cacheSize=%ukB, limit=%ukB]", cacheUsage, cacheLimit
); } } while (0)
2969 cacheUsage, cacheLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size over "
"limit. [cacheSize=%ukB, limit=%ukB]", cacheUsage, cacheLimit
); } } while (0)
;
2970
2971 // We allow cache size to go over the specified limit. Eviction should
2972 // keep the size within the limit in a long run, but in case the eviction
2973 // is too slow, the cache could go way over the limit. To prevent this we
2974 // set flag mCacheSizeOnHardLimit when the size reaches 105% of the limit
2975 // and WriteInternal() and TruncateSeekSetEOFInternal() fail to cache
2976 // additional data.
2977 if ((cacheUsage - cacheLimit) > (cacheLimit / 20)) {
2978 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size "
"reached hard limit."); } } while (0)
2979 ("CacheFileIOManager::OverLimitEvictionInternal() - Cache size "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size "
"reached hard limit."); } } while (0)
2980 "reached hard limit."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size "
"reached hard limit."); } } while (0)
;
2981 mCacheSizeOnHardLimit = true;
2982 } else {
2983 mCacheSizeOnHardLimit = false;
2984 }
2985 } else if (freeSpace != -1 && freeSpace < freeSpaceLimit) {
2986 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Free space under "
"limit. [freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", freeSpace
, freeSpaceLimit); } } while (0)
2987 ("CacheFileIOManager::OverLimitEvictionInternal() - Free space under "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Free space under "
"limit. [freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", freeSpace
, freeSpaceLimit); } } while (0)
2988 "limit. [freeSpace=%" PRId64 "kB, freeSpaceLimit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Free space under "
"limit. [freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", freeSpace
, freeSpaceLimit); } } while (0)
2989 freeSpace, freeSpaceLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Free space under "
"limit. [freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", freeSpace
, freeSpaceLimit); } } while (0)
;
2990 } else {
2991 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "
"free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "
"freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage
, cacheLimit, freeSpace, freeSpaceLimit); } } while (0)
2992 ("CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "
"free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "
"freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage
, cacheLimit, freeSpace, freeSpaceLimit); } } while (0)
2993 "free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "
"free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "
"freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage
, cacheLimit, freeSpace, freeSpaceLimit); } } while (0)
2994 "freeSpace=%" PRId64 "kB, freeSpaceLimit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "
"free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "
"freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage
, cacheLimit, freeSpace, freeSpaceLimit); } } while (0)
2995 cacheUsage, cacheLimit, freeSpace, freeSpaceLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "
"free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "
"freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage
, cacheLimit, freeSpace, freeSpaceLimit); } } while (0)
;
2996
2997 mCacheSizeOnHardLimit = false;
2998 return NS_OK;
2999 }
3000
3001 if (CacheIOThread::YieldAndRerun()) {
3002 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Breaking loop "
"for higher level events."); } } while (0)
3003 ("CacheFileIOManager::OverLimitEvictionInternal() - Breaking loop "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Breaking loop "
"for higher level events."); } } while (0)
3004 "for higher level events."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Breaking loop "
"for higher level events."); } } while (0)
;
3005 mOverLimitEvicting = true;
3006 return NS_OK;
3007 }
3008
3009 SHA1Sum::Hash hash;
3010 uint32_t cnt;
3011 static uint32_t consecutiveFailures = 0;
3012 rv = CacheIndex::GetEntryForEviction(false, &hash, &cnt);
3013 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3013); return rv; } } while (false)
;
3014
3015 rv = DoomFileByKeyInternal(&hash);
3016 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
3017 consecutiveFailures = 0;
3018 } else if (rv == NS_ERROR_NOT_AVAILABLE) {
3019 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3020 ("CacheFileIOManager::OverLimitEvictionInternal() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3021 "DoomFileByKeyInternal() failed. [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3022 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
;
3023 // TODO index is outdated, start update
3024
3025 // Make sure index won't return the same entry again
3026 CacheIndex::RemoveEntry(&hash);
3027 consecutiveFailures = 0;
3028 } else {
3029 // This shouldn't normally happen, but the eviction must not fail
3030 // completely if we ever encounter this problem.
3031 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager::OverLimitEvictionInternal() - Unexpected "
"failure of DoomFileByKeyInternal()", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3033)
3032 "CacheFileIOManager::OverLimitEvictionInternal() - Unexpected "NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager::OverLimitEvictionInternal() - Unexpected "
"failure of DoomFileByKeyInternal()", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3033)
3033 "failure of DoomFileByKeyInternal()")NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager::OverLimitEvictionInternal() - Unexpected "
"failure of DoomFileByKeyInternal()", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3033)
;
3034
3035 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3036 ("CacheFileIOManager::OverLimitEvictionInternal() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3037 "DoomFileByKeyInternal() failed. [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3038 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
;
3039
3040 // Normally, CacheIndex::UpdateEntry() is called only to update newly
3041 // created/opened entries which are always fresh and UpdateEntry() expects
3042 // and checks this flag. The way we use UpdateEntry() here is a kind of
3043 // hack and we must make sure the flag is set by calling
3044 // EnsureEntryExists().
3045 rv = CacheIndex::EnsureEntryExists(&hash);
3046 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3046); return rv; } } while (false)
;
3047
3048 // Move the entry at the end of both lists to make sure we won't end up
3049 // failing on one entry forever.
3050 uint32_t frecency = 0;
3051 rv = CacheIndex::UpdateEntry(&hash, &frecency, nullptr, nullptr, nullptr,
3052 nullptr, nullptr);
3053 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3053); return rv; } } while (false)
;
3054
3055 consecutiveFailures++;
3056 if (consecutiveFailures >= cnt) {
3057 // This doesn't necessarily mean that we've tried to doom every entry
3058 // but we've reached a sane number of tries. It is likely that another
3059 // eviction will start soon. And as said earlier, this normally doesn't
3060 // happen at all.
3061 return NS_OK;
3062 }
3063 }
3064 }
3065
3066 MOZ_ASSERT_UNREACHABLE("We should never get here")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"We should never get here" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3066); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")"); do
{ *((volatile int*)__null) = 3066; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3067 return NS_OK;
3068}
3069
3070// static
3071nsresult CacheFileIOManager::EvictAll() {
3072 LOG(("CacheFileIOManager::EvictAll()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictAll()"
); } } while (0)
;
3073
3074 nsresult rv;
3075 RefPtr<CacheFileIOManager> ioMan = gInstance;
3076
3077 if (!ioMan) {
3078 return NS_ERROR_NOT_INITIALIZED;
3079 }
3080
3081 nsCOMPtr<nsIRunnable> ev;
3082 ev = NewRunnableMethod("net::CacheFileIOManager::EvictAllInternal", ioMan,
3083 &CacheFileIOManager::EvictAllInternal);
3084
3085 rv = ioMan->mIOThread->DispatchAfterPendingOpens(ev);
3086 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3086)
) {
3087 return rv;
3088 }
3089
3090 return NS_OK;
3091}
3092
3093namespace {
3094
3095class EvictionNotifierRunnable : public Runnable {
3096 public:
3097 EvictionNotifierRunnable() : Runnable("EvictionNotifierRunnable") {}
3098 NS_DECL_NSIRUNNABLEvirtual nsresult Run(void) override;
3099};
3100
3101NS_IMETHODIMPnsresult
3102EvictionNotifierRunnable::Run() {
3103 nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
3104 if (obsSvc) {
3105 obsSvc->NotifyObservers(nullptr, "cacheservice:empty-cache", nullptr);
3106 }
3107 return NS_OK;
3108}
3109
3110} // namespace
3111
3112nsresult CacheFileIOManager::EvictAllInternal() {
3113 LOG(("CacheFileIOManager::EvictAllInternal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictAllInternal()"
); } } while (0)
;
3114
3115 nsresult rv;
3116
3117 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3117); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 3117; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3118
3119 RefPtr<EvictionNotifierRunnable> r = new EvictionNotifierRunnable();
3120
3121 if (!mCacheDirectory) {
3122 // This is a kind of hack. Somebody called EvictAll() without a profile.
3123 // This happens in xpcshell tests that use cache without profile. We need
3124 // to notify observers in this case since the tests are waiting for it.
3125 NS_DispatchToMainThread(r);
3126 return NS_ERROR_FILE_INVALID_PATH;
3127 }
3128
3129 if (mShuttingDown) {
3130 return NS_ERROR_NOT_INITIALIZED;
3131 }
3132
3133 if (!mTreeCreated) {
3134 rv = CreateCacheTree();
3135 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3136 return rv;
3137 }
3138 }
3139
3140 // Doom all active handles
3141 nsTArray<RefPtr<CacheFileHandle>> handles;
3142 mHandles.GetActiveHandles(&handles);
3143
3144 for (uint32_t i = 0; i < handles.Length(); ++i) {
3145 rv = DoomFileInternal(handles[i]);
3146 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3146)
) {
3147 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictAllInternal() - Cannot doom handle "
"[handle=%p]", handles[i].get()); } } while (0)
3148 ("CacheFileIOManager::EvictAllInternal() - Cannot doom handle "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictAllInternal() - Cannot doom handle "
"[handle=%p]", handles[i].get()); } } while (0)
3149 "[handle=%p]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictAllInternal() - Cannot doom handle "
"[handle=%p]", handles[i].get()); } } while (0)
3150 handles[i].get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictAllInternal() - Cannot doom handle "
"[handle=%p]", handles[i].get()); } } while (0)
;
3151 }
3152 }
3153
3154 nsCOMPtr<nsIFile> file;
3155 rv = mCacheDirectory->Clone(getter_AddRefs(file));
3156 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3156)
) {
3157 return rv;
3158 }
3159
3160 rv = file->AppendNative(nsLiteralCString(ENTRIES_DIR"entries"));
3161 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3161)
) {
3162 return rv;
3163 }
3164
3165 // Trash current entries directory
3166 rv = TrashDirectory(file);
3167 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3167)
) {
3168 return rv;
3169 }
3170
3171 // Files are now inaccessible in entries directory, notify observers.
3172 NS_DispatchToMainThread(r);
3173
3174 // Create a new empty entries directory
3175 rv = CheckAndCreateDir(mCacheDirectory, ENTRIES_DIR"entries", false);
3176 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3176)
) {
3177 return rv;
3178 }
3179
3180 CacheIndex::RemoveAll();
3181
3182 return NS_OK;
3183}
3184
3185// static
3186nsresult CacheFileIOManager::EvictByContext(
3187 nsILoadContextInfo* aLoadContextInfo, bool aPinned,
3188 const nsAString& aOrigin, const nsAString& aBaseDomain) {
3189 LOG(("CacheFileIOManager::EvictByContext() [loadContextInfo=%p]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContext() [loadContextInfo=%p]"
, aLoadContextInfo); } } while (0)
3190 aLoadContextInfo))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContext() [loadContextInfo=%p]"
, aLoadContextInfo); } } while (0)
;
3191
3192 nsresult rv;
3193 RefPtr<CacheFileIOManager> ioMan = gInstance;
3194
3195 if (!ioMan) {
3196 return NS_ERROR_NOT_INITIALIZED;
3197 }
3198
3199 nsCOMPtr<nsIRunnable> ev;
3200 ev =
3201 NewRunnableMethod<nsCOMPtr<nsILoadContextInfo>, bool, nsString, nsString>(
3202 "net::CacheFileIOManager::EvictByContextInternal", ioMan,
3203 &CacheFileIOManager::EvictByContextInternal, aLoadContextInfo,
3204 aPinned, aOrigin, aBaseDomain);
3205
3206 rv = ioMan->mIOThread->DispatchAfterPendingOpens(ev);
3207 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3207)
) {
3208 return rv;
3209 }
3210
3211 return NS_OK;
3212}
3213
3214nsresult CacheFileIOManager::EvictByContextInternal(
3215 nsILoadContextInfo* aLoadContextInfo, bool aPinned,
3216 const nsAString& aOrigin, const nsAString& aBaseDomain) {
3217 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%p, "
"pinned=%d]", aLoadContextInfo, aPinned); } } while (0)
3218 ("CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%p, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%p, "
"pinned=%d]", aLoadContextInfo, aPinned); } } while (0)
3219 "pinned=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%p, "
"pinned=%d]", aLoadContextInfo, aPinned); } } while (0)
3220 aLoadContextInfo, aPinned))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%p, "
"pinned=%d]", aLoadContextInfo, aPinned); } } while (0)
;
3221
3222 nsresult rv;
3223
3224 if (aLoadContextInfo) {
3225 nsAutoCString suffix;
3226 aLoadContextInfo->OriginAttributesPtr()->CreateSuffix(suffix);
3227 LOG((" anonymous=%u, suffix=%s]", aLoadContextInfo->IsAnonymous(),do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " anonymous=%u, suffix=%s]"
, aLoadContextInfo->IsAnonymous(), suffix.get()); } } while
(0)
3228 suffix.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " anonymous=%u, suffix=%s]"
, aLoadContextInfo->IsAnonymous(), suffix.get()); } } while
(0)
;
3229
3230 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3230); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 3230; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3231
3232 MOZ_ASSERT(!aLoadContextInfo->IsPrivate())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aLoadContextInfo->IsPrivate())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aLoadContextInfo->IsPrivate
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!aLoadContextInfo->IsPrivate()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3232); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aLoadContextInfo->IsPrivate()"
")"); do { *((volatile int*)__null) = 3232; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3233 if (aLoadContextInfo->IsPrivate()) {
3234 return NS_ERROR_INVALID_ARG;
3235 }
3236 }
3237
3238 if (!mCacheDirectory) {
3239 // This is a kind of hack. Somebody called EvictAll() without a profile.
3240 // This happens in xpcshell tests that use cache without profile. We need
3241 // to notify observers in this case since the tests are waiting for it.
3242 // Also notify for aPinned == true, those are interested as well.
3243 if (!aLoadContextInfo) {
3244 RefPtr<EvictionNotifierRunnable> r = new EvictionNotifierRunnable();
3245 NS_DispatchToMainThread(r);
3246 }
3247 return NS_ERROR_FILE_INVALID_PATH;
3248 }
3249
3250 if (mShuttingDown) {
3251 return NS_ERROR_NOT_INITIALIZED;
3252 }
3253
3254 if (!mTreeCreated) {
3255 rv = CreateCacheTree();
3256 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3257 return rv;
3258 }
3259 }
3260
3261 NS_ConvertUTF16toUTF8 origin(aOrigin);
3262 NS_ConvertUTF16toUTF8 baseDomain(aBaseDomain);
3263
3264 // Doom all active handles that matches the load context
3265 nsTArray<RefPtr<CacheFileHandle>> handles;
3266 mHandles.GetActiveHandles(&handles);
3267
3268 for (uint32_t i = 0; i < handles.Length(); ++i) {
3269 CacheFileHandle* handle = handles[i];
3270
3271 const bool shouldRemove = [&] {
3272 nsAutoCString uriSpec;
3273 RefPtr<nsILoadContextInfo> info =
3274 CacheFileUtils::ParseKey(handle->Key(), nullptr, &uriSpec);
3275 if (!info) {
3276 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot parse key "
"in " "handle! [handle=%p, key=%s]", handle, handle->Key(
).get()); } } while (0)
3277 ("CacheFileIOManager::EvictByContextInternal() - Cannot parse key "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot parse key "
"in " "handle! [handle=%p, key=%s]", handle, handle->Key(
).get()); } } while (0)
3278 "in "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot parse key "
"in " "handle! [handle=%p, key=%s]", handle, handle->Key(
).get()); } } while (0)
3279 "handle! [handle=%p, key=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot parse key "
"in " "handle! [handle=%p, key=%s]", handle, handle->Key(
).get()); } } while (0)
3280 handle, handle->Key().get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot parse key "
"in " "handle! [handle=%p, key=%s]", handle, handle->Key(
).get()); } } while (0)
;
3281 MOZ_CRASH("Unexpected error!")do { do { } while (false); MOZ_ReportCrash("" "Unexpected error!"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3281); AnnotateMozCrashReason("MOZ_CRASH(" "Unexpected error!"
")"); do { *((volatile int*)__null) = 3281; __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
3282 }
3283
3284 // Filter by base domain.
3285 if (!aBaseDomain.IsEmpty()) {
3286 if (StoragePrincipalHelper::PartitionKeyHasBaseDomain(
3287 info->OriginAttributesPtr()->mPartitionKey, aBaseDomain)) {
3288 return true;
3289 }
3290
3291 // If the partitionKey does not match, check the entry URI next.
3292
3293 // Get host portion of uriSpec.
3294 nsCOMPtr<nsIURI> uri;
3295 rv = NS_NewURI(getter_AddRefs(uri), uriSpec);
3296 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3296)
) {
3297 return false;
3298 }
3299 nsAutoCString host;
3300 rv = uri->GetHost(host);
3301 // Some entries may not have valid hosts. We can skip them.
3302 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || host.IsEmpty()) {
3303 return false;
3304 }
3305
3306 // Clear entry if the host belongs to the given base domain.
3307 bool hasRootDomain = false;
3308 rv = HasRootDomain(host, baseDomain, &hasRootDomain);
3309 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3309)
) {
3310 return false;
3311 }
3312
3313 return hasRootDomain;
3314 }
3315
3316 // Filter by LoadContextInfo.
3317 if (aLoadContextInfo && !info->EqualsIgnoringFPD(aLoadContextInfo)) {
3318 return false;
3319 }
3320
3321 // Filter by origin.
3322 if (!origin.IsEmpty()) {
3323 RefPtr<MozURL> url;
3324 rv = MozURL::Init(getter_AddRefs(url), uriSpec);
3325 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3326 return false;
3327 }
3328
3329 nsAutoCString urlOrigin;
3330 url->Origin(urlOrigin);
3331
3332 if (!urlOrigin.Equals(origin)) {
3333 return false;
3334 }
3335 }
3336 return true;
3337 }();
3338
3339 if (!shouldRemove) {
3340 continue;
3341 }
3342
3343 // handle will be doomed only when pinning status is known and equal or
3344 // doom decision will be deferred until pinning status is determined.
3345 rv = DoomFileInternal(handle,
3346 aPinned ? CacheFileIOManager::DOOM_WHEN_PINNED
3347 : CacheFileIOManager::DOOM_WHEN_NON_PINNED);
3348 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3348)
) {
3349 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot doom handle"
" [handle=%p]", handle); } } while (0)
3350 ("CacheFileIOManager::EvictByContextInternal() - Cannot doom handle"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot doom handle"
" [handle=%p]", handle); } } while (0)
3351 " [handle=%p]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot doom handle"
" [handle=%p]", handle); } } while (0)
3352 handle))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot doom handle"
" [handle=%p]", handle); } } while (0)
;
3353 }
3354 }
3355
3356 if (!aLoadContextInfo) {
3357 RefPtr<EvictionNotifierRunnable> r = new EvictionNotifierRunnable();
3358 NS_DispatchToMainThread(r);
3359 }
3360
3361 if (!mContextEvictor) {
3362 mContextEvictor = new CacheFileContextEvictor();
3363 mContextEvictor->Init(mCacheDirectory);
3364 }
3365
3366 mContextEvictor->AddContext(aLoadContextInfo, aPinned, aOrigin);
3367
3368 return NS_OK;
3369}
3370
3371// static
3372nsresult CacheFileIOManager::CacheIndexStateChanged() {
3373 LOG(("CacheFileIOManager::CacheIndexStateChanged()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::CacheIndexStateChanged()"
); } } while (0)
;
3374
3375 nsresult rv;
3376
3377 // CacheFileIOManager lives longer than CacheIndex so gInstance must be
3378 // non-null here.
3379 MOZ_ASSERT(gInstance)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(gInstance)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(gInstance))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("gInstance", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3379); AnnotateMozCrashReason("MOZ_ASSERT" "(" "gInstance" ")"
); do { *((volatile int*)__null) = 3379; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3380
3381 // We have to re-distatch even if we are on IO thread to prevent reentering
3382 // the lock in CacheIndex
3383 nsCOMPtr<nsIRunnable> ev = NewRunnableMethod(
3384 "net::CacheFileIOManager::CacheIndexStateChangedInternal",
3385 gInstance.get(), &CacheFileIOManager::CacheIndexStateChangedInternal);
3386
3387 nsCOMPtr<nsIEventTarget> ioTarget = IOTarget();
3388 MOZ_ASSERT(ioTarget)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(ioTarget)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(ioTarget))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("ioTarget", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3388); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioTarget" ")"
); do { *((volatile int*)__null) = 3388; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3389
3390 rv = ioTarget->Dispatch(ev, nsIEventTarget::DISPATCH_NORMAL);
3391 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3391)
) {
3392 return rv;
3393 }
3394
3395 return NS_OK;
3396}
3397
3398void CacheFileIOManager::CacheIndexStateChangedInternal() {
3399 if (mShuttingDown) {
3400 // ignore notification during shutdown
3401 return;
3402 }
3403
3404 if (!mContextEvictor) {
3405 return;
3406 }
3407
3408 mContextEvictor->CacheIndexStateChanged();
3409}
3410
3411nsresult CacheFileIOManager::TrashDirectory(nsIFile* aFile) {
3412 LOG(("CacheFileIOManager::TrashDirectory() [file=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() [file=%s]"
, aFile->HumanReadablePath().get()); } } while (0)
3413 aFile->HumanReadablePath().get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() [file=%s]"
, aFile->HumanReadablePath().get()); } } while (0)
;
3414
3415 nsresult rv;
3416
3417 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3417); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 3417; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3418 MOZ_ASSERT(mCacheDirectory)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mCacheDirectory)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mCacheDirectory))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("mCacheDirectory"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3418); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mCacheDirectory"
")"); do { *((volatile int*)__null) = 3418; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3419
3420 // When the directory is empty, it is cheaper to remove it directly instead of
3421 // using the trash mechanism.
3422 bool isEmpty;
3423 rv = IsEmptyDirectory(aFile, &isEmpty);
3424 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3424); return rv; } } while (false)
;
3425
3426 if (isEmpty) {
3427 rv = aFile->Remove(false);
3428 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Directory removed "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
3429 ("CacheFileIOManager::TrashDirectory() - Directory removed "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Directory removed "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
3430 "[rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Directory removed "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
3431 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Directory removed "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
;
3432 return rv;
3433 }
3434
3435#ifdef DEBUG1
3436 nsCOMPtr<nsIFile> dirCheck;
3437 rv = aFile->GetParent(getter_AddRefs(dirCheck));
3438 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3438); return rv; } } while (false)
;
3439
3440 bool equals = false;
3441 rv = dirCheck->Equals(mCacheDirectory, &equals);
3442 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3442); return rv; } } while (false)
;
3443
3444 MOZ_ASSERT(equals)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(equals)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(equals))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("equals", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3444); AnnotateMozCrashReason("MOZ_ASSERT" "(" "equals" ")"
); do { *((volatile int*)__null) = 3444; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3445#endif
3446
3447 nsCOMPtr<nsIFile> dir, trash;
3448 nsAutoCString leaf;
3449
3450 rv = aFile->Clone(getter_AddRefs(dir));
3451 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3451); return rv; } } while (false)
;
3452
3453 rv = aFile->Clone(getter_AddRefs(trash));
3454 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3454); return rv; } } while (false)
;
3455
3456 const int32_t kMaxTries = 16;
3457 srand(static_cast<unsigned>(PR_Now()));
3458 for (int32_t triesCount = 0;; ++triesCount) {
3459 leaf = TRASH_DIR"trash";
3460 leaf.AppendInt(rand());
3461 rv = trash->SetNativeLeafName(leaf);
3462 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3462); return rv; } } while (false)
;
3463
3464 bool exists;
3465 if (NS_SUCCEEDED(trash->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(trash->Exists(
&exists))), 1)))
&& !exists) {
3466 break;
3467 }
3468
3469 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Trash directory already "
"exists [leaf=%s]", leaf.get()); } } while (0)
3470 ("CacheFileIOManager::TrashDirectory() - Trash directory already "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Trash directory already "
"exists [leaf=%s]", leaf.get()); } } while (0)
3471 "exists [leaf=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Trash directory already "
"exists [leaf=%s]", leaf.get()); } } while (0)
3472 leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Trash directory already "
"exists [leaf=%s]", leaf.get()); } } while (0)
;
3473
3474 if (triesCount == kMaxTries) {
3475 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Could not find unused trash "
"directory in %d tries.", kMaxTries); } } while (0)
3476 ("CacheFileIOManager::TrashDirectory() - Could not find unused trash "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Could not find unused trash "
"directory in %d tries.", kMaxTries); } } while (0)
3477 "directory in %d tries.",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Could not find unused trash "
"directory in %d tries.", kMaxTries); } } while (0)
3478 kMaxTries))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Could not find unused trash "
"directory in %d tries.", kMaxTries); } } while (0)
;
3479 return NS_ERROR_FAILURE;
3480 }
3481 }
3482
3483 LOG(("CacheFileIOManager::TrashDirectory() - Renaming directory [leaf=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Renaming directory [leaf=%s]"
, leaf.get()); } } while (0)
3484 leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Renaming directory [leaf=%s]"
, leaf.get()); } } while (0)
;
3485
3486 rv = dir->MoveToNative(nullptr, leaf);
3487 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3487); return rv; } } while (false)
;
3488
3489 StartRemovingTrash();
3490 return NS_OK;
3491}
3492
3493// static
3494void CacheFileIOManager::OnTrashTimer(nsITimer* aTimer, void* aClosure) {
3495 LOG(("CacheFileIOManager::OnTrashTimer() [timer=%p, closure=%p]", aTimer,do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OnTrashTimer() [timer=%p, closure=%p]"
, aTimer, aClosure); } } while (0)
3496 aClosure))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OnTrashTimer() [timer=%p, closure=%p]"
, aTimer, aClosure); } } while (0)
;
3497
3498 RefPtr<CacheFileIOManager> ioMan = gInstance;
3499
3500 if (!ioMan) {
3501 return;
3502 }
3503
3504 ioMan->mTrashTimer = nullptr;
3505 ioMan->StartRemovingTrash();
3506}
3507
3508nsresult CacheFileIOManager::StartRemovingTrash() {
3509 LOG(("CacheFileIOManager::StartRemovingTrash()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::StartRemovingTrash()"
); } } while (0)
;
3510
3511 nsresult rv;
3512
3513 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3513); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 3513; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3514
3515 if (mShuttingDown) {
3516 return NS_ERROR_NOT_INITIALIZED;
3517 }
3518
3519 if (!mCacheDirectory) {
3520 return NS_ERROR_FILE_INVALID_PATH;
3521 }
3522
3523 if (mTrashTimer) {
3524 LOG(("CacheFileIOManager::StartRemovingTrash() - Trash timer exists."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::StartRemovingTrash() - Trash timer exists."
); } } while (0)
;
3525 return NS_OK;
3526 }
3527
3528 if (mRemovingTrashDirs) {
3529 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::StartRemovingTrash() - Trash removing in "
"progress."); } } while (0)
3530 ("CacheFileIOManager::StartRemovingTrash() - Trash removing in "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::StartRemovingTrash() - Trash removing in "
"progress."); } } while (0)
3531 "progress."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::StartRemovingTrash() - Trash removing in "
"progress."); } } while (0)
;
3532 return NS_OK;
3533 }
3534
3535 uint32_t elapsed = (TimeStamp::NowLoRes() - mStartTime).ToMilliseconds();
3536 if (elapsed < kRemoveTrashStartDelay60000) {
3537 nsCOMPtr<nsIEventTarget> ioTarget = IOTarget();
3538 MOZ_ASSERT(ioTarget)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(ioTarget)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(ioTarget))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("ioTarget", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3538); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioTarget" ")"
); do { *((volatile int*)__null) = 3538; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3539
3540 return NS_NewTimerWithFuncCallback(
3541 getter_AddRefs(mTrashTimer), CacheFileIOManager::OnTrashTimer, nullptr,
3542 kRemoveTrashStartDelay60000 - elapsed, nsITimer::TYPE_ONE_SHOT,
3543 "net::CacheFileIOManager::StartRemovingTrash", ioTarget);
3544 }
3545
3546 nsCOMPtr<nsIRunnable> ev;
3547 ev = NewRunnableMethod("net::CacheFileIOManager::RemoveTrashInternal", this,
3548 &CacheFileIOManager::RemoveTrashInternal);
3549
3550 rv = mIOThread->Dispatch(ev, CacheIOThread::EVICT);
3551 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3551); return rv; } } while (false)
;
3552
3553 mRemovingTrashDirs = true;
3554 return NS_OK;
3555}
3556
3557nsresult CacheFileIOManager::RemoveTrashInternal() {
3558 LOG(("CacheFileIOManager::RemoveTrashInternal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal()"
); } } while (0)
;
3559
3560 nsresult rv;
3561
3562 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3562); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 3562; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3563
3564 if (mShuttingDown) {
3565 return NS_ERROR_NOT_INITIALIZED;
3566 }
3567
3568 CacheIOThread::Cancelable cancelable(true);
3569
3570 MOZ_ASSERT(!mTrashTimer)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mTrashTimer)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mTrashTimer))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!mTrashTimer", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3570); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mTrashTimer"
")"); do { *((volatile int*)__null) = 3570; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3571 MOZ_ASSERT(mRemovingTrashDirs)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mRemovingTrashDirs)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mRemovingTrashDirs))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("mRemovingTrashDirs"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3571); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mRemovingTrashDirs"
")"); do { *((volatile int*)__null) = 3571; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3572
3573 if (!mTreeCreated) {
3574 rv = CreateCacheTree();
3575 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3576 return rv;
3577 }
3578 }
3579
3580 // mRemovingTrashDirs is accessed only on IO thread, so we can drop the flag
3581 // here and set it again once we dispatch a continuation event. By doing so,
3582 // we don't have to drop the flag on any possible early return.
3583 mRemovingTrashDirs = false;
3584
3585 while (true) {
3586 if (CacheIOThread::YieldAndRerun()) {
3587 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Breaking loop for "
"higher level events."); } } while (0)
3588 ("CacheFileIOManager::RemoveTrashInternal() - Breaking loop for "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Breaking loop for "
"higher level events."); } } while (0)
3589 "higher level events."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Breaking loop for "
"higher level events."); } } while (0)
;
3590 mRemovingTrashDirs = true;
3591 return NS_OK;
3592 }
3593
3594 // Find some trash directory
3595 if (!mTrashDir) {
3596 MOZ_ASSERT(!mTrashDirEnumerator)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mTrashDirEnumerator)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mTrashDirEnumerator))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!mTrashDirEnumerator"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3596); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mTrashDirEnumerator"
")"); do { *((volatile int*)__null) = 3596; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3597
3598 rv = FindTrashDirToRemove();
3599 if (rv == NS_ERROR_NOT_AVAILABLE) {
3600 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - No trash directory "
"found."); } } while (0)
3601 ("CacheFileIOManager::RemoveTrashInternal() - No trash directory "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - No trash directory "
"found."); } } while (0)
3602 "found."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - No trash directory "
"found."); } } while (0)
;
3603 return NS_OK;
3604 }
3605 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3605); return rv; } } while (false)
;
3606
3607 rv = mTrashDir->GetDirectoryEntries(getter_AddRefs(mTrashDirEnumerator));
3608 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3608); return rv; } } while (false)
;
3609
3610 continue; // check elapsed time
3611 }
3612
3613 // We null out mTrashDirEnumerator once we remove all files in the
3614 // directory, so remove the trash directory if we don't have enumerator.
3615 if (!mTrashDirEnumerator) {
3616 rv = mTrashDir->Remove(false);
3617 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3618 // There is no reason why removing an empty directory should fail, but
3619 // if it does, we should continue and try to remove all other trash
3620 // directories.
3621 nsAutoCString leafName;
3622 mTrashDir->GetNativeLeafName(leafName);
3623 mFailedTrashDirs.AppendElement(leafName);
3624 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Cannot remove "
"trashdir. [name=%s]", leafName.get()); } } while (0)
3625 ("CacheFileIOManager::RemoveTrashInternal() - Cannot remove "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Cannot remove "
"trashdir. [name=%s]", leafName.get()); } } while (0)
3626 "trashdir. [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Cannot remove "
"trashdir. [name=%s]", leafName.get()); } } while (0)
3627 leafName.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Cannot remove "
"trashdir. [name=%s]", leafName.get()); } } while (0)
;
3628 }
3629
3630 mTrashDir = nullptr;
3631 continue; // check elapsed time
3632 }
3633
3634 nsCOMPtr<nsIFile> file;
3635 rv = mTrashDirEnumerator->GetNextFile(getter_AddRefs(file));
3636 if (!file) {
3637 mTrashDirEnumerator->Close();
3638 mTrashDirEnumerator = nullptr;
3639 continue; // check elapsed time
3640 }
3641 bool isDir = false;
3642 file->IsDirectory(&isDir);
3643 if (isDir) {
3644 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "Found a directory in a trash directory! It will be removed "
"recursively, but this can block IO thread for a while!", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3646)
3645 "Found a directory in a trash directory! It will be removed "NS_DebugBreak(NS_DEBUG_WARNING, "Found a directory in a trash directory! It will be removed "
"recursively, but this can block IO thread for a while!", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3646)
3646 "recursively, but this can block IO thread for a while!")NS_DebugBreak(NS_DEBUG_WARNING, "Found a directory in a trash directory! It will be removed "
"recursively, but this can block IO thread for a while!", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3646)
;
3647 if (LOG_ENABLED()(__builtin_expect(!!(mozilla::detail::log_test(gCache2Log, mozilla
::LogLevel::Debug)), 0))
) {
3648 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
3649 ("CacheFileIOManager::RemoveTrashInternal() - Found a directory in "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
3650 "a trash "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
3651 "directory! It will be removed recursively, but this can block IO "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
3652 "thread for a while! [file=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
3653 file->HumanReadablePath().get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
;
3654 }
3655 }
3656 file->Remove(isDir);
3657 }
3658
3659 MOZ_ASSERT_UNREACHABLE("We should never get here")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"We should never get here" ")", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3659); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")"); do
{ *((volatile int*)__null) = 3659; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3660 return NS_OK;
3661}
3662
3663nsresult CacheFileIOManager::FindTrashDirToRemove() {
3664 LOG(("CacheFileIOManager::FindTrashDirToRemove()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::FindTrashDirToRemove()"
); } } while (0)
;
3665
3666 nsresult rv;
3667
3668 if (!mCacheDirectory) {
3669 return NS_ERROR_UNEXPECTED;
3670 }
3671
3672 // We call this method on the main thread during shutdown when user wants to
3673 // remove all cache files.
3674 MOZ_ASSERT(mIOThread->IsCurrentThread() || mShuttingDown)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread() || mShuttingDown)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mIOThread->IsCurrentThread() || mShuttingDown))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("mIOThread->IsCurrentThread() || mShuttingDown"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3674); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread() || mShuttingDown"
")"); do { *((volatile int*)__null) = 3674; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3675
3676 nsCOMPtr<nsIDirectoryEnumerator> iter;
3677 rv = mCacheDirectory->GetDirectoryEntries(getter_AddRefs(iter));
3678 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3678); return rv; } } while (false)
;
3679
3680 nsCOMPtr<nsIFile> file;
3681 while (NS_SUCCEEDED(iter->GetNextFile(getter_AddRefs(file)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(iter->GetNextFile
(getter_AddRefs(file)))), 1)))
&& file) {
3682 bool isDir = false;
3683 file->IsDirectory(&isDir);
3684 if (!isDir) {
3685 continue;
3686 }
3687
3688 nsAutoCString leafName;
3689 rv = file->GetNativeLeafName(leafName);
3690 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3691 continue;
3692 }
3693
3694 if (leafName.Length() < strlen(TRASH_DIR"trash")) {
3695 continue;
3696 }
3697
3698 if (!StringBeginsWith(leafName, nsLiteralCString(TRASH_DIR"trash"))) {
3699 continue;
3700 }
3701
3702 if (mFailedTrashDirs.Contains(leafName)) {
3703 continue;
3704 }
3705
3706 LOG(("CacheFileIOManager::FindTrashDirToRemove() - Returning directory %s",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::FindTrashDirToRemove() - Returning directory %s"
, leafName.get()); } } while (0)
3707 leafName.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::FindTrashDirToRemove() - Returning directory %s"
, leafName.get()); } } while (0)
;
3708
3709 mTrashDir = file;
3710 return NS_OK;
3711 }
3712
3713 // When we're here we've tried to delete all trash directories. Clear
3714 // mFailedTrashDirs so we will try to delete them again when we start removing
3715 // trash directories next time.
3716 mFailedTrashDirs.Clear();
3717 return NS_ERROR_NOT_AVAILABLE;
3718}
3719
3720// static
3721nsresult CacheFileIOManager::InitIndexEntry(CacheFileHandle* aHandle,
3722 OriginAttrsHash aOriginAttrsHash,
3723 bool aAnonymous, bool aPinning) {
3724 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::InitIndexEntry() [handle=%p, "
"originAttrsHash=%" "l" "x" ", " "anonymous=%d, pinning=%d]"
, aHandle, aOriginAttrsHash, aAnonymous, aPinning); } } while
(0)
3725 ("CacheFileIOManager::InitIndexEntry() [handle=%p, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::InitIndexEntry() [handle=%p, "
"originAttrsHash=%" "l" "x" ", " "anonymous=%d, pinning=%d]"
, aHandle, aOriginAttrsHash, aAnonymous, aPinning); } } while
(0)
3726 "originAttrsHash=%" PRIx64 ", "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::InitIndexEntry() [handle=%p, "
"originAttrsHash=%" "l" "x" ", " "anonymous=%d, pinning=%d]"
, aHandle, aOriginAttrsHash, aAnonymous, aPinning); } } while
(0)
3727 "anonymous=%d, pinning=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::InitIndexEntry() [handle=%p, "
"originAttrsHash=%" "l" "x" ", " "anonymous=%d, pinning=%d]"
, aHandle, aOriginAttrsHash, aAnonymous, aPinning); } } while
(0)
3728 aHandle, aOriginAttrsHash, aAnonymous, aPinning))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::InitIndexEntry() [handle=%p, "
"originAttrsHash=%" "l" "x" ", " "anonymous=%d, pinning=%d]"
, aHandle, aOriginAttrsHash, aAnonymous, aPinning); } } while
(0)
;
3729
3730 nsresult rv;
3731 RefPtr<CacheFileIOManager> ioMan = gInstance;
3732
3733 if (aHandle->IsClosed() || !ioMan) {
3734 return NS_ERROR_NOT_INITIALIZED;
3735 }
3736
3737 if (aHandle->IsSpecialFile()) {
3738 return NS_ERROR_UNEXPECTED;
3739 }
3740
3741 RefPtr<InitIndexEntryEvent> ev =
3742 new InitIndexEntryEvent(aHandle, aOriginAttrsHash, aAnonymous, aPinning);
3743 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
3744 ? CacheIOThread::WRITE_PRIORITY
3745 : CacheIOThread::WRITE);
3746 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3746); return rv; } } while (false)
;
3747
3748 return NS_OK;
3749}
3750
3751// static
3752nsresult CacheFileIOManager::UpdateIndexEntry(CacheFileHandle* aHandle,
3753 const uint32_t* aFrecency,
3754 const bool* aHasAltData,
3755 const uint16_t* aOnStartTime,
3756 const uint16_t* aOnStopTime,
3757 const uint8_t* aContentType) {
3758 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, onStartTime=%s, onStopTime=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aOnStartTime ? nsPrintfCString("%u", *aOnStartTime).get() : ""
, aOnStopTime ? nsPrintfCString("%u", *aOnStopTime).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3759 ("CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, onStartTime=%s, onStopTime=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aOnStartTime ? nsPrintfCString("%u", *aOnStartTime).get() : ""
, aOnStopTime ? nsPrintfCString("%u", *aOnStopTime).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3760 "hasAltData=%s, onStartTime=%s, onStopTime=%s, contentType=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, onStartTime=%s, onStopTime=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aOnStartTime ? nsPrintfCString("%u", *aOnStartTime).get() : ""
, aOnStopTime ? nsPrintfCString("%u", *aOnStopTime).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3761 aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, onStartTime=%s, onStopTime=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aOnStartTime ? nsPrintfCString("%u", *aOnStartTime).get() : ""
, aOnStopTime ? nsPrintfCString("%u", *aOnStopTime).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3762 aHasAltData ? (*aHasAltData ? "true" : "false") : "",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, onStartTime=%s, onStopTime=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aOnStartTime ? nsPrintfCString("%u", *aOnStartTime).get() : ""
, aOnStopTime ? nsPrintfCString("%u", *aOnStopTime).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3763 aOnStartTime ? nsPrintfCString("%u", *aOnStartTime).get() : "",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, onStartTime=%s, onStopTime=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aOnStartTime ? nsPrintfCString("%u", *aOnStartTime).get() : ""
, aOnStopTime ? nsPrintfCString("%u", *aOnStopTime).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3764 aOnStopTime ? nsPrintfCString("%u", *aOnStopTime).get() : "",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, onStartTime=%s, onStopTime=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aOnStartTime ? nsPrintfCString("%u", *aOnStartTime).get() : ""
, aOnStopTime ? nsPrintfCString("%u", *aOnStopTime).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3765 aContentType ? nsPrintfCString("%u", *aContentType).get() : ""))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, onStartTime=%s, onStopTime=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aOnStartTime ? nsPrintfCString("%u", *aOnStartTime).get() : ""
, aOnStopTime ? nsPrintfCString("%u", *aOnStopTime).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
;
3766
3767 nsresult rv;
3768 RefPtr<CacheFileIOManager> ioMan = gInstance;
3769
3770 if (aHandle->IsClosed() || !ioMan) {
3771 return NS_ERROR_NOT_INITIALIZED;
3772 }
3773
3774 if (aHandle->IsSpecialFile()) {
3775 return NS_ERROR_UNEXPECTED;
3776 }
3777
3778 RefPtr<UpdateIndexEntryEvent> ev = new UpdateIndexEntryEvent(
3779 aHandle, aFrecency, aHasAltData, aOnStartTime, aOnStopTime, aContentType);
3780 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
3781 ? CacheIOThread::WRITE_PRIORITY
3782 : CacheIOThread::WRITE);
3783 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3783); return rv; } } while (false)
;
3784
3785 return NS_OK;
3786}
3787
3788nsresult CacheFileIOManager::CreateFile(CacheFileHandle* aHandle) {
3789 MOZ_ASSERT(!aHandle->mFD)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aHandle->mFD)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aHandle->mFD))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!aHandle->mFD"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3789); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aHandle->mFD"
")"); do { *((volatile int*)__null) = 3789; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3790 MOZ_ASSERT(aHandle->mFile)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHandle->mFile)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aHandle->mFile))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("aHandle->mFile"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3790); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHandle->mFile"
")"); do { *((volatile int*)__null) = 3790; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3791
3792 nsresult rv;
3793
3794 if (aHandle->IsDoomed()) {
3795 nsCOMPtr<nsIFile> file;
3796
3797 rv = GetDoomedFile(getter_AddRefs(file));
3798 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3798); return rv; } } while (false)
;
3799
3800 aHandle->mFile.swap(file);
3801 } else {
3802 bool exists;
3803 if (NS_SUCCEEDED(aHandle->mFile->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aHandle->mFile
->Exists(&exists))), 1)))
&& exists) {
3804 NS_WARNING("Found a file that should not exist!")NS_DebugBreak(NS_DEBUG_WARNING, "Found a file that should not exist!"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3804)
;
3805 }
3806 }
3807
3808 rv = OpenNSPRHandle(aHandle, true);
3809 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3809); return rv; } } while (false)
;
3810
3811 aHandle->mFileSize = 0;
3812 return NS_OK;
3813}
3814
3815// static
3816void CacheFileIOManager::HashToStr(const SHA1Sum::Hash* aHash,
3817 nsACString& _retval) {
3818 _retval.Truncate();
3819 const char hexChars[] = {'0', '1', '2', '3', '4', '5', '6', '7',
3820 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
3821 for (uint32_t i = 0; i < sizeof(SHA1Sum::Hash); i++) {
3822 _retval.Append(hexChars[(*aHash)[i] >> 4]);
3823 _retval.Append(hexChars[(*aHash)[i] & 0xF]);
3824 }
3825}
3826
3827// static
3828nsresult CacheFileIOManager::StrToHash(const nsACString& aHash,
3829 SHA1Sum::Hash* _retval) {
3830 if (aHash.Length() != 2 * sizeof(SHA1Sum::Hash)) {
3831 return NS_ERROR_INVALID_ARG;
3832 }
3833
3834 for (uint32_t i = 0; i < aHash.Length(); i++) {
3835 uint8_t value;
3836
3837 if (aHash[i] >= '0' && aHash[i] <= '9') {
3838 value = aHash[i] - '0';
3839 } else if (aHash[i] >= 'A' && aHash[i] <= 'F') {
3840 value = aHash[i] - 'A' + 10;
3841 } else if (aHash[i] >= 'a' && aHash[i] <= 'f') {
3842 value = aHash[i] - 'a' + 10;
3843 } else {
3844 return NS_ERROR_INVALID_ARG;
3845 }
3846
3847 if (i % 2 == 0) {
3848 (reinterpret_cast<uint8_t*>(_retval))[i / 2] = value << 4;
3849 } else {
3850 (reinterpret_cast<uint8_t*>(_retval))[i / 2] += value;
3851 }
3852 }
3853
3854 return NS_OK;
3855}
3856
3857nsresult CacheFileIOManager::GetFile(const SHA1Sum::Hash* aHash,
3858 nsIFile** _retval) {
3859 nsresult rv;
3860 nsCOMPtr<nsIFile> file;
3861 rv = mCacheDirectory->Clone(getter_AddRefs(file));
3862 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3862); return rv; } } while (false)
;
3863
3864 rv = file->AppendNative(nsLiteralCString(ENTRIES_DIR"entries"));
3865 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3865); return rv; } } while (false)
;
3866
3867 nsAutoCString leafName;
3868 HashToStr(aHash, leafName);
3869
3870 rv = file->AppendNative(leafName);
3871 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3871); return rv; } } while (false)
;
3872
3873 file.swap(*_retval);
3874 return NS_OK;
3875}
3876
3877nsresult CacheFileIOManager::GetSpecialFile(const nsACString& aKey,
3878 nsIFile** _retval) {
3879 nsresult rv;
3880 nsCOMPtr<nsIFile> file;
3881 rv = mCacheDirectory->Clone(getter_AddRefs(file));
3882 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3882); return rv; } } while (false)
;
3883
3884 rv = file->AppendNative(aKey);
3885 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3885); return rv; } } while (false)
;
3886
3887 file.swap(*_retval);
3888 return NS_OK;
3889}
3890
3891nsresult CacheFileIOManager::GetDoomedFile(nsIFile** _retval) {
3892 nsresult rv;
3893 nsCOMPtr<nsIFile> file;
3894 rv = mCacheDirectory->Clone(getter_AddRefs(file));
3895 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3895); return rv; } } while (false)
;
3896
3897 rv = file->AppendNative(nsLiteralCString(DOOMED_DIR"doomed"));
3898 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3898); return rv; } } while (false)
;
3899
3900 rv = file->AppendNative("dummyleaf"_ns);
3901 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3901); return rv; } } while (false)
;
3902
3903 const int32_t kMaxTries = 64;
3904 srand(static_cast<unsigned>(PR_Now()));
3905 nsAutoCString leafName;
3906 for (int32_t triesCount = 0;; ++triesCount) {
3907 leafName.AppendInt(rand());
3908 rv = file->SetNativeLeafName(leafName);
3909 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3909); return rv; } } while (false)
;
3910
3911 bool exists;
3912 if (NS_SUCCEEDED(file->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(file->Exists(&
exists))), 1)))
&& !exists) {
3913 break;
3914 }
3915
3916 if (triesCount == kMaxTries) {
3917 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::GetDoomedFile() - Could not find unused file "
"name in %d tries.", kMaxTries); } } while (0)
3918 ("CacheFileIOManager::GetDoomedFile() - Could not find unused file "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::GetDoomedFile() - Could not find unused file "
"name in %d tries.", kMaxTries); } } while (0)
3919 "name in %d tries.",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::GetDoomedFile() - Could not find unused file "
"name in %d tries.", kMaxTries); } } while (0)
3920 kMaxTries))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::GetDoomedFile() - Could not find unused file "
"name in %d tries.", kMaxTries); } } while (0)
;
3921 return NS_ERROR_FAILURE;
3922 }
3923
3924 leafName.Truncate();
3925 }
3926
3927 file.swap(*_retval);
3928 return NS_OK;
3929}
3930
3931nsresult CacheFileIOManager::IsEmptyDirectory(nsIFile* aFile, bool* _retval) {
3932 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3932); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 3932; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3933
3934 nsresult rv;
3935
3936 nsCOMPtr<nsIDirectoryEnumerator> enumerator;
3937 rv = aFile->GetDirectoryEntries(getter_AddRefs(enumerator));
3938 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3938); return rv; } } while (false)
;
3939
3940 bool hasMoreElements = false;
3941 rv = enumerator->HasMoreElements(&hasMoreElements);
3942 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3942); return rv; } } while (false)
;
3943
3944 *_retval = !hasMoreElements;
3945 return NS_OK;
3946}
3947
3948nsresult CacheFileIOManager::CheckAndCreateDir(nsIFile* aFile, const char* aDir,
3949 bool aEnsureEmptyDir) {
3950 nsresult rv;
3951
3952 nsCOMPtr<nsIFile> file;
3953 if (!aDir) {
3954 file = aFile;
3955 } else {
3956 nsAutoCString dir(aDir);
3957 rv = aFile->Clone(getter_AddRefs(file));
3958 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3958); return rv; } } while (false)
;
3959 rv = file->AppendNative(dir);
3960 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3960); return rv; } } while (false)
;
3961 }
3962
3963 bool exists = false;
3964 rv = file->Exists(&exists);
3965 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && exists) {
3966 bool isDirectory = false;
3967 rv = file->IsDirectory(&isDirectory);
3968 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || !isDirectory) {
3969 // Try to remove the file
3970 rv = file->Remove(false);
3971 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
3972 exists = false;
3973 }
3974 }
3975 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3975); return rv; } } while (false)
;
3976 }
3977
3978 if (aEnsureEmptyDir && NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && exists) {
3979 bool isEmpty;
3980 rv = IsEmptyDirectory(file, &isEmpty);
3981 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3981); return rv; } } while (false)
;
3982
3983 if (!isEmpty) {
3984 // Don't check the result, if this fails, it's OK. We do this
3985 // only for the doomed directory that doesn't need to be deleted
3986 // for the cost of completely disabling the whole browser.
3987 TrashDirectory(file);
3988 }
3989 }
3990
3991 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && !exists) {
3992 rv = file->Create(nsIFile::DIRECTORY_TYPE, 0700);
3993 }
3994 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3995 NS_WARNING("Cannot create directory")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot create directory", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 3995)
;
3996 return NS_ERROR_FAILURE;
3997 }
3998
3999 return NS_OK;
4000}
4001
4002nsresult CacheFileIOManager::CreateCacheTree() {
4003 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4003); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 4003; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4004 MOZ_ASSERT(!mTreeCreated)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mTreeCreated)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mTreeCreated))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!mTreeCreated",
"/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4004); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mTreeCreated"
")"); do { *((volatile int*)__null) = 4004; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4005
4006 if (!mCacheDirectory || mTreeCreationFailed) {
4007 return NS_ERROR_FILE_INVALID_PATH;
4008 }
4009
4010 nsresult rv;
4011
4012 // Set the flag here and clear it again below when the tree is created
4013 // successfully.
4014 mTreeCreationFailed = true;
4015
4016 // ensure parent directory exists
4017 nsCOMPtr<nsIFile> parentDir;
4018 rv = mCacheDirectory->GetParent(getter_AddRefs(parentDir));
4019 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4019); return rv; } } while (false)
;
4020 rv = CheckAndCreateDir(parentDir, nullptr, false);
4021 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4021); return rv; } } while (false)
;
4022
4023 // ensure cache directory exists
4024 rv = CheckAndCreateDir(mCacheDirectory, nullptr, false);
4025 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4025); return rv; } } while (false)
;
4026
4027 // ensure entries directory exists
4028 rv = CheckAndCreateDir(mCacheDirectory, ENTRIES_DIR"entries", false);
4029 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4029); return rv; } } while (false)
;
4030
4031 // ensure doomed directory exists
4032 rv = CheckAndCreateDir(mCacheDirectory, DOOMED_DIR"doomed", true);
4033 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4033); return rv; } } while (false)
;
4034
4035 mTreeCreated = true;
4036 mTreeCreationFailed = false;
4037
4038 if (!mContextEvictor) {
4039 RefPtr<CacheFileContextEvictor> contextEvictor;
4040 contextEvictor = new CacheFileContextEvictor();
4041
4042 // Init() method will try to load unfinished contexts from the disk. Store
4043 // the evictor as a member only when there is some unfinished job.
4044 contextEvictor->Init(mCacheDirectory);
4045 if (contextEvictor->ContextsCount()) {
4046 contextEvictor.swap(mContextEvictor);
4047 }
4048 }
4049
4050 StartRemovingTrash();
4051
4052 return NS_OK;
4053}
4054
4055nsresult CacheFileIOManager::OpenNSPRHandle(CacheFileHandle* aHandle,
4056 bool aCreate) {
4057 LOG(("CacheFileIOManager::OpenNSPRHandle BEGIN, handle=%p", aHandle))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle BEGIN, handle=%p"
, aHandle); } } while (0)
;
4058
4059 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4059); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 4059; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4060 MOZ_ASSERT(!aHandle->mFD)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aHandle->mFD)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aHandle->mFD))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!aHandle->mFD"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4060); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aHandle->mFD"
")"); do { *((volatile int*)__null) = 4060; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4061 MOZ_ASSERT(mHandlesByLastUsed.IndexOf(aHandle) == mHandlesByLastUsed.NoIndex)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mHandlesByLastUsed.IndexOf(aHandle) == mHandlesByLastUsed
.NoIndex)>::isValid, "invalid assertion condition"); if ((
__builtin_expect(!!(!(!!(mHandlesByLastUsed.IndexOf(aHandle) ==
mHandlesByLastUsed.NoIndex))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mHandlesByLastUsed.IndexOf(aHandle) == mHandlesByLastUsed.NoIndex"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4061); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mHandlesByLastUsed.IndexOf(aHandle) == mHandlesByLastUsed.NoIndex"
")"); do { *((volatile int*)__null) = 4061; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4062 MOZ_ASSERT(mHandlesByLastUsed.Length() <= kOpenHandlesLimit)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mHandlesByLastUsed.Length() <= 128)>::isValid,
"invalid assertion condition"); if ((__builtin_expect(!!(!(!
!(mHandlesByLastUsed.Length() <= 128))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("mHandlesByLastUsed.Length() <= 128"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4062); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mHandlesByLastUsed.Length() <= 128"
")"); do { *((volatile int*)__null) = 4062; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4063 MOZ_ASSERT((aCreate && !aHandle->mFileExists) ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype((aCreate && !aHandle->mFileExists) || (!aCreate
&& aHandle->mFileExists))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!((aCreate && !aHandle
->mFileExists) || (!aCreate && aHandle->mFileExists
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("(aCreate && !aHandle->mFileExists) || (!aCreate && aHandle->mFileExists)"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4064); AnnotateMozCrashReason("MOZ_ASSERT" "(" "(aCreate && !aHandle->mFileExists) || (!aCreate && aHandle->mFileExists)"
")"); do { *((volatile int*)__null) = 4064; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4064 (!aCreate && aHandle->mFileExists))do { static_assert( mozilla::detail::AssertionConditionType<
decltype((aCreate && !aHandle->mFileExists) || (!aCreate
&& aHandle->mFileExists))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!((aCreate && !aHandle
->mFileExists) || (!aCreate && aHandle->mFileExists
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("(aCreate && !aHandle->mFileExists) || (!aCreate && aHandle->mFileExists)"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4064); AnnotateMozCrashReason("MOZ_ASSERT" "(" "(aCreate && !aHandle->mFileExists) || (!aCreate && aHandle->mFileExists)"
")"); do { *((volatile int*)__null) = 4064; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4065
4066 nsresult rv;
4067
4068 if (mHandlesByLastUsed.Length() == kOpenHandlesLimit128) {
4069 // close handle that hasn't been used for the longest time
4070 rv = MaybeReleaseNSPRHandleInternal(mHandlesByLastUsed[0], true);
4071 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4071); return rv; } } while (false)
;
4072 }
4073
4074 if (aCreate) {
4075 rv = aHandle->mFile->OpenNSPRFileDesc(
4076 PR_RDWR0x04 | PR_CREATE_FILE0x08 | PR_TRUNCATE0x20, 0600, &aHandle->mFD);
4077 if (rv == NS_ERROR_FILE_ALREADY_EXISTS || // error from nsLocalFileWin
4078 rv == NS_ERROR_FILE_NO_DEVICE_SPACE) { // error from nsLocalFileUnix
4079 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
" might reached a limit on FAT32. Will evict a single entry and try "
"again. [hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
4080 ("CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
" might reached a limit on FAT32. Will evict a single entry and try "
"again. [hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
4081 " might reached a limit on FAT32. Will evict a single entry and try "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
" might reached a limit on FAT32. Will evict a single entry and try "
"again. [hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
4082 "again. [hash=%08x%08x%08x%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
" might reached a limit on FAT32. Will evict a single entry and try "
"again. [hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
4083 LOGSHA1(aHandle->Hash())))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
" might reached a limit on FAT32. Will evict a single entry and try "
"again. [hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
;
4084
4085 SHA1Sum::Hash hash;
4086 uint32_t cnt;
4087
4088 rv = CacheIndex::GetEntryForEviction(true, &hash, &cnt);
4089 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
4090 rv = DoomFileByKeyInternal(&hash);
4091 }
4092 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
4093 rv = aHandle->mFile->OpenNSPRFileDesc(
4094 PR_RDWR0x04 | PR_CREATE_FILE0x08 | PR_TRUNCATE0x20, 0600, &aHandle->mFD);
4095 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"
" with hash %08x%08x%08x%08x%08x. %s to create the new file."
, PR_htonl((reinterpret_cast<const uint32_t*>(&hash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(&
hash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>
(&hash))[2]), PR_htonl((reinterpret_cast<const uint32_t
*>(&hash))[3]), PR_htonl((reinterpret_cast<const uint32_t
*>(&hash))[4]), ((bool)(__builtin_expect(!!(!NS_FAILED_impl
(rv)), 1))) ? "Succeeded" : "Failed"); } } while (0)
4096 ("CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"
" with hash %08x%08x%08x%08x%08x. %s to create the new file."
, PR_htonl((reinterpret_cast<const uint32_t*>(&hash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(&
hash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>
(&hash))[2]), PR_htonl((reinterpret_cast<const uint32_t
*>(&hash))[3]), PR_htonl((reinterpret_cast<const uint32_t
*>(&hash))[4]), ((bool)(__builtin_expect(!!(!NS_FAILED_impl
(rv)), 1))) ? "Succeeded" : "Failed"); } } while (0)
4097 " with hash %08x%08x%08x%08x%08x. %s to create the new file.",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"
" with hash %08x%08x%08x%08x%08x. %s to create the new file."
, PR_htonl((reinterpret_cast<const uint32_t*>(&hash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(&
hash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>
(&hash))[2]), PR_htonl((reinterpret_cast<const uint32_t
*>(&hash))[3]), PR_htonl((reinterpret_cast<const uint32_t
*>(&hash))[4]), ((bool)(__builtin_expect(!!(!NS_FAILED_impl
(rv)), 1))) ? "Succeeded" : "Failed"); } } while (0)
4098 LOGSHA1(&hash), NS_SUCCEEDED(rv) ? "Succeeded" : "Failed"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"
" with hash %08x%08x%08x%08x%08x. %s to create the new file."
, PR_htonl((reinterpret_cast<const uint32_t*>(&hash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(&
hash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>
(&hash))[2]), PR_htonl((reinterpret_cast<const uint32_t
*>(&hash))[3]), PR_htonl((reinterpret_cast<const uint32_t
*>(&hash))[4]), ((bool)(__builtin_expect(!!(!NS_FAILED_impl
(rv)), 1))) ? "Succeeded" : "Failed"); } } while (0)
;
4099 } else {
4100 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Couldn't evict an existing"
" entry."); } } while (0)
4101 ("CacheFileIOManager::OpenNSPRHandle() - Couldn't evict an existing"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Couldn't evict an existing"
" entry."); } } while (0)
4102 " entry."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Couldn't evict an existing"
" entry."); } } while (0)
;
4103 rv = NS_ERROR_FILE_NO_DEVICE_SPACE;
4104 }
4105 }
4106 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4107 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() Create failed with "
"0x%08" "x", static_cast<uint32_t>(rv)); } } while (0)
4108 ("CacheFileIOManager::OpenNSPRHandle() Create failed with "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() Create failed with "
"0x%08" "x", static_cast<uint32_t>(rv)); } } while (0)
4109 "0x%08" PRIx32,do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() Create failed with "
"0x%08" "x", static_cast<uint32_t>(rv)); } } while (0)
4110 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() Create failed with "
"0x%08" "x", static_cast<uint32_t>(rv)); } } while (0)
;
4111 }
4112 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4112); return rv; } } while (false)
;
4113
4114 aHandle->mFileExists = true;
4115 } else {
4116 rv = aHandle->mFile->OpenNSPRFileDesc(PR_RDWR0x04, 0600, &aHandle->mFD);
4117 if (NS_ERROR_FILE_NOT_FOUND == rv) {
4118 LOG((" file doesn't exists"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " file doesn't exists"
); } } while (0)
;
4119 aHandle->mFileExists = false;
4120 return DoomFileInternal(aHandle);
4121 }
4122 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4123 LOG(("CacheFileIOManager::OpenNSPRHandle() Open failed with 0x%08" PRIx32,do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() Open failed with 0x%08"
"x", static_cast<uint32_t>(rv)); } } while (0)
4124 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() Open failed with 0x%08"
"x", static_cast<uint32_t>(rv)); } } while (0)
;
4125 }
4126 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4126); return rv; } } while (false)
;
4127 }
4128
4129 mHandlesByLastUsed.AppendElement(aHandle);
4130
4131 LOG(("CacheFileIOManager::OpenNSPRHandle END, handle=%p", aHandle))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle END, handle=%p"
, aHandle); } } while (0)
;
4132
4133 return NS_OK;
4134}
4135
4136void CacheFileIOManager::NSPRHandleUsed(CacheFileHandle* aHandle) {
4137 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4137); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 4137; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4138 MOZ_ASSERT(aHandle->mFD)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHandle->mFD)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aHandle->mFD))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("aHandle->mFD"
, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4138); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHandle->mFD"
")"); do { *((volatile int*)__null) = 4138; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4139
4140 DebugOnly<bool> found{};
4141 found = mHandlesByLastUsed.RemoveElement(aHandle);
4142 MOZ_ASSERT(found)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(found)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(found))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("found", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4142); AnnotateMozCrashReason("MOZ_ASSERT" "(" "found" ")")
; do { *((volatile int*)__null) = 4142; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4143
4144 mHandlesByLastUsed.AppendElement(aHandle);
4145}
4146
4147nsresult CacheFileIOManager::SyncRemoveDir(nsIFile* aFile, const char* aDir) {
4148 nsresult rv;
4149 nsCOMPtr<nsIFile> file;
4150
4151 if (!aFile) {
4152 return NS_ERROR_INVALID_ARG;
4153 }
4154
4155 if (!aDir) {
4156 file = aFile;
4157 } else {
4158 rv = aFile->Clone(getter_AddRefs(file));
4159 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4159)
) {
4160 return rv;
4161 }
4162
4163 rv = file->AppendNative(nsDependentCString(aDir));
4164 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4164)
) {
4165 return rv;
4166 }
4167 }
4168
4169 if (LOG_ENABLED()(__builtin_expect(!!(mozilla::detail::log_test(gCache2Log, mozilla
::LogLevel::Debug)), 0))
) {
4170 LOG(("CacheFileIOManager::SyncRemoveDir() - Removing directory %s",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveDir() - Removing directory %s"
, file->HumanReadablePath().get()); } } while (0)
4171 file->HumanReadablePath().get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveDir() - Removing directory %s"
, file->HumanReadablePath().get()); } } while (0)
;
4172 }
4173
4174 rv = file->Remove(true);
4175 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4175)
) {
4176 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveDir() - Removing failed! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4177 ("CacheFileIOManager::SyncRemoveDir() - Removing failed! "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveDir() - Removing failed! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4178 "[rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveDir() - Removing failed! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4179 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveDir() - Removing failed! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
;
4180 }
4181
4182 return rv;
4183}
4184
4185nsresult CacheFileIOManager::DispatchPurgeTask(
4186 const nsCString& aCacheDirName, const nsCString& aSecondsToWait,
4187 const nsCString& aPurgeExtension) {
4188#if !defined(MOZ_BACKGROUNDTASKS1)
4189 // If background tasks are disabled, then we should just bail out early.
4190 return NS_ERROR_NOT_IMPLEMENTED;
4191#else
4192 nsCOMPtr<nsIFile> cacheDir;
4193 nsresult rv = mCacheDirectory->Clone(getter_AddRefs(cacheDir));
4194 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4194); return rv; } } while (false)
;
4195
4196 nsCOMPtr<nsIFile> profileDir;
4197 rv = cacheDir->GetParent(getter_AddRefs(profileDir));
4198 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4198); return rv; } } while (false)
;
4199
4200 nsCOMPtr<nsIFile> lf;
4201 rv = XRE_GetBinaryPath(getter_AddRefs(lf));
4202 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4202); return rv; } } while (false)
;
4203
4204 nsAutoCString path;
4205# if !defined(XP_WIN)
4206 rv = profileDir->GetNativePath(path);
4207# else
4208 rv = profileDir->GetNativeTarget(path);
4209# endif
4210 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4210); return rv; } } while (false)
;
4211
4212 nsCOMPtr<nsIBackgroundTasksRunner> runner =
4213 do_GetService("@mozilla.org/backgroundtasksrunner;1");
4214
4215 return runner->RemoveDirectoryInDetachedProcess(
4216 path, aCacheDirName, aSecondsToWait, aPurgeExtension, "HttpCache"_ns);
4217#endif
4218}
4219
4220void CacheFileIOManager::SyncRemoveAllCacheFiles() {
4221 LOG(("CacheFileIOManager::SyncRemoveAllCacheFiles()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles()"
); } } while (0)
;
4222 nsresult rv;
4223
4224 // If we are already running in a background task, we
4225 // don't want to spawn yet another one at shutdown.
4226 if (inBackgroundTask()) {
4227 return;
4228 }
4229
4230 if (StaticPrefs::network_cache_shutdown_purge_in_background_task()) {
4231 rv = [&]() -> nsresult {
4232 nsresult rv;
4233
4234 // If there is no cache directory, there's nothing to remove.
4235 if (!mCacheDirectory) {
4236 return NS_OK;
4237 }
4238
4239 nsAutoCString leafName;
4240 rv = mCacheDirectory->GetNativeLeafName(leafName);
4241 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4241); return rv; } } while (false)
;
4242
4243 leafName.Append('.');
4244
4245 PRExplodedTime now;
4246 PR_ExplodeTime(PR_Now(), PR_GMTParameters, &now);
4247 leafName.Append(nsPrintfCString(
4248 "%04d-%02d-%02d-%02d-%02d-%02d", now.tm_year, now.tm_month + 1,
4249 now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec));
4250 leafName.Append(kPurgeExtension);
4251
4252 nsAutoCString secondsToWait;
4253 secondsToWait.AppendInt(
4254 StaticPrefs::network_cache_shutdown_purge_folder_wait_seconds());
4255
4256 rv = DispatchPurgeTask(leafName, secondsToWait, kPurgeExtension);
4257 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4257); return rv; } } while (false)
;
4258
4259 rv = mCacheDirectory->RenameToNative(nullptr, leafName);
4260 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4260); return rv; } } while (false)
;
4261
4262 return NS_OK;
4263 }();
4264
4265 // Dispatching to the background task has succeeded. This is finished.
4266 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
4267 return;
4268 }
4269 }
4270
4271 SyncRemoveDir(mCacheDirectory, ENTRIES_DIR"entries");
4272 SyncRemoveDir(mCacheDirectory, DOOMED_DIR"doomed");
4273
4274 // Clear any intermediate state of trash dir enumeration.
4275 mFailedTrashDirs.Clear();
4276 mTrashDir = nullptr;
4277
4278 while (true) {
4279 // FindTrashDirToRemove() fills mTrashDir if there is any trash directory.
4280 rv = FindTrashDirToRemove();
4281 if (rv == NS_ERROR_NOT_AVAILABLE) {
4282 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - No trash directory "
"found."); } } while (0)
4283 ("CacheFileIOManager::SyncRemoveAllCacheFiles() - No trash directory "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - No trash directory "
"found."); } } while (0)
4284 "found."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - No trash directory "
"found."); } } while (0)
;
4285 break;
4286 }
4287 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4287)
) {
4288 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - "
"FindTrashDirToRemove() returned an unexpected error. " "[rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
4289 ("CacheFileIOManager::SyncRemoveAllCacheFiles() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - "
"FindTrashDirToRemove() returned an unexpected error. " "[rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
4290 "FindTrashDirToRemove() returned an unexpected error. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - "
"FindTrashDirToRemove() returned an unexpected error. " "[rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
4291 "[rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - "
"FindTrashDirToRemove() returned an unexpected error. " "[rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
4292 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - "
"FindTrashDirToRemove() returned an unexpected error. " "[rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
;
4293 break;
4294 }
4295
4296 rv = SyncRemoveDir(mTrashDir, nullptr);
4297 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4298 nsAutoCString leafName;
4299 mTrashDir->GetNativeLeafName(leafName);
4300 mFailedTrashDirs.AppendElement(leafName);
4301 }
4302 }
4303}
4304
4305// Returns default ("smart") size (in KB) of cache, given available disk space
4306// (also in KB)
4307static uint32_t SmartCacheSize(const int64_t availKB) {
4308 uint32_t maxSize;
4309
4310 if (CacheObserver::ClearCacheOnShutdown()) {
4311 maxSize = kMaxClearOnShutdownCacheSizeKB;
4312 } else {
4313 maxSize = kMaxCacheSizeKB;
4314 }
4315
4316 if (availKB > 25 * 1024 * 1024) {
4317 return maxSize; // skip computing if we're over 25 GB
4318 }
4319
4320 // Grow/shrink in 10 MB units, deliberately, so that in the common case we
4321 // don't shrink cache and evict items every time we startup (it's important
4322 // that we don't slow down startup benchmarks).
4323 uint32_t sz10MBs = 0;
4324 uint32_t avail10MBs = availKB / (1024 * 10);
4325
4326 // 2.5% of space above 7GB
4327 if (avail10MBs > 700) {
4328 sz10MBs += static_cast<uint32_t>((avail10MBs - 700) * .025);
4329 avail10MBs = 700;
4330 }
4331 // 7.5% of space between 500 MB -> 7 GB
4332 if (avail10MBs > 50) {
4333 sz10MBs += static_cast<uint32_t>((avail10MBs - 50) * .075);
4334 avail10MBs = 50;
4335 }
4336
4337#ifdef ANDROID
4338 // On Android, smaller/older devices may have very little storage and
4339 // device owners may be sensitive to storage footprint: Use a smaller
4340 // percentage of available space and a smaller minimum.
4341
4342 // 16% of space up to 500 MB (10 MB min)
4343 sz10MBs += std::max<uint32_t>(1, static_cast<uint32_t>(avail10MBs * .16));
4344#else
4345 // 30% of space up to 500 MB (50 MB min)
4346 sz10MBs += std::max<uint32_t>(5, static_cast<uint32_t>(avail10MBs * .3));
4347#endif
4348
4349 return std::min<uint32_t>(maxSize, sz10MBs * 10 * 1024);
4350}
4351
4352nsresult CacheFileIOManager::UpdateSmartCacheSize(int64_t aFreeSpace) {
4353 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4353); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 4353; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4354
4355 nsresult rv;
4356
4357 if (!CacheObserver::SmartCacheSizeEnabled()) {
4358 return NS_ERROR_NOT_AVAILABLE;
4359 }
4360
4361 // Wait at least kSmartSizeUpdateInterval before recomputing smart size.
4362 static const TimeDuration kUpdateLimit =
4363 TimeDuration::FromMilliseconds(kSmartSizeUpdateInterval60000);
4364 if (!mLastSmartSizeTime.IsNull() &&
4365 (TimeStamp::NowLoRes() - mLastSmartSizeTime) < kUpdateLimit) {
4366 return NS_OK;
4367 }
4368
4369 // Do not compute smart size when cache size is not reliable.
4370 bool isUpToDate = false;
4371 CacheIndex::IsUpToDate(&isUpToDate);
4372 if (!isUpToDate) {
4373 return NS_ERROR_NOT_AVAILABLE;
4374 }
4375
4376 uint32_t cacheUsage;
4377 rv = CacheIndex::GetCacheSize(&cacheUsage);
4378 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4378)
) {
4379 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateSmartCacheSize() - Cannot get cacheUsage! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4380 ("CacheFileIOManager::UpdateSmartCacheSize() - Cannot get cacheUsage! "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateSmartCacheSize() - Cannot get cacheUsage! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4381 "[rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateSmartCacheSize() - Cannot get cacheUsage! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4382 static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateSmartCacheSize() - Cannot get cacheUsage! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
;
4383 return rv;
4384 }
4385
4386 mLastSmartSizeTime = TimeStamp::NowLoRes();
4387
4388 uint32_t smartSize = SmartCacheSize(aFreeSpace + cacheUsage);
4389
4390 if (smartSize == CacheObserver::DiskCacheCapacity()) {
4391 // Smart size has not changed.
4392 return NS_OK;
4393 }
4394
4395 CacheObserver::SetSmartDiskCacheCapacity(smartSize);
4396
4397 return NS_OK;
4398}
4399
4400// Memory reporting
4401
4402namespace {
4403
4404// A helper class that dispatches and waits for an event that gets result of
4405// CacheFileIOManager->mHandles.SizeOfExcludingThis() on the I/O thread
4406// to safely get handles memory report.
4407// We must do this, since the handle list is only accessed and managed w/o
4408// locking on the I/O thread. That is by design.
4409class SizeOfHandlesRunnable : public Runnable {
4410 public:
4411 SizeOfHandlesRunnable(mozilla::MallocSizeOf mallocSizeOf,
4412 CacheFileHandles const& handles,
4413 nsTArray<CacheFileHandle*> const& specialHandles,
4414 nsCOMPtr<nsITimer> const& metadataWritesTimer)
4415 : Runnable("net::SizeOfHandlesRunnable"),
4416 mMonitor("SizeOfHandlesRunnable.mMonitor"),
4417 mMonitorNotified(false),
4418 mMallocSizeOf(mallocSizeOf),
4419 mHandles(handles),
4420 mSpecialHandles(specialHandles),
4421 mMetadataWritesTimer(metadataWritesTimer),
4422 mSize(0) {}
4423
4424 size_t Get(CacheIOThread* thread) {
4425 nsCOMPtr<nsIEventTarget> target = thread->Target();
4426 if (!target) {
4427 NS_ERROR("If we have the I/O thread we also must have the I/O target")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "If we have the I/O thread we also must have the I/O target"
, "Error", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4427); MOZ_PretendNoReturn(); } while (0)
;
4428 return 0;
4429 }
4430
4431 mozilla::MonitorAutoLock mon(mMonitor);
4432 mMonitorNotified = false;
4433 nsresult rv = target->Dispatch(this, nsIEventTarget::DISPATCH_NORMAL);
4434 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4435 NS_ERROR("Dispatch failed, cannot do memory report of CacheFileHandles")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "Dispatch failed, cannot do memory report of CacheFileHandles"
, "Error", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp"
, 4435); MOZ_PretendNoReturn(); } while (0)
;
4436 return 0;
4437 }
4438
4439 while (!mMonitorNotified) {
4440 mon.Wait();
4441 }
4442 return mSize;
4443 }
4444
4445 NS_IMETHODvirtual nsresult Run() override {
4446 mozilla::MonitorAutoLock mon(mMonitor);
4447 // Excluding this since the object itself is a member of CacheFileIOManager
4448 // reported in CacheFileIOManager::SizeOfIncludingThis as part of |this|.
4449 mSize = mHandles.SizeOfExcludingThis(mMallocSizeOf);
4450 for (uint32_t i = 0; i < mSpecialHandles.Length(); ++i) {
4451 mSize += mSpecialHandles[i]->SizeOfIncludingThis(mMallocSizeOf);
4452 }
4453 nsCOMPtr<nsISizeOf> sizeOf = do_QueryInterface(mMetadataWritesTimer);
4454 if (sizeOf) {
4455 mSize += sizeOf->SizeOfIncludingThis(mMallocSizeOf);
4456 }
4457
4458 mMonitorNotified = true;
4459 mon.Notify();
4460 return NS_OK;
4461 }
4462
4463 private:
4464 mozilla::Monitor mMonitor;
4465 bool mMonitorNotified;
4466 mozilla::MallocSizeOf mMallocSizeOf;
4467 CacheFileHandles const& mHandles;
4468 nsTArray<CacheFileHandle*> const& mSpecialHandles;
4469 nsCOMPtr<nsITimer> const& mMetadataWritesTimer;
4470 size_t mSize;
4471};
4472
4473} // namespace
4474
4475size_t CacheFileIOManager::SizeOfExcludingThisInternal(
4476 mozilla::MallocSizeOf mallocSizeOf) const {
4477 size_t n = 0;
4478 nsCOMPtr<nsISizeOf> sizeOf;
4479
4480 if (mIOThread) {
4481 n += mIOThread->SizeOfIncludingThis(mallocSizeOf);
4482
4483 // mHandles, mSpecialHandles and mMetadataWritesTimer must be accessed
4484 // only on the I/O thread, must sync dispatch.
4485 RefPtr<SizeOfHandlesRunnable> sizeOfHandlesRunnable =
4486 new SizeOfHandlesRunnable(mallocSizeOf, mHandles, mSpecialHandles,
4487 mMetadataWritesTimer);
4488 n += sizeOfHandlesRunnable->Get(mIOThread);
4489 }
4490
4491 // mHandlesByLastUsed just refers handles reported by mHandles.
4492
4493 sizeOf = do_QueryInterface(mCacheDirectory);
4494 if (sizeOf) n += sizeOf->SizeOfIncludingThis(mallocSizeOf);
4495
4496 sizeOf = do_QueryInterface(mTrashTimer);
4497 if (sizeOf) n += sizeOf->SizeOfIncludingThis(mallocSizeOf);
4498
4499 sizeOf = do_QueryInterface(mTrashDir);
4500 if (sizeOf) n += sizeOf->SizeOfIncludingThis(mallocSizeOf);
4501
4502 for (uint32_t i = 0; i < mFailedTrashDirs.Length(); ++i) {
4503 n += mFailedTrashDirs[i].SizeOfExcludingThisIfUnshared(mallocSizeOf);
4504 }
4505
4506 return n;
4507}
4508
4509// static
4510size_t CacheFileIOManager::SizeOfExcludingThis(
4511 mozilla::MallocSizeOf mallocSizeOf) {
4512 if (!gInstance) return 0;
4513
4514 return gInstance->SizeOfExcludingThisInternal(mallocSizeOf);
4515}
4516
4517// static
4518size_t CacheFileIOManager::SizeOfIncludingThis(
4519 mozilla::MallocSizeOf mallocSizeOf) {
4520 return mallocSizeOf(gInstance) + SizeOfExcludingThis(mallocSizeOf);
4521}
4522
4523} // namespace mozilla::net