File: | var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp |
Warning: | line 1547, column 5 Value stored to 'srv' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
2 | * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : |
3 | * This Source Code Form is subject to the terms of the Mozilla Public |
4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | |
7 | #include "BaseVFS.h" |
8 | #include "ErrorList.h" |
9 | #include "nsError.h" |
10 | #include "nsThreadUtils.h" |
11 | #include "nsIFile.h" |
12 | #include "nsIFileURL.h" |
13 | #include "nsIXPConnect.h" |
14 | #include "mozilla/AppShutdown.h" |
15 | #include "mozilla/CheckedInt.h" |
16 | #include "mozilla/Telemetry.h" |
17 | #include "mozilla/Mutex.h" |
18 | #include "mozilla/CondVar.h" |
19 | #include "mozilla/Attributes.h" |
20 | #include "mozilla/ErrorNames.h" |
21 | #include "mozilla/Unused.h" |
22 | #include "mozilla/dom/quota/QuotaObject.h" |
23 | #include "mozilla/ScopeExit.h" |
24 | #include "mozilla/SpinEventLoopUntil.h" |
25 | #include "mozilla/StaticPrefs_storage.h" |
26 | |
27 | #include "mozIStorageCompletionCallback.h" |
28 | #include "mozIStorageFunction.h" |
29 | |
30 | #include "mozStorageAsyncStatementExecution.h" |
31 | #include "mozStorageSQLFunctions.h" |
32 | #include "mozStorageConnection.h" |
33 | #include "mozStorageService.h" |
34 | #include "mozStorageStatement.h" |
35 | #include "mozStorageAsyncStatement.h" |
36 | #include "mozStorageArgValueArray.h" |
37 | #include "mozStoragePrivateHelpers.h" |
38 | #include "mozStorageStatementData.h" |
39 | #include "ObfuscatingVFS.h" |
40 | #include "QuotaVFS.h" |
41 | #include "StorageBaseStatementInternal.h" |
42 | #include "SQLCollations.h" |
43 | #include "FileSystemModule.h" |
44 | #include "mozStorageHelper.h" |
45 | |
46 | #include "mozilla/Assertions.h" |
47 | #include "mozilla/Logging.h" |
48 | #include "mozilla/Printf.h" |
49 | #include "mozilla/ProfilerLabels.h" |
50 | #include "mozilla/RefPtr.h" |
51 | #include "nsComponentManagerUtils.h" |
52 | #include "nsProxyRelease.h" |
53 | #include "nsStringFwd.h" |
54 | #include "nsURLHelper.h" |
55 | |
56 | #define MIN_AVAILABLE_BYTES_PER_CHUNKED_GROWTH524288000 524288000 // 500 MiB |
57 | |
58 | // Maximum size of the pages cache per connection. |
59 | #define MAX_CACHE_SIZE_KIBIBYTES2048 2048 // 2 MiB |
60 | |
61 | mozilla::LazyLogModule gStorageLog("mozStorage"); |
62 | |
63 | // Checks that the protected code is running on the main-thread only if the |
64 | // connection was also opened on it. |
65 | #ifdef DEBUG1 |
66 | # define CHECK_MAINTHREAD_ABUSE()do { do { if (!(eventTargetOpenedOn == GetMainThreadSerialEventTarget () || !NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_WARNING, "Using Storage synchronous API on main-thread, but " "the connection was opened on another thread.", "eventTargetOpenedOn == GetMainThreadSerialEventTarget() || !NS_IsMainThread()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 66); } } while (false); } while (0) \ |
67 | do { \ |
68 | NS_WARNING_ASSERTION( \do { if (!(eventTargetOpenedOn == GetMainThreadSerialEventTarget () || !NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_WARNING, "Using Storage synchronous API on main-thread, but " "the connection was opened on another thread.", "eventTargetOpenedOn == GetMainThreadSerialEventTarget() || !NS_IsMainThread()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 72); } } while (false) |
69 | eventTargetOpenedOn == GetMainThreadSerialEventTarget() || \do { if (!(eventTargetOpenedOn == GetMainThreadSerialEventTarget () || !NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_WARNING, "Using Storage synchronous API on main-thread, but " "the connection was opened on another thread.", "eventTargetOpenedOn == GetMainThreadSerialEventTarget() || !NS_IsMainThread()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 72); } } while (false) |
70 | !NS_IsMainThread(), \do { if (!(eventTargetOpenedOn == GetMainThreadSerialEventTarget () || !NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_WARNING, "Using Storage synchronous API on main-thread, but " "the connection was opened on another thread.", "eventTargetOpenedOn == GetMainThreadSerialEventTarget() || !NS_IsMainThread()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 72); } } while (false) |
71 | "Using Storage synchronous API on main-thread, but " \do { if (!(eventTargetOpenedOn == GetMainThreadSerialEventTarget () || !NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_WARNING, "Using Storage synchronous API on main-thread, but " "the connection was opened on another thread.", "eventTargetOpenedOn == GetMainThreadSerialEventTarget() || !NS_IsMainThread()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 72); } } while (false) |
72 | "the connection was opened on another thread.")do { if (!(eventTargetOpenedOn == GetMainThreadSerialEventTarget () || !NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_WARNING, "Using Storage synchronous API on main-thread, but " "the connection was opened on another thread.", "eventTargetOpenedOn == GetMainThreadSerialEventTarget() || !NS_IsMainThread()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 72); } } while (false); \ |
73 | } while (0) |
74 | #else |
75 | # define CHECK_MAINTHREAD_ABUSE()do { do { if (!(eventTargetOpenedOn == GetMainThreadSerialEventTarget () || !NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_WARNING, "Using Storage synchronous API on main-thread, but " "the connection was opened on another thread.", "eventTargetOpenedOn == GetMainThreadSerialEventTarget() || !NS_IsMainThread()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 75); } } while (false); } while (0) \ |
76 | do { /* Nothing */ \ |
77 | } while (0) |
78 | #endif |
79 | |
80 | namespace mozilla::storage { |
81 | |
82 | using mozilla::dom::quota::QuotaObject; |
83 | using mozilla::Telemetry::AccumulateCategoricalKeyed; |
84 | using mozilla::Telemetry::LABELS_SQLITE_STORE_OPEN; |
85 | using mozilla::Telemetry::LABELS_SQLITE_STORE_QUERY; |
86 | |
87 | namespace { |
88 | |
89 | int nsresultToSQLiteResult(nsresult aXPCOMResultCode) { |
90 | if (NS_SUCCEEDED(aXPCOMResultCode)((bool)(__builtin_expect(!!(!NS_FAILED_impl(aXPCOMResultCode) ), 1)))) { |
91 | return SQLITE_OK0; |
92 | } |
93 | |
94 | switch (aXPCOMResultCode) { |
95 | case NS_ERROR_FILE_CORRUPTED: |
96 | return SQLITE_CORRUPT11; |
97 | case NS_ERROR_FILE_ACCESS_DENIED: |
98 | return SQLITE_CANTOPEN14; |
99 | case NS_ERROR_STORAGE_BUSY: |
100 | return SQLITE_BUSY5; |
101 | case NS_ERROR_FILE_IS_LOCKED: |
102 | return SQLITE_LOCKED6; |
103 | case NS_ERROR_FILE_READ_ONLY: |
104 | return SQLITE_READONLY8; |
105 | case NS_ERROR_STORAGE_IOERR: |
106 | return SQLITE_IOERR10; |
107 | case NS_ERROR_FILE_NO_DEVICE_SPACE: |
108 | return SQLITE_FULL13; |
109 | case NS_ERROR_OUT_OF_MEMORY: |
110 | return SQLITE_NOMEM7; |
111 | case NS_ERROR_UNEXPECTED: |
112 | return SQLITE_MISUSE21; |
113 | case NS_ERROR_ABORT: |
114 | return SQLITE_ABORT4; |
115 | case NS_ERROR_STORAGE_CONSTRAINT: |
116 | return SQLITE_CONSTRAINT19; |
117 | default: |
118 | return SQLITE_ERROR1; |
119 | } |
120 | |
121 | MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Must return in switch above!")do { 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: " "Must return in switch above!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 121); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "Must return in switch above!" ")" ); do { *((volatile int*)__null) = 121; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); __builtin_unreachable (); } while (false); |
122 | } |
123 | |
124 | //////////////////////////////////////////////////////////////////////////////// |
125 | //// Variant Specialization Functions (variantToSQLiteT) |
126 | |
127 | int sqlite3_T_int(sqlite3_context* aCtx, int aValue) { |
128 | ::sqlite3_result_int(aCtx, aValue); |
129 | return SQLITE_OK0; |
130 | } |
131 | |
132 | int sqlite3_T_int64(sqlite3_context* aCtx, sqlite3_int64 aValue) { |
133 | ::sqlite3_result_int64(aCtx, aValue); |
134 | return SQLITE_OK0; |
135 | } |
136 | |
137 | int sqlite3_T_double(sqlite3_context* aCtx, double aValue) { |
138 | ::sqlite3_result_double(aCtx, aValue); |
139 | return SQLITE_OK0; |
140 | } |
141 | |
142 | int sqlite3_T_text(sqlite3_context* aCtx, const nsCString& aValue) { |
143 | CheckedInt<int32_t> length(aValue.Length()); |
144 | if (!length.isValid()) { |
145 | return SQLITE_MISUSE21; |
146 | } |
147 | ::sqlite3_result_text(aCtx, aValue.get(), length.value(), SQLITE_TRANSIENT((sqlite3_destructor_type)-1)); |
148 | return SQLITE_OK0; |
149 | } |
150 | |
151 | int sqlite3_T_text16(sqlite3_context* aCtx, const nsString& aValue) { |
152 | CheckedInt<int32_t> n_bytes = |
153 | CheckedInt<int32_t>(aValue.Length()) * sizeof(char16_t); |
154 | if (!n_bytes.isValid()) { |
155 | return SQLITE_MISUSE21; |
156 | } |
157 | ::sqlite3_result_text16(aCtx, aValue.get(), n_bytes.value(), |
158 | SQLITE_TRANSIENT((sqlite3_destructor_type)-1)); |
159 | return SQLITE_OK0; |
160 | } |
161 | |
162 | int sqlite3_T_null(sqlite3_context* aCtx) { |
163 | ::sqlite3_result_null(aCtx); |
164 | return SQLITE_OK0; |
165 | } |
166 | |
167 | int sqlite3_T_blob(sqlite3_context* aCtx, const void* aData, int aSize) { |
168 | ::sqlite3_result_blob(aCtx, aData, aSize, free); |
169 | return SQLITE_OK0; |
170 | } |
171 | |
172 | #include "variantToSQLiteT_impl.h" |
173 | |
174 | //////////////////////////////////////////////////////////////////////////////// |
175 | //// Modules |
176 | |
177 | struct Module { |
178 | const char* name; |
179 | int (*registerFunc)(sqlite3*, const char*); |
180 | }; |
181 | |
182 | Module gModules[] = {{"filesystem", RegisterFileSystemModule}}; |
183 | |
184 | //////////////////////////////////////////////////////////////////////////////// |
185 | //// Local Functions |
186 | |
187 | int tracefunc(unsigned aReason, void* aClosure, void* aP, void* aX) { |
188 | switch (aReason) { |
189 | case SQLITE_TRACE_STMT0x01: { |
190 | // aP is a pointer to the prepared statement. |
191 | sqlite3_stmt* stmt = static_cast<sqlite3_stmt*>(aP); |
192 | // aX is a pointer to a string containing the unexpanded SQL or a comment, |
193 | // starting with "--"" in case of a trigger. |
194 | char* expanded = static_cast<char*>(aX); |
195 | // Simulate what sqlite_trace was doing. |
196 | if (!::strncmp(expanded, "--", 2)) { |
197 | MOZ_LOG(gStorageLog, LogLevel::Debug,do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "TRACE_STMT on %p: '%s'", aClosure, expanded ); } } while (0) |
198 | ("TRACE_STMT on %p: '%s'", aClosure, expanded))do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "TRACE_STMT on %p: '%s'", aClosure, expanded ); } } while (0); |
199 | } else { |
200 | char* sql = ::sqlite3_expanded_sql(stmt); |
201 | MOZ_LOG(gStorageLog, LogLevel::Debug,do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "TRACE_STMT on %p: '%s'", aClosure, sql); } } while (0) |
202 | ("TRACE_STMT on %p: '%s'", aClosure, sql))do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "TRACE_STMT on %p: '%s'", aClosure, sql); } } while (0); |
203 | ::sqlite3_free(sql); |
204 | } |
205 | break; |
206 | } |
207 | case SQLITE_TRACE_PROFILE0x02: { |
208 | // aX is pointer to a 64bit integer containing nanoseconds it took to |
209 | // execute the last command. |
210 | sqlite_int64 time = *(static_cast<sqlite_int64*>(aX)) / 1000000; |
211 | if (time > 0) { |
212 | MOZ_LOG(gStorageLog, LogLevel::Debug,do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "TRACE_TIME on %p: %lldms", aClosure, time ); } } while (0) |
213 | ("TRACE_TIME on %p: %lldms", aClosure, time))do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "TRACE_TIME on %p: %lldms", aClosure, time ); } } while (0); |
214 | } |
215 | break; |
216 | } |
217 | } |
218 | return 0; |
219 | } |
220 | |
221 | void basicFunctionHelper(sqlite3_context* aCtx, int aArgc, |
222 | sqlite3_value** aArgv) { |
223 | void* userData = ::sqlite3_user_data(aCtx); |
224 | |
225 | mozIStorageFunction* func = static_cast<mozIStorageFunction*>(userData); |
226 | |
227 | RefPtr<ArgValueArray> arguments(new ArgValueArray(aArgc, aArgv)); |
228 | if (!arguments) return; |
229 | |
230 | nsCOMPtr<nsIVariant> result; |
231 | nsresult rv = func->OnFunctionCall(arguments, getter_AddRefs(result)); |
232 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
233 | nsAutoCString errorMessage; |
234 | GetErrorName(rv, errorMessage); |
235 | errorMessage.InsertLiteral("User function returned ", 0); |
236 | errorMessage.Append('!'); |
237 | |
238 | NS_WARNING(errorMessage.get())NS_DebugBreak(NS_DEBUG_WARNING, errorMessage.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 238); |
239 | |
240 | ::sqlite3_result_error(aCtx, errorMessage.get(), -1); |
241 | ::sqlite3_result_error_code(aCtx, nsresultToSQLiteResult(rv)); |
242 | return; |
243 | } |
244 | int retcode = variantToSQLiteT(aCtx, result); |
245 | if (retcode != SQLITE_OK0) { |
246 | NS_WARNING("User function returned invalid data type!")NS_DebugBreak(NS_DEBUG_WARNING, "User function returned invalid data type!" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 246); |
247 | ::sqlite3_result_error(aCtx, "User function returned invalid data type", |
248 | -1); |
249 | } |
250 | } |
251 | |
252 | RefPtr<QuotaObject> GetQuotaObject(sqlite3_file* aFile, bool obfuscatingVFS) { |
253 | return obfuscatingVFS |
254 | ? mozilla::storage::obfsvfs::GetQuotaObjectForFile(aFile) |
255 | : mozilla::storage::quotavfs::GetQuotaObjectForFile(aFile); |
256 | } |
257 | |
258 | /** |
259 | * This code is heavily based on the sample at: |
260 | * http://www.sqlite.org/unlock_notify.html |
261 | */ |
262 | class UnlockNotification { |
263 | public: |
264 | UnlockNotification() |
265 | : mMutex("UnlockNotification mMutex"), |
266 | mCondVar(mMutex, "UnlockNotification condVar"), |
267 | mSignaled(false) {} |
268 | |
269 | void Wait() { |
270 | MutexAutoLock lock(mMutex); |
271 | while (!mSignaled) { |
272 | (void)mCondVar.Wait(); |
273 | } |
274 | } |
275 | |
276 | void Signal() { |
277 | MutexAutoLock lock(mMutex); |
278 | mSignaled = true; |
279 | (void)mCondVar.Notify(); |
280 | } |
281 | |
282 | private: |
283 | Mutex mMutex MOZ_UNANNOTATED; |
284 | CondVar mCondVar; |
285 | bool mSignaled; |
286 | }; |
287 | |
288 | void UnlockNotifyCallback(void** aArgs, int aArgsSize) { |
289 | for (int i = 0; i < aArgsSize; i++) { |
290 | UnlockNotification* notification = |
291 | static_cast<UnlockNotification*>(aArgs[i]); |
292 | notification->Signal(); |
293 | } |
294 | } |
295 | |
296 | int WaitForUnlockNotify(sqlite3* aDatabase) { |
297 | UnlockNotification notification; |
298 | int srv = |
299 | ::sqlite3_unlock_notify(aDatabase, UnlockNotifyCallback, ¬ification); |
300 | MOZ_ASSERT(srv == SQLITE_LOCKED || srv == SQLITE_OK)do { static_assert( mozilla::detail::AssertionConditionType< decltype(srv == 6 || srv == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(srv == 6 || srv == 0))), 0)) ) { do { } while (false); MOZ_ReportAssertionFailure("srv == 6 || srv == 0" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 300); AnnotateMozCrashReason("MOZ_ASSERT" "(" "srv == 6 || srv == 0" ")"); do { *((volatile int*)__null) = 300; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
301 | if (srv == SQLITE_OK0) { |
302 | notification.Wait(); |
303 | } |
304 | |
305 | return srv; |
306 | } |
307 | |
308 | //////////////////////////////////////////////////////////////////////////////// |
309 | //// Local Classes |
310 | |
311 | class AsyncCloseConnection final : public Runnable { |
312 | public: |
313 | AsyncCloseConnection(Connection* aConnection, sqlite3* aNativeConnection, |
314 | nsIRunnable* aCallbackEvent) |
315 | : Runnable("storage::AsyncCloseConnection"), |
316 | mConnection(aConnection), |
317 | mNativeConnection(aNativeConnection), |
318 | mCallbackEvent(aCallbackEvent) {} |
319 | |
320 | NS_IMETHODvirtual nsresult Run() override { |
321 | // Make sure we don't dispatch to the current thread. |
322 | MOZ_ASSERT(!IsOnCurrentSerialEventTarget(mConnection->eventTargetOpenedOn))do { static_assert( mozilla::detail::AssertionConditionType< decltype(!IsOnCurrentSerialEventTarget(mConnection->eventTargetOpenedOn ))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!IsOnCurrentSerialEventTarget(mConnection->eventTargetOpenedOn )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!IsOnCurrentSerialEventTarget(mConnection->eventTargetOpenedOn)" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 322); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsOnCurrentSerialEventTarget(mConnection->eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 322; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
323 | |
324 | nsCOMPtr<nsIRunnable> event = |
325 | NewRunnableMethod("storage::Connection::shutdownAsyncThread", |
326 | mConnection, &Connection::shutdownAsyncThread); |
327 | MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(event))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (NS_DispatchToMainThread(event))), 1)))), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType<decltype (false)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("false" " (" "NS_SUCCEEDED(NS_DispatchToMainThread(event))" ")" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 327); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(NS_DispatchToMainThread(event))" ")"); do { *((volatile int*)__null) = 327; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); } } while (false ); |
328 | |
329 | // Internal close. |
330 | (void)mConnection->internalClose(mNativeConnection); |
331 | |
332 | // Callback |
333 | if (mCallbackEvent) { |
334 | nsCOMPtr<nsIThread> thread; |
335 | (void)NS_GetMainThread(getter_AddRefs(thread)); |
336 | (void)thread->Dispatch(mCallbackEvent, NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL); |
337 | } |
338 | |
339 | return NS_OK; |
340 | } |
341 | |
342 | ~AsyncCloseConnection() override { |
343 | NS_ReleaseOnMainThread("AsyncCloseConnection::mConnection", |
344 | mConnection.forget()); |
345 | NS_ReleaseOnMainThread("AsyncCloseConnection::mCallbackEvent", |
346 | mCallbackEvent.forget()); |
347 | } |
348 | |
349 | private: |
350 | RefPtr<Connection> mConnection; |
351 | sqlite3* mNativeConnection; |
352 | nsCOMPtr<nsIRunnable> mCallbackEvent; |
353 | }; |
354 | |
355 | /** |
356 | * An event used to initialize the clone of a connection. |
357 | * |
358 | * Must be executed on the clone's async execution thread. |
359 | */ |
360 | class AsyncInitializeClone final : public Runnable { |
361 | public: |
362 | /** |
363 | * @param aConnection The connection being cloned. |
364 | * @param aClone The clone. |
365 | * @param aReadOnly If |true|, the clone is read only. |
366 | * @param aCallback A callback to trigger once initialization |
367 | * is complete. This event will be called on |
368 | * aClone->eventTargetOpenedOn. |
369 | */ |
370 | AsyncInitializeClone(Connection* aConnection, Connection* aClone, |
371 | const bool aReadOnly, |
372 | mozIStorageCompletionCallback* aCallback) |
373 | : Runnable("storage::AsyncInitializeClone"), |
374 | mConnection(aConnection), |
375 | mClone(aClone), |
376 | mReadOnly(aReadOnly), |
377 | mCallback(aCallback) { |
378 | 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/storage/mozStorageConnection.cpp" , 378); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 378; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
379 | } |
380 | |
381 | NS_IMETHODvirtual nsresult Run() override { |
382 | 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/storage/mozStorageConnection.cpp" , 382); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 382; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
383 | nsresult rv = mConnection->initializeClone(mClone, mReadOnly); |
384 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
385 | return Dispatch(rv, nullptr); |
386 | } |
387 | return Dispatch(NS_OK, |
388 | NS_ISUPPORTS_CAST(mozIStorageAsyncConnection*, mClone)static_cast<nsISupports*>(static_cast<mozIStorageAsyncConnection *>(mClone))); |
389 | } |
390 | |
391 | private: |
392 | nsresult Dispatch(nsresult aResult, nsISupports* aValue) { |
393 | RefPtr<CallbackComplete> event = |
394 | new CallbackComplete(aResult, aValue, mCallback.forget()); |
395 | return mClone->eventTargetOpenedOn->Dispatch(event, NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL); |
396 | } |
397 | |
398 | ~AsyncInitializeClone() override { |
399 | nsCOMPtr<nsIThread> thread; |
400 | DebugOnly<nsresult> rv = NS_GetMainThread(getter_AddRefs(thread)); |
401 | 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/storage/mozStorageConnection.cpp" , 401); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 401; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
402 | |
403 | // Handle ambiguous nsISupports inheritance. |
404 | NS_ProxyRelease("AsyncInitializeClone::mConnection", thread, |
405 | mConnection.forget()); |
406 | NS_ProxyRelease("AsyncInitializeClone::mClone", thread, mClone.forget()); |
407 | |
408 | // Generally, the callback will be released by CallbackComplete. |
409 | // However, if for some reason Run() is not executed, we still |
410 | // need to ensure that it is released here. |
411 | NS_ProxyRelease("AsyncInitializeClone::mCallback", thread, |
412 | mCallback.forget()); |
413 | } |
414 | |
415 | RefPtr<Connection> mConnection; |
416 | RefPtr<Connection> mClone; |
417 | const bool mReadOnly; |
418 | nsCOMPtr<mozIStorageCompletionCallback> mCallback; |
419 | }; |
420 | |
421 | /** |
422 | * A listener for async connection closing. |
423 | */ |
424 | class CloseListener final : public mozIStorageCompletionCallback { |
425 | public: |
426 | NS_DECL_ISUPPORTSpublic: virtual nsresult QueryInterface(const nsIID& aIID , void** aInstancePtr) override; virtual MozExternalRefCountType AddRef(void) override; virtual MozExternalRefCountType Release (void) override; using HasThreadSafeRefCnt = std::false_type; protected: nsAutoRefCnt mRefCnt; nsAutoOwningThread _mOwningThread ; public: |
427 | CloseListener() : mClosed(false) {} |
428 | |
429 | NS_IMETHODvirtual nsresult Complete(nsresult, nsISupports*) override { |
430 | mClosed = true; |
431 | return NS_OK; |
432 | } |
433 | |
434 | bool mClosed; |
435 | |
436 | private: |
437 | ~CloseListener() = default; |
438 | }; |
439 | |
440 | NS_IMPL_ISUPPORTS(CloseListener, mozIStorageCompletionCallback)MozExternalRefCountType CloseListener::AddRef(void) { static_assert (!std::is_destructible_v<CloseListener>, "Reference-counted class " "CloseListener" " 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/storage/mozStorageConnection.cpp" , 440); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { *((volatile int*)__null) = 440; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("CloseListener" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("CloseListener" != nullptr)) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"CloseListener\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 440); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CloseListener\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 440; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("CloseListener" " not thread-safe"); nsrefcnt count = ++mRefCnt; NS_LogAddRef((this), (count), ("CloseListener" ), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType CloseListener::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/storage/mozStorageConnection.cpp" , 440); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { *((volatile int*)__null) = 440 ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("CloseListener" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("CloseListener" != nullptr)) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"CloseListener\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 440); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CloseListener\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 440; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("CloseListener" " not thread-safe"); const char * const nametmp = "CloseListener"; nsrefcnt count = --mRefCnt ; NS_LogRelease((this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult CloseListener::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/storage/mozStorageConnection.cpp" , 440); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<CloseListener, mozIStorageCompletionCallback >, int32_t( reinterpret_cast<char*>(static_cast<mozIStorageCompletionCallback *>((CloseListener*)0x1000)) - reinterpret_cast<char*> ((CloseListener*)0x1000))}, {&mozilla::detail::kImplementedIID <CloseListener, nsISupports>, int32_t(reinterpret_cast< char*>(static_cast<nsISupports*>( static_cast<mozIStorageCompletionCallback *>((CloseListener*)0x1000))) - reinterpret_cast<char*> ((CloseListener*)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; } |
441 | |
442 | class AsyncVacuumEvent final : public Runnable { |
443 | public: |
444 | AsyncVacuumEvent(Connection* aConnection, |
445 | mozIStorageCompletionCallback* aCallback, |
446 | bool aUseIncremental, int32_t aSetPageSize) |
447 | : Runnable("storage::AsyncVacuum"), |
448 | mConnection(aConnection), |
449 | mCallback(aCallback), |
450 | mUseIncremental(aUseIncremental), |
451 | mSetPageSize(aSetPageSize), |
452 | mStatus(NS_ERROR_UNEXPECTED) {} |
453 | |
454 | NS_IMETHODvirtual nsresult Run() override { |
455 | // This is initially dispatched to the helper thread, then re-dispatched |
456 | // to the opener thread, where it will callback. |
457 | if (IsOnCurrentSerialEventTarget(mConnection->eventTargetOpenedOn)) { |
458 | // Send the completion event. |
459 | if (mCallback) { |
460 | mozilla::Unused << mCallback->Complete(mStatus, nullptr); |
461 | } |
462 | return NS_OK; |
463 | } |
464 | |
465 | // Ensure to invoke the callback regardless of errors. |
466 | auto guard = MakeScopeExit([&]() { |
467 | mConnection->mIsStatementOnHelperThreadInterruptible = false; |
468 | mozilla::Unused << mConnection->eventTargetOpenedOn->Dispatch( |
469 | this, NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL); |
470 | }); |
471 | |
472 | // Get list of attached databases. |
473 | nsCOMPtr<mozIStorageStatement> stmt; |
474 | nsresult rv = mConnection->CreateStatement(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" " */ " |
475 | "PRAGMA database_list"_ns, |
476 | getter_AddRefs(stmt)); |
477 | 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/storage/mozStorageConnection.cpp" , 477); return rv; } } while (false); |
478 | // We must accumulate names and loop through them later, otherwise VACUUM |
479 | // will see an ongoing statement and bail out. |
480 | nsTArray<nsCString> schemaNames; |
481 | bool hasResult = false; |
482 | while (stmt && NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep (&hasResult))), 1))) && hasResult) { |
483 | nsAutoCString name; |
484 | rv = stmt->GetUTF8String(1, name); |
485 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && !name.EqualsLiteral("temp")) { |
486 | schemaNames.AppendElement(name); |
487 | } |
488 | } |
489 | mStatus = NS_OK; |
490 | // Mark this vacuum as an interruptible operation, so it can be interrupted |
491 | // if the connection closes during shutdown. |
492 | mConnection->mIsStatementOnHelperThreadInterruptible = true; |
493 | for (const nsCString& schemaName : schemaNames) { |
494 | rv = this->Vacuum(schemaName); |
495 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
496 | // This is sub-optimal since it's only keeping the last error reason, |
497 | // but it will do for now. |
498 | mStatus = rv; |
499 | } |
500 | } |
501 | return mStatus; |
502 | } |
503 | |
504 | nsresult Vacuum(const nsACString& aSchemaName) { |
505 | // Abort if we're in shutdown. |
506 | if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) { |
507 | return NS_ERROR_ABORT; |
508 | } |
509 | int32_t removablePages = mConnection->RemovablePagesInFreeList(aSchemaName); |
510 | if (!removablePages) { |
511 | // There's no empty pages to remove, so skip this vacuum for now. |
512 | return NS_OK; |
513 | } |
514 | nsresult rv; |
515 | bool needsFullVacuum = true; |
516 | |
517 | if (mSetPageSize) { |
518 | nsAutoCString query(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" " */ " "PRAGMA "); |
519 | query.Append(aSchemaName); |
520 | query.AppendLiteral(".page_size = "); |
521 | query.AppendInt(mSetPageSize); |
522 | nsCOMPtr<mozIStorageStatement> stmt; |
523 | rv = mConnection->ExecuteSimpleSQL(query); |
524 | 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/storage/mozStorageConnection.cpp" , 524); return rv; } } while (false); |
525 | } |
526 | |
527 | // Check auto_vacuum. |
528 | { |
529 | nsAutoCString query(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" " */ " "PRAGMA "); |
530 | query.Append(aSchemaName); |
531 | query.AppendLiteral(".auto_vacuum"); |
532 | nsCOMPtr<mozIStorageStatement> stmt; |
533 | rv = mConnection->CreateStatement(query, getter_AddRefs(stmt)); |
534 | 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/storage/mozStorageConnection.cpp" , 534); return rv; } } while (false); |
535 | bool hasResult = false; |
536 | bool changeAutoVacuum = false; |
537 | if (stmt && NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep (&hasResult))), 1))) && hasResult) { |
538 | bool isIncrementalVacuum = stmt->AsInt32(0) == 2; |
539 | changeAutoVacuum = isIncrementalVacuum != mUseIncremental; |
540 | if (isIncrementalVacuum && !changeAutoVacuum) { |
541 | needsFullVacuum = false; |
542 | } |
543 | } |
544 | // Changing auto_vacuum is only supported on the main schema. |
545 | if (aSchemaName.EqualsLiteral("main") && changeAutoVacuum) { |
546 | nsAutoCString query(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" " */ " "PRAGMA "); |
547 | query.Append(aSchemaName); |
548 | query.AppendLiteral(".auto_vacuum = "); |
549 | query.AppendInt(mUseIncremental ? 2 : 0); |
550 | rv = mConnection->ExecuteSimpleSQL(query); |
551 | 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/storage/mozStorageConnection.cpp" , 551); return rv; } } while (false); |
552 | } |
553 | } |
554 | |
555 | if (needsFullVacuum) { |
556 | nsAutoCString query(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" " */ " "VACUUM "); |
557 | query.Append(aSchemaName); |
558 | rv = mConnection->ExecuteSimpleSQL(query); |
559 | // TODO (Bug 1818039): Report failed vacuum telemetry. |
560 | 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/storage/mozStorageConnection.cpp" , 560); return rv; } } while (false); |
561 | } else { |
562 | nsAutoCString query(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" " */ " "PRAGMA "); |
563 | query.Append(aSchemaName); |
564 | query.AppendLiteral(".incremental_vacuum("); |
565 | query.AppendInt(removablePages); |
566 | query.AppendLiteral(")"); |
567 | rv = mConnection->ExecuteSimpleSQL(query); |
568 | 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/storage/mozStorageConnection.cpp" , 568); return rv; } } while (false); |
569 | } |
570 | |
571 | return NS_OK; |
572 | } |
573 | |
574 | ~AsyncVacuumEvent() override { |
575 | NS_ReleaseOnMainThread("AsyncVacuum::mConnection", mConnection.forget()); |
576 | NS_ReleaseOnMainThread("AsyncVacuum::mCallback", mCallback.forget()); |
577 | } |
578 | |
579 | private: |
580 | RefPtr<Connection> mConnection; |
581 | nsCOMPtr<mozIStorageCompletionCallback> mCallback; |
582 | bool mUseIncremental; |
583 | int32_t mSetPageSize; |
584 | Atomic<nsresult> mStatus; |
585 | }; |
586 | |
587 | /** |
588 | * A runnable to perform an SQLite database backup when there may be one or more |
589 | * open connections on that database. |
590 | */ |
591 | class AsyncBackupDatabaseFile final : public Runnable, public nsITimerCallback { |
592 | public: |
593 | NS_DECL_ISUPPORTS_INHERITEDpublic: virtual nsresult QueryInterface(const nsIID& aIID , void** aInstancePtr) override; virtual MozExternalRefCountType AddRef(void) override; virtual MozExternalRefCountType Release (void) override; |
594 | |
595 | /** |
596 | * @param aConnection The connection to the database being backed up. |
597 | * @param aNativeConnection The native connection to the database being backed |
598 | * up. |
599 | * @param aDestinationFile The destination file for the created backup. |
600 | * @param aCallback A callback to trigger once the backup process has |
601 | * completed. The callback will be supplied with an nsresult |
602 | * indicating whether or not the backup was successfully |
603 | * created. This callback will be called on the |
604 | * mConnection->eventTargetOpenedOn thread. |
605 | * @throws |
606 | */ |
607 | AsyncBackupDatabaseFile(Connection* aConnection, sqlite3* aNativeConnection, |
608 | nsIFile* aDestinationFile, |
609 | mozIStorageCompletionCallback* aCallback, |
610 | int32_t aPagesPerStep, uint32_t aStepDelayMs) |
611 | : Runnable("storage::AsyncBackupDatabaseFile"), |
612 | mConnection(aConnection), |
613 | mNativeConnection(aNativeConnection), |
614 | mDestinationFile(aDestinationFile), |
615 | mCallback(aCallback), |
616 | mPagesPerStep(aPagesPerStep), |
617 | mStepDelayMs(aStepDelayMs), |
618 | mBackupFile(nullptr), |
619 | mBackupHandle(nullptr) { |
620 | 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/storage/mozStorageConnection.cpp" , 620); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 620; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
621 | } |
622 | |
623 | NS_IMETHODvirtual nsresult Run() override { |
624 | 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/storage/mozStorageConnection.cpp" , 624); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 624; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
625 | |
626 | nsAutoString path; |
627 | nsresult rv = mDestinationFile->GetPath(path); |
628 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
629 | return Dispatch(rv, nullptr); |
630 | } |
631 | // Put a .tmp on the end of the destination while the backup is underway. |
632 | // This extension will be stripped off after the backup successfully |
633 | // completes. |
634 | path.AppendLiteral(".tmp"); |
635 | |
636 | int srv = ::sqlite3_open(NS_ConvertUTF16toUTF8(path).get(), &mBackupFile); |
637 | if (srv != SQLITE_OK0) { |
638 | return Dispatch(NS_ERROR_FAILURE, nullptr); |
639 | } |
640 | |
641 | static const char* mainDBName = "main"; |
642 | |
643 | mBackupHandle = ::sqlite3_backup_init(mBackupFile, mainDBName, |
644 | mNativeConnection, mainDBName); |
645 | if (!mBackupHandle) { |
646 | MOZ_ALWAYS_TRUE(::sqlite3_close(mBackupFile) == SQLITE_OK)do { if ((__builtin_expect(!!(::sqlite3_close(mBackupFile) == 0), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "::sqlite3_close(mBackupFile) == SQLITE_OK" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 646); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "::sqlite3_close(mBackupFile) == SQLITE_OK" ")"); do { *((volatile int*)__null) = 646; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); } } while (false); |
647 | return Dispatch(NS_ERROR_FAILURE, nullptr); |
648 | } |
649 | |
650 | return DoStep(); |
651 | } |
652 | |
653 | NS_IMETHODvirtual nsresult |
654 | Notify(nsITimer* aTimer) override { return DoStep(); } |
655 | |
656 | private: |
657 | nsresult DoStep() { |
658 | #define DISPATCH_AND_RETURN_IF_FAILED(rv) \ |
659 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { \ |
660 | return Dispatch(rv, nullptr); \ |
661 | } |
662 | |
663 | // This guard is used to close the backup database in the event of |
664 | // some failure throughout this process. We release the exit guard |
665 | // only if we complete the backup successfully, or defer to another |
666 | // later call to DoStep. |
667 | auto guard = MakeScopeExit([&]() { |
668 | MOZ_ALWAYS_TRUE(::sqlite3_close(mBackupFile) == SQLITE_OK)do { if ((__builtin_expect(!!(::sqlite3_close(mBackupFile) == 0), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "::sqlite3_close(mBackupFile) == SQLITE_OK" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 668); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "::sqlite3_close(mBackupFile) == SQLITE_OK" ")"); do { *((volatile int*)__null) = 668; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); } } while (false); |
669 | mBackupFile = nullptr; |
670 | }); |
671 | |
672 | 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/storage/mozStorageConnection.cpp" , 672); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 672; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
673 | nsAutoString originalPath; |
674 | nsresult rv = mDestinationFile->GetPath(originalPath); |
675 | DISPATCH_AND_RETURN_IF_FAILED(rv); |
676 | |
677 | nsAutoString tempPath = originalPath; |
678 | tempPath.AppendLiteral(".tmp"); |
679 | |
680 | nsCOMPtr<nsIFile> file = |
681 | do_CreateInstance("@mozilla.org/file/local;1", &rv); |
682 | DISPATCH_AND_RETURN_IF_FAILED(rv); |
683 | |
684 | rv = file->InitWithPath(tempPath); |
685 | DISPATCH_AND_RETURN_IF_FAILED(rv); |
686 | |
687 | int srv = ::sqlite3_backup_step(mBackupHandle, mPagesPerStep); |
688 | if (srv == SQLITE_OK0 || srv == SQLITE_BUSY5 || srv == SQLITE_LOCKED6) { |
689 | // We're continuing the backup later. Release the guard to avoid closing |
690 | // the database. |
691 | guard.release(); |
692 | // Queue up the next step |
693 | return NS_NewTimerWithCallback(getter_AddRefs(mTimer), this, mStepDelayMs, |
694 | nsITimer::TYPE_ONE_SHOT, |
695 | GetCurrentSerialEventTarget()); |
696 | } |
697 | #ifdef DEBUG1 |
698 | if (srv != SQLITE_DONE101) { |
699 | nsCString warnMsg; |
700 | warnMsg.AppendLiteral( |
701 | "The SQLite database copy could not be completed due to an error: "); |
702 | warnMsg.Append(::sqlite3_errmsg(mBackupFile)); |
703 | NS_WARNING(warnMsg.get())NS_DebugBreak(NS_DEBUG_WARNING, warnMsg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 703); |
704 | } |
705 | #endif |
706 | |
707 | (void)::sqlite3_backup_finish(mBackupHandle); |
708 | MOZ_ALWAYS_TRUE(::sqlite3_close(mBackupFile) == SQLITE_OK)do { if ((__builtin_expect(!!(::sqlite3_close(mBackupFile) == 0), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "::sqlite3_close(mBackupFile) == SQLITE_OK" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 708); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "::sqlite3_close(mBackupFile) == SQLITE_OK" ")"); do { *((volatile int*)__null) = 708; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); } } while (false); |
709 | mBackupFile = nullptr; |
710 | |
711 | // The database is already closed, so we can release this guard now. |
712 | guard.release(); |
713 | |
714 | if (srv != SQLITE_DONE101) { |
715 | NS_WARNING("Failed to create database copy.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to create database copy." , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 715); |
716 | |
717 | // The partially created database file is not useful. Let's remove it. |
718 | rv = file->Remove(false); |
719 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
720 | NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "Removing a partially backed up SQLite database file failed." , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 721) |
721 | "Removing a partially backed up SQLite database file failed.")NS_DebugBreak(NS_DEBUG_WARNING, "Removing a partially backed up SQLite database file failed." , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 721); |
722 | } |
723 | |
724 | return Dispatch(convertResultCode(srv), nullptr); |
725 | } |
726 | |
727 | // Now that we've successfully created the copy, we'll strip off the .tmp |
728 | // extension. |
729 | |
730 | nsAutoString leafName; |
731 | rv = mDestinationFile->GetLeafName(leafName); |
732 | DISPATCH_AND_RETURN_IF_FAILED(rv); |
733 | |
734 | rv = file->RenameTo(nullptr, leafName); |
735 | DISPATCH_AND_RETURN_IF_FAILED(rv); |
736 | |
737 | #undef DISPATCH_AND_RETURN_IF_FAILED |
738 | return Dispatch(NS_OK, nullptr); |
739 | } |
740 | |
741 | nsresult Dispatch(nsresult aResult, nsISupports* aValue) { |
742 | RefPtr<CallbackComplete> event = |
743 | new CallbackComplete(aResult, aValue, mCallback.forget()); |
744 | return mConnection->eventTargetOpenedOn->Dispatch(event, |
745 | NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL); |
746 | } |
747 | |
748 | ~AsyncBackupDatabaseFile() override { |
749 | nsresult rv; |
750 | nsCOMPtr<nsIThread> thread = |
751 | do_QueryInterface(mConnection->eventTargetOpenedOn, &rv); |
752 | 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/storage/mozStorageConnection.cpp" , 752); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 752; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
753 | |
754 | // Handle ambiguous nsISupports inheritance. |
755 | NS_ProxyRelease("AsyncBackupDatabaseFile::mConnection", thread, |
756 | mConnection.forget()); |
757 | NS_ProxyRelease("AsyncBackupDatabaseFile::mDestinationFile", thread, |
758 | mDestinationFile.forget()); |
759 | |
760 | // Generally, the callback will be released by CallbackComplete. |
761 | // However, if for some reason Run() is not executed, we still |
762 | // need to ensure that it is released here. |
763 | NS_ProxyRelease("AsyncInitializeClone::mCallback", thread, |
764 | mCallback.forget()); |
765 | } |
766 | |
767 | RefPtr<Connection> mConnection; |
768 | sqlite3* mNativeConnection; |
769 | nsCOMPtr<nsITimer> mTimer; |
770 | nsCOMPtr<nsIFile> mDestinationFile; |
771 | nsCOMPtr<mozIStorageCompletionCallback> mCallback; |
772 | int32_t mPagesPerStep; |
773 | uint32_t mStepDelayMs; |
774 | sqlite3* mBackupFile; |
775 | sqlite3_backup* mBackupHandle; |
776 | }; |
777 | |
778 | NS_IMPL_ISUPPORTS_INHERITED(AsyncBackupDatabaseFile, Runnable, nsITimerCallback)nsresult AsyncBackupDatabaseFile::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/storage/mozStorageConnection.cpp" , 778); 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<AsyncBackupDatabaseFile, nsITimerCallback >, int32_t( reinterpret_cast<char*>(static_cast<nsITimerCallback *>((AsyncBackupDatabaseFile*)0x1000)) - reinterpret_cast< char*>((AsyncBackupDatabaseFile*)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 AsyncBackupDatabaseFile::AddRef(void) { static_assert(!std:: is_destructible_v<AsyncBackupDatabaseFile>, "Reference-counted class " "AsyncBackupDatabaseFile" " should not have a public destructor. " "Make this class's destructor non-public"); nsrefcnt r = Runnable ::AddRef(); if constexpr (::mozilla::detail::ShouldLogInheritedRefcnt <AsyncBackupDatabaseFile>) { NS_LogAddRef((this), (r), ( "AsyncBackupDatabaseFile"), (uint32_t)(sizeof(*this))); } return r; } MozExternalRefCountType AsyncBackupDatabaseFile::Release (void) { nsrefcnt r = Runnable::Release(); if constexpr (::mozilla ::detail::ShouldLogInheritedRefcnt<AsyncBackupDatabaseFile >) { NS_LogRelease((this), (r), ("AsyncBackupDatabaseFile" )); } return r; } |
779 | |
780 | } // namespace |
781 | |
782 | //////////////////////////////////////////////////////////////////////////////// |
783 | //// Connection |
784 | |
785 | Connection::Connection(Service* aService, int aFlags, |
786 | ConnectionOperation aSupportedOperations, |
787 | const nsCString& aTelemetryFilename, bool aInterruptible, |
788 | bool aIgnoreLockingMode, bool aOpenNotExclusive) |
789 | : sharedAsyncExecutionMutex("Connection::sharedAsyncExecutionMutex"), |
790 | sharedDBMutex("Connection::sharedDBMutex"), |
791 | eventTargetOpenedOn(WrapNotNull(GetCurrentSerialEventTarget())), |
792 | mIsStatementOnHelperThreadInterruptible(false), |
793 | mDBConn(nullptr), |
794 | mDefaultTransactionType(mozIStorageConnection::TRANSACTION_DEFERRED), |
795 | mDestroying(false), |
796 | mProgressHandler(nullptr), |
797 | mStorageService(aService), |
798 | mFlags(aFlags), |
799 | mTransactionNestingLevel(0), |
800 | mSupportedOperations(aSupportedOperations), |
801 | mInterruptible(aSupportedOperations == Connection::ASYNCHRONOUS || |
802 | aInterruptible), |
803 | mIgnoreLockingMode(aIgnoreLockingMode), |
804 | mOpenNotExclusive(aOpenNotExclusive), |
805 | mAsyncExecutionThreadShuttingDown(false), |
806 | mConnectionClosed(false), |
807 | mGrowthChunkSize(0) { |
808 | MOZ_ASSERT(!mIgnoreLockingMode || mFlags & SQLITE_OPEN_READONLY,do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mIgnoreLockingMode || mFlags & 0x00000001)>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!mIgnoreLockingMode || mFlags & 0x00000001))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!mIgnoreLockingMode || mFlags & 0x00000001" " (" "Can't ignore locking for a non-readonly connection!" ")" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 809); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mIgnoreLockingMode || mFlags & 0x00000001" ") (" "Can't ignore locking for a non-readonly connection!" ")" ); do { *((volatile int*)__null) = 809; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
809 | "Can't ignore locking for a non-readonly connection!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mIgnoreLockingMode || mFlags & 0x00000001)>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!mIgnoreLockingMode || mFlags & 0x00000001))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!mIgnoreLockingMode || mFlags & 0x00000001" " (" "Can't ignore locking for a non-readonly connection!" ")" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 809); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mIgnoreLockingMode || mFlags & 0x00000001" ") (" "Can't ignore locking for a non-readonly connection!" ")" ); do { *((volatile int*)__null) = 809; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
810 | mStorageService->registerConnection(this); |
811 | MOZ_ASSERT(!aTelemetryFilename.IsEmpty(),do { static_assert( mozilla::detail::AssertionConditionType< decltype(!aTelemetryFilename.IsEmpty())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!aTelemetryFilename.IsEmpty( )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!aTelemetryFilename.IsEmpty()" " (" "A telemetry filename should have been passed-in." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 812); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aTelemetryFilename.IsEmpty()" ") (" "A telemetry filename should have been passed-in." ")" ); do { *((volatile int*)__null) = 812; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
812 | "A telemetry filename should have been passed-in.")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!aTelemetryFilename.IsEmpty())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!aTelemetryFilename.IsEmpty( )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!aTelemetryFilename.IsEmpty()" " (" "A telemetry filename should have been passed-in." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 812); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aTelemetryFilename.IsEmpty()" ") (" "A telemetry filename should have been passed-in." ")" ); do { *((volatile int*)__null) = 812; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
813 | mTelemetryFilename.Assign(aTelemetryFilename); |
814 | } |
815 | |
816 | Connection::~Connection() { |
817 | // Failsafe Close() occurs in our custom Release method because of |
818 | // complications related to Close() potentially invoking AsyncClose() which |
819 | // will increment our refcount. |
820 | MOZ_ASSERT(!mAsyncExecutionThread,do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mAsyncExecutionThread)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mAsyncExecutionThread))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!mAsyncExecutionThread" " (" "The async thread has not been shutdown properly!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 821); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mAsyncExecutionThread" ") (" "The async thread has not been shutdown properly!" ")" ); do { *((volatile int*)__null) = 821; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
821 | "The async thread has not been shutdown properly!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mAsyncExecutionThread)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mAsyncExecutionThread))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!mAsyncExecutionThread" " (" "The async thread has not been shutdown properly!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 821); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mAsyncExecutionThread" ") (" "The async thread has not been shutdown properly!" ")" ); do { *((volatile int*)__null) = 821; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
822 | } |
823 | |
824 | NS_IMPL_ADDREF(Connection)MozExternalRefCountType Connection::AddRef(void) { static_assert (!std::is_destructible_v<Connection>, "Reference-counted class " "Connection" " 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/storage/mozStorageConnection.cpp" , 824); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { *((volatile int*)__null) = 824; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("Connection" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("Connection" != nullptr))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("\"Connection\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 824); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"Connection\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 824; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("Connection" " not thread-safe"); nsrefcnt count = ++mRefCnt; NS_LogAddRef((this), (count), ("Connection"), ( uint32_t)(sizeof(*this))); return count; } |
825 | |
826 | NS_INTERFACE_MAP_BEGIN(Connection)nsresult Connection::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/storage/mozStorageConnection.cpp" , 826); MOZ_PretendNoReturn(); } } while (0); nsISupports* foundInterface ; |
827 | NS_INTERFACE_MAP_ENTRY(mozIStorageAsyncConnection)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, mozIStorageAsyncConnection>)) foundInterface = static_cast<mozIStorageAsyncConnection*>(this); else |
828 | NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, nsIInterfaceRequestor>)) foundInterface = static_cast<nsIInterfaceRequestor*>(this); else |
829 | NS_INTERFACE_MAP_ENTRY(mozIStorageConnection)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, mozIStorageConnection>)) foundInterface = static_cast<mozIStorageConnection*>(this); else |
830 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozIStorageConnection)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, nsISupports>)) foundInterface = static_cast <nsISupports*>(static_cast<mozIStorageConnection*> (this)); else |
831 | NS_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/storage/mozStorageConnection.cpp" , 831); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIID.Equals((nsISupports::COMTypeInfo<nsISupports, void>::kIID))" ")"); do { *((volatile int*)__null) = 831; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); status = NS_NOINTERFACE ; } else { (foundInterface)->AddRef(); status = NS_OK; } * aInstancePtr = foundInterface; return status; } |
832 | |
833 | // This is identical to what NS_IMPL_RELEASE provides, but with the |
834 | // extra |1 == count| case. |
835 | NS_IMETHODIMP_(MozExternalRefCountType)MozExternalRefCountType Connection::Release(void) { |
836 | 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/storage/mozStorageConnection.cpp" , 836); AnnotateMozCrashReason("MOZ_ASSERT" "(" "0 != mRefCnt" ") (" "dup release" ")"); do { *((volatile int*)__null) = 836 ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
837 | nsrefcnt count = --mRefCnt; |
838 | NS_LOG_RELEASE(this, count, "Connection")NS_LogRelease((this), (count), ("Connection")); |
839 | if (1 == count) { |
840 | // If the refcount went to 1, the single reference must be from |
841 | // gService->mConnections (in class |Service|). And the code calling |
842 | // Release is either: |
843 | // - The "user" code that had created the connection, releasing on any |
844 | // thread. |
845 | // - One of Service's getConnections() callers had acquired a strong |
846 | // reference to the Connection that out-lived the last "user" reference, |
847 | // and now that just got dropped. Note that this reference could be |
848 | // getting dropped on the main thread or Connection->eventTargetOpenedOn |
849 | // (because of the NewRunnableMethod used by minimizeMemory). |
850 | // |
851 | // Either way, we should now perform our failsafe Close() and unregister. |
852 | // However, we only want to do this once, and the reality is that our |
853 | // refcount could go back up above 1 and down again at any time if we are |
854 | // off the main thread and getConnections() gets called on the main thread, |
855 | // so we use an atomic here to do this exactly once. |
856 | if (mDestroying.compareExchange(false, true)) { |
857 | // Close the connection, dispatching to the opening event target if we're |
858 | // not on that event target already and that event target is still |
859 | // accepting runnables. We do this because it's possible we're on the main |
860 | // thread because of getConnections(), and we REALLY don't want to |
861 | // transfer I/O to the main thread if we can avoid it. |
862 | if (IsOnCurrentSerialEventTarget(eventTargetOpenedOn)) { |
863 | // This could cause SpinningSynchronousClose() to be invoked and AddRef |
864 | // triggered for AsyncCloseConnection's strong ref if the conn was ever |
865 | // use for async purposes. (Main-thread only, though.) |
866 | Unused << synchronousClose(); |
867 | } else { |
868 | nsCOMPtr<nsIRunnable> event = |
869 | NewRunnableMethod("storage::Connection::synchronousClose", this, |
870 | &Connection::synchronousClose); |
871 | if (NS_FAILED(eventTargetOpenedOn->Dispatch(event.forget(),((bool)(__builtin_expect(!!(NS_FAILED_impl(eventTargetOpenedOn ->Dispatch(event.forget(), nsIEventTarget::DISPATCH_NORMAL ))), 0))) |
872 | NS_DISPATCH_NORMAL))((bool)(__builtin_expect(!!(NS_FAILED_impl(eventTargetOpenedOn ->Dispatch(event.forget(), nsIEventTarget::DISPATCH_NORMAL ))), 0)))) { |
873 | // The event target was dead and so we've just leaked our runnable. |
874 | // This should not happen because our non-main-thread consumers should |
875 | // be explicitly closing their connections, not relying on us to close |
876 | // them for them. (It's okay to let a statement go out of scope for |
877 | // automatic cleanup, but not a Connection.) |
878 | MOZ_ASSERT(false,do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Leaked Connection::synchronousClose(), ownership fail." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 879); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Leaked Connection::synchronousClose(), ownership fail." ")" ); do { *((volatile int*)__null) = 879; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
879 | "Leaked Connection::synchronousClose(), ownership fail.")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Leaked Connection::synchronousClose(), ownership fail." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 879); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Leaked Connection::synchronousClose(), ownership fail." ")" ); do { *((volatile int*)__null) = 879; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
880 | Unused << synchronousClose(); |
881 | } |
882 | } |
883 | |
884 | // This will drop its strong reference right here, right now. |
885 | mStorageService->unregisterConnection(this); |
886 | } |
887 | } else if (0 == count) { |
888 | mRefCnt = 1; /* stabilize */ |
889 | #if 0 /* enable this to find non-threadsafe destructors: */ |
890 | NS_ASSERT_OWNINGTHREAD(Connection)_mOwningThread.AssertOwnership("Connection" " not thread-safe" ); |
891 | #endif |
892 | delete (this); |
893 | return 0; |
894 | } |
895 | return count; |
896 | } |
897 | |
898 | int32_t Connection::getSqliteRuntimeStatus(int32_t aStatusOption, |
899 | int32_t* aMaxValue) { |
900 | MOZ_ASSERT(connectionReady(), "A connection must exist at this point")do { static_assert( mozilla::detail::AssertionConditionType< decltype(connectionReady())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(connectionReady()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("connectionReady()" " (" "A connection must exist at this point" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 900); AnnotateMozCrashReason("MOZ_ASSERT" "(" "connectionReady()" ") (" "A connection must exist at this point" ")"); do { *(( volatile int*)__null) = 900; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
901 | int curr = 0, max = 0; |
902 | DebugOnly<int> rc = |
903 | ::sqlite3_db_status(mDBConn, aStatusOption, &curr, &max, 0); |
904 | MOZ_ASSERT(NS_SUCCEEDED(convertResultCode(rc)))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(convertResultCode (rc))), 1))))>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (convertResultCode(rc))), 1)))))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("((bool)(__builtin_expect(!!(!NS_FAILED_impl(convertResultCode(rc))), 1)))" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 904); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(convertResultCode(rc))), 1)))" ")"); do { *((volatile int*)__null) = 904; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
905 | if (aMaxValue) *aMaxValue = max; |
906 | return curr; |
907 | } |
908 | |
909 | nsIEventTarget* Connection::getAsyncExecutionTarget() { |
910 | NS_ENSURE_TRUE(IsOnCurrentSerialEventTarget(eventTargetOpenedOn), nullptr)do { if ((__builtin_expect(!!(!(IsOnCurrentSerialEventTarget( eventTargetOpenedOn))), 0))) { NS_DebugBreak(NS_DEBUG_WARNING , "NS_ENSURE_TRUE(" "IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 910); return nullptr; } } while (false); |
911 | |
912 | // Don't return the asynchronous event target if we are shutting down. |
913 | if (mAsyncExecutionThreadShuttingDown) { |
914 | return nullptr; |
915 | } |
916 | |
917 | // Create the async event target if there's none yet. |
918 | if (!mAsyncExecutionThread) { |
919 | // Names start with "sqldb:" followed by a recognizable name, like the |
920 | // database file name, or a specially crafted name like "memory". |
921 | // This name will be surfaced on https://crash-stats.mozilla.org, so any |
922 | // sensitive part of the file name (e.g. an URL origin) should be replaced |
923 | // by passing an explicit telemetryName to openDatabaseWithFileURL. |
924 | nsAutoCString name("sqldb:"_ns); |
925 | name.Append(mTelemetryFilename); |
926 | static nsThreadPoolNaming naming; |
927 | nsresult rv = NS_NewNamedThread(naming.GetNextThreadName(name), |
928 | getter_AddRefs(mAsyncExecutionThread)); |
929 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
930 | NS_WARNING("Failed to create async thread.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to create async thread." , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 930); |
931 | return nullptr; |
932 | } |
933 | mAsyncExecutionThread->SetNameForWakeupTelemetry("mozStorage (all)"_ns); |
934 | } |
935 | |
936 | return mAsyncExecutionThread; |
937 | } |
938 | |
939 | void Connection::RecordOpenStatus(nsresult rv) { |
940 | nsCString histogramKey = mTelemetryFilename; |
941 | |
942 | if (histogramKey.IsEmpty()) { |
943 | histogramKey.AssignLiteral("unknown"); |
944 | } |
945 | |
946 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
947 | AccumulateCategoricalKeyed(histogramKey, LABELS_SQLITE_STORE_OPEN::success); |
948 | return; |
949 | } |
950 | |
951 | switch (rv) { |
952 | case NS_ERROR_FILE_CORRUPTED: |
953 | AccumulateCategoricalKeyed(histogramKey, |
954 | LABELS_SQLITE_STORE_OPEN::corrupt); |
955 | break; |
956 | case NS_ERROR_STORAGE_IOERR: |
957 | AccumulateCategoricalKeyed(histogramKey, |
958 | LABELS_SQLITE_STORE_OPEN::diskio); |
959 | break; |
960 | case NS_ERROR_FILE_ACCESS_DENIED: |
961 | case NS_ERROR_FILE_IS_LOCKED: |
962 | case NS_ERROR_FILE_READ_ONLY: |
963 | AccumulateCategoricalKeyed(histogramKey, |
964 | LABELS_SQLITE_STORE_OPEN::access); |
965 | break; |
966 | case NS_ERROR_FILE_NO_DEVICE_SPACE: |
967 | AccumulateCategoricalKeyed(histogramKey, |
968 | LABELS_SQLITE_STORE_OPEN::diskspace); |
969 | break; |
970 | default: |
971 | AccumulateCategoricalKeyed(histogramKey, |
972 | LABELS_SQLITE_STORE_OPEN::failure); |
973 | } |
974 | } |
975 | |
976 | void Connection::RecordQueryStatus(int srv) { |
977 | nsCString histogramKey = mTelemetryFilename; |
978 | |
979 | if (histogramKey.IsEmpty()) { |
980 | histogramKey.AssignLiteral("unknown"); |
981 | } |
982 | |
983 | switch (srv) { |
984 | case SQLITE_OK0: |
985 | case SQLITE_ROW100: |
986 | case SQLITE_DONE101: |
987 | |
988 | // Note that these are returned when we intentionally cancel a statement so |
989 | // they aren't indicating a failure. |
990 | case SQLITE_ABORT4: |
991 | case SQLITE_INTERRUPT9: |
992 | AccumulateCategoricalKeyed(histogramKey, |
993 | LABELS_SQLITE_STORE_QUERY::success); |
994 | break; |
995 | case SQLITE_CORRUPT11: |
996 | case SQLITE_NOTADB26: |
997 | AccumulateCategoricalKeyed(histogramKey, |
998 | LABELS_SQLITE_STORE_QUERY::corrupt); |
999 | break; |
1000 | case SQLITE_PERM3: |
1001 | case SQLITE_CANTOPEN14: |
1002 | case SQLITE_LOCKED6: |
1003 | case SQLITE_READONLY8: |
1004 | AccumulateCategoricalKeyed(histogramKey, |
1005 | LABELS_SQLITE_STORE_QUERY::access); |
1006 | break; |
1007 | case SQLITE_IOERR10: |
1008 | case SQLITE_NOLFS22: |
1009 | AccumulateCategoricalKeyed(histogramKey, |
1010 | LABELS_SQLITE_STORE_QUERY::diskio); |
1011 | break; |
1012 | case SQLITE_FULL13: |
1013 | case SQLITE_TOOBIG18: |
1014 | AccumulateCategoricalKeyed(histogramKey, |
1015 | LABELS_SQLITE_STORE_QUERY::diskspace); |
1016 | break; |
1017 | case SQLITE_CONSTRAINT19: |
1018 | case SQLITE_RANGE25: |
1019 | case SQLITE_MISMATCH20: |
1020 | case SQLITE_MISUSE21: |
1021 | AccumulateCategoricalKeyed(histogramKey, |
1022 | LABELS_SQLITE_STORE_QUERY::misuse); |
1023 | break; |
1024 | case SQLITE_BUSY5: |
1025 | AccumulateCategoricalKeyed(histogramKey, LABELS_SQLITE_STORE_QUERY::busy); |
1026 | break; |
1027 | default: |
1028 | AccumulateCategoricalKeyed(histogramKey, |
1029 | LABELS_SQLITE_STORE_QUERY::failure); |
1030 | } |
1031 | } |
1032 | |
1033 | nsresult Connection::initialize(const nsACString& aStorageKey, |
1034 | const nsACString& aName) { |
1035 | MOZ_ASSERT(aStorageKey.Equals(kMozStorageMemoryStorageKey))do { static_assert( mozilla::detail::AssertionConditionType< decltype(aStorageKey.Equals(kMozStorageMemoryStorageKey))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(aStorageKey.Equals(kMozStorageMemoryStorageKey)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("aStorageKey.Equals(kMozStorageMemoryStorageKey)" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1035); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStorageKey.Equals(kMozStorageMemoryStorageKey)" ")"); do { *((volatile int*)__null) = 1035; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1036 | NS_ASSERTION(!connectionReady(),do { if (!(!connectionReady())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Initialize called on already opened database!", "!connectionReady()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1037); MOZ_PretendNoReturn(); } } while (0) |
1037 | "Initialize called on already opened database!")do { if (!(!connectionReady())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Initialize called on already opened database!", "!connectionReady()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1037); MOZ_PretendNoReturn(); } } while (0); |
1038 | MOZ_ASSERT(!mIgnoreLockingMode, "Can't ignore locking on an in-memory db.")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mIgnoreLockingMode)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mIgnoreLockingMode))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mIgnoreLockingMode" " (" "Can't ignore locking on an in-memory db." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1038); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mIgnoreLockingMode" ") (" "Can't ignore locking on an in-memory db." ")"); do { * ((volatile int*)__null) = 1038; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
1039 | AUTO_PROFILER_LABEL("Connection::initialize", OTHER)mozilla::AutoProfilerLabel raiiObject1039( "Connection::initialize" , nullptr, JS::ProfilingCategoryPair::OTHER); |
1040 | |
1041 | mStorageKey = aStorageKey; |
1042 | mName = aName; |
1043 | |
1044 | // in memory database requested, sqlite uses a magic file name |
1045 | |
1046 | const nsAutoCString path = |
1047 | mName.IsEmpty() ? nsAutoCString(":memory:"_ns) |
1048 | : "file:"_ns + mName + "?mode=memory&cache=shared"_ns; |
1049 | |
1050 | int srv = ::sqlite3_open_v2(path.get(), &mDBConn, mFlags, |
1051 | basevfs::GetVFSName(true)); |
1052 | if (srv != SQLITE_OK0) { |
1053 | mDBConn = nullptr; |
1054 | nsresult rv = convertResultCode(srv); |
1055 | RecordOpenStatus(rv); |
1056 | return rv; |
1057 | } |
1058 | |
1059 | #ifdef MOZ_SQLITE_FTS3_TOKENIZER |
1060 | srv = |
1061 | ::sqlite3_db_config(mDBConn, SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER1004, 1, 0); |
1062 | MOZ_ASSERT(srv == SQLITE_OK,do { static_assert( mozilla::detail::AssertionConditionType< decltype(srv == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(srv == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("srv == 0" " (" "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1063); AnnotateMozCrashReason("MOZ_ASSERT" "(" "srv == 0" ") (" "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled" ")" ); do { *((volatile int*)__null) = 1063; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
1063 | "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled")do { static_assert( mozilla::detail::AssertionConditionType< decltype(srv == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(srv == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("srv == 0" " (" "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1063); AnnotateMozCrashReason("MOZ_ASSERT" "(" "srv == 0" ") (" "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled" ")" ); do { *((volatile int*)__null) = 1063; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1064 | #endif |
1065 | |
1066 | // Do not set mDatabaseFile or mFileURL here since this is a "memory" |
1067 | // database. |
1068 | |
1069 | nsresult rv = initializeInternal(); |
1070 | RecordOpenStatus(rv); |
1071 | 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/storage/mozStorageConnection.cpp" , 1071); return rv; } } while (false); |
1072 | |
1073 | return NS_OK; |
1074 | } |
1075 | |
1076 | nsresult Connection::initialize(nsIFile* aDatabaseFile) { |
1077 | NS_ASSERTION(aDatabaseFile, "Passed null file!")do { if (!(aDatabaseFile)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Passed null file!", "aDatabaseFile", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1077); MOZ_PretendNoReturn(); } } while (0); |
1078 | NS_ASSERTION(!connectionReady(),do { if (!(!connectionReady())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Initialize called on already opened database!", "!connectionReady()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1079); MOZ_PretendNoReturn(); } } while (0) |
1079 | "Initialize called on already opened database!")do { if (!(!connectionReady())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Initialize called on already opened database!", "!connectionReady()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1079); MOZ_PretendNoReturn(); } } while (0); |
1080 | AUTO_PROFILER_LABEL("Connection::initialize", OTHER)mozilla::AutoProfilerLabel raiiObject1080( "Connection::initialize" , nullptr, JS::ProfilingCategoryPair::OTHER); |
1081 | |
1082 | // Do not set mFileURL here since this is database does not have an associated |
1083 | // URL. |
1084 | mDatabaseFile = aDatabaseFile; |
1085 | |
1086 | nsAutoString path; |
1087 | nsresult rv = aDatabaseFile->GetPath(path); |
1088 | 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/storage/mozStorageConnection.cpp" , 1088); return rv; } } while (false); |
1089 | |
1090 | bool exclusive = |
1091 | StaticPrefs::storage_sqlite_exclusiveLock_enabled() && !mOpenNotExclusive; |
1092 | int srv; |
1093 | if (mIgnoreLockingMode) { |
1094 | exclusive = false; |
1095 | srv = ::sqlite3_open_v2(NS_ConvertUTF16toUTF8(path).get(), &mDBConn, mFlags, |
1096 | "readonly-immutable-nolock"); |
1097 | } else { |
1098 | srv = ::sqlite3_open_v2(NS_ConvertUTF16toUTF8(path).get(), &mDBConn, mFlags, |
1099 | basevfs::GetVFSName(exclusive)); |
1100 | if (exclusive && (srv == SQLITE_LOCKED6 || srv == SQLITE_BUSY5)) { |
1101 | // Retry without trying to get an exclusive lock. |
1102 | exclusive = false; |
1103 | srv = ::sqlite3_open_v2(NS_ConvertUTF16toUTF8(path).get(), &mDBConn, |
1104 | mFlags, basevfs::GetVFSName(false)); |
1105 | } |
1106 | } |
1107 | if (srv != SQLITE_OK0) { |
1108 | mDBConn = nullptr; |
1109 | rv = convertResultCode(srv); |
1110 | RecordOpenStatus(rv); |
1111 | return rv; |
1112 | } |
1113 | |
1114 | rv = initializeInternal(); |
1115 | if (exclusive && |
1116 | (rv == NS_ERROR_STORAGE_BUSY || rv == NS_ERROR_FILE_IS_LOCKED)) { |
1117 | // Usually SQLite will fail to acquire an exclusive lock on opening, but in |
1118 | // some cases it may successfully open the database and then lock on the |
1119 | // first query execution. When initializeInternal fails it closes the |
1120 | // connection, so we can try to restart it in non-exclusive mode. |
1121 | srv = ::sqlite3_open_v2(NS_ConvertUTF16toUTF8(path).get(), &mDBConn, mFlags, |
1122 | basevfs::GetVFSName(false)); |
1123 | if (srv == SQLITE_OK0) { |
1124 | rv = initializeInternal(); |
1125 | } |
1126 | } |
1127 | |
1128 | RecordOpenStatus(rv); |
1129 | 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/storage/mozStorageConnection.cpp" , 1129); return rv; } } while (false); |
1130 | |
1131 | return NS_OK; |
1132 | } |
1133 | |
1134 | nsresult Connection::initialize(nsIFileURL* aFileURL) { |
1135 | NS_ASSERTION(aFileURL, "Passed null file URL!")do { if (!(aFileURL)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Passed null file URL!" , "aFileURL", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1135); MOZ_PretendNoReturn(); } } while (0); |
1136 | NS_ASSERTION(!connectionReady(),do { if (!(!connectionReady())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Initialize called on already opened database!", "!connectionReady()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1137); MOZ_PretendNoReturn(); } } while (0) |
1137 | "Initialize called on already opened database!")do { if (!(!connectionReady())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Initialize called on already opened database!", "!connectionReady()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1137); MOZ_PretendNoReturn(); } } while (0); |
1138 | AUTO_PROFILER_LABEL("Connection::initialize", OTHER)mozilla::AutoProfilerLabel raiiObject1138( "Connection::initialize" , nullptr, JS::ProfilingCategoryPair::OTHER); |
1139 | |
1140 | nsCOMPtr<nsIFile> databaseFile; |
1141 | nsresult rv = aFileURL->GetFile(getter_AddRefs(databaseFile)); |
1142 | 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/storage/mozStorageConnection.cpp" , 1142); return rv; } } while (false); |
1143 | |
1144 | // Set both mDatabaseFile and mFileURL here. |
1145 | mFileURL = aFileURL; |
1146 | mDatabaseFile = databaseFile; |
1147 | |
1148 | nsAutoCString spec; |
1149 | rv = aFileURL->GetSpec(spec); |
1150 | 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/storage/mozStorageConnection.cpp" , 1150); return rv; } } while (false); |
1151 | |
1152 | // If there is a key specified, we need to use the obfuscating VFS. |
1153 | nsAutoCString query; |
1154 | rv = aFileURL->GetQuery(query); |
1155 | 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/storage/mozStorageConnection.cpp" , 1155); return rv; } } while (false); |
1156 | |
1157 | bool hasKey = false; |
1158 | bool hasDirectoryLockId = false; |
1159 | |
1160 | MOZ_ALWAYS_TRUE(do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1161 | URLParams::Parse(query, true,do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1162 | [&hasKey, &hasDirectoryLockId](do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1163 | const nsACString& aName, const nsACString& aValue) {do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1164 | if (aName.EqualsLiteral("key")) {do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1165 | hasKey = true;do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1166 | return true;do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1167 | }do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1168 | if (aName.EqualsLiteral("directoryLockId")) {do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1169 | hasDirectoryLockId = true;do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1170 | return true;do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1171 | }do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1172 | return true;do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1173 | }))do { if ((__builtin_expect(!!(URLParams::Parse(query, true, [ &hasKey, &hasDirectoryLockId]( const nsACString& aName , const nsACString& aValue) { if (aName.EqualsLiteral("key" )) { hasKey = true; return true; } if (aName.EqualsLiteral("directoryLockId" )) { hasDirectoryLockId = true; return true; } return true; } )), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1173); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "URLParams::Parse(query, true, [&hasKey, &hasDirectoryLockId]( const nsACString& aName, const nsACString& aValue) { if (aName.EqualsLiteral(\"key\")) { hasKey = true; return true; } if (aName.EqualsLiteral(\"directoryLockId\")) { hasDirectoryLockId = true; return true; } return true; })" ")"); do { *((volatile int*)__null) = 1173; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
1174 | |
1175 | bool exclusive = |
1176 | StaticPrefs::storage_sqlite_exclusiveLock_enabled() && !mOpenNotExclusive; |
1177 | |
1178 | const char* const vfs = hasKey ? obfsvfs::GetVFSName() |
1179 | : hasDirectoryLockId ? quotavfs::GetVFSName() |
1180 | : basevfs::GetVFSName(exclusive); |
1181 | |
1182 | int srv = ::sqlite3_open_v2(spec.get(), &mDBConn, mFlags, vfs); |
1183 | if (srv != SQLITE_OK0) { |
1184 | mDBConn = nullptr; |
1185 | rv = convertResultCode(srv); |
1186 | RecordOpenStatus(rv); |
1187 | return rv; |
1188 | } |
1189 | |
1190 | rv = initializeInternal(); |
1191 | RecordOpenStatus(rv); |
1192 | 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/storage/mozStorageConnection.cpp" , 1192); return rv; } } while (false); |
1193 | |
1194 | return NS_OK; |
1195 | } |
1196 | |
1197 | nsresult Connection::initializeInternal() { |
1198 | MOZ_ASSERT(mDBConn)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mDBConn)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mDBConn))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mDBConn", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1198); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mDBConn" ")" ); do { *((volatile int*)__null) = 1198; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1199 | auto guard = MakeScopeExit([&]() { initializeFailed(); }); |
1200 | |
1201 | mConnectionClosed = false; |
1202 | |
1203 | #ifdef MOZ_SQLITE_FTS3_TOKENIZER |
1204 | DebugOnly<int> srv2 = |
1205 | ::sqlite3_db_config(mDBConn, SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER1004, 1, 0); |
1206 | MOZ_ASSERT(srv2 == SQLITE_OK,do { static_assert( mozilla::detail::AssertionConditionType< decltype(srv2 == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(srv2 == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("srv2 == 0" " (" "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1207); AnnotateMozCrashReason("MOZ_ASSERT" "(" "srv2 == 0" ") (" "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled" ")" ); do { *((volatile int*)__null) = 1207; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
1207 | "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled")do { static_assert( mozilla::detail::AssertionConditionType< decltype(srv2 == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(srv2 == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("srv2 == 0" " (" "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1207); AnnotateMozCrashReason("MOZ_ASSERT" "(" "srv2 == 0" ") (" "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled" ")" ); do { *((volatile int*)__null) = 1207; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1208 | #endif |
1209 | |
1210 | // Properly wrap the database handle's mutex. |
1211 | sharedDBMutex.initWithMutex(sqlite3_db_mutex(mDBConn)); |
1212 | |
1213 | // SQLite tracing can slow down queries (especially long queries) |
1214 | // significantly. Don't trace unless the user is actively monitoring SQLite. |
1215 | if (MOZ_LOG_TEST(gStorageLog, LogLevel::Debug)(__builtin_expect(!!(mozilla::detail::log_test(gStorageLog, LogLevel ::Debug)), 0))) { |
1216 | ::sqlite3_trace_v2(mDBConn, SQLITE_TRACE_STMT0x01 | SQLITE_TRACE_PROFILE0x02, |
1217 | tracefunc, this); |
1218 | |
1219 | MOZ_LOG(do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "Opening connection to '%s' (%p)", mTelemetryFilename .get(), this); } } while (0) |
1220 | gStorageLog, LogLevel::Debug,do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "Opening connection to '%s' (%p)", mTelemetryFilename .get(), this); } } while (0) |
1221 | ("Opening connection to '%s' (%p)", mTelemetryFilename.get(), this))do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "Opening connection to '%s' (%p)", mTelemetryFilename .get(), this); } } while (0); |
1222 | } |
1223 | |
1224 | int64_t pageSize = Service::kDefaultPageSize; |
1225 | |
1226 | // Set page_size to the preferred default value. This is effective only if |
1227 | // the database has just been created, otherwise, if the database does not |
1228 | // use WAL journal mode, a VACUUM operation will updated its page_size. |
1229 | nsAutoCString pageSizeQuery(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" " */ " |
1230 | "PRAGMA page_size = "); |
1231 | pageSizeQuery.AppendInt(pageSize); |
1232 | int srv = executeSql(mDBConn, pageSizeQuery.get()); |
1233 | if (srv != SQLITE_OK0) { |
1234 | return convertResultCode(srv); |
1235 | } |
1236 | |
1237 | // Setting the cache_size forces the database open, verifying if it is valid |
1238 | // or corrupt. So this is executed regardless it being actually needed. |
1239 | // The cache_size is calculated from the actual page_size, to save memory. |
1240 | nsAutoCString cacheSizeQuery(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" " */ " |
1241 | "PRAGMA cache_size = "); |
1242 | cacheSizeQuery.AppendInt(-MAX_CACHE_SIZE_KIBIBYTES2048); |
1243 | srv = executeSql(mDBConn, cacheSizeQuery.get()); |
1244 | if (srv != SQLITE_OK0) { |
1245 | return convertResultCode(srv); |
1246 | } |
1247 | |
1248 | // Register our built-in SQL functions. |
1249 | srv = registerFunctions(mDBConn); |
1250 | if (srv != SQLITE_OK0) { |
1251 | return convertResultCode(srv); |
1252 | } |
1253 | |
1254 | // Register our built-in SQL collating sequences. |
1255 | srv = registerCollations(mDBConn, mStorageService); |
1256 | if (srv != SQLITE_OK0) { |
1257 | return convertResultCode(srv); |
1258 | } |
1259 | |
1260 | // Set the default synchronous value. Each consumer can switch this |
1261 | // accordingly to their needs. |
1262 | #if defined(ANDROID) |
1263 | // Android prefers synchronous = OFF for performance reasons. |
1264 | Unused << ExecuteSimpleSQL("PRAGMA synchronous = OFF;"_ns); |
1265 | #else |
1266 | // Normal is the suggested value for WAL journals. |
1267 | Unused << ExecuteSimpleSQL("PRAGMA synchronous = NORMAL;"_ns); |
1268 | #endif |
1269 | |
1270 | // Initialization succeeded, we can stop guarding for failures. |
1271 | guard.release(); |
1272 | return NS_OK; |
1273 | } |
1274 | |
1275 | nsresult Connection::initializeOnAsyncThread(nsIFile* aStorageFile) { |
1276 | MOZ_ASSERT(!IsOnCurrentSerialEventTarget(eventTargetOpenedOn))do { static_assert( mozilla::detail::AssertionConditionType< decltype(!IsOnCurrentSerialEventTarget(eventTargetOpenedOn))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!IsOnCurrentSerialEventTarget(eventTargetOpenedOn))) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1276); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 1276; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1277 | nsresult rv = aStorageFile |
1278 | ? initialize(aStorageFile) |
1279 | : initialize(kMozStorageMemoryStorageKey, VoidCString()); |
1280 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1281 | // Shutdown the async thread, since initialization failed. |
1282 | MutexAutoLock lockedScope(sharedAsyncExecutionMutex); |
1283 | mAsyncExecutionThreadShuttingDown = true; |
1284 | nsCOMPtr<nsIRunnable> event = |
1285 | NewRunnableMethod("Connection::shutdownAsyncThread", this, |
1286 | &Connection::shutdownAsyncThread); |
1287 | Unused << NS_DispatchToMainThread(event); |
1288 | } |
1289 | return rv; |
1290 | } |
1291 | |
1292 | void Connection::initializeFailed() { |
1293 | { |
1294 | MutexAutoLock lockedScope(sharedAsyncExecutionMutex); |
1295 | mConnectionClosed = true; |
1296 | } |
1297 | MOZ_ALWAYS_TRUE(::sqlite3_close(mDBConn) == SQLITE_OK)do { if ((__builtin_expect(!!(::sqlite3_close(mDBConn) == 0), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "::sqlite3_close(mDBConn) == SQLITE_OK" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1297); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "::sqlite3_close(mDBConn) == SQLITE_OK" ")"); do { *(( volatile int*)__null) = 1297; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); } } while (false); |
1298 | mDBConn = nullptr; |
1299 | sharedDBMutex.destroy(); |
1300 | } |
1301 | |
1302 | nsresult Connection::databaseElementExists( |
1303 | enum DatabaseElementType aElementType, const nsACString& aElementName, |
1304 | bool* _exists) { |
1305 | if (!connectionReady()) { |
1306 | return NS_ERROR_NOT_AVAILABLE; |
1307 | } |
1308 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
1309 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1310 | return rv; |
1311 | } |
1312 | |
1313 | // When constructing the query, make sure to SELECT the correct db's |
1314 | // sqlite_master if the user is prefixing the element with a specific db. ex: |
1315 | // sample.test |
1316 | nsCString query("SELECT name FROM (SELECT * FROM "); |
1317 | nsDependentCSubstring element; |
1318 | int32_t ind = aElementName.FindChar('.'); |
1319 | if (ind == kNotFound) { |
1320 | element.Assign(aElementName); |
1321 | } else { |
1322 | nsDependentCSubstring db(Substring(aElementName, 0, ind + 1)); |
1323 | element.Assign(Substring(aElementName, ind + 1, aElementName.Length())); |
1324 | query.Append(db); |
1325 | } |
1326 | query.AppendLiteral( |
1327 | "sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = " |
1328 | "'"); |
1329 | |
1330 | switch (aElementType) { |
1331 | case INDEX: |
1332 | query.AppendLiteral("index"); |
1333 | break; |
1334 | case TABLE: |
1335 | query.AppendLiteral("table"); |
1336 | break; |
1337 | } |
1338 | query.AppendLiteral("' AND name ='"); |
1339 | query.Append(element); |
1340 | query.Append('\''); |
1341 | |
1342 | sqlite3_stmt* stmt; |
1343 | int srv = prepareStatement(mDBConn, query, &stmt); |
1344 | if (srv != SQLITE_OK0) { |
1345 | RecordQueryStatus(srv); |
1346 | return convertResultCode(srv); |
1347 | } |
1348 | |
1349 | srv = stepStatement(mDBConn, stmt); |
1350 | // we just care about the return value from step |
1351 | (void)::sqlite3_finalize(stmt); |
1352 | |
1353 | RecordQueryStatus(srv); |
1354 | |
1355 | if (srv == SQLITE_ROW100) { |
1356 | *_exists = true; |
1357 | return NS_OK; |
1358 | } |
1359 | if (srv == SQLITE_DONE101) { |
1360 | *_exists = false; |
1361 | return NS_OK; |
1362 | } |
1363 | |
1364 | return convertResultCode(srv); |
1365 | } |
1366 | |
1367 | bool Connection::findFunctionByInstance(mozIStorageFunction* aInstance) { |
1368 | sharedDBMutex.assertCurrentThreadOwns(); |
1369 | |
1370 | for (const auto& data : mFunctions.Values()) { |
1371 | if (data.function == aInstance) { |
1372 | return true; |
1373 | } |
1374 | } |
1375 | return false; |
1376 | } |
1377 | |
1378 | /* static */ |
1379 | int Connection::sProgressHelper(void* aArg) { |
1380 | Connection* _this = static_cast<Connection*>(aArg); |
1381 | return _this->progressHandler(); |
1382 | } |
1383 | |
1384 | int Connection::progressHandler() { |
1385 | sharedDBMutex.assertCurrentThreadOwns(); |
1386 | if (mProgressHandler) { |
1387 | bool result; |
1388 | nsresult rv = mProgressHandler->OnProgress(this, &result); |
1389 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return 0; // Don't break request |
1390 | return result ? 1 : 0; |
1391 | } |
1392 | return 0; |
1393 | } |
1394 | |
1395 | nsresult Connection::setClosedState() { |
1396 | // Flag that we are shutting down the async thread, so that |
1397 | // getAsyncExecutionTarget knows not to expose/create the async thread. |
1398 | MutexAutoLock lockedScope(sharedAsyncExecutionMutex); |
1399 | NS_ENSURE_FALSE(mAsyncExecutionThreadShuttingDown, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(!(mAsyncExecutionThreadShuttingDown ))), 0))) { NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "!(mAsyncExecutionThreadShuttingDown)" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1399); return NS_ERROR_UNEXPECTED; } } while (false); |
1400 | |
1401 | mAsyncExecutionThreadShuttingDown = true; |
1402 | |
1403 | // Set the property to null before closing the connection, otherwise the |
1404 | // other functions in the module may try to use the connection after it is |
1405 | // closed. |
1406 | mDBConn = nullptr; |
1407 | |
1408 | return NS_OK; |
1409 | } |
1410 | |
1411 | bool Connection::operationSupported(ConnectionOperation aOperationType) { |
1412 | if (aOperationType == ASYNCHRONOUS) { |
1413 | // Async operations are supported for all connections, on any thread. |
1414 | return true; |
1415 | } |
1416 | // Sync operations are supported for sync connections (on any thread), and |
1417 | // async connections on a background thread. |
1418 | MOZ_ASSERT(aOperationType == SYNCHRONOUS)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aOperationType == SYNCHRONOUS)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aOperationType == SYNCHRONOUS ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "aOperationType == SYNCHRONOUS", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1418); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOperationType == SYNCHRONOUS" ")"); do { *((volatile int*)__null) = 1418; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1419 | return mSupportedOperations == SYNCHRONOUS || !NS_IsMainThread(); |
1420 | } |
1421 | |
1422 | nsresult Connection::ensureOperationSupported( |
1423 | ConnectionOperation aOperationType) { |
1424 | if (NS_WARN_IF(!operationSupported(aOperationType))NS_warn_if_impl(!operationSupported(aOperationType), "!operationSupported(aOperationType)" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1424)) { |
1425 | #ifdef DEBUG1 |
1426 | if (NS_IsMainThread()) { |
1427 | nsCOMPtr<nsIXPConnect> xpc = nsIXPConnect::XPConnect(); |
1428 | Unused << xpc->DebugDumpJSStack(false, false, false); |
1429 | } |
1430 | #endif |
1431 | MOZ_ASSERT(false,do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Don't use async connections synchronously on the main thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1432); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Don't use async connections synchronously on the main thread" ")"); do { *((volatile int*)__null) = 1432; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
1432 | "Don't use async connections synchronously on the main thread")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Don't use async connections synchronously on the main thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1432); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Don't use async connections synchronously on the main thread" ")"); do { *((volatile int*)__null) = 1432; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1433 | return NS_ERROR_NOT_AVAILABLE; |
1434 | } |
1435 | return NS_OK; |
1436 | } |
1437 | |
1438 | bool Connection::isConnectionReadyOnThisThread() { |
1439 | MOZ_ASSERT_IF(connectionReady(), !mConnectionClosed)do { if (connectionReady()) { do { static_assert( mozilla::detail ::AssertionConditionType<decltype(!mConnectionClosed)>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!mConnectionClosed))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!mConnectionClosed", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1439); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mConnectionClosed" ")"); do { *((volatile int*)__null) = 1439; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
1440 | if (mAsyncExecutionThread && mAsyncExecutionThread->IsOnCurrentThread()) { |
1441 | return true; |
1442 | } |
1443 | return connectionReady(); |
1444 | } |
1445 | |
1446 | bool Connection::isClosing() { |
1447 | MutexAutoLock lockedScope(sharedAsyncExecutionMutex); |
1448 | return mAsyncExecutionThreadShuttingDown && !mConnectionClosed; |
1449 | } |
1450 | |
1451 | bool Connection::isClosed() { |
1452 | MutexAutoLock lockedScope(sharedAsyncExecutionMutex); |
1453 | return mConnectionClosed; |
1454 | } |
1455 | |
1456 | bool Connection::isClosed(MutexAutoLock& lock) { return mConnectionClosed; } |
1457 | |
1458 | bool Connection::isAsyncExecutionThreadAvailable() { |
1459 | MOZ_ASSERT(IsOnCurrentSerialEventTarget(eventTargetOpenedOn))do { static_assert( mozilla::detail::AssertionConditionType< decltype(IsOnCurrentSerialEventTarget(eventTargetOpenedOn))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(IsOnCurrentSerialEventTarget(eventTargetOpenedOn)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1459); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 1459; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1460 | return mAsyncExecutionThread && !mAsyncExecutionThreadShuttingDown; |
1461 | } |
1462 | |
1463 | void Connection::shutdownAsyncThread() { |
1464 | MOZ_ASSERT(IsOnCurrentSerialEventTarget(eventTargetOpenedOn))do { static_assert( mozilla::detail::AssertionConditionType< decltype(IsOnCurrentSerialEventTarget(eventTargetOpenedOn))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(IsOnCurrentSerialEventTarget(eventTargetOpenedOn)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1464); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 1464; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1465 | MOZ_ASSERT(mAsyncExecutionThread)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mAsyncExecutionThread)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mAsyncExecutionThread))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("mAsyncExecutionThread" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1465); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mAsyncExecutionThread" ")"); do { *((volatile int*)__null) = 1465; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1466 | MOZ_ASSERT(mAsyncExecutionThreadShuttingDown)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mAsyncExecutionThreadShuttingDown)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mAsyncExecutionThreadShuttingDown ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mAsyncExecutionThreadShuttingDown", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1466); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mAsyncExecutionThreadShuttingDown" ")"); do { *((volatile int*)__null) = 1466; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1467 | |
1468 | MOZ_ALWAYS_SUCCEEDS(mAsyncExecutionThread->Shutdown())do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (mAsyncExecutionThread->Shutdown())), 1)))), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(mAsyncExecutionThread->Shutdown())" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1468); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(mAsyncExecutionThread->Shutdown())" ")" ); do { *((volatile int*)__null) = 1468; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
1469 | mAsyncExecutionThread = nullptr; |
1470 | } |
1471 | |
1472 | nsresult Connection::internalClose(sqlite3* aNativeConnection) { |
1473 | #ifdef DEBUG1 |
1474 | { // Make sure we have marked our async thread as shutting down. |
1475 | MutexAutoLock lockedScope(sharedAsyncExecutionMutex); |
1476 | MOZ_ASSERT(mAsyncExecutionThreadShuttingDown,do { static_assert( mozilla::detail::AssertionConditionType< decltype(mAsyncExecutionThreadShuttingDown)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mAsyncExecutionThreadShuttingDown ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mAsyncExecutionThreadShuttingDown" " (" "Did not call setClosedState!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1477); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mAsyncExecutionThreadShuttingDown" ") (" "Did not call setClosedState!" ")"); do { *((volatile int *)__null) = 1477; __attribute__((nomerge)) ::abort(); } while (false); } } while (false) |
1477 | "Did not call setClosedState!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(mAsyncExecutionThreadShuttingDown)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mAsyncExecutionThreadShuttingDown ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mAsyncExecutionThreadShuttingDown" " (" "Did not call setClosedState!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1477); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mAsyncExecutionThreadShuttingDown" ") (" "Did not call setClosedState!" ")"); do { *((volatile int *)__null) = 1477; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
1478 | MOZ_ASSERT(!isClosed(lockedScope), "Unexpected closed state")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!isClosed(lockedScope))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!isClosed(lockedScope)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!isClosed(lockedScope)" " (" "Unexpected closed state" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1478); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!isClosed(lockedScope)" ") (" "Unexpected closed state" ")"); do { *((volatile int*) __null) = 1478; __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
1479 | } |
1480 | #endif // DEBUG |
1481 | |
1482 | if (MOZ_LOG_TEST(gStorageLog, LogLevel::Debug)(__builtin_expect(!!(mozilla::detail::log_test(gStorageLog, LogLevel ::Debug)), 0))) { |
1483 | nsAutoCString leafName(":memory"); |
1484 | if (mDatabaseFile) (void)mDatabaseFile->GetNativeLeafName(leafName); |
1485 | MOZ_LOG(gStorageLog, LogLevel::Debug,do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "Closing connection to '%s'", leafName.get ()); } } while (0) |
1486 | ("Closing connection to '%s'", leafName.get()))do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "Closing connection to '%s'", leafName.get ()); } } while (0); |
1487 | } |
1488 | |
1489 | // At this stage, we may still have statements that need to be |
1490 | // finalized. Attempt to close the database connection. This will |
1491 | // always disconnect any virtual tables and cleanly finalize their |
1492 | // internal statements. Once this is done, closing may fail due to |
1493 | // unfinalized client statements, in which case we need to finalize |
1494 | // these statements and close again. |
1495 | { |
1496 | MutexAutoLock lockedScope(sharedAsyncExecutionMutex); |
1497 | mConnectionClosed = true; |
1498 | } |
1499 | |
1500 | // Nothing else needs to be done if we don't have a connection here. |
1501 | if (!aNativeConnection) return NS_OK; |
1502 | |
1503 | int srv = ::sqlite3_close(aNativeConnection); |
1504 | |
1505 | if (srv == SQLITE_BUSY5) { |
1506 | { |
1507 | // Nothing else should change the connection or statements status until we |
1508 | // are done here. |
1509 | SQLiteMutexAutoLock lockedScope(sharedDBMutex); |
1510 | // We still have non-finalized statements. Finalize them. |
1511 | sqlite3_stmt* stmt = nullptr; |
1512 | while ((stmt = ::sqlite3_next_stmt(aNativeConnection, stmt))) { |
1513 | MOZ_LOG(gStorageLog, LogLevel::Debug,do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "Auto-finalizing SQL statement '%s' (%p)", ::sqlite3_sql(stmt), stmt); } } while (0) |
1514 | ("Auto-finalizing SQL statement '%s' (%p)", ::sqlite3_sql(stmt),do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "Auto-finalizing SQL statement '%s' (%p)", ::sqlite3_sql(stmt), stmt); } } while (0) |
1515 | stmt))do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "Auto-finalizing SQL statement '%s' (%p)", ::sqlite3_sql(stmt), stmt); } } while (0); |
1516 | |
1517 | #ifdef DEBUG1 |
1518 | SmprintfPointer msg = ::mozilla::Smprintf( |
1519 | "SQL statement '%s' (%p) should have been finalized before closing " |
1520 | "the connection", |
1521 | ::sqlite3_sql(stmt), stmt); |
1522 | NS_WARNING(msg.get())NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1522); |
1523 | #endif // DEBUG |
1524 | |
1525 | srv = ::sqlite3_finalize(stmt); |
1526 | |
1527 | #ifdef DEBUG1 |
1528 | if (srv != SQLITE_OK0) { |
1529 | SmprintfPointer msg = ::mozilla::Smprintf( |
1530 | "Could not finalize SQL statement (%p)", stmt); |
1531 | NS_WARNING(msg.get())NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1531); |
1532 | } |
1533 | #endif // DEBUG |
1534 | |
1535 | // Ensure that the loop continues properly, whether closing has |
1536 | // succeeded or not. |
1537 | if (srv == SQLITE_OK0) { |
1538 | stmt = nullptr; |
1539 | } |
1540 | } |
1541 | // Scope exiting will unlock the mutex before we invoke sqlite3_close() |
1542 | // again, since Sqlite will try to acquire it. |
1543 | } |
1544 | |
1545 | // Now that all statements have been finalized, we |
1546 | // should be able to close. |
1547 | srv = ::sqlite3_close(aNativeConnection); |
Value stored to 'srv' is never read | |
1548 | MOZ_ASSERT(false,do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Had to forcibly close the database connection because not all " "the statements have been finalized." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1550); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Had to forcibly close the database connection because not all " "the statements have been finalized." ")"); do { *((volatile int*)__null) = 1550; __attribute__((nomerge)) ::abort(); } while (false); } } while (false) |
1549 | "Had to forcibly close the database connection because not all "do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Had to forcibly close the database connection because not all " "the statements have been finalized." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1550); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Had to forcibly close the database connection because not all " "the statements have been finalized." ")"); do { *((volatile int*)__null) = 1550; __attribute__((nomerge)) ::abort(); } while (false); } } while (false) |
1550 | "the statements have been finalized.")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Had to forcibly close the database connection because not all " "the statements have been finalized." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1550); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Had to forcibly close the database connection because not all " "the statements have been finalized." ")"); do { *((volatile int*)__null) = 1550; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
1551 | } |
1552 | |
1553 | if (srv == SQLITE_OK0) { |
1554 | sharedDBMutex.destroy(); |
1555 | } else { |
1556 | MOZ_ASSERT(false,do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "sqlite3_close failed. There are probably outstanding " "statements that are listed above!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1558); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "sqlite3_close failed. There are probably outstanding " "statements that are listed above!" ")"); do { *((volatile int*)__null) = 1558; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
1557 | "sqlite3_close failed. There are probably outstanding "do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "sqlite3_close failed. There are probably outstanding " "statements that are listed above!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1558); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "sqlite3_close failed. There are probably outstanding " "statements that are listed above!" ")"); do { *((volatile int*)__null) = 1558; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
1558 | "statements that are listed above!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "sqlite3_close failed. There are probably outstanding " "statements that are listed above!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1558); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "sqlite3_close failed. There are probably outstanding " "statements that are listed above!" ")"); do { *((volatile int*)__null) = 1558; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1559 | } |
1560 | |
1561 | return convertResultCode(srv); |
1562 | } |
1563 | |
1564 | nsCString Connection::getFilename() { return mTelemetryFilename; } |
1565 | |
1566 | int Connection::stepStatement(sqlite3* aNativeConnection, |
1567 | sqlite3_stmt* aStatement) { |
1568 | MOZ_ASSERT(aStatement)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aStatement)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aStatement))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aStatement", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1568); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStatement" ")"); do { *((volatile int*)__null) = 1568; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1569 | |
1570 | AUTO_PROFILER_LABEL_DYNAMIC_CSTR("Connection::stepStatement", OTHER,mozilla::AutoProfilerLabel raiiObject1571( "Connection::stepStatement" , ::sqlite3_sql(aStatement), JS::ProfilingCategoryPair::OTHER ) |
1571 | ::sqlite3_sql(aStatement))mozilla::AutoProfilerLabel raiiObject1571( "Connection::stepStatement" , ::sqlite3_sql(aStatement), JS::ProfilingCategoryPair::OTHER ); |
1572 | |
1573 | bool checkedMainThread = false; |
1574 | TimeStamp startTime = TimeStamp::Now(); |
1575 | |
1576 | // The connection may have been closed if the executing statement has been |
1577 | // created and cached after a call to asyncClose() but before the actual |
1578 | // sqlite3_close(). This usually happens when other tasks using cached |
1579 | // statements are asynchronously scheduled for execution and any of them ends |
1580 | // up after asyncClose. See bug 728653 for details. |
1581 | if (!isConnectionReadyOnThisThread()) return SQLITE_MISUSE21; |
1582 | |
1583 | (void)::sqlite3_extended_result_codes(aNativeConnection, 1); |
1584 | |
1585 | int srv; |
1586 | while ((srv = ::sqlite3_step(aStatement)) == SQLITE_LOCKED_SHAREDCACHE(6 | (1<<8))) { |
1587 | if (!checkedMainThread) { |
1588 | checkedMainThread = true; |
1589 | if (::NS_IsMainThread()) { |
1590 | NS_WARNING("We won't allow blocking on the main thread!")NS_DebugBreak(NS_DEBUG_WARNING, "We won't allow blocking on the main thread!" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1590); |
1591 | break; |
1592 | } |
1593 | } |
1594 | |
1595 | srv = WaitForUnlockNotify(aNativeConnection); |
1596 | if (srv != SQLITE_OK0) { |
1597 | break; |
1598 | } |
1599 | |
1600 | ::sqlite3_reset(aStatement); |
1601 | } |
1602 | |
1603 | // Report very slow SQL statements to Telemetry |
1604 | TimeDuration duration = TimeStamp::Now() - startTime; |
1605 | const uint32_t threshold = NS_IsMainThread() |
1606 | ? Telemetry::kSlowSQLThresholdForMainThread |
1607 | : Telemetry::kSlowSQLThresholdForHelperThreads; |
1608 | if (duration.ToMilliseconds() >= threshold) { |
1609 | nsDependentCString statementString(::sqlite3_sql(aStatement)); |
1610 | Telemetry::RecordSlowSQLStatement( |
1611 | statementString, mTelemetryFilename, |
1612 | static_cast<uint32_t>(duration.ToMilliseconds())); |
1613 | } |
1614 | |
1615 | (void)::sqlite3_extended_result_codes(aNativeConnection, 0); |
1616 | // Drop off the extended result bits of the result code. |
1617 | return srv & 0xFF; |
1618 | } |
1619 | |
1620 | int Connection::prepareStatement(sqlite3* aNativeConnection, |
1621 | const nsCString& aSQL, sqlite3_stmt** _stmt) { |
1622 | // We should not even try to prepare statements after the connection has |
1623 | // been closed. |
1624 | if (!isConnectionReadyOnThisThread()) return SQLITE_MISUSE21; |
1625 | |
1626 | bool checkedMainThread = false; |
1627 | |
1628 | (void)::sqlite3_extended_result_codes(aNativeConnection, 1); |
1629 | |
1630 | int srv; |
1631 | while ((srv = ::sqlite3_prepare_v2(aNativeConnection, aSQL.get(), -1, _stmt, |
1632 | nullptr)) == SQLITE_LOCKED_SHAREDCACHE(6 | (1<<8))) { |
1633 | if (!checkedMainThread) { |
1634 | checkedMainThread = true; |
1635 | if (::NS_IsMainThread()) { |
1636 | NS_WARNING("We won't allow blocking on the main thread!")NS_DebugBreak(NS_DEBUG_WARNING, "We won't allow blocking on the main thread!" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1636); |
1637 | break; |
1638 | } |
1639 | } |
1640 | |
1641 | srv = WaitForUnlockNotify(aNativeConnection); |
1642 | if (srv != SQLITE_OK0) { |
1643 | break; |
1644 | } |
1645 | } |
1646 | |
1647 | if (srv != SQLITE_OK0) { |
1648 | nsCString warnMsg; |
1649 | warnMsg.AppendLiteral("The SQL statement '"); |
1650 | warnMsg.Append(aSQL); |
1651 | warnMsg.AppendLiteral("' could not be compiled due to an error: "); |
1652 | warnMsg.Append(::sqlite3_errmsg(aNativeConnection)); |
1653 | |
1654 | #ifdef DEBUG1 |
1655 | NS_WARNING(warnMsg.get())NS_DebugBreak(NS_DEBUG_WARNING, warnMsg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1655); |
1656 | #endif |
1657 | MOZ_LOG(gStorageLog, LogLevel::Error, ("%s", warnMsg.get()))do { const ::mozilla::LogModule* moz_real_module = gStorageLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Error)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Error, "%s", warnMsg.get()); } } while (0); |
1658 | } |
1659 | |
1660 | (void)::sqlite3_extended_result_codes(aNativeConnection, 0); |
1661 | // Drop off the extended result bits of the result code. |
1662 | int rc = srv & 0xFF; |
1663 | // sqlite will return OK on a comment only string and set _stmt to nullptr. |
1664 | // The callers of this function are used to only checking the return value, |
1665 | // so it is safer to return an error code. |
1666 | if (rc == SQLITE_OK0 && *_stmt == nullptr) { |
1667 | return SQLITE_MISUSE21; |
1668 | } |
1669 | |
1670 | return rc; |
1671 | } |
1672 | |
1673 | int Connection::executeSql(sqlite3* aNativeConnection, const char* aSqlString) { |
1674 | if (!isConnectionReadyOnThisThread()) return SQLITE_MISUSE21; |
1675 | |
1676 | AUTO_PROFILER_LABEL_DYNAMIC_CSTR("Connection::executeSql", OTHER, aSqlString)mozilla::AutoProfilerLabel raiiObject1676( "Connection::executeSql" , aSqlString, JS::ProfilingCategoryPair::OTHER); |
1677 | |
1678 | TimeStamp startTime = TimeStamp::Now(); |
1679 | int srv = |
1680 | ::sqlite3_exec(aNativeConnection, aSqlString, nullptr, nullptr, nullptr); |
1681 | RecordQueryStatus(srv); |
1682 | |
1683 | // Report very slow SQL statements to Telemetry |
1684 | TimeDuration duration = TimeStamp::Now() - startTime; |
1685 | const uint32_t threshold = NS_IsMainThread() |
1686 | ? Telemetry::kSlowSQLThresholdForMainThread |
1687 | : Telemetry::kSlowSQLThresholdForHelperThreads; |
1688 | if (duration.ToMilliseconds() >= threshold) { |
1689 | nsDependentCString statementString(aSqlString); |
1690 | Telemetry::RecordSlowSQLStatement( |
1691 | statementString, mTelemetryFilename, |
1692 | static_cast<uint32_t>(duration.ToMilliseconds())); |
1693 | } |
1694 | |
1695 | return srv; |
1696 | } |
1697 | |
1698 | //////////////////////////////////////////////////////////////////////////////// |
1699 | //// nsIInterfaceRequestor |
1700 | |
1701 | NS_IMETHODIMPnsresult |
1702 | Connection::GetInterface(const nsIID& aIID, void** _result) { |
1703 | if (aIID.Equals(NS_GET_IID(nsIEventTarget)(nsIEventTarget::COMTypeInfo<nsIEventTarget, void>::kIID ))) { |
1704 | nsIEventTarget* background = getAsyncExecutionTarget(); |
1705 | NS_IF_ADDREF(background)ns_if_addref(background); |
1706 | *_result = background; |
1707 | return NS_OK; |
1708 | } |
1709 | return NS_ERROR_NO_INTERFACE; |
1710 | } |
1711 | |
1712 | //////////////////////////////////////////////////////////////////////////////// |
1713 | //// mozIStorageConnection |
1714 | |
1715 | NS_IMETHODIMPnsresult |
1716 | Connection::Close() { |
1717 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
1718 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1719 | return rv; |
1720 | } |
1721 | return synchronousClose(); |
1722 | } |
1723 | |
1724 | nsresult Connection::synchronousClose() { |
1725 | if (!connectionReady()) { |
1726 | return NS_ERROR_NOT_INITIALIZED; |
1727 | } |
1728 | |
1729 | #ifdef DEBUG1 |
1730 | // Since we're accessing mAsyncExecutionThread, we need to be on the opener |
1731 | // event target. We make this check outside of debug code below in |
1732 | // setClosedState, but this is here to be explicit. |
1733 | MOZ_ASSERT(IsOnCurrentSerialEventTarget(eventTargetOpenedOn))do { static_assert( mozilla::detail::AssertionConditionType< decltype(IsOnCurrentSerialEventTarget(eventTargetOpenedOn))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(IsOnCurrentSerialEventTarget(eventTargetOpenedOn)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1733); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 1733; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1734 | #endif // DEBUG |
1735 | |
1736 | // Make sure we have not executed any asynchronous statements. |
1737 | // If this fails, the mDBConn may be left open, resulting in a leak. |
1738 | // We'll try to finalize the pending statements and close the connection. |
1739 | if (isAsyncExecutionThreadAvailable()) { |
1740 | #ifdef DEBUG1 |
1741 | if (NS_IsMainThread()) { |
1742 | nsCOMPtr<nsIXPConnect> xpc = nsIXPConnect::XPConnect(); |
1743 | Unused << xpc->DebugDumpJSStack(false, false, false); |
1744 | } |
1745 | #endif |
1746 | MOZ_ASSERT(false,do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Close() was invoked on a connection that executed asynchronous " "statements. " "Should have used asyncClose()." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1749); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Close() was invoked on a connection that executed asynchronous " "statements. " "Should have used asyncClose()." ")"); do { * ((volatile int*)__null) = 1749; __attribute__((nomerge)) ::abort (); } while (false); } } while (false) |
1747 | "Close() was invoked on a connection that executed asynchronous "do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Close() was invoked on a connection that executed asynchronous " "statements. " "Should have used asyncClose()." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1749); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Close() was invoked on a connection that executed asynchronous " "statements. " "Should have used asyncClose()." ")"); do { * ((volatile int*)__null) = 1749; __attribute__((nomerge)) ::abort (); } while (false); } } while (false) |
1748 | "statements. "do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Close() was invoked on a connection that executed asynchronous " "statements. " "Should have used asyncClose()." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1749); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Close() was invoked on a connection that executed asynchronous " "statements. " "Should have used asyncClose()." ")"); do { * ((volatile int*)__null) = 1749; __attribute__((nomerge)) ::abort (); } while (false); } } while (false) |
1749 | "Should have used asyncClose().")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Close() was invoked on a connection that executed asynchronous " "statements. " "Should have used asyncClose()." ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1749); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Close() was invoked on a connection that executed asynchronous " "statements. " "Should have used asyncClose()." ")"); do { * ((volatile int*)__null) = 1749; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
1750 | // Try to close the database regardless, to free up resources. |
1751 | Unused << SpinningSynchronousClose(); |
1752 | return NS_ERROR_UNEXPECTED; |
1753 | } |
1754 | |
1755 | // setClosedState nullifies our connection pointer, so we take a raw pointer |
1756 | // off it, to pass it through the close procedure. |
1757 | sqlite3* nativeConn = mDBConn; |
1758 | nsresult rv = setClosedState(); |
1759 | 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/storage/mozStorageConnection.cpp" , 1759); return rv; } } while (false); |
1760 | |
1761 | return internalClose(nativeConn); |
1762 | } |
1763 | |
1764 | NS_IMETHODIMPnsresult |
1765 | Connection::SpinningSynchronousClose() { |
1766 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
1767 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1768 | return rv; |
1769 | } |
1770 | if (!IsOnCurrentSerialEventTarget(eventTargetOpenedOn)) { |
1771 | return NS_ERROR_NOT_SAME_THREAD; |
1772 | } |
1773 | |
1774 | // As currently implemented, we can't spin to wait for an existing AsyncClose. |
1775 | // Our only existing caller will never have called close; assert if misused |
1776 | // so that no new callers assume this works after an AsyncClose. |
1777 | MOZ_DIAGNOSTIC_ASSERT(connectionReady())do { static_assert( mozilla::detail::AssertionConditionType< decltype(connectionReady())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(connectionReady()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("connectionReady()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1777); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "connectionReady()" ")"); do { *((volatile int*)__null) = 1777; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1778 | if (!connectionReady()) { |
1779 | return NS_ERROR_UNEXPECTED; |
1780 | } |
1781 | |
1782 | RefPtr<CloseListener> listener = new CloseListener(); |
1783 | rv = AsyncClose(listener); |
1784 | 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/storage/mozStorageConnection.cpp" , 1784); return rv; } } while (false); |
1785 | MOZ_ALWAYS_TRUE(do { if ((__builtin_expect(!!(SpinEventLoopUntil("storage::Connection::SpinningSynchronousClose"_ns , [&]() { return listener->mClosed; })), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "SpinEventLoopUntil(\"storage::Connection::SpinningSynchronousClose\"_ns, [&]() { return listener->mClosed; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1787); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "SpinEventLoopUntil(\"storage::Connection::SpinningSynchronousClose\"_ns, [&]() { return listener->mClosed; })" ")"); do { *((volatile int*)__null) = 1787; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1786 | SpinEventLoopUntil("storage::Connection::SpinningSynchronousClose"_ns,do { if ((__builtin_expect(!!(SpinEventLoopUntil("storage::Connection::SpinningSynchronousClose"_ns , [&]() { return listener->mClosed; })), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "SpinEventLoopUntil(\"storage::Connection::SpinningSynchronousClose\"_ns, [&]() { return listener->mClosed; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1787); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "SpinEventLoopUntil(\"storage::Connection::SpinningSynchronousClose\"_ns, [&]() { return listener->mClosed; })" ")"); do { *((volatile int*)__null) = 1787; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
1787 | [&]() { return listener->mClosed; }))do { if ((__builtin_expect(!!(SpinEventLoopUntil("storage::Connection::SpinningSynchronousClose"_ns , [&]() { return listener->mClosed; })), 1))) { } else { do { static_assert( mozilla::detail::AssertionConditionType <decltype(false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("false" " (" "SpinEventLoopUntil(\"storage::Connection::SpinningSynchronousClose\"_ns, [&]() { return listener->mClosed; })" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1787); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "SpinEventLoopUntil(\"storage::Connection::SpinningSynchronousClose\"_ns, [&]() { return listener->mClosed; })" ")"); do { *((volatile int*)__null) = 1787; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
1788 | MOZ_ASSERT(isClosed(), "The connection should be closed at this point")do { static_assert( mozilla::detail::AssertionConditionType< decltype(isClosed())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(isClosed()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("isClosed()" " (" "The connection should be closed at this point" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1788); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isClosed()" ") (" "The connection should be closed at this point" ")"); do { *((volatile int*)__null) = 1788; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
1789 | |
1790 | return rv; |
1791 | } |
1792 | |
1793 | NS_IMETHODIMPnsresult |
1794 | Connection::AsyncClose(mozIStorageCompletionCallback* aCallback) { |
1795 | NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_NOT_SAME_THREAD)do { if ((__builtin_expect(!!(!(NS_IsMainThread())), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "NS_IsMainThread()" ") failed" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1795); return NS_ERROR_NOT_SAME_THREAD; } } while (false); |
1796 | // Check if AsyncClose or Close were already invoked. |
1797 | if (!connectionReady()) { |
1798 | return NS_ERROR_NOT_INITIALIZED; |
1799 | } |
1800 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
1801 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1802 | return rv; |
1803 | } |
1804 | |
1805 | // The two relevant factors at this point are whether we have a database |
1806 | // connection and whether we have an async execution thread. Here's what the |
1807 | // states mean and how we handle them: |
1808 | // |
1809 | // - (mDBConn && asyncThread): The expected case where we are either an |
1810 | // async connection or a sync connection that has been used asynchronously. |
1811 | // Either way the caller must call us and not Close(). Nothing surprising |
1812 | // about this. We'll dispatch AsyncCloseConnection to the already-existing |
1813 | // async thread. |
1814 | // |
1815 | // - (mDBConn && !asyncThread): A somewhat unusual case where the caller |
1816 | // opened the connection synchronously and was planning to use it |
1817 | // asynchronously, but never got around to using it asynchronously before |
1818 | // needing to shutdown. This has been observed to happen for the cookie |
1819 | // service in a case where Firefox shuts itself down almost immediately |
1820 | // after startup (for unknown reasons). In the Firefox shutdown case, |
1821 | // we may also fail to create a new async execution thread if one does not |
1822 | // already exist. (nsThreadManager will refuse to create new threads when |
1823 | // it has already been told to shutdown.) As such, we need to handle a |
1824 | // failure to create the async execution thread by falling back to |
1825 | // synchronous Close() and also dispatching the completion callback because |
1826 | // at least Places likes to spin a nested event loop that depends on the |
1827 | // callback being invoked. |
1828 | // |
1829 | // Note that we have considered not trying to spin up the async execution |
1830 | // thread in this case if it does not already exist, but the overhead of |
1831 | // thread startup (if successful) is significantly less expensive than the |
1832 | // worst-case potential I/O hit of synchronously closing a database when we |
1833 | // could close it asynchronously. |
1834 | // |
1835 | // - (!mDBConn && asyncThread): This happens in some but not all cases where |
1836 | // OpenAsyncDatabase encountered a problem opening the database. If it |
1837 | // happened in all cases AsyncInitDatabase would just shut down the thread |
1838 | // directly and we would avoid this case. But it doesn't, so for simplicity |
1839 | // and consistency AsyncCloseConnection knows how to handle this and we |
1840 | // act like this was the (mDBConn && asyncThread) case in this method. |
1841 | // |
1842 | // - (!mDBConn && !asyncThread): The database was never successfully opened or |
1843 | // Close() or AsyncClose() has already been called (at least) once. This is |
1844 | // undeniably a misuse case by the caller. We could optimize for this |
1845 | // case by adding an additional check of mAsyncExecutionThread without using |
1846 | // getAsyncExecutionTarget() to avoid wastefully creating a thread just to |
1847 | // shut it down. But this complicates the method for broken caller code |
1848 | // whereas we're still correct and safe without the special-case. |
1849 | nsIEventTarget* asyncThread = getAsyncExecutionTarget(); |
1850 | |
1851 | // Create our callback event if we were given a callback. This will |
1852 | // eventually be dispatched in all cases, even if we fall back to Close() and |
1853 | // the database wasn't open and we return an error. The rationale is that |
1854 | // no existing consumer checks our return value and several of them like to |
1855 | // spin nested event loops until the callback fires. Given that, it seems |
1856 | // preferable for us to dispatch the callback in all cases. (Except the |
1857 | // wrong thread misuse case we bailed on up above. But that's okay because |
1858 | // that is statically wrong whereas these edge cases are dynamic.) |
1859 | nsCOMPtr<nsIRunnable> completeEvent; |
1860 | if (aCallback) { |
1861 | completeEvent = newCompletionEvent(aCallback); |
1862 | } |
1863 | |
1864 | if (!asyncThread) { |
1865 | // We were unable to create an async thread, so we need to fall back to |
1866 | // using normal Close(). Since there is no async thread, Close() will |
1867 | // not complain about that. (Close() may, however, complain if the |
1868 | // connection is closed, but that's okay.) |
1869 | if (completeEvent) { |
1870 | // Closing the database is more important than returning an error code |
1871 | // about a failure to dispatch, especially because all existing native |
1872 | // callers ignore our return value. |
1873 | Unused << NS_DispatchToMainThread(completeEvent.forget()); |
1874 | } |
1875 | MOZ_ALWAYS_SUCCEEDS(synchronousClose())do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (synchronousClose())), 1)))), 1))) { } else { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(false)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("false" " (" "NS_SUCCEEDED(synchronousClose())" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1875); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(synchronousClose())" ")"); do { *((volatile int*)__null) = 1875; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } } while (false); |
1876 | // Return a success inconditionally here, since Close() is unlikely to fail |
1877 | // and we want to reassure the consumer that its callback will be invoked. |
1878 | return NS_OK; |
1879 | } |
1880 | |
1881 | // If we're closing the connection during shutdown, and there is an |
1882 | // interruptible statement running on the helper thread, issue a |
1883 | // sqlite3_interrupt() to avoid crashing when that statement takes a long |
1884 | // time (for example a vacuum). |
1885 | if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed) && |
1886 | mInterruptible && mIsStatementOnHelperThreadInterruptible) { |
1887 | MOZ_ASSERT(!isClosing(), "Must not be closing, see Interrupt()")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!isClosing())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!isClosing()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!isClosing()" " (" "Must not be closing, see Interrupt()" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1887); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!isClosing()" ") (" "Must not be closing, see Interrupt()" ")"); do { *((volatile int*)__null) = 1887; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
1888 | DebugOnly<nsresult> rv2 = Interrupt(); |
1889 | MOZ_ASSERT(NS_SUCCEEDED(rv2))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv2)), 1 ))))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv2)), 1 )))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv2)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1889); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv2)), 1)))" ")"); do { *((volatile int*)__null) = 1889; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1890 | } |
1891 | |
1892 | // setClosedState nullifies our connection pointer, so we take a raw pointer |
1893 | // off it, to pass it through the close procedure. |
1894 | sqlite3* nativeConn = mDBConn; |
1895 | rv = setClosedState(); |
1896 | 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/storage/mozStorageConnection.cpp" , 1896); return rv; } } while (false); |
1897 | |
1898 | // Create and dispatch our close event to the background thread. |
1899 | nsCOMPtr<nsIRunnable> closeEvent = |
1900 | new AsyncCloseConnection(this, nativeConn, completeEvent); |
1901 | rv = asyncThread->Dispatch(closeEvent, NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL); |
1902 | 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/storage/mozStorageConnection.cpp" , 1902); return rv; } } while (false); |
1903 | |
1904 | return NS_OK; |
1905 | } |
1906 | |
1907 | NS_IMETHODIMPnsresult |
1908 | Connection::AsyncClone(bool aReadOnly, |
1909 | mozIStorageCompletionCallback* aCallback) { |
1910 | AUTO_PROFILER_LABEL("Connection::AsyncClone", OTHER)mozilla::AutoProfilerLabel raiiObject1910( "Connection::AsyncClone" , nullptr, JS::ProfilingCategoryPair::OTHER); |
1911 | |
1912 | NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_NOT_SAME_THREAD)do { if ((__builtin_expect(!!(!(NS_IsMainThread())), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "NS_IsMainThread()" ") failed" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 1912); return NS_ERROR_NOT_SAME_THREAD; } } while (false); |
1913 | if (!connectionReady()) { |
1914 | return NS_ERROR_NOT_INITIALIZED; |
1915 | } |
1916 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
1917 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1918 | return rv; |
1919 | } |
1920 | if (!mDatabaseFile) return NS_ERROR_UNEXPECTED; |
1921 | |
1922 | int flags = mFlags; |
1923 | if (aReadOnly) { |
1924 | // Turn off SQLITE_OPEN_READWRITE, and set SQLITE_OPEN_READONLY. |
1925 | flags = (~SQLITE_OPEN_READWRITE0x00000002 & flags) | SQLITE_OPEN_READONLY0x00000001; |
1926 | // Turn off SQLITE_OPEN_CREATE. |
1927 | flags = (~SQLITE_OPEN_CREATE0x00000004 & flags); |
1928 | } |
1929 | |
1930 | // The cloned connection will still implement the synchronous API, but throw |
1931 | // if any synchronous methods are called on the main thread. |
1932 | RefPtr<Connection> clone = |
1933 | new Connection(mStorageService, flags, ASYNCHRONOUS, mTelemetryFilename, |
1934 | mInterruptible, mIgnoreLockingMode, mOpenNotExclusive); |
1935 | |
1936 | RefPtr<AsyncInitializeClone> initEvent = |
1937 | new AsyncInitializeClone(this, clone, aReadOnly, aCallback); |
1938 | // Dispatch to our async thread, since the originating connection must remain |
1939 | // valid and open for the whole cloning process. This also ensures we are |
1940 | // properly serialized with a `close` operation, rather than race with it. |
1941 | nsCOMPtr<nsIEventTarget> target = getAsyncExecutionTarget(); |
1942 | if (!target) { |
1943 | return NS_ERROR_UNEXPECTED; |
1944 | } |
1945 | return target->Dispatch(initEvent, NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL); |
1946 | } |
1947 | |
1948 | nsresult Connection::initializeClone(Connection* aClone, bool aReadOnly) { |
1949 | nsresult rv; |
1950 | if (!mStorageKey.IsEmpty()) { |
1951 | rv = aClone->initialize(mStorageKey, mName); |
1952 | } else if (mFileURL) { |
1953 | rv = aClone->initialize(mFileURL); |
1954 | } else { |
1955 | rv = aClone->initialize(mDatabaseFile); |
1956 | } |
1957 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1958 | return rv; |
1959 | } |
1960 | |
1961 | auto guard = MakeScopeExit([&]() { aClone->initializeFailed(); }); |
1962 | |
1963 | rv = aClone->SetDefaultTransactionType(mDefaultTransactionType); |
1964 | 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/storage/mozStorageConnection.cpp" , 1964); return rv; } } while (false); |
1965 | |
1966 | // Re-attach on-disk databases that were attached to the original connection. |
1967 | { |
1968 | nsCOMPtr<mozIStorageStatement> stmt; |
1969 | rv = CreateStatement("PRAGMA database_list"_ns, getter_AddRefs(stmt)); |
1970 | 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/storage/mozStorageConnection.cpp" , 1970); return rv; } } while (false); |
1971 | bool hasResult = false; |
1972 | while (stmt && NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep (&hasResult))), 1))) && hasResult) { |
1973 | nsAutoCString name; |
1974 | rv = stmt->GetUTF8String(1, name); |
1975 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && !name.EqualsLiteral("main") && |
1976 | !name.EqualsLiteral("temp")) { |
1977 | nsCString path; |
1978 | rv = stmt->GetUTF8String(2, path); |
1979 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && !path.IsEmpty()) { |
1980 | nsCOMPtr<mozIStorageStatement> attachStmt; |
1981 | rv = aClone->CreateStatement("ATTACH DATABASE :path AS "_ns + name, |
1982 | getter_AddRefs(attachStmt)); |
1983 | 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/storage/mozStorageConnection.cpp" , 1983); return rv; } } while (false); |
1984 | rv = attachStmt->BindUTF8StringByName("path"_ns, path); |
1985 | 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/storage/mozStorageConnection.cpp" , 1985); return rv; } } while (false); |
1986 | rv = attachStmt->Execute(); |
1987 | 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/storage/mozStorageConnection.cpp" , 1987); return rv; } } while (false); |
1988 | } |
1989 | } |
1990 | } |
1991 | } |
1992 | |
1993 | // Copy over pragmas from the original connection. |
1994 | // LIMITATION WARNING! Many of these pragmas are actually scoped to the |
1995 | // schema ("main" and any other attached databases), and this implmentation |
1996 | // fails to propagate them. This is being addressed on trunk. |
1997 | static const char* pragmas[] = { |
1998 | "cache_size", "temp_store", "foreign_keys", "journal_size_limit", |
1999 | "synchronous", "wal_autocheckpoint", "busy_timeout"}; |
2000 | for (auto& pragma : pragmas) { |
2001 | // Read-only connections just need cache_size and temp_store pragmas. |
2002 | if (aReadOnly && ::strcmp(pragma, "cache_size") != 0 && |
2003 | ::strcmp(pragma, "temp_store") != 0) { |
2004 | continue; |
2005 | } |
2006 | |
2007 | nsAutoCString pragmaQuery("PRAGMA "); |
2008 | pragmaQuery.Append(pragma); |
2009 | nsCOMPtr<mozIStorageStatement> stmt; |
2010 | rv = CreateStatement(pragmaQuery, getter_AddRefs(stmt)); |
2011 | 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/storage/mozStorageConnection.cpp" , 2011); return rv; } } while (false); |
2012 | bool hasResult = false; |
2013 | if (stmt && NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep (&hasResult))), 1))) && hasResult) { |
2014 | pragmaQuery.AppendLiteral(" = "); |
2015 | pragmaQuery.AppendInt(stmt->AsInt32(0)); |
2016 | rv = aClone->ExecuteSimpleSQL(pragmaQuery); |
2017 | 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/storage/mozStorageConnection.cpp" , 2017); return rv; } } while (false); |
2018 | } |
2019 | } |
2020 | |
2021 | // Copy over temporary tables, triggers, and views from the original |
2022 | // connections. Entities in `sqlite_temp_master` are only visible to the |
2023 | // connection that created them. |
2024 | if (!aReadOnly) { |
2025 | rv = aClone->ExecuteSimpleSQL("BEGIN TRANSACTION"_ns); |
2026 | 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/storage/mozStorageConnection.cpp" , 2026); return rv; } } while (false); |
2027 | |
2028 | nsCOMPtr<mozIStorageStatement> stmt; |
2029 | rv = CreateStatement(nsLiteralCString("SELECT sql FROM sqlite_temp_master " |
2030 | "WHERE type IN ('table', 'view', " |
2031 | "'index', 'trigger')"), |
2032 | getter_AddRefs(stmt)); |
2033 | // Propagate errors, because failing to copy triggers might cause schema |
2034 | // coherency issues when writing to the database from the cloned connection. |
2035 | 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/storage/mozStorageConnection.cpp" , 2035); return rv; } } while (false); |
2036 | bool hasResult = false; |
2037 | while (stmt && NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep (&hasResult))), 1))) && hasResult) { |
2038 | nsAutoCString query; |
2039 | rv = stmt->GetUTF8String(0, query); |
2040 | 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/storage/mozStorageConnection.cpp" , 2040); return rv; } } while (false); |
2041 | |
2042 | // The `CREATE` SQL statements in `sqlite_temp_master` omit the `TEMP` |
2043 | // keyword. We need to add it back, or we'll recreate temporary entities |
2044 | // as persistent ones. `sqlite_temp_master` also holds `CREATE INDEX` |
2045 | // statements, but those don't need `TEMP` keywords. |
2046 | if (StringBeginsWith(query, "CREATE TABLE "_ns) || |
2047 | StringBeginsWith(query, "CREATE TRIGGER "_ns) || |
2048 | StringBeginsWith(query, "CREATE VIEW "_ns)) { |
2049 | query.Replace(0, 6, "CREATE TEMP"); |
2050 | } |
2051 | |
2052 | rv = aClone->ExecuteSimpleSQL(query); |
2053 | 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/storage/mozStorageConnection.cpp" , 2053); return rv; } } while (false); |
2054 | } |
2055 | |
2056 | rv = aClone->ExecuteSimpleSQL("COMMIT"_ns); |
2057 | 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/storage/mozStorageConnection.cpp" , 2057); return rv; } } while (false); |
2058 | } |
2059 | |
2060 | // Copy any functions that have been added to this connection. |
2061 | SQLiteMutexAutoLock lockedScope(sharedDBMutex); |
2062 | for (const auto& entry : mFunctions) { |
2063 | const nsACString& key = entry.GetKey(); |
2064 | Connection::FunctionInfo data = entry.GetData(); |
2065 | |
2066 | rv = aClone->CreateFunction(key, data.numArgs, data.function); |
2067 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2068 | NS_WARNING("Failed to copy function to cloned connection")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to copy function to cloned connection" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2068); |
2069 | } |
2070 | } |
2071 | |
2072 | // Load SQLite extensions that were on this connection. |
2073 | // Copy into an array rather than holding the mutex while we load extensions. |
2074 | nsTArray<nsCString> loadedExtensions; |
2075 | { |
2076 | MutexAutoLock lockedScope(sharedAsyncExecutionMutex); |
2077 | AppendToArray(loadedExtensions, mLoadedExtensions); |
2078 | } |
2079 | for (const auto& extension : loadedExtensions) { |
2080 | (void)aClone->LoadExtension(extension, nullptr); |
2081 | } |
2082 | |
2083 | guard.release(); |
2084 | return NS_OK; |
2085 | } |
2086 | |
2087 | NS_IMETHODIMPnsresult |
2088 | Connection::Clone(bool aReadOnly, mozIStorageConnection** _connection) { |
2089 | MOZ_ASSERT(IsOnCurrentSerialEventTarget(eventTargetOpenedOn))do { static_assert( mozilla::detail::AssertionConditionType< decltype(IsOnCurrentSerialEventTarget(eventTargetOpenedOn))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(IsOnCurrentSerialEventTarget(eventTargetOpenedOn)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2089); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 2089; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2090 | |
2091 | AUTO_PROFILER_LABEL("Connection::Clone", OTHER)mozilla::AutoProfilerLabel raiiObject2091( "Connection::Clone" , nullptr, JS::ProfilingCategoryPair::OTHER); |
2092 | |
2093 | if (!connectionReady()) { |
2094 | return NS_ERROR_NOT_INITIALIZED; |
2095 | } |
2096 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2097 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2098 | return rv; |
2099 | } |
2100 | |
2101 | int flags = mFlags; |
2102 | if (aReadOnly) { |
2103 | // Turn off SQLITE_OPEN_READWRITE, and set SQLITE_OPEN_READONLY. |
2104 | flags = (~SQLITE_OPEN_READWRITE0x00000002 & flags) | SQLITE_OPEN_READONLY0x00000001; |
2105 | // Turn off SQLITE_OPEN_CREATE. |
2106 | flags = (~SQLITE_OPEN_CREATE0x00000004 & flags); |
2107 | } |
2108 | |
2109 | RefPtr<Connection> clone = |
2110 | new Connection(mStorageService, flags, mSupportedOperations, |
2111 | mTelemetryFilename, mInterruptible); |
2112 | |
2113 | rv = initializeClone(clone, aReadOnly); |
2114 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2115 | return rv; |
2116 | } |
2117 | |
2118 | NS_IF_ADDREF(*_connection = clone)ns_if_addref(*_connection = clone); |
2119 | return NS_OK; |
2120 | } |
2121 | |
2122 | NS_IMETHODIMPnsresult |
2123 | Connection::Interrupt() { |
2124 | MOZ_ASSERT(mInterruptible, "Interrupt method not allowed")do { static_assert( mozilla::detail::AssertionConditionType< decltype(mInterruptible)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mInterruptible))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mInterruptible" " (" "Interrupt method not allowed" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2124); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mInterruptible" ") (" "Interrupt method not allowed" ")"); do { *((volatile int *)__null) = 2124; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
2125 | MOZ_ASSERT_IF(SYNCHRONOUS == mSupportedOperations,do { if (SYNCHRONOUS == mSupportedOperations) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(!IsOnCurrentSerialEventTarget (eventTargetOpenedOn))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!IsOnCurrentSerialEventTarget (eventTargetOpenedOn)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!IsOnCurrentSerialEventTarget(eventTargetOpenedOn)", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2126); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 2126; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
2126 | !IsOnCurrentSerialEventTarget(eventTargetOpenedOn))do { if (SYNCHRONOUS == mSupportedOperations) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(!IsOnCurrentSerialEventTarget (eventTargetOpenedOn))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!IsOnCurrentSerialEventTarget (eventTargetOpenedOn)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!IsOnCurrentSerialEventTarget(eventTargetOpenedOn)", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2126); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 2126; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
2127 | MOZ_ASSERT_IF(ASYNCHRONOUS == mSupportedOperations,do { if (ASYNCHRONOUS == mSupportedOperations) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(IsOnCurrentSerialEventTarget (eventTargetOpenedOn))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(IsOnCurrentSerialEventTarget (eventTargetOpenedOn)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("IsOnCurrentSerialEventTarget(eventTargetOpenedOn)", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2128); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 2128; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
2128 | IsOnCurrentSerialEventTarget(eventTargetOpenedOn))do { if (ASYNCHRONOUS == mSupportedOperations) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(IsOnCurrentSerialEventTarget (eventTargetOpenedOn))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(IsOnCurrentSerialEventTarget (eventTargetOpenedOn)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("IsOnCurrentSerialEventTarget(eventTargetOpenedOn)", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2128); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 2128; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
2129 | |
2130 | if (!connectionReady()) { |
2131 | return NS_ERROR_NOT_INITIALIZED; |
2132 | } |
2133 | |
2134 | if (isClosing()) { // Closing already in asynchronous case |
2135 | return NS_OK; |
2136 | } |
2137 | |
2138 | { |
2139 | // As stated on https://www.sqlite.org/c3ref/interrupt.html, |
2140 | // it is not safe to call sqlite3_interrupt() when |
2141 | // database connection is closed or might close before |
2142 | // sqlite3_interrupt() returns. |
2143 | MutexAutoLock lockedScope(sharedAsyncExecutionMutex); |
2144 | if (!isClosed(lockedScope)) { |
2145 | MOZ_ASSERT(mDBConn)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mDBConn)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mDBConn))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mDBConn", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2145); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mDBConn" ")" ); do { *((volatile int*)__null) = 2145; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2146 | ::sqlite3_interrupt(mDBConn); |
2147 | } |
2148 | } |
2149 | |
2150 | return NS_OK; |
2151 | } |
2152 | |
2153 | NS_IMETHODIMPnsresult |
2154 | Connection::AsyncVacuum(mozIStorageCompletionCallback* aCallback, |
2155 | bool aUseIncremental, int32_t aSetPageSize) { |
2156 | NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_NOT_SAME_THREAD)do { if ((__builtin_expect(!!(!(NS_IsMainThread())), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "NS_IsMainThread()" ") failed" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2156); return NS_ERROR_NOT_SAME_THREAD; } } while (false); |
2157 | // Abort if we're shutting down. |
2158 | if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) { |
2159 | return NS_ERROR_ABORT; |
2160 | } |
2161 | // Check if AsyncClose or Close were already invoked. |
2162 | if (!connectionReady()) { |
2163 | return NS_ERROR_NOT_INITIALIZED; |
2164 | } |
2165 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
2166 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2167 | return rv; |
2168 | } |
2169 | nsIEventTarget* asyncThread = getAsyncExecutionTarget(); |
2170 | if (!asyncThread) { |
2171 | return NS_ERROR_NOT_INITIALIZED; |
2172 | } |
2173 | |
2174 | // Create and dispatch our vacuum event to the background thread. |
2175 | nsCOMPtr<nsIRunnable> vacuumEvent = |
2176 | new AsyncVacuumEvent(this, aCallback, aUseIncremental, aSetPageSize); |
2177 | rv = asyncThread->Dispatch(vacuumEvent, NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL); |
2178 | 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/storage/mozStorageConnection.cpp" , 2178); return rv; } } while (false); |
2179 | |
2180 | return NS_OK; |
2181 | } |
2182 | |
2183 | NS_IMETHODIMPnsresult |
2184 | Connection::GetDefaultPageSize(int32_t* _defaultPageSize) { |
2185 | *_defaultPageSize = Service::kDefaultPageSize; |
2186 | return NS_OK; |
2187 | } |
2188 | |
2189 | NS_IMETHODIMPnsresult |
2190 | Connection::GetConnectionReady(bool* _ready) { |
2191 | MOZ_ASSERT(IsOnCurrentSerialEventTarget(eventTargetOpenedOn))do { static_assert( mozilla::detail::AssertionConditionType< decltype(IsOnCurrentSerialEventTarget(eventTargetOpenedOn))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(IsOnCurrentSerialEventTarget(eventTargetOpenedOn)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2191); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsOnCurrentSerialEventTarget(eventTargetOpenedOn)" ")"); do { *((volatile int*)__null) = 2191; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2192 | *_ready = connectionReady(); |
2193 | return NS_OK; |
2194 | } |
2195 | |
2196 | NS_IMETHODIMPnsresult |
2197 | Connection::GetDatabaseFile(nsIFile** _dbFile) { |
2198 | if (!connectionReady()) { |
2199 | return NS_ERROR_NOT_INITIALIZED; |
2200 | } |
2201 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
2202 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2203 | return rv; |
2204 | } |
2205 | |
2206 | NS_IF_ADDREF(*_dbFile = mDatabaseFile)ns_if_addref(*_dbFile = mDatabaseFile); |
2207 | |
2208 | return NS_OK; |
2209 | } |
2210 | |
2211 | NS_IMETHODIMPnsresult |
2212 | Connection::GetLastInsertRowID(int64_t* _id) { |
2213 | if (!connectionReady()) { |
2214 | return NS_ERROR_NOT_INITIALIZED; |
2215 | } |
2216 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2217 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2218 | return rv; |
2219 | } |
2220 | |
2221 | sqlite_int64 id = ::sqlite3_last_insert_rowid(mDBConn); |
2222 | *_id = id; |
2223 | |
2224 | return NS_OK; |
2225 | } |
2226 | |
2227 | NS_IMETHODIMPnsresult |
2228 | Connection::GetAffectedRows(int32_t* _rows) { |
2229 | if (!connectionReady()) { |
2230 | return NS_ERROR_NOT_INITIALIZED; |
2231 | } |
2232 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2233 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2234 | return rv; |
2235 | } |
2236 | |
2237 | *_rows = ::sqlite3_changes(mDBConn); |
2238 | |
2239 | return NS_OK; |
2240 | } |
2241 | |
2242 | NS_IMETHODIMPnsresult |
2243 | Connection::GetLastError(int32_t* _error) { |
2244 | if (!connectionReady()) { |
2245 | return NS_ERROR_NOT_INITIALIZED; |
2246 | } |
2247 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2248 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2249 | return rv; |
2250 | } |
2251 | |
2252 | *_error = ::sqlite3_errcode(mDBConn); |
2253 | |
2254 | return NS_OK; |
2255 | } |
2256 | |
2257 | NS_IMETHODIMPnsresult |
2258 | Connection::GetLastErrorString(nsACString& _errorString) { |
2259 | if (!connectionReady()) { |
2260 | return NS_ERROR_NOT_INITIALIZED; |
2261 | } |
2262 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2263 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2264 | return rv; |
2265 | } |
2266 | |
2267 | const char* serr = ::sqlite3_errmsg(mDBConn); |
2268 | _errorString.Assign(serr); |
2269 | |
2270 | return NS_OK; |
2271 | } |
2272 | |
2273 | NS_IMETHODIMPnsresult |
2274 | Connection::GetSchemaVersion(int32_t* _version) { |
2275 | if (!connectionReady()) { |
2276 | return NS_ERROR_NOT_INITIALIZED; |
2277 | } |
2278 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2279 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2280 | return rv; |
2281 | } |
2282 | |
2283 | nsCOMPtr<mozIStorageStatement> stmt; |
2284 | (void)CreateStatement("PRAGMA user_version"_ns, getter_AddRefs(stmt)); |
2285 | NS_ENSURE_TRUE(stmt, NS_ERROR_OUT_OF_MEMORY)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2285); return NS_ERROR_OUT_OF_MEMORY; } } while (false); |
2286 | |
2287 | *_version = 0; |
2288 | bool hasResult; |
2289 | if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep (&hasResult))), 1))) && hasResult) { |
2290 | *_version = stmt->AsInt32(0); |
2291 | } |
2292 | |
2293 | return NS_OK; |
2294 | } |
2295 | |
2296 | NS_IMETHODIMPnsresult |
2297 | Connection::SetSchemaVersion(int32_t aVersion) { |
2298 | if (!connectionReady()) { |
2299 | return NS_ERROR_NOT_INITIALIZED; |
2300 | } |
2301 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2302 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2303 | return rv; |
2304 | } |
2305 | |
2306 | nsAutoCString stmt("PRAGMA user_version = "_ns); |
2307 | stmt.AppendInt(aVersion); |
2308 | |
2309 | return ExecuteSimpleSQL(stmt); |
2310 | } |
2311 | |
2312 | NS_IMETHODIMPnsresult |
2313 | Connection::CreateStatement(const nsACString& aSQLStatement, |
2314 | mozIStorageStatement** _stmt) { |
2315 | NS_ENSURE_ARG_POINTER(_stmt)do { if ((__builtin_expect(!!(!(_stmt)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_stmt" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2315); return NS_ERROR_INVALID_POINTER; } } while (false); |
2316 | if (!connectionReady()) { |
2317 | return NS_ERROR_NOT_INITIALIZED; |
2318 | } |
2319 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2320 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2321 | return rv; |
2322 | } |
2323 | |
2324 | RefPtr<Statement> statement(new Statement()); |
2325 | NS_ENSURE_TRUE(statement, NS_ERROR_OUT_OF_MEMORY)do { if ((__builtin_expect(!!(!(statement)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "statement" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2325); return NS_ERROR_OUT_OF_MEMORY; } } while (false); |
2326 | |
2327 | rv = statement->initialize(this, mDBConn, aSQLStatement); |
2328 | 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/storage/mozStorageConnection.cpp" , 2328); return rv; } } while (false); |
2329 | |
2330 | Statement* rawPtr; |
2331 | statement.forget(&rawPtr); |
2332 | *_stmt = rawPtr; |
2333 | return NS_OK; |
2334 | } |
2335 | |
2336 | NS_IMETHODIMPnsresult |
2337 | Connection::CreateAsyncStatement(const nsACString& aSQLStatement, |
2338 | mozIStorageAsyncStatement** _stmt) { |
2339 | NS_ENSURE_ARG_POINTER(_stmt)do { if ((__builtin_expect(!!(!(_stmt)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_stmt" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2339); return NS_ERROR_INVALID_POINTER; } } while (false); |
2340 | if (!connectionReady()) { |
2341 | return NS_ERROR_NOT_INITIALIZED; |
2342 | } |
2343 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
2344 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2345 | return rv; |
2346 | } |
2347 | |
2348 | RefPtr<AsyncStatement> statement(new AsyncStatement()); |
2349 | NS_ENSURE_TRUE(statement, NS_ERROR_OUT_OF_MEMORY)do { if ((__builtin_expect(!!(!(statement)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "statement" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2349); return NS_ERROR_OUT_OF_MEMORY; } } while (false); |
2350 | |
2351 | rv = statement->initialize(this, mDBConn, aSQLStatement); |
2352 | 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/storage/mozStorageConnection.cpp" , 2352); return rv; } } while (false); |
2353 | |
2354 | AsyncStatement* rawPtr; |
2355 | statement.forget(&rawPtr); |
2356 | *_stmt = rawPtr; |
2357 | return NS_OK; |
2358 | } |
2359 | |
2360 | NS_IMETHODIMPnsresult |
2361 | Connection::ExecuteSimpleSQL(const nsACString& aSQLStatement) { |
2362 | CHECK_MAINTHREAD_ABUSE()do { do { if (!(eventTargetOpenedOn == GetMainThreadSerialEventTarget () || !NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_WARNING, "Using Storage synchronous API on main-thread, but " "the connection was opened on another thread.", "eventTargetOpenedOn == GetMainThreadSerialEventTarget() || !NS_IsMainThread()" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2362); } } while (false); } while (0); |
2363 | if (!connectionReady()) { |
2364 | return NS_ERROR_NOT_INITIALIZED; |
2365 | } |
2366 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2367 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2368 | return rv; |
2369 | } |
2370 | |
2371 | int srv = executeSql(mDBConn, PromiseFlatCStringTPromiseFlatString<char>(aSQLStatement).get()); |
2372 | return convertResultCode(srv); |
2373 | } |
2374 | |
2375 | NS_IMETHODIMPnsresult |
2376 | Connection::ExecuteAsync( |
2377 | const nsTArray<RefPtr<mozIStorageBaseStatement>>& aStatements, |
2378 | mozIStorageStatementCallback* aCallback, |
2379 | mozIStoragePendingStatement** _handle) { |
2380 | nsTArray<StatementData> stmts(aStatements.Length()); |
2381 | for (uint32_t i = 0; i < aStatements.Length(); i++) { |
2382 | nsCOMPtr<StorageBaseStatementInternal> stmt = |
2383 | do_QueryInterface(aStatements[i]); |
2384 | NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2384); return NS_ERROR_UNEXPECTED; } } while (false); |
2385 | |
2386 | // Obtain our StatementData. |
2387 | StatementData data; |
2388 | nsresult rv = stmt->getAsynchronousStatementData(data); |
2389 | 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/storage/mozStorageConnection.cpp" , 2389); return rv; } } while (false); |
2390 | |
2391 | NS_ASSERTION(stmt->getOwner() == this,do { if (!(stmt->getOwner() == this)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Statement must be from this database connection!", "stmt->getOwner() == this" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2392); MOZ_PretendNoReturn(); } } while (0) |
2392 | "Statement must be from this database connection!")do { if (!(stmt->getOwner() == this)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Statement must be from this database connection!", "stmt->getOwner() == this" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2392); MOZ_PretendNoReturn(); } } while (0); |
2393 | |
2394 | // Now append it to our array. |
2395 | stmts.AppendElement(data); |
2396 | } |
2397 | |
2398 | // Dispatch to the background |
2399 | return AsyncExecuteStatements::execute(std::move(stmts), this, mDBConn, |
2400 | aCallback, _handle); |
2401 | } |
2402 | |
2403 | NS_IMETHODIMPnsresult |
2404 | Connection::ExecuteSimpleSQLAsync(const nsACString& aSQLStatement, |
2405 | mozIStorageStatementCallback* aCallback, |
2406 | mozIStoragePendingStatement** _handle) { |
2407 | NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_NOT_SAME_THREAD)do { if ((__builtin_expect(!!(!(NS_IsMainThread())), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "NS_IsMainThread()" ") failed" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2407); return NS_ERROR_NOT_SAME_THREAD; } } while (false); |
2408 | |
2409 | nsCOMPtr<mozIStorageAsyncStatement> stmt; |
2410 | nsresult rv = CreateAsyncStatement(aSQLStatement, getter_AddRefs(stmt)); |
2411 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2412 | return rv; |
2413 | } |
2414 | |
2415 | nsCOMPtr<mozIStoragePendingStatement> pendingStatement; |
2416 | rv = stmt->ExecuteAsync(aCallback, getter_AddRefs(pendingStatement)); |
2417 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2418 | return rv; |
2419 | } |
2420 | |
2421 | pendingStatement.forget(_handle); |
2422 | return rv; |
2423 | } |
2424 | |
2425 | NS_IMETHODIMPnsresult |
2426 | Connection::TableExists(const nsACString& aTableName, bool* _exists) { |
2427 | return databaseElementExists(TABLE, aTableName, _exists); |
2428 | } |
2429 | |
2430 | NS_IMETHODIMPnsresult |
2431 | Connection::IndexExists(const nsACString& aIndexName, bool* _exists) { |
2432 | return databaseElementExists(INDEX, aIndexName, _exists); |
2433 | } |
2434 | |
2435 | NS_IMETHODIMPnsresult |
2436 | Connection::GetTransactionInProgress(bool* _inProgress) { |
2437 | if (!connectionReady()) { |
2438 | return NS_ERROR_NOT_INITIALIZED; |
2439 | } |
2440 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
2441 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2442 | return rv; |
2443 | } |
2444 | |
2445 | SQLiteMutexAutoLock lockedScope(sharedDBMutex); |
2446 | *_inProgress = transactionInProgress(lockedScope); |
2447 | return NS_OK; |
2448 | } |
2449 | |
2450 | NS_IMETHODIMPnsresult |
2451 | Connection::GetDefaultTransactionType(int32_t* _type) { |
2452 | *_type = mDefaultTransactionType; |
2453 | return NS_OK; |
2454 | } |
2455 | |
2456 | NS_IMETHODIMPnsresult |
2457 | Connection::SetDefaultTransactionType(int32_t aType) { |
2458 | NS_ENSURE_ARG_RANGE(aType, TRANSACTION_DEFERRED, TRANSACTION_EXCLUSIVE)do { if ((__builtin_expect(!!(!(((aType) >= TRANSACTION_DEFERRED ) && ((aType) <= TRANSACTION_EXCLUSIVE))), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "((aType) >= TRANSACTION_DEFERRED) && ((aType) <= TRANSACTION_EXCLUSIVE)" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2458); return NS_ERROR_INVALID_ARG; } } while (false); |
2459 | mDefaultTransactionType = aType; |
2460 | return NS_OK; |
2461 | } |
2462 | |
2463 | NS_IMETHODIMPnsresult |
2464 | Connection::GetVariableLimit(int32_t* _limit) { |
2465 | if (!connectionReady()) { |
2466 | return NS_ERROR_NOT_INITIALIZED; |
2467 | } |
2468 | int limit = ::sqlite3_limit(mDBConn, SQLITE_LIMIT_VARIABLE_NUMBER9, -1); |
2469 | if (limit < 0) { |
2470 | return NS_ERROR_UNEXPECTED; |
2471 | } |
2472 | *_limit = limit; |
2473 | return NS_OK; |
2474 | } |
2475 | |
2476 | NS_IMETHODIMPnsresult |
2477 | Connection::SetVariableLimit(int32_t limit) { |
2478 | if (!connectionReady()) { |
2479 | return NS_ERROR_NOT_INITIALIZED; |
2480 | } |
2481 | int oldLimit = ::sqlite3_limit(mDBConn, SQLITE_LIMIT_VARIABLE_NUMBER9, limit); |
2482 | if (oldLimit < 0) { |
2483 | return NS_ERROR_UNEXPECTED; |
2484 | } |
2485 | return NS_OK; |
2486 | } |
2487 | |
2488 | NS_IMETHODIMPnsresult |
2489 | Connection::BeginTransaction() { |
2490 | if (!connectionReady()) { |
2491 | return NS_ERROR_NOT_INITIALIZED; |
2492 | } |
2493 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2494 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2495 | return rv; |
2496 | } |
2497 | |
2498 | SQLiteMutexAutoLock lockedScope(sharedDBMutex); |
2499 | return beginTransactionInternal(lockedScope, mDBConn, |
2500 | mDefaultTransactionType); |
2501 | } |
2502 | |
2503 | nsresult Connection::beginTransactionInternal( |
2504 | const SQLiteMutexAutoLock& aProofOfLock, sqlite3* aNativeConnection, |
2505 | int32_t aTransactionType) { |
2506 | if (transactionInProgress(aProofOfLock)) { |
2507 | return NS_ERROR_FAILURE; |
2508 | } |
2509 | nsresult rv; |
2510 | switch (aTransactionType) { |
2511 | case TRANSACTION_DEFERRED: |
2512 | rv = convertResultCode(executeSql(aNativeConnection, "BEGIN DEFERRED")); |
2513 | break; |
2514 | case TRANSACTION_IMMEDIATE: |
2515 | rv = convertResultCode(executeSql(aNativeConnection, "BEGIN IMMEDIATE")); |
2516 | break; |
2517 | case TRANSACTION_EXCLUSIVE: |
2518 | rv = convertResultCode(executeSql(aNativeConnection, "BEGIN EXCLUSIVE")); |
2519 | break; |
2520 | default: |
2521 | return NS_ERROR_ILLEGAL_VALUE; |
2522 | } |
2523 | return rv; |
2524 | } |
2525 | |
2526 | NS_IMETHODIMPnsresult |
2527 | Connection::CommitTransaction() { |
2528 | if (!connectionReady()) { |
2529 | return NS_ERROR_NOT_INITIALIZED; |
2530 | } |
2531 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2532 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2533 | return rv; |
2534 | } |
2535 | |
2536 | SQLiteMutexAutoLock lockedScope(sharedDBMutex); |
2537 | return commitTransactionInternal(lockedScope, mDBConn); |
2538 | } |
2539 | |
2540 | nsresult Connection::commitTransactionInternal( |
2541 | const SQLiteMutexAutoLock& aProofOfLock, sqlite3* aNativeConnection) { |
2542 | if (!transactionInProgress(aProofOfLock)) { |
2543 | return NS_ERROR_UNEXPECTED; |
2544 | } |
2545 | nsresult rv = |
2546 | convertResultCode(executeSql(aNativeConnection, "COMMIT TRANSACTION")); |
2547 | return rv; |
2548 | } |
2549 | |
2550 | NS_IMETHODIMPnsresult |
2551 | Connection::RollbackTransaction() { |
2552 | if (!connectionReady()) { |
2553 | return NS_ERROR_NOT_INITIALIZED; |
2554 | } |
2555 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2556 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2557 | return rv; |
2558 | } |
2559 | |
2560 | SQLiteMutexAutoLock lockedScope(sharedDBMutex); |
2561 | return rollbackTransactionInternal(lockedScope, mDBConn); |
2562 | } |
2563 | |
2564 | nsresult Connection::rollbackTransactionInternal( |
2565 | const SQLiteMutexAutoLock& aProofOfLock, sqlite3* aNativeConnection) { |
2566 | if (!transactionInProgress(aProofOfLock)) { |
2567 | return NS_ERROR_UNEXPECTED; |
2568 | } |
2569 | |
2570 | nsresult rv = |
2571 | convertResultCode(executeSql(aNativeConnection, "ROLLBACK TRANSACTION")); |
2572 | return rv; |
2573 | } |
2574 | |
2575 | NS_IMETHODIMPnsresult |
2576 | Connection::CreateTable(const char* aTableName, const char* aTableSchema) { |
2577 | if (!connectionReady()) { |
2578 | return NS_ERROR_NOT_INITIALIZED; |
2579 | } |
2580 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2581 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2582 | return rv; |
2583 | } |
2584 | |
2585 | SmprintfPointer buf = |
2586 | ::mozilla::Smprintf("CREATE TABLE %s (%s)", aTableName, aTableSchema); |
2587 | if (!buf) return NS_ERROR_OUT_OF_MEMORY; |
2588 | |
2589 | int srv = executeSql(mDBConn, buf.get()); |
2590 | |
2591 | return convertResultCode(srv); |
2592 | } |
2593 | |
2594 | NS_IMETHODIMPnsresult |
2595 | Connection::CreateFunction(const nsACString& aFunctionName, |
2596 | int32_t aNumArguments, |
2597 | mozIStorageFunction* aFunction) { |
2598 | if (!connectionReady()) { |
2599 | return NS_ERROR_NOT_INITIALIZED; |
2600 | } |
2601 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
2602 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2603 | return rv; |
2604 | } |
2605 | |
2606 | // Check to see if this function is already defined. We only check the name |
2607 | // because a function can be defined with the same body but different names. |
2608 | SQLiteMutexAutoLock lockedScope(sharedDBMutex); |
2609 | NS_ENSURE_FALSE(mFunctions.Contains(aFunctionName), NS_ERROR_FAILURE)do { if ((__builtin_expect(!!(!(!(mFunctions.Contains(aFunctionName )))), 0))) { NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "!(mFunctions.Contains(aFunctionName))" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2609); return NS_ERROR_FAILURE; } } while (false); |
2610 | |
2611 | int srv = ::sqlite3_create_function( |
2612 | mDBConn, nsPromiseFlatCString(aFunctionName).get(), aNumArguments, |
2613 | SQLITE_ANY5, aFunction, basicFunctionHelper, nullptr, nullptr); |
2614 | if (srv != SQLITE_OK0) return convertResultCode(srv); |
2615 | |
2616 | FunctionInfo info = {aFunction, aNumArguments}; |
2617 | mFunctions.InsertOrUpdate(aFunctionName, info); |
2618 | |
2619 | return NS_OK; |
2620 | } |
2621 | |
2622 | NS_IMETHODIMPnsresult |
2623 | Connection::RemoveFunction(const nsACString& aFunctionName) { |
2624 | if (!connectionReady()) { |
2625 | return NS_ERROR_NOT_INITIALIZED; |
2626 | } |
2627 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
2628 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2629 | return rv; |
2630 | } |
2631 | |
2632 | SQLiteMutexAutoLock lockedScope(sharedDBMutex); |
2633 | NS_ENSURE_TRUE(mFunctions.Get(aFunctionName, nullptr), NS_ERROR_FAILURE)do { if ((__builtin_expect(!!(!(mFunctions.Get(aFunctionName, nullptr))), 0))) { NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "mFunctions.Get(aFunctionName, nullptr)" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2633); return NS_ERROR_FAILURE; } } while (false); |
2634 | |
2635 | int srv = ::sqlite3_create_function( |
2636 | mDBConn, nsPromiseFlatCString(aFunctionName).get(), 0, SQLITE_ANY5, |
2637 | nullptr, nullptr, nullptr, nullptr); |
2638 | if (srv != SQLITE_OK0) return convertResultCode(srv); |
2639 | |
2640 | mFunctions.Remove(aFunctionName); |
2641 | |
2642 | return NS_OK; |
2643 | } |
2644 | |
2645 | NS_IMETHODIMPnsresult |
2646 | Connection::SetProgressHandler(int32_t aGranularity, |
2647 | mozIStorageProgressHandler* aHandler, |
2648 | mozIStorageProgressHandler** _oldHandler) { |
2649 | if (!connectionReady()) { |
2650 | return NS_ERROR_NOT_INITIALIZED; |
2651 | } |
2652 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
2653 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2654 | return rv; |
2655 | } |
2656 | |
2657 | // Return previous one |
2658 | SQLiteMutexAutoLock lockedScope(sharedDBMutex); |
2659 | NS_IF_ADDREF(*_oldHandler = mProgressHandler)ns_if_addref(*_oldHandler = mProgressHandler); |
2660 | |
2661 | if (!aHandler || aGranularity <= 0) { |
2662 | aHandler = nullptr; |
2663 | aGranularity = 0; |
2664 | } |
2665 | mProgressHandler = aHandler; |
2666 | ::sqlite3_progress_handler(mDBConn, aGranularity, sProgressHelper, this); |
2667 | |
2668 | return NS_OK; |
2669 | } |
2670 | |
2671 | NS_IMETHODIMPnsresult |
2672 | Connection::RemoveProgressHandler(mozIStorageProgressHandler** _oldHandler) { |
2673 | if (!connectionReady()) { |
2674 | return NS_ERROR_NOT_INITIALIZED; |
2675 | } |
2676 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
2677 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2678 | return rv; |
2679 | } |
2680 | |
2681 | // Return previous one |
2682 | SQLiteMutexAutoLock lockedScope(sharedDBMutex); |
2683 | NS_IF_ADDREF(*_oldHandler = mProgressHandler)ns_if_addref(*_oldHandler = mProgressHandler); |
2684 | |
2685 | mProgressHandler = nullptr; |
2686 | ::sqlite3_progress_handler(mDBConn, 0, nullptr, nullptr); |
2687 | |
2688 | return NS_OK; |
2689 | } |
2690 | |
2691 | NS_IMETHODIMPnsresult |
2692 | Connection::SetGrowthIncrement(int32_t aChunkSize, |
2693 | const nsACString& aDatabaseName) { |
2694 | if (!connectionReady()) { |
2695 | return NS_ERROR_NOT_INITIALIZED; |
2696 | } |
2697 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2698 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2699 | return rv; |
2700 | } |
2701 | |
2702 | // Bug 597215: Disk space is extremely limited on Android |
2703 | // so don't preallocate space. This is also not effective |
2704 | // on log structured file systems used by Android devices |
2705 | #if !defined(ANDROID) && !defined(MOZ_PLATFORM_MAEMO) |
2706 | // Don't preallocate if less than 500MiB is available. |
2707 | int64_t bytesAvailable; |
2708 | rv = mDatabaseFile->GetDiskSpaceAvailable(&bytesAvailable); |
2709 | 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/storage/mozStorageConnection.cpp" , 2709); return rv; } } while (false); |
2710 | if (bytesAvailable < MIN_AVAILABLE_BYTES_PER_CHUNKED_GROWTH524288000) { |
2711 | return NS_ERROR_FILE_TOO_BIG; |
2712 | } |
2713 | |
2714 | int srv = ::sqlite3_file_control( |
2715 | mDBConn, |
2716 | aDatabaseName.Length() ? nsPromiseFlatCString(aDatabaseName).get() |
2717 | : nullptr, |
2718 | SQLITE_FCNTL_CHUNK_SIZE6, &aChunkSize); |
2719 | if (srv == SQLITE_OK0) { |
2720 | mGrowthChunkSize = aChunkSize; |
2721 | } |
2722 | #endif |
2723 | return NS_OK; |
2724 | } |
2725 | |
2726 | int32_t Connection::RemovablePagesInFreeList(const nsACString& aSchemaName) { |
2727 | int32_t freeListPagesCount = 0; |
2728 | if (!isConnectionReadyOnThisThread()) { |
2729 | MOZ_ASSERT(false, "Database connection is not ready")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Database connection is not ready" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2729); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Database connection is not ready" ")"); do { *((volatile int *)__null) = 2729; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
2730 | return freeListPagesCount; |
2731 | } |
2732 | { |
2733 | nsAutoCString query(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" " */ " "PRAGMA "); |
2734 | query.Append(aSchemaName); |
2735 | query.AppendLiteral(".freelist_count"); |
2736 | nsCOMPtr<mozIStorageStatement> stmt; |
2737 | DebugOnly<nsresult> rv = CreateStatement(query, getter_AddRefs(stmt)); |
2738 | 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/storage/mozStorageConnection.cpp" , 2738); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 2738; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2739 | bool hasResult = false; |
2740 | if (stmt && NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep (&hasResult))), 1))) && hasResult) { |
2741 | freeListPagesCount = stmt->AsInt32(0); |
2742 | } |
2743 | } |
2744 | // If there's no chunk size set, any page is good to be removed. |
2745 | if (mGrowthChunkSize == 0 || freeListPagesCount == 0) { |
2746 | return freeListPagesCount; |
2747 | } |
2748 | int32_t pageSize; |
2749 | { |
2750 | nsAutoCString query(MOZ_STORAGE_UNIQUIFY_QUERY_STR"/* " "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" " */ " "PRAGMA "); |
2751 | query.Append(aSchemaName); |
2752 | query.AppendLiteral(".page_size"); |
2753 | nsCOMPtr<mozIStorageStatement> stmt; |
2754 | DebugOnly<nsresult> rv = CreateStatement(query, getter_AddRefs(stmt)); |
2755 | 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/storage/mozStorageConnection.cpp" , 2755); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { *((volatile int*)__null) = 2755; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2756 | bool hasResult = false; |
2757 | if (stmt && NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep (&hasResult))), 1))) && hasResult) { |
2758 | pageSize = stmt->AsInt32(0); |
2759 | } else { |
2760 | MOZ_ASSERT(false, "Couldn't get page_size")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Couldn't get page_size" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2760); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Couldn't get page_size" ")"); do { *((volatile int*)__null) = 2760; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
2761 | return 0; |
2762 | } |
2763 | } |
2764 | return std::max(0, freeListPagesCount - (mGrowthChunkSize / pageSize)); |
2765 | } |
2766 | |
2767 | NS_IMETHODIMPnsresult |
2768 | Connection::LoadExtension(const nsACString& aExtensionName, |
2769 | mozIStorageCompletionCallback* aCallback) { |
2770 | AUTO_PROFILER_LABEL("Connection::LoadExtension", OTHER)mozilla::AutoProfilerLabel raiiObject2770( "Connection::LoadExtension" , nullptr, JS::ProfilingCategoryPair::OTHER); |
2771 | |
2772 | // This is a static list of extensions we can load. |
2773 | // Please use lowercase ASCII names and keep this list alphabetically ordered. |
2774 | static constexpr nsLiteralCString sSupportedExtensions[] = { |
2775 | // clang-format off |
2776 | "fts5"_ns, |
2777 | // clang-format on |
2778 | }; |
2779 | if (std::find(std::begin(sSupportedExtensions), |
2780 | std::end(sSupportedExtensions), |
2781 | aExtensionName) == std::end(sSupportedExtensions)) { |
2782 | return NS_ERROR_INVALID_ARG; |
2783 | } |
2784 | |
2785 | if (!connectionReady()) { |
2786 | return NS_ERROR_NOT_INITIALIZED; |
2787 | } |
2788 | |
2789 | int srv = ::sqlite3_db_config(mDBConn, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION1005, |
2790 | 1, nullptr); |
2791 | if (srv != SQLITE_OK0) { |
2792 | return NS_ERROR_UNEXPECTED; |
2793 | } |
2794 | |
2795 | // Track the loaded extension for later connection cloning operations. |
2796 | { |
2797 | MutexAutoLock lockedScope(sharedAsyncExecutionMutex); |
2798 | if (!mLoadedExtensions.EnsureInserted(aExtensionName)) { |
2799 | // Already loaded, bail out but issue a warning. |
2800 | NS_WARNING(nsPrintfCString(NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString( "Tried to register '%s' SQLite extension multiple times!" , TPromiseFlatString<char>(aExtensionName).get()) .get( ), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2803) |
2801 | "Tried to register '%s' SQLite extension multiple times!",NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString( "Tried to register '%s' SQLite extension multiple times!" , TPromiseFlatString<char>(aExtensionName).get()) .get( ), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2803) |
2802 | PromiseFlatCString(aExtensionName).get())NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString( "Tried to register '%s' SQLite extension multiple times!" , TPromiseFlatString<char>(aExtensionName).get()) .get( ), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2803) |
2803 | .get())NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString( "Tried to register '%s' SQLite extension multiple times!" , TPromiseFlatString<char>(aExtensionName).get()) .get( ), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2803); |
2804 | return NS_OK; |
2805 | } |
2806 | } |
2807 | |
2808 | nsAutoCString entryPoint("sqlite3_"); |
2809 | entryPoint.Append(aExtensionName); |
2810 | entryPoint.AppendLiteral("_init"); |
2811 | |
2812 | RefPtr<Runnable> loadTask = NS_NewRunnableFunction( |
2813 | "mozStorageConnection::LoadExtension", |
2814 | [this, self = RefPtr(this), entryPoint, |
2815 | callback = RefPtr(aCallback)]() mutable { |
2816 | MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType< decltype(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ()))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ())))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" " (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2821); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" ") (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")"); do { *((volatile int*)__null ) = 2821; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false) |
2817 | !NS_IsMainThread() ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ()))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ())))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" " (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2821); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" ") (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")"); do { *((volatile int*)__null ) = 2821; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false) |
2818 | (operationSupported(Connection::SYNCHRONOUS) &&do { static_assert( mozilla::detail::AssertionConditionType< decltype(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ()))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ())))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" " (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2821); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" ") (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")"); do { *((volatile int*)__null ) = 2821; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false) |
2819 | eventTargetOpenedOn == GetMainThreadSerialEventTarget()),do { static_assert( mozilla::detail::AssertionConditionType< decltype(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ()))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ())))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" " (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2821); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" ") (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")"); do { *((volatile int*)__null ) = 2821; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false) |
2820 | "Should happen on main-thread only for synchronous connections "do { static_assert( mozilla::detail::AssertionConditionType< decltype(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ()))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ())))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" " (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2821); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" ") (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")"); do { *((volatile int*)__null ) = 2821; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false) |
2821 | "opened on the main thread")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ()))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!NS_IsMainThread() || (operationSupported(Connection ::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget ())))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" " (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2821); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!NS_IsMainThread() || (operationSupported(Connection::SYNCHRONOUS) && eventTargetOpenedOn == GetMainThreadSerialEventTarget())" ") (" "Should happen on main-thread only for synchronous connections " "opened on the main thread" ")"); do { *((volatile int*)__null ) = 2821; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false); |
2822 | #ifdef MOZ_FOLD_LIBS |
2823 | int srv = ::sqlite3_load_extension(mDBConn, |
2824 | MOZ_DLL_PREFIX"lib" "nss3" MOZ_DLL_SUFFIX".so", |
2825 | entryPoint.get(), nullptr); |
2826 | #else |
2827 | int srv = ::sqlite3_load_extension( |
2828 | mDBConn, MOZ_DLL_PREFIX"lib" "mozsqlite3" MOZ_DLL_SUFFIX".so", |
2829 | entryPoint.get(), nullptr); |
2830 | #endif |
2831 | if (!callback) { |
2832 | return; |
2833 | }; |
2834 | RefPtr<Runnable> callbackTask = NS_NewRunnableFunction( |
2835 | "mozStorageConnection::LoadExtension_callback", |
2836 | [callback = std::move(callback), srv]() { |
2837 | (void)callback->Complete(convertResultCode(srv), nullptr); |
2838 | }); |
2839 | if (IsOnCurrentSerialEventTarget(eventTargetOpenedOn)) { |
2840 | MOZ_ALWAYS_SUCCEEDS(callbackTask->Run())do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (callbackTask->Run())), 1)))), 1))) { } else { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(false)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("false" " (" "NS_SUCCEEDED(callbackTask->Run())" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2840); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(callbackTask->Run())" ")"); do { *((volatile int*)__null) = 2840; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } } while (false); |
2841 | } else { |
2842 | // Redispatch the callback to the calling thread. |
2843 | MOZ_ALWAYS_SUCCEEDS(eventTargetOpenedOn->Dispatch(do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (eventTargetOpenedOn->Dispatch( callbackTask.forget(), nsIEventTarget ::DISPATCH_NORMAL))), 1)))), 1))) { } else { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(false)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("false" " (" "NS_SUCCEEDED(eventTargetOpenedOn->Dispatch( callbackTask.forget(), nsIEventTarget::DISPATCH_NORMAL))" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2844); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(eventTargetOpenedOn->Dispatch( callbackTask.forget(), nsIEventTarget::DISPATCH_NORMAL))" ")"); do { *((volatile int*)__null) = 2844; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
2844 | callbackTask.forget(), NS_DISPATCH_NORMAL))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (eventTargetOpenedOn->Dispatch( callbackTask.forget(), nsIEventTarget ::DISPATCH_NORMAL))), 1)))), 1))) { } else { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(false)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("false" " (" "NS_SUCCEEDED(eventTargetOpenedOn->Dispatch( callbackTask.forget(), nsIEventTarget::DISPATCH_NORMAL))" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2844); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(eventTargetOpenedOn->Dispatch( callbackTask.forget(), nsIEventTarget::DISPATCH_NORMAL))" ")"); do { *((volatile int*)__null) = 2844; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
2845 | } |
2846 | }); |
2847 | |
2848 | if (NS_IsMainThread() && !operationSupported(Connection::SYNCHRONOUS)) { |
2849 | // This is a main-thread call to an async-only connection, thus we should |
2850 | // load the library in the helper thread. |
2851 | nsIEventTarget* helperThread = getAsyncExecutionTarget(); |
2852 | if (!helperThread) { |
2853 | return NS_ERROR_NOT_INITIALIZED; |
2854 | } |
2855 | MOZ_ALWAYS_SUCCEEDS(do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (helperThread->Dispatch(loadTask.forget(), nsIEventTarget:: DISPATCH_NORMAL))), 1)))), 1))) { } else { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(false)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("false" " (" "NS_SUCCEEDED(helperThread->Dispatch(loadTask.forget(), nsIEventTarget::DISPATCH_NORMAL))" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2856); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(helperThread->Dispatch(loadTask.forget(), nsIEventTarget::DISPATCH_NORMAL))" ")"); do { *((volatile int*)__null) = 2856; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
2856 | helperThread->Dispatch(loadTask.forget(), NS_DISPATCH_NORMAL))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (helperThread->Dispatch(loadTask.forget(), nsIEventTarget:: DISPATCH_NORMAL))), 1)))), 1))) { } else { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(false)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("false" " (" "NS_SUCCEEDED(helperThread->Dispatch(loadTask.forget(), nsIEventTarget::DISPATCH_NORMAL))" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2856); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(helperThread->Dispatch(loadTask.forget(), nsIEventTarget::DISPATCH_NORMAL))" ")"); do { *((volatile int*)__null) = 2856; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
2857 | } else { |
2858 | // In any other case we just load the extension on the current thread. |
2859 | MOZ_ALWAYS_SUCCEEDS(loadTask->Run())do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (loadTask->Run())), 1)))), 1))) { } else { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(false)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("false" " (" "NS_SUCCEEDED(loadTask->Run())" ")", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2859); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false" ") (" "NS_SUCCEEDED(loadTask->Run())" ")"); do { *((volatile int*)__null) = 2859; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } } while (false); |
2860 | } |
2861 | return NS_OK; |
2862 | } |
2863 | |
2864 | NS_IMETHODIMPnsresult |
2865 | Connection::EnableModule(const nsACString& aModuleName) { |
2866 | if (!connectionReady()) { |
2867 | return NS_ERROR_NOT_INITIALIZED; |
2868 | } |
2869 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2870 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2871 | return rv; |
2872 | } |
2873 | |
2874 | for (auto& gModule : gModules) { |
2875 | struct Module* m = &gModule; |
2876 | if (aModuleName.Equals(m->name)) { |
2877 | int srv = m->registerFunc(mDBConn, m->name); |
2878 | if (srv != SQLITE_OK0) return convertResultCode(srv); |
2879 | |
2880 | return NS_OK; |
2881 | } |
2882 | } |
2883 | |
2884 | return NS_ERROR_FAILURE; |
2885 | } |
2886 | |
2887 | NS_IMETHODIMPnsresult |
2888 | Connection::GetQuotaObjects(QuotaObject** aDatabaseQuotaObject, |
2889 | QuotaObject** aJournalQuotaObject) { |
2890 | MOZ_ASSERT(aDatabaseQuotaObject)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aDatabaseQuotaObject)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aDatabaseQuotaObject))), 0)) ) { do { } while (false); MOZ_ReportAssertionFailure("aDatabaseQuotaObject" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2890); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDatabaseQuotaObject" ")"); do { *((volatile int*)__null) = 2890; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2891 | MOZ_ASSERT(aJournalQuotaObject)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aJournalQuotaObject)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aJournalQuotaObject))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aJournalQuotaObject" , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2891); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aJournalQuotaObject" ")"); do { *((volatile int*)__null) = 2891; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2892 | |
2893 | if (!connectionReady()) { |
2894 | return NS_ERROR_NOT_INITIALIZED; |
2895 | } |
2896 | nsresult rv = ensureOperationSupported(SYNCHRONOUS); |
2897 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2898 | return rv; |
2899 | } |
2900 | |
2901 | sqlite3_file* file; |
2902 | int srv = ::sqlite3_file_control(mDBConn, nullptr, SQLITE_FCNTL_FILE_POINTER7, |
2903 | &file); |
2904 | if (srv != SQLITE_OK0) { |
2905 | return convertResultCode(srv); |
2906 | } |
2907 | |
2908 | sqlite3_vfs* vfs; |
2909 | srv = |
2910 | ::sqlite3_file_control(mDBConn, nullptr, SQLITE_FCNTL_VFS_POINTER27, &vfs); |
2911 | if (srv != SQLITE_OK0) { |
2912 | return convertResultCode(srv); |
2913 | } |
2914 | |
2915 | bool obfusactingVFS = false; |
2916 | |
2917 | { |
2918 | const nsDependentCString vfsName{vfs->zName}; |
2919 | |
2920 | if (vfsName == obfsvfs::GetVFSName()) { |
2921 | obfusactingVFS = true; |
2922 | } else if (vfsName != quotavfs::GetVFSName()) { |
2923 | NS_WARNING("Got unexpected vfs")NS_DebugBreak(NS_DEBUG_WARNING, "Got unexpected vfs", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2923); |
2924 | return NS_ERROR_FAILURE; |
2925 | } |
2926 | } |
2927 | |
2928 | RefPtr<QuotaObject> databaseQuotaObject = |
2929 | GetQuotaObject(file, obfusactingVFS); |
2930 | if (NS_WARN_IF(!databaseQuotaObject)NS_warn_if_impl(!databaseQuotaObject, "!databaseQuotaObject", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2930)) { |
2931 | return NS_ERROR_FAILURE; |
2932 | } |
2933 | |
2934 | srv = ::sqlite3_file_control(mDBConn, nullptr, SQLITE_FCNTL_JOURNAL_POINTER28, |
2935 | &file); |
2936 | if (srv != SQLITE_OK0) { |
2937 | return convertResultCode(srv); |
2938 | } |
2939 | |
2940 | RefPtr<QuotaObject> journalQuotaObject = GetQuotaObject(file, obfusactingVFS); |
2941 | if (NS_WARN_IF(!journalQuotaObject)NS_warn_if_impl(!journalQuotaObject, "!journalQuotaObject", "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2941)) { |
2942 | return NS_ERROR_FAILURE; |
2943 | } |
2944 | |
2945 | databaseQuotaObject.forget(aDatabaseQuotaObject); |
2946 | journalQuotaObject.forget(aJournalQuotaObject); |
2947 | return NS_OK; |
2948 | } |
2949 | |
2950 | SQLiteMutex& Connection::GetSharedDBMutex() { return sharedDBMutex; } |
2951 | |
2952 | uint32_t Connection::GetTransactionNestingLevel( |
2953 | const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) { |
2954 | return mTransactionNestingLevel; |
2955 | } |
2956 | |
2957 | uint32_t Connection::IncreaseTransactionNestingLevel( |
2958 | const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) { |
2959 | return ++mTransactionNestingLevel; |
2960 | } |
2961 | |
2962 | uint32_t Connection::DecreaseTransactionNestingLevel( |
2963 | const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) { |
2964 | return --mTransactionNestingLevel; |
2965 | } |
2966 | |
2967 | NS_IMETHODIMPnsresult |
2968 | Connection::BackupToFileAsync(nsIFile* aDestinationFile, |
2969 | mozIStorageCompletionCallback* aCallback, |
2970 | uint32_t aPagesPerStep, uint32_t aStepDelayMs) { |
2971 | NS_ENSURE_ARG(aDestinationFile)do { if ((__builtin_expect(!!(!(aDestinationFile)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aDestinationFile" ") failed" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2971); return NS_ERROR_INVALID_ARG; } } while (false); |
2972 | NS_ENSURE_ARG(aCallback)do { if ((__builtin_expect(!!(!(aCallback)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aCallback" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2972); return NS_ERROR_INVALID_ARG; } } while (false); |
2973 | NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_NOT_SAME_THREAD)do { if ((__builtin_expect(!!(!(NS_IsMainThread())), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "NS_IsMainThread()" ") failed" , nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/storage/mozStorageConnection.cpp" , 2973); return NS_ERROR_NOT_SAME_THREAD; } } while (false); |
2974 | |
2975 | // Abort if we're shutting down. |
2976 | if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) { |
2977 | return NS_ERROR_ABORT; |
2978 | } |
2979 | // Check if AsyncClose or Close were already invoked. |
2980 | if (!connectionReady()) { |
2981 | return NS_ERROR_NOT_INITIALIZED; |
2982 | } |
2983 | nsresult rv = ensureOperationSupported(ASYNCHRONOUS); |
2984 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2985 | return rv; |
2986 | } |
2987 | nsIEventTarget* asyncThread = getAsyncExecutionTarget(); |
2988 | if (!asyncThread) { |
2989 | return NS_ERROR_NOT_INITIALIZED; |
2990 | } |
2991 | |
2992 | // The number of pages of the database to copy per step |
2993 | static constexpr int32_t DEFAULT_PAGES_PER_STEP = 5; |
2994 | // The number of milliseconds to wait between each step. |
2995 | static constexpr uint32_t DEFAULT_STEP_DELAY_MS = 250; |
2996 | |
2997 | CheckedInt<int32_t> pagesPerStep(aPagesPerStep); |
2998 | if (!pagesPerStep.isValid()) { |
2999 | return NS_ERROR_INVALID_ARG; |
3000 | } |
3001 | |
3002 | if (!pagesPerStep.value()) { |
3003 | pagesPerStep = DEFAULT_PAGES_PER_STEP; |
3004 | } |
3005 | |
3006 | if (!aStepDelayMs) { |
3007 | aStepDelayMs = DEFAULT_STEP_DELAY_MS; |
3008 | } |
3009 | |
3010 | // Create and dispatch our backup event to the execution thread. |
3011 | nsCOMPtr<nsIRunnable> backupEvent = |
3012 | new AsyncBackupDatabaseFile(this, mDBConn, aDestinationFile, aCallback, |
3013 | pagesPerStep.value(), aStepDelayMs); |
3014 | rv = asyncThread->Dispatch(backupEvent, NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL); |
3015 | return rv; |
3016 | } |
3017 | |
3018 | } // namespace mozilla::storage |