Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp
Warning:line 1335, column 10
Although the value stored to 'r' is used in the enclosing expression, the value is never actually read from 'r'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name nr_socket_prsock.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dom/media/webrtc/transport/build -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dom/media/webrtc/transport/build -resource-dir /usr/lib/llvm-19/lib/clang/19 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D LINUX -D HAVE_STRDUP -D NR_SOCKET_IS_VOID_PTR -D R_DEFINED_INT2=int16_t -D R_DEFINED_UINT2=uint16_t -D R_DEFINED_INT4=int32_t -D R_DEFINED_UINT4=uint32_t -D R_DEFINED_INT8=int64_t -D R_DEFINED_UINT8=uint64_t -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/build -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dom/media/webrtc/transport/build -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nICEr/src/crypto -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nICEr/src/ice -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nICEr/src/net -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nICEr/src/stun -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nICEr/src/util -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/event -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/log -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/plugin -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/port/generic/include -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/registry -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/share -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/stats -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr -I /var/lib/jenkins/workspace/firefox-scan-build/third_party/libsrtp/src/crypto/include -I /var/lib/jenkins/workspace/firefox-scan-build/third_party/libsrtp/src/include -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/port/linux/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-09-22-115206-3586786-1 -x c++ /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=2 et sw=2 tw=80: */
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6/*
7Modified version of nr_socket_local, adapted for NSPR
8*/
9
10/* This Source Code Form is subject to the terms of the Mozilla Public
11 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
12 * You can obtain one at http://mozilla.org/MPL/2.0/. */
13
14/*
15Original code from nICEr and nrappkit.
16
17nICEr copyright:
18
19Copyright (c) 2007, Adobe Systems, Incorporated
20All rights reserved.
21
22Redistribution and use in source and binary forms, with or without
23modification, are permitted provided that the following conditions are
24met:
25
26* Redistributions of source code must retain the above copyright
27 notice, this list of conditions and the following disclaimer.
28
29* Redistributions in binary form must reproduce the above copyright
30 notice, this list of conditions and the following disclaimer in the
31 documentation and/or other materials provided with the distribution.
32
33* Neither the name of Adobe Systems, Network Resonance nor the names of its
34 contributors may be used to endorse or promote products derived from
35 this software without specific prior written permission.
36
37THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
49
50nrappkit copyright:
51
52 Copyright (C) 2001-2003, Network Resonance, Inc.
53 Copyright (C) 2006, Network Resonance, Inc.
54 All Rights Reserved
55
56 Redistribution and use in source and binary forms, with or without
57 modification, are permitted provided that the following conditions
58 are met:
59
60 1. Redistributions of source code must retain the above copyright
61 notice, this list of conditions and the following disclaimer.
62 2. Redistributions in binary form must reproduce the above copyright
63 notice, this list of conditions and the following disclaimer in the
64 documentation and/or other materials provided with the distribution.
65 3. Neither the name of Network Resonance, Inc. nor the name of any
66 contributors to this software may be used to endorse or promote
67 products derived from this software without specific prior written
68 permission.
69
70 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
71 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
73 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
74 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
75 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
76 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
77 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
78 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
79 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
80 POSSIBILITY OF SUCH DAMAGE.
81
82
83 ekr@rtfm.com Thu Dec 20 20:14:49 2001
84*/
85
86#include <csi_platform.h>
87#include <stdio.h>
88#include <string.h>
89#include <sys/types.h>
90#include <assert.h>
91#include <errno(*__errno_location ()).h>
92#include <string>
93
94#include "nspr.h"
95#include "prerror.h"
96#include "prio.h"
97#include "prnetdb.h"
98
99#include "mozilla/net/DNS.h"
100#include "mozilla/ProfilerBandwidthCounter.h"
101#include "nsCOMPtr.h"
102#include "nsASocketHandler.h"
103#include "nsISocketTransportService.h"
104#include "nsNetCID.h"
105#include "nsISupportsImpl.h"
106#include "nsServiceManagerUtils.h"
107#include "nsComponentManagerUtils.h"
108#include "nsXPCOM.h"
109#include "nsXULAppAPI.h"
110#include "runnable_utils.h"
111#include "mozilla/SyncRunnable.h"
112#include "nsTArray.h"
113#include "nsISocketFilter.h"
114#include "nsDebug.h"
115#include "nsNetUtil.h"
116
117#if defined(MOZILLA_INTERNAL_API1)
118// csi_platform.h deep in nrappkit defines LOG_INFO and LOG_WARNING
119# ifdef LOG_INFO6
120# define LOG_TEMP_INFO LOG_INFO6
121# undef LOG_INFO6
122# endif
123# ifdef LOG_WARNING4
124# define LOG_TEMP_WARNING LOG_WARNING4
125# undef LOG_WARNING4
126# endif
127# if defined(LOG_DEBUG7)
128# define LOG_TEMP_DEBUG LOG_DEBUG7
129# undef LOG_DEBUG7
130# endif
131# undef strlcpy
132
133# include "mozilla/dom/network/UDPSocketChild.h"
134
135# ifdef LOG_TEMP_INFO
136# define LOG_INFO6 LOG_TEMP_INFO
137# endif
138# ifdef LOG_TEMP_WARNING
139# define LOG_WARNING4 LOG_TEMP_WARNING
140# endif
141
142# ifdef LOG_TEMP_DEBUG
143# define LOG_DEBUG7 LOG_TEMP_DEBUG
144# endif
145# ifdef XP_WIN
146# ifdef LOG_DEBUG7
147# undef LOG_DEBUG7
148# endif
149// cloned from csi_platform.h. Win32 doesn't like how we hide symbols
150# define LOG_DEBUG7 7
151# endif
152#endif
153
154extern "C" {
155#include "nr_api.h"
156#include "async_wait.h"
157#include "nr_socket.h"
158#include "nr_socket_local.h"
159#include "stun_hint.h"
160}
161#include "nr_socket_prsock.h"
162#include "simpletokenbucket.h"
163#include "test_nr_socket.h"
164#include "nr_socket_tcp.h"
165#include "nr_socket_proxy_config.h"
166
167// Implement the nsISupports ref counting
168namespace mozilla {
169
170#if defined(MOZILLA_INTERNAL_API1)
171class SingletonThreadHolder final {
172 private:
173 ~SingletonThreadHolder() {
174 r_log(LOG_GENERIC0, LOG_DEBUG7, "Deleting SingletonThreadHolder");
175 if (mThread) {
176 // Likely a connection is somehow being held in CC or GC
177 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "SingletonThreads should be Released and shut down before exit!"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 178)
178 "SingletonThreads should be Released and shut down before exit!")NS_DebugBreak(NS_DEBUG_WARNING, "SingletonThreads should be Released and shut down before exit!"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 178)
;
179 mThread->Shutdown();
180 mThread = nullptr;
181 }
182 }
183
184 DISALLOW_COPY_ASSIGN(SingletonThreadHolder)SingletonThreadHolder(const SingletonThreadHolder& other)
= delete; void operator=(const SingletonThreadHolder& other
) = delete
;
185
186 public:
187 // Must be threadsafe for StaticRefPtr/ClearOnShutdown
188 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SingletonThreadHolder)public: MozExternalRefCountType AddRef(void) { static_assert(
!std::is_destructible_v<SingletonThreadHolder>, "Reference-counted class "
"SingletonThreadHolder" " 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 188); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
188; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); nsrefcnt count = ++mRefCnt; NS_LogAddRef((this
), (count), ("SingletonThreadHolder"), (uint32_t)(sizeof(*this
))); return (nsrefcnt)count; } MozExternalRefCountType 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 188); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 188
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); nsrefcnt count = --mRefCnt; NS_LogRelease((this), (
count), ("SingletonThreadHolder")); if (count == 0) { delete (
this); return 0; } return count; } using HasThreadSafeRefCnt =
std::true_type; protected: ::mozilla::ThreadSafeAutoRefCnt mRefCnt
; public:
189
190 explicit SingletonThreadHolder(const nsACString& aName) : mName(aName) {
191 mParentThread = NS_GetCurrentThread();
192 }
193
194 nsIThread* GetThread() { return mThread; }
195
196 /*
197 * Keep track of how many instances are using a SingletonThreadHolder.
198 * When no one is using it, shut it down
199 */
200 void AddUse() {
201 MOZ_ASSERT(mParentThread == NS_GetCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mParentThread == NS_GetCurrentThread())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(mParentThread == NS_GetCurrentThread()))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("mParentThread == NS_GetCurrentThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 201); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mParentThread == NS_GetCurrentThread()"
")"); do { *((volatile int*)__null) = 201; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
202 MOZ_ASSERT(int32_t(mUseCount) >= 0, "illegal refcnt")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(int32_t(mUseCount) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mUseCount) >= 0))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mUseCount) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 202); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mUseCount) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
202; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false)
;
203 nsrefcnt count = ++mUseCount;
204 if (count == 1) {
205 // idle -> in-use
206 nsresult rv = NS_NewNamedThread(mName, getter_AddRefs(mThread));
207 MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && mThread,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)) && mThread)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1))) && mThread))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && mThread"
" (" "Should successfully create mtransport I/O thread" ")",
"/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 208); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && mThread"
") (" "Should successfully create mtransport I/O thread" ")"
); do { *((volatile int*)__null) = 208; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
208 "Should successfully create mtransport I/O thread")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)) && mThread)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1))) && mThread))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && mThread"
" (" "Should successfully create mtransport I/O thread" ")",
"/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 208); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && mThread"
") (" "Should successfully create mtransport I/O thread" ")"
); do { *((volatile int*)__null) = 208; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
209 r_log(LOG_GENERIC0, LOG_DEBUG7, "Created wrapped SingletonThread %p",
210 mThread.get());
211 }
212 r_log(LOG_GENERIC0, LOG_DEBUG7, "AddUse_i: %lu", (unsigned long)count);
213 }
214
215 void ReleaseUse() {
216 MOZ_ASSERT(mParentThread == NS_GetCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mParentThread == NS_GetCurrentThread())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(mParentThread == NS_GetCurrentThread()))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("mParentThread == NS_GetCurrentThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 216); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mParentThread == NS_GetCurrentThread()"
")"); do { *((volatile int*)__null) = 216; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
217 nsrefcnt count = --mUseCount;
218 MOZ_ASSERT(int32_t(mUseCount) >= 0, "illegal refcnt")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(int32_t(mUseCount) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mUseCount) >= 0))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mUseCount) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 218); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mUseCount) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
218; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false)
;
219 if (mThread && count == 0) {
220 // in-use -> idle -- no one forcing it to remain instantiated
221 r_log(LOG_GENERIC0, LOG_DEBUG7, "Shutting down wrapped SingletonThread %p",
222 mThread.get());
223 mThread->AsyncShutdown();
224 mThread = nullptr;
225 // It'd be nice to use a timer instead... But be careful of
226 // xpcom-shutdown-threads in that case
227 }
228 r_log(LOG_GENERIC0, LOG_DEBUG7, "ReleaseUse_i: %lu", (unsigned long)count);
229 }
230
231 private:
232 nsCString mName;
233 nsAutoRefCnt mUseCount;
234 nsCOMPtr<nsIThread> mParentThread;
235 nsCOMPtr<nsIThread> mThread;
236};
237
238static StaticRefPtr<SingletonThreadHolder> sThread;
239
240static void ClearSingletonOnShutdown() {
241 // We expect everybody to have done ReleaseUse() at the latest during
242 // xpcom-shutdown-threads. So we need to live longer than that.
243 ClearOnShutdown(&sThread, ShutdownPhase::XPCOMShutdownFinal);
244}
245#endif
246
247static nsIThread* GetIOThreadAndAddUse_s() {
248 // Always runs on STS thread!
249#if defined(MOZILLA_INTERNAL_API1)
250 // We need to safely release this on shutdown to avoid leaks
251 if (!sThread) {
252 sThread = new SingletonThreadHolder("mtransport"_ns);
253 NS_DispatchToMainThread(mozilla::WrapRunnableNM(&ClearSingletonOnShutdown));
254 }
255 // Mark that we're using the shared thread and need it to stick around
256 sThread->AddUse();
257 return sThread->GetThread();
258#else
259 static nsCOMPtr<nsIThread> sThread;
260 if (!sThread) {
261 (void)NS_NewNamedThread("mtransport", getter_AddRefs(sThread));
262 }
263 return sThread;
264#endif
265}
266
267NrSocketIpc::NrSocketIpc(nsIEventTarget* aThread) : io_thread_(aThread) {}
268
269static TimeStamp nr_socket_short_term_violation_time;
270static TimeStamp nr_socket_long_term_violation_time;
271
272TimeStamp NrSocketBase::short_term_violation_time() {
273 return nr_socket_short_term_violation_time;
274}
275
276TimeStamp NrSocketBase::long_term_violation_time() {
277 return nr_socket_long_term_violation_time;
278}
279
280// NrSocketBase implementation
281// async_event APIs
282int NrSocketBase::async_wait(int how, NR_async_cb cb, void* cb_arg,
283 char* function, int line) {
284 uint16_t flag;
285
286 switch (how) {
287 case NR_ASYNC_WAIT_READ0:
288 flag = PR_POLL_READ0x1;
289 break;
290 case NR_ASYNC_WAIT_WRITE1:
291 flag = PR_POLL_WRITE0x2;
292 break;
293 default:
294 return R_BAD_ARGS6;
295 }
296
297 cbs_[how] = cb;
298 cb_args_[how] = cb_arg;
299 poll_flags_ |= flag;
300
301 return 0;
302}
303
304int NrSocketBase::cancel(int how) {
305 uint16_t flag;
306
307 switch (how) {
308 case NR_ASYNC_WAIT_READ0:
309 flag = PR_POLL_READ0x1;
310 break;
311 case NR_ASYNC_WAIT_WRITE1:
312 flag = PR_POLL_WRITE0x2;
313 break;
314 default:
315 return R_BAD_ARGS6;
316 }
317
318 poll_flags_ &= ~flag;
319
320 return 0;
321}
322
323void NrSocketBase::fire_callback(int how) {
324 // This can't happen unless we are armed because we only set
325 // the flags if we are armed
326 MOZ_ASSERT(cbs_[how])do { static_assert( mozilla::detail::AssertionConditionType<
decltype(cbs_[how])>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(cbs_[how]))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("cbs_[how]", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 326); AnnotateMozCrashReason("MOZ_ASSERT" "(" "cbs_[how]" ")"
); do { *((volatile int*)__null) = 326; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
327
328 // Now cancel so that we need to be re-armed. Note that
329 // the re-arming probably happens in the callback we are
330 // about to fire.
331 cancel(how);
332
333 cbs_[how](this, how, cb_args_[how]);
334}
335
336// NrSocket implementation
337NS_IMPL_QUERY_INTERFACE0(NrSocket)nsresult NrSocket::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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 337); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<NrSocket, nsISupports>, int32_t( reinterpret_cast
<char*>(static_cast<nsISupports*>((NrSocket*)0x1000
)) - reinterpret_cast<char*>((NrSocket*)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; }
338
339// The nsASocket callbacks
340void NrSocket::OnSocketReady(PRFileDesc* fd, int16_t outflags) {
341 if (outflags & PR_POLL_READ0x1 & poll_flags()) fire_callback(NR_ASYNC_WAIT_READ0);
342 if (outflags & PR_POLL_WRITE0x2 & poll_flags())
343 fire_callback(NR_ASYNC_WAIT_WRITE1);
344 if (outflags & (PR_POLL_ERR0x8 | PR_POLL_NVAL0x10 | PR_POLL_HUP0x20))
345 // TODO: Bug 946423: how do we notify the upper layers about this?
346 close();
347}
348
349void NrSocket::OnSocketDetached(PRFileDesc* fd) {
350 r_log(LOG_GENERIC0, LOG_DEBUG7, "Socket %p detached", fd);
351}
352
353void NrSocket::IsLocal(bool* aIsLocal) {
354 // TODO(jesup): better check? Does it matter? (likely no)
355 *aIsLocal = false;
356}
357
358// async_event APIs
359int NrSocket::async_wait(int how, NR_async_cb cb, void* cb_arg, char* function,
360 int line) {
361 int r = NrSocketBase::async_wait(how, cb, cb_arg, function, line);
362
363 if (!r) {
364 mPollFlags = poll_flags();
365 }
366
367 return r;
368}
369
370int NrSocket::cancel(int how) {
371 int r = NrSocketBase::cancel(how);
372
373 if (!r) {
374 mPollFlags = poll_flags();
375 }
376
377 return r;
378}
379
380// Helper functions for addresses
381static int nr_transport_addr_to_praddr(const nr_transport_addr* addr,
382 PRNetAddr* naddr) {
383 int _status;
384
385 memset(naddr, 0, sizeof(*naddr));
386
387 switch (addr->protocol) {
388 case IPPROTO_TCPIPPROTO_TCP:
389 break;
390 case IPPROTO_UDPIPPROTO_UDP:
391 break;
392 default:
393 ABORT(R_BAD_ARGS)do { int _r=6; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
394 }
395
396 switch (addr->ip_version) {
397 case NR_IPV44:
398 naddr->inet.family = PR_AF_INET2;
399 naddr->inet.port = addr->u.addr4.sin_port;
400 naddr->inet.ip = addr->u.addr4.sin_addr.s_addr;
401 break;
402 case NR_IPV66:
403 naddr->ipv6.family = PR_AF_INET610;
404 naddr->ipv6.port = addr->u.addr6.sin6_port;
405 naddr->ipv6.flowinfo = addr->u.addr6.sin6_flowinfo;
406 memcpy(&naddr->ipv6.ip, &addr->u.addr6.sin6_addr, sizeof(in6_addr));
407 naddr->ipv6.scope_id = addr->u.addr6.sin6_scope_id;
408 break;
409 default:
410 ABORT(R_BAD_ARGS)do { int _r=6; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
411 }
412
413 _status = 0;
414abort:
415 return (_status);
416}
417
418// XXX schien@mozilla.com: copy from PRNetAddrToNetAddr,
419// should be removed after fix the link error in signaling_unittests
420static int praddr_to_netaddr(const PRNetAddr* prAddr, net::NetAddr* addr) {
421 int _status;
422
423 switch (prAddr->raw.family) {
424 case PR_AF_INET2:
425 addr->inet.family = AF_INET2;
426 addr->inet.port = prAddr->inet.port;
427 addr->inet.ip = prAddr->inet.ip;
428 break;
429 case PR_AF_INET610:
430 addr->inet6.family = AF_INET610;
431 addr->inet6.port = prAddr->ipv6.port;
432 addr->inet6.flowinfo = prAddr->ipv6.flowinfo;
433 memcpy(&addr->inet6.ip, &prAddr->ipv6.ip, sizeof(addr->inet6.ip.u8));
434 addr->inet6.scope_id = prAddr->ipv6.scope_id;
435 break;
436 default:
437 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", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 437); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")");
do { *((volatile int*)__null) = 437; __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
438 ABORT(R_BAD_ARGS)do { int _r=6; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
439 }
440
441 _status = 0;
442abort:
443 return (_status);
444}
445
446static int nr_transport_addr_to_netaddr(const nr_transport_addr* addr,
447 net::NetAddr* naddr) {
448 int r, _status;
449 PRNetAddr praddr;
450
451 if ((r = nr_transport_addr_to_praddr(addr, &praddr))) {
452 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
453 }
454
455 if ((r = praddr_to_netaddr(&praddr, naddr))) {
456 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
457 }
458
459 _status = 0;
460abort:
461 return (_status);
462}
463
464int nr_netaddr_to_transport_addr(const net::NetAddr* netaddr,
465 nr_transport_addr* addr, int protocol) {
466 int _status;
467 int r;
468
469 switch (netaddr->raw.family) {
470 case AF_INET2:
471 if ((r = nr_ip4_port_to_transport_addr(ntohl(netaddr->inet.ip)__bswap_32 (netaddr->inet.ip),
472 ntohs(netaddr->inet.port)__bswap_16 (netaddr->inet.port),
473 protocol, addr)))
474 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
475 break;
476 case AF_INET610:
477 if ((r = nr_ip6_port_to_transport_addr((in6_addr*)&netaddr->inet6.ip.u8,
478 ntohs(netaddr->inet6.port)__bswap_16 (netaddr->inet6.port),
479 protocol, addr)))
480 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
481 break;
482 default:
483 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", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 483); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")");
do { *((volatile int*)__null) = 483; __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
484 ABORT(R_BAD_ARGS)do { int _r=6; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
485 }
486 _status = 0;
487abort:
488 return (_status);
489}
490
491int nr_praddr_to_transport_addr(const PRNetAddr* praddr,
492 nr_transport_addr* addr, int protocol,
493 int keep) {
494 int _status;
495 int r;
496 struct sockaddr_in ip4;
497 struct sockaddr_in6 ip6;
498
499 switch (praddr->raw.family) {
500 case PR_AF_INET2:
501 ip4.sin_family = PF_INET2;
502 ip4.sin_addr.s_addr = praddr->inet.ip;
503 ip4.sin_port = praddr->inet.port;
504 if ((r = nr_sockaddr_to_transport_addr((sockaddr*)&ip4, protocol, keep,
505 addr)))
506 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
507 break;
508 case PR_AF_INET610:
509 ip6.sin6_family = PF_INET610;
510 ip6.sin6_port = praddr->ipv6.port;
511 ip6.sin6_flowinfo = praddr->ipv6.flowinfo;
512 memcpy(&ip6.sin6_addr, &praddr->ipv6.ip, sizeof(in6_addr));
513 ip6.sin6_scope_id = praddr->ipv6.scope_id;
514 if ((r = nr_sockaddr_to_transport_addr((sockaddr*)&ip6, protocol, keep,
515 addr)))
516 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
517 break;
518 default:
519 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", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 519); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")");
do { *((volatile int*)__null) = 519; __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
520 ABORT(R_BAD_ARGS)do { int _r=6; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
521 }
522
523 _status = 0;
524abort:
525 return (_status);
526}
527
528/*
529 * nr_transport_addr_get_addrstring_and_port
530 * convert nr_transport_addr to IP address string and port number
531 */
532int nr_transport_addr_get_addrstring_and_port(const nr_transport_addr* addr,
533 nsACString* host, int32_t* port) {
534 int r, _status;
535 char addr_string[64];
536
537 // We cannot directly use |nr_transport_addr.as_string| because it contains
538 // more than ip address, therefore, we need to explicity convert it
539 // from |nr_transport_addr_get_addrstring|.
540 if ((r = nr_transport_addr_get_addrstring(addr, addr_string,
541 sizeof(addr_string)))) {
542 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
543 }
544
545 if ((r = nr_transport_addr_get_port(addr, port))) {
546 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
547 }
548
549 *host = addr_string;
550
551 _status = 0;
552abort:
553 return (_status);
554}
555
556// nr_socket APIs (as member functions)
557int NrSocket::create(nr_transport_addr* addr) {
558 int r, _status;
559
560 PRStatus status;
561 PRNetAddr naddr;
562
563 nsresult rv;
564 nsCOMPtr<nsISocketTransportService> stservice =
565 do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/socket-transport-service;1", &rv);
566
567 if (!NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
568 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
569 }
570
571 if ((r = nr_transport_addr_to_praddr(addr, &naddr))) ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
572
573 switch (addr->protocol) {
574 case IPPROTO_UDPIPPROTO_UDP:
575 if (!(fd_ = PR_OpenUDPSocket(naddr.raw.family))) {
576 r_log(LOG_GENERIC0, LOG_CRIT2,
577 "Couldn't create UDP socket, "
578 "family=%d, err=%d",
579 naddr.raw.family, PR_GetError());
580 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
581 }
582 break;
583 case IPPROTO_TCPIPPROTO_TCP:
584 // TODO: Rewrite this to use WebrtcTcpSocket.
585 // Also use the same logic for TLS.
586 if (my_addr_.fqdn[0] != '\0') ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
587
588 if (!(fd_ = PR_OpenTCPSocket(naddr.raw.family))) {
589 r_log(LOG_GENERIC0, LOG_CRIT2,
590 "Couldn't create TCP socket, "
591 "family=%d, err=%d",
592 naddr.raw.family, PR_GetError());
593 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
594 }
595 // Set ReuseAddr for TCP sockets to enable having several
596 // sockets bound to same local IP and port
597 PRSocketOptionData opt_reuseaddr;
598 opt_reuseaddr.option = PR_SockOpt_Reuseaddr;
599 opt_reuseaddr.value.reuse_addr = PR_TRUE1;
600 status = PR_SetSocketOption(fd_, &opt_reuseaddr);
601 if (status != PR_SUCCESS) {
602 r_log(LOG_GENERIC0, LOG_CRIT2,
603 "Couldn't set reuse addr socket option: %d", status);
604 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
605 }
606 // And also set ReusePort for platforms supporting this socket option
607 PRSocketOptionData opt_reuseport;
608 opt_reuseport.option = PR_SockOpt_Reuseport;
609 opt_reuseport.value.reuse_port = PR_TRUE1;
610 status = PR_SetSocketOption(fd_, &opt_reuseport);
611 if (status != PR_SUCCESS) {
612 if (PR_GetError() != PR_OPERATION_NOT_SUPPORTED_ERROR(-5965L)) {
613 r_log(LOG_GENERIC0, LOG_CRIT2,
614 "Couldn't set reuse port socket option: %d", status);
615 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
616 }
617 }
618 // Try to speedup packet delivery by disabling TCP Nagle
619 PRSocketOptionData opt_nodelay;
620 opt_nodelay.option = PR_SockOpt_NoDelay;
621 opt_nodelay.value.no_delay = PR_TRUE1;
622 status = PR_SetSocketOption(fd_, &opt_nodelay);
623 if (status != PR_SUCCESS) {
624 r_log(LOG_GENERIC0, LOG_WARNING4,
625 "Couldn't set Nodelay socket option: %d", status);
626 }
627 break;
628 default:
629 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
630 }
631
632 status = PR_Bind(fd_, &naddr);
633 if (status != PR_SUCCESS) {
634 r_log(LOG_GENERIC0, LOG_CRIT2, "Couldn't bind socket to address %s",
635 addr->as_string);
636 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
637 }
638
639 r_log(LOG_GENERIC0, LOG_DEBUG7, "Creating socket %p with addr %s", fd_,
640 addr->as_string);
641 nr_transport_addr_copy(&my_addr_, addr);
642
643 /* If we have a wildcard port, patch up the addr */
644 if (nr_transport_addr_is_wildcard(addr)) {
645 status = PR_GetSockName(fd_, &naddr);
646 if (status != PR_SUCCESS) {
647 r_log(LOG_GENERIC0, LOG_CRIT2, "Couldn't get sock name for socket");
648 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
649 }
650
651 if ((r = nr_praddr_to_transport_addr(&naddr, &my_addr_, addr->protocol, 1)))
652 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
653 }
654
655 // Set nonblocking
656 PRSocketOptionData opt_nonblock;
657 opt_nonblock.option = PR_SockOpt_Nonblocking;
658 opt_nonblock.value.non_blocking = PR_TRUE1;
659 status = PR_SetSocketOption(fd_, &opt_nonblock);
660 if (status != PR_SUCCESS) {
661 r_log(LOG_GENERIC0, LOG_CRIT2, "Couldn't make socket nonblocking");
662 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
663 }
664
665 // Remember our thread.
666 ststhread_ = do_QueryInterface(stservice, &rv);
667 if (!NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
668
669 // Finally, register with the STS
670 rv = stservice->AttachSocket(fd_, this);
671 if (!NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
672 r_log(LOG_GENERIC0, LOG_CRIT2, "Couldn't attach socket to STS, rv=%u",
673 static_cast<unsigned>(rv));
674 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
675 }
676
677 _status = 0;
678
679abort:
680 return (_status);
681}
682
683static int ShouldDrop(size_t len) {
684 // Global rate limiting for stun requests, to mitigate the ice hammer DoS
685 // (see http://tools.ietf.org/html/draft-thomson-mmusic-ice-webrtc)
686
687 // Tolerate rate of 8k/sec, for one second.
688 static SimpleTokenBucket burst(16384 * 1, 16384);
689 // Tolerate rate of 7.2k/sec over twenty seconds.
690 static SimpleTokenBucket sustained(7372 * 20, 7372);
691
692 // Check number of tokens in each bucket.
693 if (burst.getTokens(UINT32_MAX(4294967295U)) < len) {
694 r_log(LOG_GENERIC0, LOG_ERR3,
695 "Short term global rate limit for STUN requests exceeded.");
696#ifdef MOZILLA_INTERNAL_API1
697 nr_socket_short_term_violation_time = TimeStamp::Now();
698#endif
699
700// Bug 1013007
701#if !EARLY_BETA_OR_EARLIER1
702 return R_WOULDBLOCK8;
703#else
704 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" " (" "Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 707); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 707; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
705 "Short term global rate limit for STUN requests exceeded. Go "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 707); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 707; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
706 "bug bcampen@mozilla.com if you weren't intentionally "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 707); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 707; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
707 "spamming ICE candidates, or don't know what that means.")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 707); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 707; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
708#endif
709 }
710
711 if (sustained.getTokens(UINT32_MAX(4294967295U)) < len) {
712 r_log(LOG_GENERIC0, LOG_ERR3,
713 "Long term global rate limit for STUN requests exceeded.");
714#ifdef MOZILLA_INTERNAL_API1
715 nr_socket_long_term_violation_time = TimeStamp::Now();
716#endif
717// Bug 1013007
718#if !EARLY_BETA_OR_EARLIER1
719 return R_WOULDBLOCK8;
720#else
721 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" " (" "Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 724); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 724; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
722 "Long term global rate limit for STUN requests exceeded. Go "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 724); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 724; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
723 "bug bcampen@mozilla.com if you weren't intentionally "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 724); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 724; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
724 "spamming ICE candidates, or don't know what that means.")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 724); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 724; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
725#endif
726 }
727
728 // Take len tokens from both buckets.
729 // (not threadsafe, but no problem since this is only called from STS)
730 burst.getTokens(len);
731 sustained.getTokens(len);
732 return 0;
733}
734
735// This should be called on the STS thread.
736int NrSocket::sendto(const void* msg, size_t len, int flags,
737 const nr_transport_addr* to) {
738 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 738); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 738; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 738); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 738; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
739 int r, _status;
740 PRNetAddr naddr;
741 int32_t status;
742
743 if ((r = nr_transport_addr_to_praddr(to, &naddr))) ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
744
745 if (fd_ == nullptr) ABORT(R_EOD)do { int _r=5; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
746
747 if (nr_is_stun_request_message((UCHAR*)msg, len) && ShouldDrop(len)) {
748 ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
749 }
750
751 // TODO: Convert flags?
752 status = PR_SendTo(fd_, msg, len, flags, &naddr, PR_INTERVAL_NO_WAIT0UL);
753 if (status < 0 || (size_t)status != len) {
754 if (PR_GetError() == PR_WOULD_BLOCK_ERROR(-5998L)) ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
755
756 r_log(LOG_GENERIC0, LOG_INFO6, "Error in sendto %s: %d", to->as_string,
757 PR_GetError());
758 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
759 }
760
761 mozilla::profiler_count_bandwidth_written_bytes(status);
762 _status = 0;
763abort:
764 return (_status);
765}
766
767int NrSocket::recvfrom(void* buf, size_t maxlen, size_t* len, int flags,
768 nr_transport_addr* from) {
769 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 769); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 769; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 769); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 769; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
770 int r, _status;
771 PRNetAddr nfrom;
772 int32_t status;
773
774 status = PR_RecvFrom(fd_, buf, maxlen, flags, &nfrom, PR_INTERVAL_NO_WAIT0UL);
775 if (status <= 0) {
776 if (PR_GetError() == PR_WOULD_BLOCK_ERROR(-5998L)) ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
777 r_log(LOG_GENERIC0, LOG_INFO6, "Error in recvfrom: %d", (int)PR_GetError());
778 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
779 }
780 *len = status;
781
782 if ((r = nr_praddr_to_transport_addr(&nfrom, from, my_addr_.protocol, 0)))
783 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
784
785 // r_log(LOG_GENERIC,LOG_DEBUG,"Read %d bytes from %s",*len,addr->as_string);
786 mozilla::profiler_count_bandwidth_read_bytes(status);
787
788 _status = 0;
789abort:
790 return (_status);
791}
792
793int NrSocket::getaddr(nr_transport_addr* addrp) {
794 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 794); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 794; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 794); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 794; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
795 return nr_transport_addr_copy(addrp, &my_addr_);
796}
797
798// Close the socket so that the STS will detach and then kill it
799void NrSocket::close() {
800 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 800); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 800; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 800); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 800; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
801 mCondition = NS_BASE_STREAM_CLOSED;
802 cancel(NR_ASYNC_WAIT_READ0);
803 cancel(NR_ASYNC_WAIT_WRITE1);
804}
805
806int NrSocket::connect(const nr_transport_addr* addr) {
807 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 807); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 807; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 807); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 807; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
808 int r, _status;
809 PRNetAddr naddr;
810 int32_t connect_status, getsockname_status;
811
812 if ((r = nr_transport_addr_to_praddr(addr, &naddr))) ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
813
814 if (!fd_) ABORT(R_EOD)do { int _r=5; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
815
816 // Note: this just means we tried to connect, not that we
817 // are actually live.
818 connect_invoked_ = true;
819 connect_status = PR_Connect(fd_, &naddr, PR_INTERVAL_NO_WAIT0UL);
820 if (connect_status != PR_SUCCESS) {
821 if (PR_GetError() != PR_IN_PROGRESS_ERROR(-5934L)) {
822 r_log(LOG_GENERIC0, LOG_CRIT2, "PR_Connect failed: %d", PR_GetError());
823 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
824 }
825 }
826
827 // If our local address is wildcard, then fill in the
828 // address now.
829 if (nr_transport_addr_is_wildcard(&my_addr_)) {
830 getsockname_status = PR_GetSockName(fd_, &naddr);
831 if (getsockname_status != PR_SUCCESS) {
832 r_log(LOG_GENERIC0, LOG_CRIT2, "Couldn't get sock name for socket");
833 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
834 }
835
836 if ((r = nr_praddr_to_transport_addr(&naddr, &my_addr_, addr->protocol, 1)))
837 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
838 }
839
840 // Now return the WOULDBLOCK if needed.
841 if (connect_status != PR_SUCCESS) {
842 ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
843 }
844
845 _status = 0;
846abort:
847 return (_status);
848}
849
850int NrSocket::write(const void* msg, size_t len, size_t* written) {
851 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 851); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 851; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 851); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 851; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
852 int _status;
853 int32_t status;
854
855 if (!connect_invoked_) ABORT(R_FAILED)do { int _r=10; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
856
857 status = PR_Write(fd_, msg, len);
858 if (status < 0) {
859 if (PR_GetError() == PR_WOULD_BLOCK_ERROR(-5998L)) ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
860 r_log(LOG_GENERIC0, LOG_INFO6, "Error in write");
861 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
862 }
863
864 *written = status;
865
866 _status = 0;
867abort:
868 return _status;
869}
870
871int NrSocket::read(void* buf, size_t maxlen, size_t* len) {
872 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 872); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 872; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 872); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 872; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
873 int _status;
874 int32_t status;
875
876 if (!connect_invoked_) ABORT(R_FAILED)do { int _r=10; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
877
878 status = PR_Read(fd_, buf, maxlen);
879 if (status < 0) {
880 if (PR_GetError() == PR_WOULD_BLOCK_ERROR(-5998L)) ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
881 r_log(LOG_GENERIC0, LOG_INFO6, "Error in read");
882 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
883 }
884 if (status == 0) ABORT(R_EOD)do { int _r=5; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
885
886 *len = (size_t)status; // Guaranteed to be > 0
887 _status = 0;
888abort:
889 return (_status);
890}
891
892int NrSocket::listen(int backlog) {
893 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 893); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 893; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 893); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 893; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
894 int32_t status;
895 int _status;
896
897 assert(fd_)(static_cast <bool> (fd_) ? void (0) : __assert_fail ("fd_"
, __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__
))
;
898 status = PR_Listen(fd_, backlog);
899 if (status != PR_SUCCESS) {
900 r_log(LOG_GENERIC0, LOG_CRIT2, "%s: PR_GetError() == %d", __FUNCTION__,
901 PR_GetError());
902 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
903 }
904
905 _status = 0;
906abort:
907 return (_status);
908}
909
910int NrSocket::accept(nr_transport_addr* addrp, nr_socket** sockp) {
911 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 911); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 911; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 911); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 911; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
912 int _status, r;
913 PRStatus status;
914 PRFileDesc* prfd;
915 PRNetAddr nfrom;
916 NrSocket* sock = nullptr;
917 nsresult rv;
918 PRSocketOptionData opt_nonblock, opt_nodelay;
919 nsCOMPtr<nsISocketTransportService> stservice =
920 do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/socket-transport-service;1", &rv);
921
922 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
923 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
924 }
925
926 if (!fd_) ABORT(R_EOD)do { int _r=5; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
927
928 prfd = PR_Accept(fd_, &nfrom, PR_INTERVAL_NO_WAIT0UL);
929
930 if (!prfd) {
931 if (PR_GetError() == PR_WOULD_BLOCK_ERROR(-5998L)) ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
932
933 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
934 }
935
936 sock = new NrSocket();
937
938 sock->fd_ = prfd;
939 nr_transport_addr_copy(&sock->my_addr_, &my_addr_);
940
941 if ((r = nr_praddr_to_transport_addr(&nfrom, addrp, my_addr_.protocol, 0)))
942 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
943
944 // Set nonblocking
945 opt_nonblock.option = PR_SockOpt_Nonblocking;
946 opt_nonblock.value.non_blocking = PR_TRUE1;
947 status = PR_SetSocketOption(prfd, &opt_nonblock);
948 if (status != PR_SUCCESS) {
949 r_log(LOG_GENERIC0, LOG_CRIT2,
950 "Failed to make accepted socket nonblocking: %d", status);
951 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
952 }
953 // Disable TCP Nagle
954 opt_nodelay.option = PR_SockOpt_NoDelay;
955 opt_nodelay.value.no_delay = PR_TRUE1;
956 status = PR_SetSocketOption(prfd, &opt_nodelay);
957 if (status != PR_SUCCESS) {
958 r_log(LOG_GENERIC0, LOG_WARNING4,
959 "Failed to set Nodelay on accepted socket: %d", status);
960 }
961
962 // Should fail only with OOM
963 if ((r = nr_socket_create_int(static_cast<void*>(sock), sock->vtbl(), sockp)))
964 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
965
966 // Remember our thread.
967 sock->ststhread_ = do_QueryInterface(stservice, &rv);
968 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
969
970 // Finally, register with the STS
971 rv = stservice->AttachSocket(prfd, sock);
972 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
973 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
974 }
975
976 sock->connect_invoked_ = true;
977
978 // Add a reference so that we can delete it in destroy()
979 sock->AddRef();
980 _status = 0;
981abort:
982 if (_status) {
983 delete sock;
984 }
985
986 return (_status);
987}
988
989NS_IMPL_ISUPPORTS(NrUdpSocketIpcProxy, nsIUDPSocketInternal)MozExternalRefCountType NrUdpSocketIpcProxy::AddRef(void) { static_assert
(!std::is_destructible_v<NrUdpSocketIpcProxy>, "Reference-counted class "
"NrUdpSocketIpcProxy" " 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 989); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
989; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("NrUdpSocketIpcProxy" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("NrUdpSocketIpcProxy" != nullptr
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"\"NrUdpSocketIpcProxy\" != nullptr" " (" "Must specify a name"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 989); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"NrUdpSocketIpcProxy\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 989; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("NrUdpSocketIpcProxy" " not thread-safe"); nsrefcnt
count = ++mRefCnt; NS_LogAddRef((this), (count), ("NrUdpSocketIpcProxy"
), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType
NrUdpSocketIpcProxy::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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 989); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 989
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("NrUdpSocketIpcProxy" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("NrUdpSocketIpcProxy" != nullptr
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"\"NrUdpSocketIpcProxy\" != nullptr" " (" "Must specify a name"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 989); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"NrUdpSocketIpcProxy\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 989; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("NrUdpSocketIpcProxy" " not thread-safe"); const
char* const nametmp = "NrUdpSocketIpcProxy"; nsrefcnt count =
--mRefCnt; NS_LogRelease((this), (count), (nametmp)); if (count
== 0) { mRefCnt = 1; delete (this); return 0; } return count
; } nsresult NrUdpSocketIpcProxy::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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 989); 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<NrUdpSocketIpcProxy, nsIUDPSocketInternal
>, int32_t( reinterpret_cast<char*>(static_cast<nsIUDPSocketInternal
*>((NrUdpSocketIpcProxy*)0x1000)) - reinterpret_cast<char
*>((NrUdpSocketIpcProxy*)0x1000))}, {&mozilla::detail::
kImplementedIID<NrUdpSocketIpcProxy, nsISupports>, int32_t
(reinterpret_cast<char*>(static_cast<nsISupports*>
( static_cast<nsIUDPSocketInternal*>((NrUdpSocketIpcProxy
*)0x1000))) - reinterpret_cast<char*>((NrUdpSocketIpcProxy
*)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; }
990
991nsresult NrUdpSocketIpcProxy::Init(const RefPtr<NrUdpSocketIpc>& socket) {
992 nsresult rv;
993 sts_thread_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/socket-transport-service;1", &rv);
994 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
995 MOZ_ASSERT(false, "Failed to get STS thread")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Failed to get STS thread"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 995); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to get STS thread" ")"); do { *((volatile int*)__null
) = 995; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
996 return rv;
997 }
998
999 socket_ = socket;
1000 return NS_OK;
1001}
1002
1003NrUdpSocketIpcProxy::~NrUdpSocketIpcProxy() {
1004 // Send our ref to STS to be released
1005 RUN_ON_THREAD(sts_thread_, mozilla::WrapRelease(socket_.forget()),
1006 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1007}
1008
1009// IUDPSocketInternal interfaces
1010// callback while error happened in UDP socket operation
1011NS_IMETHODIMPnsresult NrUdpSocketIpcProxy::CallListenerError(const nsACString& message,
1012 const nsACString& filename,
1013 uint32_t line_number) {
1014 return socket_->CallListenerError(message, filename, line_number);
1015}
1016
1017// callback while receiving UDP packet
1018NS_IMETHODIMPnsresult NrUdpSocketIpcProxy::CallListenerReceivedData(
1019 const nsACString& host, uint16_t port, const nsTArray<uint8_t>& data) {
1020 return socket_->CallListenerReceivedData(host, port, data);
1021}
1022
1023// callback while UDP socket is opened
1024NS_IMETHODIMPnsresult NrUdpSocketIpcProxy::CallListenerOpened() {
1025 return socket_->CallListenerOpened();
1026}
1027
1028// callback while UDP socket is connected
1029NS_IMETHODIMPnsresult NrUdpSocketIpcProxy::CallListenerConnected() {
1030 return socket_->CallListenerConnected();
1031}
1032
1033// callback while UDP socket is closed
1034NS_IMETHODIMPnsresult NrUdpSocketIpcProxy::CallListenerClosed() {
1035 return socket_->CallListenerClosed();
1036}
1037
1038// NrUdpSocketIpc Implementation
1039NrUdpSocketIpc::NrUdpSocketIpc()
1040 : NrSocketIpc(GetIOThreadAndAddUse_s()),
1041 monitor_("NrUdpSocketIpc"),
1042 err_(false),
1043 state_(NR_INIT) {}
1044
1045NrUdpSocketIpc::~NrUdpSocketIpc() = default;
1046
1047void NrUdpSocketIpc::Destroy() {
1048#if defined(MOZILLA_INTERNAL_API1)
1049 // destroy_i also dispatches back to STS to call ReleaseUse, to avoid shutting
1050 // down the IO thread before close() runs.
1051 // We use a NonOwning runnable because our refcount has already gone to 0.
1052 io_thread_->Dispatch(NewNonOwningRunnableMethod(
1053 "NrUdpSocketIpc::Destroy", this, &NrUdpSocketIpc::destroy_i));
1054#endif
1055}
1056
1057// IUDPSocketInternal interfaces
1058// callback while error happened in UDP socket operation
1059NS_IMETHODIMPnsresult NrUdpSocketIpc::CallListenerError(const nsACString& message,
1060 const nsACString& filename,
1061 uint32_t line_number) {
1062 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1062); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1062; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1062); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1062; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1063
1064 r_log(LOG_GENERIC0, LOG_ERR3, "UDP socket error:%s at %s:%d this=%p",
1065 message.BeginReading(), filename.BeginReading(), line_number,
1066 (void*)this);
1067
1068 ReentrantMonitorAutoEnter mon(monitor_);
1069 err_ = true;
1070 monitor_.NotifyAll();
1071
1072 return NS_OK;
1073}
1074
1075// callback while receiving UDP packet
1076NS_IMETHODIMPnsresult NrUdpSocketIpc::CallListenerReceivedData(
1077 const nsACString& host, uint16_t port, const nsTArray<uint8_t>& data) {
1078 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1078); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1078; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1078); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1078; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1079
1080 PRNetAddr addr;
1081 memset(&addr, 0, sizeof(addr));
1082
1083 {
1084 ReentrantMonitorAutoEnter mon(monitor_);
1085
1086 if (PR_SUCCESS != PR_StringToNetAddr(host.BeginReading(), &addr)) {
1087 err_ = true;
1088 MOZ_ASSERT(false, "Failed to convert remote host to PRNetAddr")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Failed to convert remote host to PRNetAddr"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1088); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to convert remote host to PRNetAddr" ")"); do { *((volatile
int*)__null) = 1088; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
1089 return NS_OK;
1090 }
1091
1092 // Use PR_IpAddrNull to avoid address being reset to 0.
1093 if (PR_SUCCESS !=
1094 PR_SetNetAddr(PR_IpAddrNull, addr.raw.family, port, &addr)) {
1095 err_ = true;
1096 MOZ_ASSERT(false, "Failed to set port in PRNetAddr")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Failed to set port in PRNetAddr"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1096); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to set port in PRNetAddr" ")"); do { *((volatile int
*)__null) = 1096; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
1097 return NS_OK;
1098 }
1099 }
1100
1101 auto buf = MakeUnique<MediaPacket>();
1102 buf->Copy(data.Elements(), data.Length());
1103 RefPtr<nr_udp_message> msg(new nr_udp_message(addr, std::move(buf)));
1104
1105 RUN_ON_THREAD(sts_thread_,
1106 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
1107 &NrUdpSocketIpc::recv_callback_s, msg),
1108 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1109 return NS_OK;
1110}
1111
1112nsresult NrUdpSocketIpc::SetAddress() {
1113 uint16_t port = socket_child_->LocalPort();
1114
1115 nsAutoCString address(socket_child_->LocalAddress());
1116
1117 PRNetAddr praddr;
1118 if (PR_SUCCESS != PR_InitializeNetAddr(PR_IpAddrAny, port, &praddr)) {
1119 err_ = true;
1120 MOZ_ASSERT(false, "Failed to set port in PRNetAddr")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Failed to set port in PRNetAddr"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1120); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to set port in PRNetAddr" ")"); do { *((volatile int
*)__null) = 1120; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
1121 return NS_OK;
1122 }
1123
1124 if (PR_SUCCESS != PR_StringToNetAddr(address.BeginReading(), &praddr)) {
1125 err_ = true;
1126 MOZ_ASSERT(false, "Failed to convert local host to PRNetAddr")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Failed to convert local host to PRNetAddr"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1126); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to convert local host to PRNetAddr" ")"); do { *((volatile
int*)__null) = 1126; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
1127 return NS_OK;
1128 }
1129
1130 nr_transport_addr expected_addr;
1131 if (nr_transport_addr_copy(&expected_addr, &my_addr_)) {
1132 err_ = true;
1133 MOZ_ASSERT(false, "Failed to copy my_addr_")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Failed to copy my_addr_"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1133); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to copy my_addr_" ")"); do { *((volatile int*)__null
) = 1133; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
1134 }
1135
1136 if (nr_praddr_to_transport_addr(&praddr, &my_addr_, IPPROTO_UDPIPPROTO_UDP, 1)) {
1137 err_ = true;
1138 MOZ_ASSERT(false, "Failed to copy local host to my_addr_")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Failed to copy local host to my_addr_"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1138); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to copy local host to my_addr_" ")"); do { *((volatile
int*)__null) = 1138; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
1139 }
1140
1141 if (!nr_transport_addr_is_wildcard(&expected_addr) &&
1142 nr_transport_addr_cmp(&expected_addr, &my_addr_,
1143 NR_TRANSPORT_ADDR_CMP_MODE_ADDR3)) {
1144 err_ = true;
1145 MOZ_ASSERT(false, "Address of opened socket is not expected")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Address of opened socket is not expected"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1145); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Address of opened socket is not expected" ")"); do { *((volatile
int*)__null) = 1145; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
1146 }
1147
1148 return NS_OK;
1149}
1150
1151// callback while UDP socket is opened
1152NS_IMETHODIMPnsresult NrUdpSocketIpc::CallListenerOpened() {
1153 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1153); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1153; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1153); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1153; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1154 ReentrantMonitorAutoEnter mon(monitor_);
1155
1156 r_log(LOG_GENERIC0, LOG_DEBUG7, "UDP socket opened this=%p", (void*)this);
1157 nsresult rv = SetAddress();
1158 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1159 return rv;
1160 }
1161
1162 mon.NotifyAll();
1163
1164 return NS_OK;
1165}
1166
1167// callback while UDP socket is connected
1168NS_IMETHODIMPnsresult NrUdpSocketIpc::CallListenerConnected() {
1169 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1169); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1169; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1169); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1169; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1170
1171 ReentrantMonitorAutoEnter mon(monitor_);
1172
1173 r_log(LOG_GENERIC0, LOG_DEBUG7, "UDP socket connected this=%p", (void*)this);
1174 MOZ_ASSERT(state_ == NR_CONNECTED)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(state_ == NR_CONNECTED)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(state_ == NR_CONNECTED))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("state_ == NR_CONNECTED"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1174); AnnotateMozCrashReason("MOZ_ASSERT" "(" "state_ == NR_CONNECTED"
")"); do { *((volatile int*)__null) = 1174; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1175
1176 nsresult rv = SetAddress();
1177 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1178 mon.NotifyAll();
1179 return rv;
1180 }
1181
1182 r_log(LOG_GENERIC0, LOG_INFO6, "Exit UDP socket connected");
1183 mon.NotifyAll();
1184
1185 return NS_OK;
1186}
1187
1188// callback while UDP socket is closed
1189NS_IMETHODIMPnsresult NrUdpSocketIpc::CallListenerClosed() {
1190 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1190); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1190; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1190); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1190; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1191
1192 ReentrantMonitorAutoEnter mon(monitor_);
1193
1194 r_log(LOG_GENERIC0, LOG_DEBUG7, "UDP socket closed this=%p", (void*)this);
1195 MOZ_ASSERT(state_ == NR_CONNECTED || state_ == NR_CLOSING)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(state_ == NR_CONNECTED || state_ == NR_CLOSING)>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(state_ == NR_CONNECTED || state_ == NR_CLOSING))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("state_ == NR_CONNECTED || state_ == NR_CLOSING"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1195); AnnotateMozCrashReason("MOZ_ASSERT" "(" "state_ == NR_CONNECTED || state_ == NR_CLOSING"
")"); do { *((volatile int*)__null) = 1195; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1196 state_ = NR_CLOSED;
1197
1198 return NS_OK;
1199}
1200
1201//
1202// NrSocketBase methods.
1203//
1204int NrUdpSocketIpc::create(nr_transport_addr* addr) {
1205 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1205); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1205; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1205); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1205; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1206
1207 int r, _status;
1208 nsresult rv;
1209 int32_t port;
1210 nsCString host;
1211
1212 ReentrantMonitorAutoEnter mon(monitor_);
1213
1214 if (state_ != NR_INIT) {
1215 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1216 }
1217
1218 sts_thread_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/socket-transport-service;1", &rv);
1219 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1220 MOZ_ASSERT(false, "Failed to get STS thread")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Failed to get STS thread"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1220); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to get STS thread" ")"); do { *((volatile int*)__null
) = 1220; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
1221 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1222 }
1223
1224 if ((r = nr_transport_addr_get_addrstring_and_port(addr, &host, &port))) {
1225 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1226 }
1227
1228 // wildcard address will be resolved at NrUdpSocketIpc::CallListenerVoid
1229 if ((r = nr_transport_addr_copy(&my_addr_, addr))) {
1230 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1231 }
1232
1233 state_ = NR_CONNECTING;
1234
1235 MOZ_ASSERT(io_thread_)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(io_thread_)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(io_thread_))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("io_thread_", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1235); AnnotateMozCrashReason("MOZ_ASSERT" "(" "io_thread_"
")"); do { *((volatile int*)__null) = 1235; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1236 RUN_ON_THREAD(io_thread_,
1237 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
1238 &NrUdpSocketIpc::create_i, host,
1239 static_cast<uint16_t>(port)),
1240 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1241
1242 // Wait until socket creation complete.
1243 mon.Wait();
1244
1245 if (err_) {
1246 close();
1247 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1248 }
1249
1250 state_ = NR_CONNECTED;
1251
1252 _status = 0;
1253abort:
1254 return (_status);
1255}
1256
1257int NrUdpSocketIpc::sendto(const void* msg, size_t len, int flags,
1258 const nr_transport_addr* to) {
1259 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1259); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1259; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1259); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1259; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1260
1261 ReentrantMonitorAutoEnter mon(monitor_);
1262
1263 // If send err happened before, simply return the error.
1264 if (err_) {
1265 return R_IO_ERROR13;
1266 }
1267
1268 if (state_ != NR_CONNECTED) {
1269 return R_INTERNAL3;
1270 }
1271
1272 int r;
1273 net::NetAddr addr;
1274 if ((r = nr_transport_addr_to_netaddr(to, &addr))) {
1275 return r;
1276 }
1277
1278 if (nr_is_stun_request_message((UCHAR*)msg, len) && ShouldDrop(len)) {
1279 return R_WOULDBLOCK8;
1280 }
1281
1282 UniquePtr<MediaPacket> buf(new MediaPacket);
1283 buf->Copy(static_cast<const uint8_t*>(msg), len);
1284
1285 RUN_ON_THREAD(
1286 io_thread_,
1287 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
1288 &NrUdpSocketIpc::sendto_i, addr, std::move(buf)),
1289 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1290 return 0;
1291}
1292
1293void NrUdpSocketIpc::close() {
1294 r_log(LOG_GENERIC0, LOG_DEBUG7, "NrUdpSocketIpc::close()");
1295
1296 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1296); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1296; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1296); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1296; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1297
1298 ReentrantMonitorAutoEnter mon(monitor_);
1299 state_ = NR_CLOSING;
1300
1301 RUN_ON_THREAD(io_thread_,
1302 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
1303 &NrUdpSocketIpc::close_i),
1304 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1305
1306 // remove all enqueued messages
1307 std::queue<RefPtr<nr_udp_message>> empty;
1308 std::swap(received_msgs_, empty);
1309}
1310
1311int NrUdpSocketIpc::recvfrom(void* buf, size_t maxlen, size_t* len, int flags,
1312 nr_transport_addr* from) {
1313 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1313); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1313; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1313); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1313; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1314
1315 ReentrantMonitorAutoEnter mon(monitor_);
1316
1317 int r, _status;
1318 uint32_t consumed_len;
1319
1320 *len = 0;
1321
1322 if (state_ != NR_CONNECTED) {
1323 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1324 }
1325
1326 if (received_msgs_.empty()) {
1327 ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1328 }
1329
1330 {
1331 RefPtr<nr_udp_message> msg(received_msgs_.front());
1332
1333 received_msgs_.pop();
1334
1335 if ((r = nr_praddr_to_transport_addr(&msg->from, from, IPPROTO_UDPIPPROTO_UDP, 0))) {
Although the value stored to 'r' is used in the enclosing expression, the value is never actually read from 'r'
1336 err_ = true;
1337 MOZ_ASSERT(false, "Get bogus address for received UDP packet")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Get bogus address for received UDP packet"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1337); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Get bogus address for received UDP packet" ")"); do { *((volatile
int*)__null) = 1337; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
1338 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1339 }
1340
1341 consumed_len = std::min(maxlen, msg->data->len());
1342 if (consumed_len < msg->data->len()) {
1343 r_log(LOG_GENERIC0, LOG_DEBUG7,
1344 "Partial received UDP packet will be discard");
1345 }
1346
1347 memcpy(buf, msg->data->data(), consumed_len);
1348 *len = consumed_len;
1349 }
1350
1351 _status = 0;
1352abort:
1353 return (_status);
1354}
1355
1356int NrUdpSocketIpc::getaddr(nr_transport_addr* addrp) {
1357 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1357); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1357; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1357); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1357; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1358
1359 ReentrantMonitorAutoEnter mon(monitor_);
1360
1361 return nr_transport_addr_copy(addrp, &my_addr_);
1362}
1363
1364int NrUdpSocketIpc::connect(const nr_transport_addr* addr) {
1365 int r, _status;
1366 int32_t port;
1367 nsCString host;
1368
1369 ReentrantMonitorAutoEnter mon(monitor_);
1370 r_log(LOG_GENERIC0, LOG_DEBUG7, "NrUdpSocketIpc::connect(%s) this=%p",
1371 addr->as_string, (void*)this);
1372
1373 if ((r = nr_transport_addr_get_addrstring_and_port(addr, &host, &port))) {
1374 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1375 }
1376
1377 RUN_ON_THREAD(io_thread_,
1378 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
1379 &NrUdpSocketIpc::connect_i, host,
1380 static_cast<uint16_t>(port)),
1381 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1382
1383 // Wait until connect() completes.
1384 mon.Wait();
1385
1386 r_log(LOG_GENERIC0, LOG_DEBUG7,
1387 "NrUdpSocketIpc::connect this=%p completed err_ = %s", (void*)this,
1388 err_ ? "true" : "false");
1389
1390 if (err_) {
1391 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1392 }
1393
1394 _status = 0;
1395abort:
1396 return _status;
1397}
1398
1399int NrUdpSocketIpc::write(const void* msg, size_t len, size_t* written) {
1400 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", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1400); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")")
; do { *((volatile int*)__null) = 1400; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1401 return R_INTERNAL3;
1402}
1403
1404int NrUdpSocketIpc::read(void* buf, size_t maxlen, size_t* len) {
1405 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", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1405); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")")
; do { *((volatile int*)__null) = 1405; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1406 return R_INTERNAL3;
1407}
1408
1409int NrUdpSocketIpc::listen(int backlog) {
1410 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", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1410); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")")
; do { *((volatile int*)__null) = 1410; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1411 return R_INTERNAL3;
1412}
1413
1414int NrUdpSocketIpc::accept(nr_transport_addr* addrp, nr_socket** sockp) {
1415 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", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1415); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")")
; do { *((volatile int*)__null) = 1415; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1416 return R_INTERNAL3;
1417}
1418
1419// IO thread executors
1420void NrUdpSocketIpc::create_i(const nsACString& host, const uint16_t port) {
1421 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1421); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1421; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1421); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1421; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1422
1423 uint32_t minBuffSize = 0;
1424 RefPtr<dom::UDPSocketChild> socketChild = new dom::UDPSocketChild();
1425
1426 // This can spin the event loop; don't do that with the monitor held
1427 socketChild->SetBackgroundSpinsEvents();
1428
1429 ReentrantMonitorAutoEnter mon(monitor_);
1430 if (!socket_child_) {
1431 socket_child_ = socketChild;
1432 socket_child_->SetFilterName(
1433 nsCString(NS_NETWORK_SOCKET_FILTER_HANDLER_STUN_SUFFIX"stun"));
1434 } else {
1435 socketChild = nullptr;
1436 }
1437
1438 RefPtr<NrUdpSocketIpcProxy> proxy(new NrUdpSocketIpcProxy);
1439 nsresult rv = proxy->Init(this);
1440 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1441 err_ = true;
1442 mon.NotifyAll();
1443 return;
1444 }
1445
1446 // XXX bug 1126232 - don't use null Principal!
1447 if (NS_FAILED(socket_child_->Bind(proxy, nullptr, host, port,((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
))), 0)))
1448 /* addressReuse = */ false,((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
))), 0)))
1449 /* loopback = */ false,((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
))), 0)))
1450 /* recv buffer size */ minBuffSize,((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
))), 0)))
1451 /* send buffer size */ minBuffSize))((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
))), 0)))
) {
1452 err_ = true;
1453 MOZ_ASSERT(false, "Failed to create UDP socket")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Failed to create UDP socket"
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1453); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to create UDP socket" ")"); do { *((volatile int*)__null
) = 1453; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
1454 mon.NotifyAll();
1455 return;
1456 }
1457}
1458
1459void NrUdpSocketIpc::connect_i(const nsACString& host, const uint16_t port) {
1460 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1460); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1460; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1460); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1460; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1461 nsresult rv;
1462 ReentrantMonitorAutoEnter mon(monitor_);
1463
1464 RefPtr<NrUdpSocketIpcProxy> proxy(new NrUdpSocketIpcProxy);
1465 rv = proxy->Init(this);
1466 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1467 err_ = true;
1468 mon.NotifyAll();
1469 return;
1470 }
1471
1472 socket_child_->Connect(proxy, host, port);
1473}
1474
1475void NrUdpSocketIpc::sendto_i(const net::NetAddr& addr,
1476 UniquePtr<MediaPacket> buf) {
1477 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1477); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1477; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1477); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1477; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1478
1479 ReentrantMonitorAutoEnter mon(monitor_);
1480
1481 if (!socket_child_) {
1482 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", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1482); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")")
; do { *((volatile int*)__null) = 1482; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1483 err_ = true;
1484 return;
1485 }
1486 if (NS_FAILED(((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
SendWithAddress(&addr, buf->data(), buf->len()))), 0
)))
1487 socket_child_->SendWithAddress(&addr, buf->data(), buf->len()))((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
SendWithAddress(&addr, buf->data(), buf->len()))), 0
)))
) {
1488 err_ = true;
1489 }
1490}
1491
1492void NrUdpSocketIpc::close_i() {
1493 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1493); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1493; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1493); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1493; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1494
1495 if (socket_child_) {
1496 socket_child_->Close();
1497 socket_child_ = nullptr;
1498 }
1499}
1500
1501#if defined(MOZILLA_INTERNAL_API1)
1502
1503static void ReleaseIOThread_s() { sThread->ReleaseUse(); }
1504
1505void NrUdpSocketIpc::destroy_i() {
1506 close_i();
1507
1508 RUN_ON_THREAD(sts_thread_, WrapRunnableNM(&ReleaseIOThread_s),
1509 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1510}
1511#endif
1512
1513void NrUdpSocketIpc::recv_callback_s(RefPtr<nr_udp_message> msg) {
1514 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); 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/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1514); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1514; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(on)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(on))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1514); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1514; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (0)
;
1515
1516 {
1517 ReentrantMonitorAutoEnter mon(monitor_);
1518 if (state_ != NR_CONNECTED) {
1519 return;
1520 }
1521 }
1522
1523 // enqueue received message
1524 received_msgs_.push(msg);
1525
1526 if ((poll_flags() & PR_POLL_READ0x1)) {
1527 fire_callback(NR_ASYNC_WAIT_READ0);
1528 }
1529}
1530
1531} // namespace mozilla
1532
1533using namespace mozilla;
1534
1535// Bridge to the nr_socket interface
1536static int nr_socket_local_destroy(void** objp);
1537static int nr_socket_local_sendto(void* obj, const void* msg, size_t len,
1538 int flags, const nr_transport_addr* to);
1539static int nr_socket_local_recvfrom(void* obj, void* restrict buf,
1540 size_t maxlen, size_t* len, int flags,
1541 nr_transport_addr* from);
1542static int nr_socket_local_getfd(void* obj, NR_SOCKET* fd);
1543static int nr_socket_local_getaddr(void* obj, nr_transport_addr* addrp);
1544static int nr_socket_local_close(void* obj);
1545static int nr_socket_local_connect(void* obj, const nr_transport_addr* addr);
1546static int nr_socket_local_write(void* obj, const void* msg, size_t len,
1547 size_t* written);
1548static int nr_socket_local_read(void* obj, void* restrict buf, size_t maxlen,
1549 size_t* len);
1550static int nr_socket_local_listen(void* obj, int backlog);
1551static int nr_socket_local_accept(void* obj, nr_transport_addr* addrp,
1552 nr_socket** sockp);
1553
1554static nr_socket_vtbl nr_socket_local_vtbl = {2,
1555 nr_socket_local_destroy,
1556 nr_socket_local_sendto,
1557 nr_socket_local_recvfrom,
1558 nr_socket_local_getfd,
1559 nr_socket_local_getaddr,
1560 nr_socket_local_connect,
1561 nr_socket_local_write,
1562 nr_socket_local_read,
1563 nr_socket_local_close,
1564 nr_socket_local_listen,
1565 nr_socket_local_accept};
1566
1567/* static */
1568int NrSocketBase::CreateSocket(
1569 nr_transport_addr* addr, RefPtr<NrSocketBase>* sock,
1570 const std::shared_ptr<NrSocketProxyConfig>& config) {
1571 int r, _status;
1572
1573 if (IsForbiddenAddress(addr)) {
1574 ABORT(R_REJECTED)do { int _r=11; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1575 }
1576
1577 if (config && config->GetForceProxy() && addr->protocol == IPPROTO_UDPIPPROTO_UDP) {
1578 ABORT(R_REJECTED)do { int _r=11; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1579 }
1580
1581 // create IPC bridge for content process
1582 if (XRE_IsParentProcess()) {
1583 // TODO: Make NrTcpSocket work on the parent process
1584 *sock = new NrSocket();
1585 } else if (XRE_IsSocketProcess()) {
1586 if (addr->protocol == IPPROTO_TCPIPPROTO_TCP) {
1587 *sock = new NrTcpSocket(config);
1588 } else {
1589 *sock = new NrSocket();
1590 }
1591 } else {
1592 if (addr->protocol == IPPROTO_TCPIPPROTO_TCP) {
1593 *sock = new NrTcpSocket(config);
1594 } else {
1595 *sock = new NrUdpSocketIpc();
1596 }
1597 }
1598
1599 r = (*sock)->create(addr);
1600 if (r) ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1601
1602 _status = 0;
1603abort:
1604 if (_status) {
1605 *sock = nullptr;
1606 }
1607 return _status;
1608}
1609
1610// static
1611bool NrSocketBase::IsForbiddenAddress(nr_transport_addr* addr) {
1612 int r, port;
1613
1614 r = nr_transport_addr_get_port(addr, &port);
1615 if (r) {
1616 return true;
1617 }
1618
1619 // allow auto assigned ports
1620 if (port != 0) {
1621 // Don't need to check an override scheme
1622 nsresult rv = NS_CheckPortSafety(port, nullptr);
1623 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1624 return true;
1625 }
1626 }
1627
1628 return false;
1629}
1630
1631static int nr_socket_local_destroy(void** objp) {
1632 if (!objp || !*objp) return 0;
1633
1634 NrSocketBase* sock = static_cast<NrSocketBase*>(*objp);
1635 *objp = nullptr;
1636
1637 sock->close(); // Signal STS that we want not to listen
1638 sock->Release(); // Decrement the ref count
1639
1640 return 0;
1641}
1642
1643static int nr_socket_local_sendto(void* obj, const void* msg, size_t len,
1644 int flags, const nr_transport_addr* addr) {
1645 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1646
1647 return sock->sendto(msg, len, flags, addr);
1648}
1649
1650static int nr_socket_local_recvfrom(void* obj, void* restrict buf,
1651 size_t maxlen, size_t* len, int flags,
1652 nr_transport_addr* addr) {
1653 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1654
1655 return sock->recvfrom(buf, maxlen, len, flags, addr);
1656}
1657
1658static int nr_socket_local_getfd(void* obj, NR_SOCKET* fd) {
1659 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1660
1661 *fd = sock;
1662
1663 return 0;
1664}
1665
1666static int nr_socket_local_getaddr(void* obj, nr_transport_addr* addrp) {
1667 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1668
1669 return sock->getaddr(addrp);
1670}
1671
1672static int nr_socket_local_close(void* obj) {
1673 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1674
1675 sock->close();
1676
1677 return 0;
1678}
1679
1680static int nr_socket_local_write(void* obj, const void* msg, size_t len,
1681 size_t* written) {
1682 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1683
1684 return sock->write(msg, len, written);
1685}
1686
1687static int nr_socket_local_read(void* obj, void* restrict buf, size_t maxlen,
1688 size_t* len) {
1689 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1690
1691 return sock->read(buf, maxlen, len);
1692}
1693
1694static int nr_socket_local_connect(void* obj, const nr_transport_addr* addr) {
1695 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1696
1697 return sock->connect(addr);
1698}
1699
1700static int nr_socket_local_listen(void* obj, int backlog) {
1701 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1702
1703 return sock->listen(backlog);
1704}
1705
1706static int nr_socket_local_accept(void* obj, nr_transport_addr* addrp,
1707 nr_socket** sockp) {
1708 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1709
1710 return sock->accept(addrp, sockp);
1711}
1712
1713// Implement async api
1714int NR_async_wait(NR_SOCKET sock, int how, NR_async_cb cb, void* cb_arg,
1715 char* function, int line) {
1716 NrSocketBase* s = static_cast<NrSocketBase*>(sock);
1717
1718 return s->async_wait(how, cb, cb_arg, function, line);
1719}
1720
1721int NR_async_cancel(NR_SOCKET sock, int how) {
1722 NrSocketBase* s = static_cast<NrSocketBase*>(sock);
1723
1724 return s->cancel(how);
1725}
1726
1727nr_socket_vtbl* NrSocketBase::vtbl() { return &nr_socket_local_vtbl; }