Bug Summary

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