Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/netwerk/cache2/CacheFileIOManager.cpp
Warning:line 1347, column 5
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-18/lib/clang/18 -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 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/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../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 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -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-05-16-034744-15991-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",
Value stored to 'rv' is never read
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;
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->Equals(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
3337 return true;
3338 }();
3339
3340 if (!shouldRemove) {
3341 continue;
3342 }
3343
3344 // handle will be doomed only when pinning status is known and equal or
3345 // doom decision will be deferred until pinning status is determined.
3346 rv = DoomFileInternal(handle,
3347 aPinned ? CacheFileIOManager::DOOM_WHEN_PINNED
3348 : CacheFileIOManager::DOOM_WHEN_NON_PINNED);
3349 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"
, 3349)
) {
3350 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)
3351 ("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)
3352 " [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)
3353 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)
;
3354 }
3355 }
3356
3357 if (!aLoadContextInfo) {
3358 RefPtr<EvictionNotifierRunnable> r = new EvictionNotifierRunnable();
3359 NS_DispatchToMainThread(r);
3360 }
3361
3362 if (!mContextEvictor) {
3363 mContextEvictor = new CacheFileContextEvictor();
3364 mContextEvictor->Init(mCacheDirectory);
3365 }
3366
3367 mContextEvictor->AddContext(aLoadContextInfo, aPinned, aOrigin);
3368
3369 return NS_OK;
3370}
3371
3372// static
3373nsresult CacheFileIOManager::CacheIndexStateChanged() {
3374 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)
;
3375
3376 nsresult rv;
3377
3378 // CacheFileIOManager lives longer than CacheIndex so gInstance must be
3379 // non-null here.
3380 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"
, 3380); AnnotateMozCrashReason("MOZ_ASSERT" "(" "gInstance" ")"
); do { *((volatile int*)__null) = 3380; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3381
3382 // We have to re-distatch even if we are on IO thread to prevent reentering
3383 // the lock in CacheIndex
3384 nsCOMPtr<nsIRunnable> ev = NewRunnableMethod(
3385 "net::CacheFileIOManager::CacheIndexStateChangedInternal",
3386 gInstance.get(), &CacheFileIOManager::CacheIndexStateChangedInternal);
3387
3388 nsCOMPtr<nsIEventTarget> ioTarget = IOTarget();
3389 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"
, 3389); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioTarget" ")"
); do { *((volatile int*)__null) = 3389; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3390
3391 rv = ioTarget->Dispatch(ev, nsIEventTarget::DISPATCH_NORMAL);
3392 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"
, 3392)
) {
3393 return rv;
3394 }
3395
3396 return NS_OK;
3397}
3398
3399void CacheFileIOManager::CacheIndexStateChangedInternal() {
3400 if (mShuttingDown) {
3401 // ignore notification during shutdown
3402 return;
3403 }
3404
3405 if (!mContextEvictor) {
3406 return;
3407 }
3408
3409 mContextEvictor->CacheIndexStateChanged();
3410}
3411
3412nsresult CacheFileIOManager::TrashDirectory(nsIFile* aFile) {
3413 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)
3414 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)
;
3415
3416 nsresult rv;
3417
3418 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"
, 3418); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 3418; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3419 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"
, 3419); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mCacheDirectory"
")"); do { *((volatile int*)__null) = 3419; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3420
3421 // When the directory is empty, it is cheaper to remove it directly instead of
3422 // using the trash mechanism.
3423 bool isEmpty;
3424 rv = IsEmptyDirectory(aFile, &isEmpty);
3425 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"
, 3425); return rv; } } while (false)
;
3426
3427 if (isEmpty) {
3428 rv = aFile->Remove(false);
3429 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)
3430 ("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)
3431 "[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)
3432 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)
;
3433 return rv;
3434 }
3435
3436#ifdef DEBUG1
3437 nsCOMPtr<nsIFile> dirCheck;
3438 rv = aFile->GetParent(getter_AddRefs(dirCheck));
3439 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"
, 3439); return rv; } } while (false)
;
3440
3441 bool equals = false;
3442 rv = dirCheck->Equals(mCacheDirectory, &equals);
3443 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"
, 3443); return rv; } } while (false)
;
3444
3445 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"
, 3445); AnnotateMozCrashReason("MOZ_ASSERT" "(" "equals" ")"
); do { *((volatile int*)__null) = 3445; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3446#endif
3447
3448 nsCOMPtr<nsIFile> dir, trash;
3449 nsAutoCString leaf;
3450
3451 rv = aFile->Clone(getter_AddRefs(dir));
3452 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"
, 3452); return rv; } } while (false)
;
3453
3454 rv = aFile->Clone(getter_AddRefs(trash));
3455 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"
, 3455); return rv; } } while (false)
;
3456
3457 const int32_t kMaxTries = 16;
3458 srand(static_cast<unsigned>(PR_Now()));
3459 for (int32_t triesCount = 0;; ++triesCount) {
3460 leaf = TRASH_DIR"trash";
3461 leaf.AppendInt(rand());
3462 rv = trash->SetNativeLeafName(leaf);
3463 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"
, 3463); return rv; } } while (false)
;
3464
3465 bool exists;
3466 if (NS_SUCCEEDED(trash->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(trash->Exists(
&exists))), 1)))
&& !exists) {
3467 break;
3468 }
3469
3470 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)
3471 ("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)
3472 "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)
3473 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)
;
3474
3475 if (triesCount == kMaxTries) {
3476 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)
3477 ("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)
3478 "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)
3479 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)
;
3480 return NS_ERROR_FAILURE;
3481 }
3482 }
3483
3484 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)
3485 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)
;
3486
3487 rv = dir->MoveToNative(nullptr, leaf);
3488 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"
, 3488); return rv; } } while (false)
;
3489
3490 StartRemovingTrash();
3491 return NS_OK;
3492}
3493
3494// static
3495void CacheFileIOManager::OnTrashTimer(nsITimer* aTimer, void* aClosure) {
3496 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)
3497 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)
;
3498
3499 RefPtr<CacheFileIOManager> ioMan = gInstance;
3500
3501 if (!ioMan) {
3502 return;
3503 }
3504
3505 ioMan->mTrashTimer = nullptr;
3506 ioMan->StartRemovingTrash();
3507}
3508
3509nsresult CacheFileIOManager::StartRemovingTrash() {
3510 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)
;
3511
3512 nsresult rv;
3513
3514 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"
, 3514); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 3514; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3515
3516 if (mShuttingDown) {
3517 return NS_ERROR_NOT_INITIALIZED;
3518 }
3519
3520 if (!mCacheDirectory) {
3521 return NS_ERROR_FILE_INVALID_PATH;
3522 }
3523
3524 if (mTrashTimer) {
3525 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)
;
3526 return NS_OK;
3527 }
3528
3529 if (mRemovingTrashDirs) {
3530 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)
3531 ("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)
3532 "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)
;
3533 return NS_OK;
3534 }
3535
3536 uint32_t elapsed = (TimeStamp::NowLoRes() - mStartTime).ToMilliseconds();
3537 if (elapsed < kRemoveTrashStartDelay60000) {
3538 nsCOMPtr<nsIEventTarget> ioTarget = IOTarget();
3539 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"
, 3539); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioTarget" ")"
); do { *((volatile int*)__null) = 3539; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3540
3541 return NS_NewTimerWithFuncCallback(
3542 getter_AddRefs(mTrashTimer), CacheFileIOManager::OnTrashTimer, nullptr,
3543 kRemoveTrashStartDelay60000 - elapsed, nsITimer::TYPE_ONE_SHOT,
3544 "net::CacheFileIOManager::StartRemovingTrash", ioTarget);
3545 }
3546
3547 nsCOMPtr<nsIRunnable> ev;
3548 ev = NewRunnableMethod("net::CacheFileIOManager::RemoveTrashInternal", this,
3549 &CacheFileIOManager::RemoveTrashInternal);
3550
3551 rv = mIOThread->Dispatch(ev, CacheIOThread::EVICT);
3552 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"
, 3552); return rv; } } while (false)
;
3553
3554 mRemovingTrashDirs = true;
3555 return NS_OK;
3556}
3557
3558nsresult CacheFileIOManager::RemoveTrashInternal() {
3559 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)
;
3560
3561 nsresult rv;
3562
3563 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"
, 3563); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 3563; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3564
3565 if (mShuttingDown) {
3566 return NS_ERROR_NOT_INITIALIZED;
3567 }
3568
3569 CacheIOThread::Cancelable cancelable(true);
3570
3571 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"
, 3571); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mTrashTimer"
")"); do { *((volatile int*)__null) = 3571; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3572 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"
, 3572); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mRemovingTrashDirs"
")"); do { *((volatile int*)__null) = 3572; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3573
3574 if (!mTreeCreated) {
3575 rv = CreateCacheTree();
3576 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3577 return rv;
3578 }
3579 }
3580
3581 // mRemovingTrashDirs is accessed only on IO thread, so we can drop the flag
3582 // here and set it again once we dispatch a continuation event. By doing so,
3583 // we don't have to drop the flag on any possible early return.
3584 mRemovingTrashDirs = false;
3585
3586 while (true) {
3587 if (CacheIOThread::YieldAndRerun()) {
3588 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)
3589 ("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)
3590 "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)
;
3591 mRemovingTrashDirs = true;
3592 return NS_OK;
3593 }
3594
3595 // Find some trash directory
3596 if (!mTrashDir) {
3597 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"
, 3597); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mTrashDirEnumerator"
")"); do { *((volatile int*)__null) = 3597; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3598
3599 rv = FindTrashDirToRemove();
3600 if (rv == NS_ERROR_NOT_AVAILABLE) {
3601 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)
3602 ("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)
3603 "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)
;
3604 return NS_OK;
3605 }
3606 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"
, 3606); return rv; } } while (false)
;
3607
3608 rv = mTrashDir->GetDirectoryEntries(getter_AddRefs(mTrashDirEnumerator));
3609 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"
, 3609); return rv; } } while (false)
;
3610
3611 continue; // check elapsed time
3612 }
3613
3614 // We null out mTrashDirEnumerator once we remove all files in the
3615 // directory, so remove the trash directory if we don't have enumerator.
3616 if (!mTrashDirEnumerator) {
3617 rv = mTrashDir->Remove(false);
3618 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3619 // There is no reason why removing an empty directory should fail, but
3620 // if it does, we should continue and try to remove all other trash
3621 // directories.
3622 nsAutoCString leafName;
3623 mTrashDir->GetNativeLeafName(leafName);
3624 mFailedTrashDirs.AppendElement(leafName);
3625 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)
3626 ("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)
3627 "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)
3628 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)
;
3629 }
3630
3631 mTrashDir = nullptr;
3632 continue; // check elapsed time
3633 }
3634
3635 nsCOMPtr<nsIFile> file;
3636 rv = mTrashDirEnumerator->GetNextFile(getter_AddRefs(file));
3637 if (!file) {
3638 mTrashDirEnumerator->Close();
3639 mTrashDirEnumerator = nullptr;
3640 continue; // check elapsed time
3641 }
3642 bool isDir = false;
3643 file->IsDirectory(&isDir);
3644 if (isDir) {
3645 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"
, 3647)
3646 "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"
, 3647)
3647 "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"
, 3647)
;
3648 if (LOG_ENABLED()(__builtin_expect(!!(mozilla::detail::log_test(gCache2Log, mozilla
::LogLevel::Debug)), 0))
) {
3649 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)
3650 ("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)
3651 "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)
3652 "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)
3653 "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)
3654 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)
;
3655 }
3656 }
3657 file->Remove(isDir);
3658 }
3659
3660 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"
, 3660); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")"); do
{ *((volatile int*)__null) = 3660; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3661 return NS_OK;
3662}
3663
3664nsresult CacheFileIOManager::FindTrashDirToRemove() {
3665 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)
;
3666
3667 nsresult rv;
3668
3669 if (!mCacheDirectory) {
3670 return NS_ERROR_UNEXPECTED;
3671 }
3672
3673 // We call this method on the main thread during shutdown when user wants to
3674 // remove all cache files.
3675 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"
, 3675); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread() || mShuttingDown"
")"); do { *((volatile int*)__null) = 3675; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3676
3677 nsCOMPtr<nsIDirectoryEnumerator> iter;
3678 rv = mCacheDirectory->GetDirectoryEntries(getter_AddRefs(iter));
3679 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"
, 3679); return rv; } } while (false)
;
3680
3681 nsCOMPtr<nsIFile> file;
3682 while (NS_SUCCEEDED(iter->GetNextFile(getter_AddRefs(file)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(iter->GetNextFile
(getter_AddRefs(file)))), 1)))
&& file) {
3683 bool isDir = false;
3684 file->IsDirectory(&isDir);
3685 if (!isDir) {
3686 continue;
3687 }
3688
3689 nsAutoCString leafName;
3690 rv = file->GetNativeLeafName(leafName);
3691 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3692 continue;
3693 }
3694
3695 if (leafName.Length() < strlen(TRASH_DIR"trash")) {
3696 continue;
3697 }
3698
3699 if (!StringBeginsWith(leafName, nsLiteralCString(TRASH_DIR"trash"))) {
3700 continue;
3701 }
3702
3703 if (mFailedTrashDirs.Contains(leafName)) {
3704 continue;
3705 }
3706
3707 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)
3708 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)
;
3709
3710 mTrashDir = file;
3711 return NS_OK;
3712 }
3713
3714 // When we're here we've tried to delete all trash directories. Clear
3715 // mFailedTrashDirs so we will try to delete them again when we start removing
3716 // trash directories next time.
3717 mFailedTrashDirs.Clear();
3718 return NS_ERROR_NOT_AVAILABLE;
3719}
3720
3721// static
3722nsresult CacheFileIOManager::InitIndexEntry(CacheFileHandle* aHandle,
3723 OriginAttrsHash aOriginAttrsHash,
3724 bool aAnonymous, bool aPinning) {
3725 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)
3726 ("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)
3727 "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)
3728 "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)
3729 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)
;
3730
3731 nsresult rv;
3732 RefPtr<CacheFileIOManager> ioMan = gInstance;
3733
3734 if (aHandle->IsClosed() || !ioMan) {
3735 return NS_ERROR_NOT_INITIALIZED;
3736 }
3737
3738 if (aHandle->IsSpecialFile()) {
3739 return NS_ERROR_UNEXPECTED;
3740 }
3741
3742 RefPtr<InitIndexEntryEvent> ev =
3743 new InitIndexEntryEvent(aHandle, aOriginAttrsHash, aAnonymous, aPinning);
3744 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
3745 ? CacheIOThread::WRITE_PRIORITY
3746 : CacheIOThread::WRITE);
3747 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"
, 3747); return rv; } } while (false)
;
3748
3749 return NS_OK;
3750}
3751
3752// static
3753nsresult CacheFileIOManager::UpdateIndexEntry(CacheFileHandle* aHandle,
3754 const uint32_t* aFrecency,
3755 const bool* aHasAltData,
3756 const uint16_t* aOnStartTime,
3757 const uint16_t* aOnStopTime,
3758 const uint8_t* aContentType) {
3759 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)
3760 ("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)
3761 "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)
3762 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)
3763 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)
3764 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)
3765 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)
3766 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)
;
3767
3768 nsresult rv;
3769 RefPtr<CacheFileIOManager> ioMan = gInstance;
3770
3771 if (aHandle->IsClosed() || !ioMan) {
3772 return NS_ERROR_NOT_INITIALIZED;
3773 }
3774
3775 if (aHandle->IsSpecialFile()) {
3776 return NS_ERROR_UNEXPECTED;
3777 }
3778
3779 RefPtr<UpdateIndexEntryEvent> ev = new UpdateIndexEntryEvent(
3780 aHandle, aFrecency, aHasAltData, aOnStartTime, aOnStopTime, aContentType);
3781 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
3782 ? CacheIOThread::WRITE_PRIORITY
3783 : CacheIOThread::WRITE);
3784 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"
, 3784); return rv; } } while (false)
;
3785
3786 return NS_OK;
3787}
3788
3789nsresult CacheFileIOManager::CreateFile(CacheFileHandle* aHandle) {
3790 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"
, 3790); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aHandle->mFD"
")"); do { *((volatile int*)__null) = 3790; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3791 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"
, 3791); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHandle->mFile"
")"); do { *((volatile int*)__null) = 3791; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3792
3793 nsresult rv;
3794
3795 if (aHandle->IsDoomed()) {
3796 nsCOMPtr<nsIFile> file;
3797
3798 rv = GetDoomedFile(getter_AddRefs(file));
3799 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"
, 3799); return rv; } } while (false)
;
3800
3801 aHandle->mFile.swap(file);
3802 } else {
3803 bool exists;
3804 if (NS_SUCCEEDED(aHandle->mFile->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aHandle->mFile
->Exists(&exists))), 1)))
&& exists) {
3805 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"
, 3805)
;
3806 }
3807 }
3808
3809 rv = OpenNSPRHandle(aHandle, true);
3810 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"
, 3810); return rv; } } while (false)
;
3811
3812 aHandle->mFileSize = 0;
3813 return NS_OK;
3814}
3815
3816// static
3817void CacheFileIOManager::HashToStr(const SHA1Sum::Hash* aHash,
3818 nsACString& _retval) {
3819 _retval.Truncate();
3820 const char hexChars[] = {'0', '1', '2', '3', '4', '5', '6', '7',
3821 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
3822 for (uint32_t i = 0; i < sizeof(SHA1Sum::Hash); i++) {
3823 _retval.Append(hexChars[(*aHash)[i] >> 4]);
3824 _retval.Append(hexChars[(*aHash)[i] & 0xF]);
3825 }
3826}
3827
3828// static
3829nsresult CacheFileIOManager::StrToHash(const nsACString& aHash,
3830 SHA1Sum::Hash* _retval) {
3831 if (aHash.Length() != 2 * sizeof(SHA1Sum::Hash)) {
3832 return NS_ERROR_INVALID_ARG;
3833 }
3834
3835 for (uint32_t i = 0; i < aHash.Length(); i++) {
3836 uint8_t value;
3837
3838 if (aHash[i] >= '0' && aHash[i] <= '9') {
3839 value = aHash[i] - '0';
3840 } else if (aHash[i] >= 'A' && aHash[i] <= 'F') {
3841 value = aHash[i] - 'A' + 10;
3842 } else if (aHash[i] >= 'a' && aHash[i] <= 'f') {
3843 value = aHash[i] - 'a' + 10;
3844 } else {
3845 return NS_ERROR_INVALID_ARG;
3846 }
3847
3848 if (i % 2 == 0) {
3849 (reinterpret_cast<uint8_t*>(_retval))[i / 2] = value << 4;
3850 } else {
3851 (reinterpret_cast<uint8_t*>(_retval))[i / 2] += value;
3852 }
3853 }
3854
3855 return NS_OK;
3856}
3857
3858nsresult CacheFileIOManager::GetFile(const SHA1Sum::Hash* aHash,
3859 nsIFile** _retval) {
3860 nsresult rv;
3861 nsCOMPtr<nsIFile> file;
3862 rv = mCacheDirectory->Clone(getter_AddRefs(file));
3863 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"
, 3863); return rv; } } while (false)
;
3864
3865 rv = file->AppendNative(nsLiteralCString(ENTRIES_DIR"entries"));
3866 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"
, 3866); return rv; } } while (false)
;
3867
3868 nsAutoCString leafName;
3869 HashToStr(aHash, leafName);
3870
3871 rv = file->AppendNative(leafName);
3872 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"
, 3872); return rv; } } while (false)
;
3873
3874 file.swap(*_retval);
3875 return NS_OK;
3876}
3877
3878nsresult CacheFileIOManager::GetSpecialFile(const nsACString& aKey,
3879 nsIFile** _retval) {
3880 nsresult rv;
3881 nsCOMPtr<nsIFile> file;
3882 rv = mCacheDirectory->Clone(getter_AddRefs(file));
3883 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"
, 3883); return rv; } } while (false)
;
3884
3885 rv = file->AppendNative(aKey);
3886 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"
, 3886); return rv; } } while (false)
;
3887
3888 file.swap(*_retval);
3889 return NS_OK;
3890}
3891
3892nsresult CacheFileIOManager::GetDoomedFile(nsIFile** _retval) {
3893 nsresult rv;
3894 nsCOMPtr<nsIFile> file;
3895 rv = mCacheDirectory->Clone(getter_AddRefs(file));
3896 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"
, 3896); return rv; } } while (false)
;
3897
3898 rv = file->AppendNative(nsLiteralCString(DOOMED_DIR"doomed"));
3899 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"
, 3899); return rv; } } while (false)
;
3900
3901 rv = file->AppendNative("dummyleaf"_ns);
3902 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"
, 3902); return rv; } } while (false)
;
3903
3904 const int32_t kMaxTries = 64;
3905 srand(static_cast<unsigned>(PR_Now()));
3906 nsAutoCString leafName;
3907 for (int32_t triesCount = 0;; ++triesCount) {
3908 leafName.AppendInt(rand());
3909 rv = file->SetNativeLeafName(leafName);
3910 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"
, 3910); return rv; } } while (false)
;
3911
3912 bool exists;
3913 if (NS_SUCCEEDED(file->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(file->Exists(&
exists))), 1)))
&& !exists) {
3914 break;
3915 }
3916
3917 if (triesCount == kMaxTries) {
3918 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)
3919 ("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)
3920 "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)
3921 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)
;
3922 return NS_ERROR_FAILURE;
3923 }
3924
3925 leafName.Truncate();
3926 }
3927
3928 file.swap(*_retval);
3929 return NS_OK;
3930}
3931
3932nsresult CacheFileIOManager::IsEmptyDirectory(nsIFile* aFile, bool* _retval) {
3933 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"
, 3933); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 3933; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3934
3935 nsresult rv;
3936
3937 nsCOMPtr<nsIDirectoryEnumerator> enumerator;
3938 rv = aFile->GetDirectoryEntries(getter_AddRefs(enumerator));
3939 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"
, 3939); return rv; } } while (false)
;
3940
3941 bool hasMoreElements = false;
3942 rv = enumerator->HasMoreElements(&hasMoreElements);
3943 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"
, 3943); return rv; } } while (false)
;
3944
3945 *_retval = !hasMoreElements;
3946 return NS_OK;
3947}
3948
3949nsresult CacheFileIOManager::CheckAndCreateDir(nsIFile* aFile, const char* aDir,
3950 bool aEnsureEmptyDir) {
3951 nsresult rv;
3952
3953 nsCOMPtr<nsIFile> file;
3954 if (!aDir) {
3955 file = aFile;
3956 } else {
3957 nsAutoCString dir(aDir);
3958 rv = aFile->Clone(getter_AddRefs(file));
3959 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"
, 3959); return rv; } } while (false)
;
3960 rv = file->AppendNative(dir);
3961 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"
, 3961); return rv; } } while (false)
;
3962 }
3963
3964 bool exists = false;
3965 rv = file->Exists(&exists);
3966 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && exists) {
3967 bool isDirectory = false;
3968 rv = file->IsDirectory(&isDirectory);
3969 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || !isDirectory) {
3970 // Try to remove the file
3971 rv = file->Remove(false);
3972 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
3973 exists = false;
3974 }
3975 }
3976 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"
, 3976); return rv; } } while (false)
;
3977 }
3978
3979 if (aEnsureEmptyDir && NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && exists) {
3980 bool isEmpty;
3981 rv = IsEmptyDirectory(file, &isEmpty);
3982 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"
, 3982); return rv; } } while (false)
;
3983
3984 if (!isEmpty) {
3985 // Don't check the result, if this fails, it's OK. We do this
3986 // only for the doomed directory that doesn't need to be deleted
3987 // for the cost of completely disabling the whole browser.
3988 TrashDirectory(file);
3989 }
3990 }
3991
3992 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && !exists) {
3993 rv = file->Create(nsIFile::DIRECTORY_TYPE, 0700);
3994 }
3995 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3996 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"
, 3996)
;
3997 return NS_ERROR_FAILURE;
3998 }
3999
4000 return NS_OK;
4001}
4002
4003nsresult CacheFileIOManager::CreateCacheTree() {
4004 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"
, 4004); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 4004; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4005 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"
, 4005); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mTreeCreated"
")"); do { *((volatile int*)__null) = 4005; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4006
4007 if (!mCacheDirectory || mTreeCreationFailed) {
4008 return NS_ERROR_FILE_INVALID_PATH;
4009 }
4010
4011 nsresult rv;
4012
4013 // Set the flag here and clear it again below when the tree is created
4014 // successfully.
4015 mTreeCreationFailed = true;
4016
4017 // ensure parent directory exists
4018 nsCOMPtr<nsIFile> parentDir;
4019 rv = mCacheDirectory->GetParent(getter_AddRefs(parentDir));
4020 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"
, 4020); return rv; } } while (false)
;
4021 rv = CheckAndCreateDir(parentDir, nullptr, false);
4022 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"
, 4022); return rv; } } while (false)
;
4023
4024 // ensure cache directory exists
4025 rv = CheckAndCreateDir(mCacheDirectory, nullptr, false);
4026 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"
, 4026); return rv; } } while (false)
;
4027
4028 // ensure entries directory exists
4029 rv = CheckAndCreateDir(mCacheDirectory, ENTRIES_DIR"entries", false);
4030 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"
, 4030); return rv; } } while (false)
;
4031
4032 // ensure doomed directory exists
4033 rv = CheckAndCreateDir(mCacheDirectory, DOOMED_DIR"doomed", true);
4034 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"
, 4034); return rv; } } while (false)
;
4035
4036 mTreeCreated = true;
4037 mTreeCreationFailed = false;
4038
4039 if (!mContextEvictor) {
4040 RefPtr<CacheFileContextEvictor> contextEvictor;
4041 contextEvictor = new CacheFileContextEvictor();
4042
4043 // Init() method will try to load unfinished contexts from the disk. Store
4044 // the evictor as a member only when there is some unfinished job.
4045 contextEvictor->Init(mCacheDirectory);
4046 if (contextEvictor->ContextsCount()) {
4047 contextEvictor.swap(mContextEvictor);
4048 }
4049 }
4050
4051 StartRemovingTrash();
4052
4053 return NS_OK;
4054}
4055
4056nsresult CacheFileIOManager::OpenNSPRHandle(CacheFileHandle* aHandle,
4057 bool aCreate) {
4058 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)
;
4059
4060 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"
, 4060); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 4060; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4061 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"
, 4061); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aHandle->mFD"
")"); do { *((volatile int*)__null) = 4061; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4062 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"
, 4062); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mHandlesByLastUsed.IndexOf(aHandle) == mHandlesByLastUsed.NoIndex"
")"); do { *((volatile int*)__null) = 4062; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4063 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"
, 4063); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mHandlesByLastUsed.Length() <= 128"
")"); do { *((volatile int*)__null) = 4063; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4064 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"
, 4065); AnnotateMozCrashReason("MOZ_ASSERT" "(" "(aCreate && !aHandle->mFileExists) || (!aCreate && aHandle->mFileExists)"
")"); do { *((volatile int*)__null) = 4065; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4065 (!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"
, 4065); AnnotateMozCrashReason("MOZ_ASSERT" "(" "(aCreate && !aHandle->mFileExists) || (!aCreate && aHandle->mFileExists)"
")"); do { *((volatile int*)__null) = 4065; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4066
4067 nsresult rv;
4068
4069 if (mHandlesByLastUsed.Length() == kOpenHandlesLimit128) {
4070 // close handle that hasn't been used for the longest time
4071 rv = MaybeReleaseNSPRHandleInternal(mHandlesByLastUsed[0], true);
4072 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"
, 4072); return rv; } } while (false)
;
4073 }
4074
4075 if (aCreate) {
4076 rv = aHandle->mFile->OpenNSPRFileDesc(
4077 PR_RDWR0x04 | PR_CREATE_FILE0x08 | PR_TRUNCATE0x20, 0600, &aHandle->mFD);
4078 if (rv == NS_ERROR_FILE_ALREADY_EXISTS || // error from nsLocalFileWin
4079 rv == NS_ERROR_FILE_NO_DEVICE_SPACE) { // error from nsLocalFileUnix
4080 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)
4081 ("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)
4082 " 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)
4083 "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)
4084 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)
;
4085
4086 SHA1Sum::Hash hash;
4087 uint32_t cnt;
4088
4089 rv = CacheIndex::GetEntryForEviction(true, &hash, &cnt);
4090 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
4091 rv = DoomFileByKeyInternal(&hash);
4092 }
4093 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
4094 rv = aHandle->mFile->OpenNSPRFileDesc(
4095 PR_RDWR0x04 | PR_CREATE_FILE0x08 | PR_TRUNCATE0x20, 0600, &aHandle->mFD);
4096 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)
4097 ("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)
4098 " 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)
4099 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)
;
4100 } else {
4101 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)
4102 ("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)
4103 " 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)
;
4104 rv = NS_ERROR_FILE_NO_DEVICE_SPACE;
4105 }
4106 }
4107 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4108 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)
4109 ("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)
4110 "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)
4111 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)
;
4112 }
4113 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"
, 4113); return rv; } } while (false)
;
4114
4115 aHandle->mFileExists = true;
4116 } else {
4117 rv = aHandle->mFile->OpenNSPRFileDesc(PR_RDWR0x04, 0600, &aHandle->mFD);
4118 if (NS_ERROR_FILE_NOT_FOUND == rv) {
4119 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)
;
4120 aHandle->mFileExists = false;
4121 return DoomFileInternal(aHandle);
4122 }
4123 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4124 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)
4125 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)
;
4126 }
4127 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"
, 4127); return rv; } } while (false)
;
4128 }
4129
4130 mHandlesByLastUsed.AppendElement(aHandle);
4131
4132 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)
;
4133
4134 return NS_OK;
4135}
4136
4137void CacheFileIOManager::NSPRHandleUsed(CacheFileHandle* aHandle) {
4138 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"
, 4138); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { *((volatile int*)__null) = 4138; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4139 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"
, 4139); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHandle->mFD"
")"); do { *((volatile int*)__null) = 4139; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4140
4141 DebugOnly<bool> found{};
4142 found = mHandlesByLastUsed.RemoveElement(aHandle);
4143 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"
, 4143); AnnotateMozCrashReason("MOZ_ASSERT" "(" "found" ")")
; do { *((volatile int*)__null) = 4143; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4144
4145 mHandlesByLastUsed.AppendElement(aHandle);
4146}
4147
4148nsresult CacheFileIOManager::SyncRemoveDir(nsIFile* aFile, const char* aDir) {
4149 nsresult rv;
4150 nsCOMPtr<nsIFile> file;
4151
4152 if (!aFile) {
4153 return NS_ERROR_INVALID_ARG;
4154 }
4155
4156 if (!aDir) {
4157 file = aFile;
4158 } else {
4159 rv = aFile->Clone(getter_AddRefs(file));
4160 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"
, 4160)
) {
4161 return rv;
4162 }
4163
4164 rv = file->AppendNative(nsDependentCString(aDir));
4165 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"
, 4165)
) {
4166 return rv;
4167 }
4168 }
4169
4170 if (LOG_ENABLED()(__builtin_expect(!!(mozilla::detail::log_test(gCache2Log, mozilla
::LogLevel::Debug)), 0))
) {
4171 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)
4172 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)
;
4173 }
4174
4175 rv = file->Remove(true);
4176 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"
, 4176)
) {
4177 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)
4178 ("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)
4179 "[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)
4180 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)
;
4181 }
4182
4183 return rv;
4184}
4185
4186nsresult CacheFileIOManager::DispatchPurgeTask(
4187 const nsCString& aCacheDirName, const nsCString& aSecondsToWait,
4188 const nsCString& aPurgeExtension) {
4189#if !defined(MOZ_BACKGROUNDTASKS1)
4190 // If background tasks are disabled, then we should just bail out early.
4191 return NS_ERROR_NOT_IMPLEMENTED;
4192#else
4193 nsCOMPtr<nsIFile> cacheDir;
4194 nsresult rv = mCacheDirectory->Clone(getter_AddRefs(cacheDir));
4195 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"
, 4195); return rv; } } while (false)
;
4196
4197 nsCOMPtr<nsIFile> profileDir;
4198 rv = cacheDir->GetParent(getter_AddRefs(profileDir));
4199 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"
, 4199); return rv; } } while (false)
;
4200
4201 nsCOMPtr<nsIFile> lf;
4202 rv = XRE_GetBinaryPath(getter_AddRefs(lf));
4203 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"
, 4203); return rv; } } while (false)
;
4204
4205 nsAutoCString path;
4206# if !defined(XP_WIN)
4207 rv = profileDir->GetNativePath(path);
4208# else
4209 rv = profileDir->GetNativeTarget(path);
4210# endif
4211 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"
, 4211); return rv; } } while (false)
;
4212
4213 nsCOMPtr<nsIBackgroundTasksRunner> runner =
4214 do_GetService("@mozilla.org/backgroundtasksrunner;1");
4215
4216 return runner->RemoveDirectoryInDetachedProcess(
4217 path, aCacheDirName, aSecondsToWait, aPurgeExtension, "HttpCache"_ns);
4218#endif
4219}
4220
4221void CacheFileIOManager::SyncRemoveAllCacheFiles() {
4222 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)
;
4223 nsresult rv;
4224
4225 // If we are already running in a background task, we
4226 // don't want to spawn yet another one at shutdown.
4227 if (inBackgroundTask()) {
4228 return;
4229 }
4230
4231 if (StaticPrefs::network_cache_shutdown_purge_in_background_task()) {
4232 rv = [&]() -> nsresult {
4233 nsresult rv;
4234
4235 // If there is no cache directory, there's nothing to remove.
4236 if (!mCacheDirectory) {
4237 return NS_OK;
4238 }
4239
4240 nsAutoCString leafName;
4241 rv = mCacheDirectory->GetNativeLeafName(leafName);
4242 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"
, 4242); return rv; } } while (false)
;
4243
4244 leafName.Append('.');
4245
4246 PRExplodedTime now;
4247 PR_ExplodeTime(PR_Now(), PR_GMTParameters, &now);
4248 leafName.Append(nsPrintfCString(
4249 "%04d-%02d-%02d-%02d-%02d-%02d", now.tm_year, now.tm_month + 1,
4250 now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec));
4251 leafName.Append(kPurgeExtension);
4252
4253 nsAutoCString secondsToWait;
4254 secondsToWait.AppendInt(
4255 StaticPrefs::network_cache_shutdown_purge_folder_wait_seconds());
4256
4257 rv = DispatchPurgeTask(leafName, secondsToWait, kPurgeExtension);
4258 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"
, 4258); return rv; } } while (false)
;
4259
4260 rv = mCacheDirectory->RenameToNative(nullptr, leafName);
4261 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"
, 4261); return rv; } } while (false)
;
4262
4263 return NS_OK;
4264 }();
4265
4266 // Dispatching to the background task has succeeded. This is finished.
4267 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
4268 return;
4269 }
4270 }
4271
4272 SyncRemoveDir(mCacheDirectory, ENTRIES_DIR"entries");
4273 SyncRemoveDir(mCacheDirectory, DOOMED_DIR"doomed");
4274
4275 // Clear any intermediate state of trash dir enumeration.
4276 mFailedTrashDirs.Clear();
4277 mTrashDir = nullptr;
4278
4279 while (true) {
4280 // FindTrashDirToRemove() fills mTrashDir if there is any trash directory.
4281 rv = FindTrashDirToRemove();
4282 if (rv == NS_ERROR_NOT_AVAILABLE) {
4283 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)
4284 ("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)
4285 "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)
;
4286 break;
4287 }
4288 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"
, 4288)
) {
4289 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)
4290 ("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)
4291 "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)
4292 "[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)
4293 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)
;
4294 break;
4295 }
4296
4297 rv = SyncRemoveDir(mTrashDir, nullptr);
4298 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4299 nsAutoCString leafName;
4300 mTrashDir->GetNativeLeafName(leafName);
4301 mFailedTrashDirs.AppendElement(leafName);
4302 }
4303 }
4304}
4305
4306// Returns default ("smart") size (in KB) of cache, given available disk space
4307// (also in KB)
4308static uint32_t SmartCacheSize(const int64_t availKB) {
4309 uint32_t maxSize;
4310
4311 if (CacheObserver::ClearCacheOnShutdown()) {
4312 maxSize = kMaxClearOnShutdownCacheSizeKB;
4313 } else {
4314 maxSize = kMaxCacheSizeKB;
4315 }
4316
4317 if (availKB > 25 * 1024 * 1024) {
4318 return maxSize; // skip computing if we're over 25 GB
4319 }
4320
4321 // Grow/shrink in 10 MB units, deliberately, so that in the common case we
4322 // don't shrink cache and evict items every time we startup (it's important
4323 // that we don't slow down startup benchmarks).
4324 uint32_t sz10MBs = 0;
4325 uint32_t avail10MBs = availKB / (1024 * 10);
4326
4327 // 2.5% of space above 7GB
4328 if (avail10MBs > 700) {
4329 sz10MBs += static_cast<uint32_t>((avail10MBs - 700) * .025);
4330 avail10MBs = 700;
4331 }
4332 // 7.5% of space between 500 MB -> 7 GB
4333 if (avail10MBs > 50) {
4334 sz10MBs += static_cast<uint32_t>((avail10MBs - 50) * .075);
4335 avail10MBs = 50;
4336 }
4337
4338#ifdef ANDROID
4339 // On Android, smaller/older devices may have very little storage and
4340 // device owners may be sensitive to storage footprint: Use a smaller
4341 // percentage of available space and a smaller minimum.
4342
4343 // 16% of space up to 500 MB (10 MB min)
4344 sz10MBs += std::max<uint32_t>(1, static_cast<uint32_t>(avail10MBs * .16));
4345#else
4346 // 30% of space up to 500 MB (50 MB min)
4347 sz10MBs += std::max<uint32_t>(5, static_cast<uint32_t>(avail10MBs * .3));
4348#endif
4349
4350 return std::min<uint32_t>(maxSize, sz10MBs * 10 * 1024);
4351}
4352
4353nsresult CacheFileIOManager::UpdateSmartCacheSize(int64_t aFreeSpace) {
4354 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"
, 4354); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { *((volatile int*)__null) = 4354; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4355
4356 nsresult rv;
4357
4358 if (!CacheObserver::SmartCacheSizeEnabled()) {
4359 return NS_ERROR_NOT_AVAILABLE;
4360 }
4361
4362 // Wait at least kSmartSizeUpdateInterval before recomputing smart size.
4363 static const TimeDuration kUpdateLimit =
4364 TimeDuration::FromMilliseconds(kSmartSizeUpdateInterval60000);
4365 if (!mLastSmartSizeTime.IsNull() &&
4366 (TimeStamp::NowLoRes() - mLastSmartSizeTime) < kUpdateLimit) {
4367 return NS_OK;
4368 }
4369
4370 // Do not compute smart size when cache size is not reliable.
4371 bool isUpToDate = false;
4372 CacheIndex::IsUpToDate(&isUpToDate);
4373 if (!isUpToDate) {
4374 return NS_ERROR_NOT_AVAILABLE;
4375 }
4376
4377 uint32_t cacheUsage;
4378 rv = CacheIndex::GetCacheSize(&cacheUsage);
4379 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"
, 4379)
) {
4380 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)
4381 ("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)
4382 "[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)
4383 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)
;
4384 return rv;
4385 }
4386
4387 mLastSmartSizeTime = TimeStamp::NowLoRes();
4388
4389 uint32_t smartSize = SmartCacheSize(aFreeSpace + cacheUsage);
4390
4391 if (smartSize == CacheObserver::DiskCacheCapacity()) {
4392 // Smart size has not changed.
4393 return NS_OK;
4394 }
4395
4396 CacheObserver::SetSmartDiskCacheCapacity(smartSize);
4397
4398 return NS_OK;
4399}
4400
4401// Memory reporting
4402
4403namespace {
4404
4405// A helper class that dispatches and waits for an event that gets result of
4406// CacheFileIOManager->mHandles.SizeOfExcludingThis() on the I/O thread
4407// to safely get handles memory report.
4408// We must do this, since the handle list is only accessed and managed w/o
4409// locking on the I/O thread. That is by design.
4410class SizeOfHandlesRunnable : public Runnable {
4411 public:
4412 SizeOfHandlesRunnable(mozilla::MallocSizeOf mallocSizeOf,
4413 CacheFileHandles const& handles,
4414 nsTArray<CacheFileHandle*> const& specialHandles)
4415 : Runnable("net::SizeOfHandlesRunnable"),
4416 mMonitor("SizeOfHandlesRunnable.mMonitor"),
4417