diff --git a/accessible/base/nsAccessibilityService.h b/accessible/base/nsAccessibilityService.h index b216985a6059..1cd5783f2fef 100644 --- a/accessible/base/nsAccessibilityService.h +++ b/accessible/base/nsAccessibilityService.h @@ -31,7 +31,7 @@ class PresShell; namespace dom { class DOMStringList; class Element; -} +} // namespace dom namespace a11y { diff --git a/browser/app/nsBrowserApp.cpp b/browser/app/nsBrowserApp.cpp index ec7a44c601b7..4649820da222 100644 --- a/browser/app/nsBrowserApp.cpp +++ b/browser/app/nsBrowserApp.cpp @@ -262,7 +262,7 @@ int main(int argc, char* argv[], char* envp[]) { // argc & argv will be updated with the values passing from the // chrome process. With the new values, this function // continues the reset of the code acting as a content process. - if(gBootstrap->XRE_ForkServer(&argc, &argv)) { + if (gBootstrap->XRE_ForkServer(&argc, &argv)) { // Return from the fork server in the fork server process. // Stop the fork server. gBootstrap->NS_LogTerm(); diff --git a/browser/app/winlauncher/DllBlocklistInit.cpp b/browser/app/winlauncher/DllBlocklistInit.cpp index 83fcbf336790..2d75c59d8f73 100644 --- a/browser/app/winlauncher/DllBlocklistInit.cpp +++ b/browser/app/winlauncher/DllBlocklistInit.cpp @@ -65,11 +65,11 @@ LauncherVoidResultWithLineInfo InitializeDllBlocklistOOP( // safely make its ntdll calls. HMODULE ourModule; -#if defined(_MSC_VER) +# if defined(_MSC_VER) ourModule = reinterpret_cast(&__ImageBase); -#else +# else ourModule = ::GetModuleHandleW(nullptr); -#endif // defined(_MSC_VER) +# endif // defined(_MSC_VER) mozilla::nt::PEHeaders ourExeImage(ourModule); if (!ourExeImage) { @@ -84,7 +84,7 @@ LauncherVoidResultWithLineInfo InitializeDllBlocklistOOP( return importDirRestored; } - Maybe> ntdllThunks = + Maybe > ntdllThunks = ourExeImage.GetIATThunksForModule("ntdll.dll"); if (!ntdllThunks) { return LAUNCHER_ERROR_FROM_WIN32(ERROR_INVALID_DATA); diff --git a/caps/ContentPrincipal.h b/caps/ContentPrincipal.h index 55855537871f..ec4fc7cedacd 100644 --- a/caps/ContentPrincipal.h +++ b/caps/ContentPrincipal.h @@ -57,7 +57,12 @@ class ContentPrincipal final : public BasePrincipal { virtual nsresult PopulateJSONObject(Json::Value& aObject) override; // Serializable keys are the valid enum fields the serialization supports - enum SerializableKeys : uint8_t { eURI = 0, eDomain, eSuffix, eMax = eSuffix }; + enum SerializableKeys : uint8_t { + eURI = 0, + eDomain, + eSuffix, + eMax = eSuffix + }; typedef mozilla::BasePrincipal::KeyValT KeyVal; static already_AddRefed FromProperties( diff --git a/docshell/shistory/ChildSHistory.h b/docshell/shistory/ChildSHistory.h index 3f078e60e12e..c29f817e7380 100644 --- a/docshell/shistory/ChildSHistory.h +++ b/docshell/shistory/ChildSHistory.h @@ -37,7 +37,6 @@ namespace dom { class ChildSHistory : public nsISupports, public nsWrapperCache { public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ChildSHistory) nsISupports* GetParentObject() const; diff --git a/dom/base/ScreenOrientation.cpp b/dom/base/ScreenOrientation.cpp index c40dd34102e9..ca588734b448 100644 --- a/dom/base/ScreenOrientation.cpp +++ b/dom/base/ScreenOrientation.cpp @@ -615,9 +615,9 @@ ScreenOrientation::VisibleEventListener::HandleEvent(Event* aEvent) { BrowsingContext* bc = doc->GetBrowsingContext(); if (bc && bc->GetCurrentOrientationType() != - orientation->DeviceType(CallerType::System)) { + orientation->DeviceType(CallerType::System)) { bc->SetCurrentOrientation(orientation->DeviceType(CallerType::System), - orientation->DeviceAngle(CallerType::System)); + orientation->DeviceAngle(CallerType::System)); nsCOMPtr runnable = orientation->DispatchChangeEventAndResolvePromise(); diff --git a/dom/bindings/BindingDeclarations.h b/dom/bindings/BindingDeclarations.h index 140e5ebee44f..9b25f2897853 100644 --- a/dom/bindings/BindingDeclarations.h +++ b/dom/bindings/BindingDeclarations.h @@ -188,19 +188,19 @@ class Optional : public Optional_base { }; template -class Optional > - : public Optional_base, JS::Rooted > { +class Optional> + : public Optional_base, JS::Rooted> { public: MOZ_ALLOW_TEMPORARY Optional() - : Optional_base, JS::Rooted >() {} + : Optional_base, JS::Rooted>() {} explicit Optional(JSContext* cx) - : Optional_base, JS::Rooted >() { + : Optional_base, JS::Rooted>() { this->Construct(cx); } Optional(JSContext* cx, const T& aValue) - : Optional_base, JS::Rooted >(cx, aValue) {} + : Optional_base, JS::Rooted>(cx, aValue) {} // Override the const Value() to return the right thing so we're not // returning references to temporaries. @@ -249,7 +249,7 @@ class Optional { template class NonNull; template -class Optional > : public Optional_base > { +class Optional> : public Optional_base> { public: // We want our Value to actually return a non-const reference, even // if we're const. At least for things that are normally pointer @@ -264,7 +264,7 @@ class Optional > : public Optional_base > { // A specialization of Optional for OwningNonNull that lets us get a // T& from Value() template -class Optional > : public Optional_base > { +class Optional> : public Optional_base> { public: // We want our Value to actually return a non-const reference, even // if we're const. At least for things that are normally pointer @@ -412,8 +412,10 @@ template class Sequence : public FallibleTArray { public: Sequence() : FallibleTArray() {} - MOZ_IMPLICIT Sequence(FallibleTArray&& aArray) : FallibleTArray(std::move(aArray)) {} - MOZ_IMPLICIT Sequence(nsTArray&& aArray) : FallibleTArray(std::move(aArray)) {} + MOZ_IMPLICIT Sequence(FallibleTArray&& aArray) + : FallibleTArray(std::move(aArray)) {} + MOZ_IMPLICIT Sequence(nsTArray&& aArray) + : FallibleTArray(std::move(aArray)) {} }; inline nsWrapperCache* GetWrapperCache(nsWrapperCache* cache) { return cache; } diff --git a/dom/bindings/test/WrapperCachedNonISupportsTestInterface.h b/dom/bindings/test/WrapperCachedNonISupportsTestInterface.h index 5d07dbdacb7e..f2b4720cba16 100644 --- a/dom/bindings/test/WrapperCachedNonISupportsTestInterface.h +++ b/dom/bindings/test/WrapperCachedNonISupportsTestInterface.h @@ -27,7 +27,8 @@ class WrapperCachedNonISupportsTestInterface final : public nsWrapperCache { public: WrapperCachedNonISupportsTestInterface() {} - static already_AddRefed Constructor(const GlobalObject& aGlobalObject); + static already_AddRefed Constructor( + const GlobalObject& aGlobalObject); protected: ~WrapperCachedNonISupportsTestInterface() {} diff --git a/dom/localstorage/LSSnapshot.h b/dom/localstorage/LSSnapshot.h index 2d8e71f19e54..c6637d0aa754 100644 --- a/dom/localstorage/LSSnapshot.h +++ b/dom/localstorage/LSSnapshot.h @@ -28,8 +28,8 @@ class LSSnapshotInitInfo; class LSWriteAndNotifyInfo; class SnapshotWriteOptimizer; -template class Optional; - +template +class Optional; class LSSnapshot final : public nsIRunnable { public: diff --git a/dom/localstorage/LSValue.h b/dom/localstorage/LSValue.h index 6ca9a3b70ebf..836d1cff9786 100644 --- a/dom/localstorage/LSValue.h +++ b/dom/localstorage/LSValue.h @@ -13,7 +13,8 @@ class mozIStorageStatement; namespace IPC { - template struct ParamTraits; +template +struct ParamTraits; } namespace mozilla { diff --git a/dom/media/FileBlockCache.cpp b/dom/media/FileBlockCache.cpp index 916f8b50da1a..8beded18eaa3 100644 --- a/dom/media/FileBlockCache.cpp +++ b/dom/media/FileBlockCache.cpp @@ -114,13 +114,14 @@ void FileBlockCache::Flush() { // Dispatch a task so we won't clear the arrays while PerformBlockIOs() is // dropping the data lock and cause InvalidArrayIndex. RefPtr self = this; - mBackgroundET->Dispatch(NS_NewRunnableFunction("FileBlockCache::Flush", [self]() { - MutexAutoLock mon(self->mDataMutex); - // Just discard pending changes, assume MediaCache won't read from - // blocks it hasn't written to. - self->mChangeIndexList.clear(); - self->mBlockChanges.Clear(); - })); + mBackgroundET->Dispatch( + NS_NewRunnableFunction("FileBlockCache::Flush", [self]() { + MutexAutoLock mon(self->mDataMutex); + // Just discard pending changes, assume MediaCache won't read from + // blocks it hasn't written to. + self->mChangeIndexList.clear(); + self->mBlockChanges.Clear(); + })); } size_t FileBlockCache::GetMaxBlocks(size_t aCacheSizeInKB) const { @@ -175,18 +176,19 @@ void FileBlockCache::Close() { } // Let the thread close the FD, and then trigger its own shutdown. - // Note that mBackgroundET is now empty, so no other task will be posted there. - // Also mBackgroundET and mFD are empty and therefore can be reused immediately. - nsresult rv = thread->Dispatch( - NS_NewRunnableFunction( - "FileBlockCache::Close", - [thread, fd] { - if (fd) { - CloseFD(fd); - } - // No need to shutdown background task queues. - }), - NS_DISPATCH_EVENT_MAY_BLOCK); + // Note that mBackgroundET is now empty, so no other task will be posted + // there. Also mBackgroundET and mFD are empty and therefore can be reused + // immediately. + nsresult rv = thread->Dispatch(NS_NewRunnableFunction("FileBlockCache::Close", + [thread, fd] { + if (fd) { + CloseFD(fd); + } + // No need to shutdown + // background task + // queues. + }), + NS_DISPATCH_EVENT_MAY_BLOCK); NS_ENSURE_SUCCESS_VOID(rv); } diff --git a/dom/media/hls/HLSDemuxer.cpp b/dom/media/hls/HLSDemuxer.cpp index 4d90ef432732..51754a77f76e 100644 --- a/dom/media/hls/HLSDemuxer.cpp +++ b/dom/media/hls/HLSDemuxer.cpp @@ -363,8 +363,7 @@ void HLSTrackDemuxer::UpdateMediaInfo(int index) { audioInfo->mBitDepth = audioInfoObj->BitDepth(); audioInfo->mMimeType = NS_ConvertUTF16toUTF8(audioInfoObj->MimeType()->ToString()); - audioInfo->mDuration = - TimeUnit::FromMicroseconds(audioInfoObj->Duration()); + audioInfo->mDuration = TimeUnit::FromMicroseconds(audioInfoObj->Duration()); jni::ByteArray::LocalRef csdBytes = audioInfoObj->CodecSpecificData(); if (csdBytes) { auto&& csd = csdBytes->GetElements(); @@ -389,11 +388,9 @@ void HLSTrackDemuxer::UpdateMediaInfo(int index) { videoInfo->mDisplay.height = videoInfoObj->PictureHeight(); videoInfo->mMimeType = NS_ConvertUTF16toUTF8(videoInfoObj->MimeType()->ToString()); - videoInfo->mDuration = - TimeUnit::FromMicroseconds(videoInfoObj->Duration()); - HLS_DEBUG("HLSTrackDemuxer", - "Update video info (%d) / I(%dx%d) / D(%dx%d)", index, - videoInfo->mImage.width, videoInfo->mImage.height, + videoInfo->mDuration = TimeUnit::FromMicroseconds(videoInfoObj->Duration()); + HLS_DEBUG("HLSTrackDemuxer", "Update video info (%d) / I(%dx%d) / D(%dx%d)", + index, videoInfo->mImage.width, videoInfo->mImage.height, videoInfo->mDisplay.width, videoInfo->mDisplay.height); } } diff --git a/dom/security/nsContentSecurityUtils.h b/dom/security/nsContentSecurityUtils.h index abeea569699b..1c5ae3fd6ada 100644 --- a/dom/security/nsContentSecurityUtils.h +++ b/dom/security/nsContentSecurityUtils.h @@ -23,7 +23,8 @@ typedef mozilla::Pair> class nsContentSecurityUtils { public: - static FilenameTypeAndDetails FilenameToFilenameType(const nsString& fileName); + static FilenameTypeAndDetails FilenameToFilenameType( + const nsString& fileName); static bool IsEvalAllowed(JSContext* cx, bool aIsSystemPrincipal, const nsAString& aScript); static void NotifyEvalUsage(bool aIsSystemPrincipal, diff --git a/gfx/2d/ScaleFactors2D.h b/gfx/2d/ScaleFactors2D.h index 7a7e789acb28..3057ebac9859 100644 --- a/gfx/2d/ScaleFactors2D.h +++ b/gfx/2d/ScaleFactors2D.h @@ -53,7 +53,8 @@ struct ScaleFactors2D { return ScaleFactor(xScale); } - ScaleFactors2D& operator=(const ScaleFactors2D&) = default; + ScaleFactors2D& operator=(const ScaleFactors2D&) = + default; bool operator==(const ScaleFactors2D& aOther) const { return xScale == aOther.xScale && yScale == aOther.yScale; diff --git a/gfx/layers/ScrollableLayerGuid.h b/gfx/layers/ScrollableLayerGuid.h index 7f81c6763af4..f23c7d93b81e 100644 --- a/gfx/layers/ScrollableLayerGuid.h +++ b/gfx/layers/ScrollableLayerGuid.h @@ -11,7 +11,7 @@ #include "mozilla/HashFunctions.h" // for HashGeneric #include "mozilla/gfx/Logging.h" // for Log #include "mozilla/layers/LayersTypes.h" // for LayersId -#include "nsHashKeys.h" // for nsPrintfCString +#include "nsHashKeys.h" // for nsPrintfCString #include "nsPrintfCString.h" // for nsPrintfCString namespace mozilla { diff --git a/image/imgTools.cpp b/image/imgTools.cpp index 00cfbd56d53f..d26d0c8a359e 100644 --- a/image/imgTools.cpp +++ b/image/imgTools.cpp @@ -86,7 +86,8 @@ class ImageDecoderListener final : public nsIStreamListener, : mURI(aURI), mImage(nullptr), mCallback(aCallback), - mObserver(aObserver ? new NotificationObserverWrapper(aObserver) : nullptr) { + mObserver(aObserver ? new NotificationObserverWrapper(aObserver) + : nullptr) { MOZ_ASSERT(NS_IsMainThread()); } diff --git a/ipc/app/MozillaRuntimeMain.cpp b/ipc/app/MozillaRuntimeMain.cpp index df61f8c47d13..2a5b18498868 100644 --- a/ipc/app/MozillaRuntimeMain.cpp +++ b/ipc/app/MozillaRuntimeMain.cpp @@ -13,8 +13,7 @@ using namespace mozilla; -static bool -UseForkServer(int argc, char* argv[]) { +static bool UseForkServer(int argc, char* argv[]) { #if defined(MOZ_ENABLE_FORKSERVER) return strcmp(argv[argc - 1], "forkserver") == 0; #else @@ -22,8 +21,8 @@ UseForkServer(int argc, char* argv[]) { #endif } -static int -RunForkServer(Bootstrap::UniquePtr&& bootstrap, int argc, char* argv[]) { +static int RunForkServer(Bootstrap::UniquePtr&& bootstrap, int argc, + char* argv[]) { #if defined(MOZ_ENABLE_FORKSERVER) int ret = 0; @@ -38,7 +37,7 @@ RunForkServer(Bootstrap::UniquePtr&& bootstrap, int argc, char* argv[]) { // argc & argv will be updated with the values passing from the // chrome process. With the new values, this function // continues the reset of the code acting as a content process. - if(bootstrap->XRE_ForkServer(&argc, &argv)) { + if (bootstrap->XRE_ForkServer(&argc, &argv)) { // Return from the fork server in the fork server process. // Stop the fork server. } else { diff --git a/ipc/chromium/src/base/process_util.h b/ipc/chromium/src/base/process_util.h index 82a983293da1..f2368072cf77 100644 --- a/ipc/chromium/src/base/process_util.h +++ b/ipc/chromium/src/base/process_util.h @@ -44,15 +44,15 @@ #include "mozilla/ipc/EnvironmentMap.h" #if defined(MOZ_ENABLE_FORKSERVER) -#include "nsString.h" -#include "mozilla/Tuple.h" -#include "mozilla/ipc/FileDescriptorShuffle.h" +# include "nsString.h" +# include "mozilla/Tuple.h" +# include "mozilla/ipc/FileDescriptorShuffle.h" namespace mozilla { namespace ipc { class FileDescriptor; } -} +} // namespace mozilla #endif #if defined(OS_MACOSX) @@ -195,7 +195,7 @@ EnvironmentArray BuildEnvironmentArray(const environment_map& env_vars_to_set); * and second step, that is why two steps. */ class AppProcessBuilder { -public: + public: AppProcessBuilder(); // This function will fork a new process for use as a // content processes. @@ -209,10 +209,10 @@ public: // The message loop may allocate resources like file descriptors. // If this function is called before the end of the loop, the // reosurces may be destroyed while the loop is still alive. - void InitAppProcess(int *argcp, char*** argvp); + void InitAppProcess(int* argcp, char*** argvp); -private: - void ReplaceArguments(int *argcp, char*** argvp); + private: + void ReplaceArguments(int* argcp, char*** argvp); mozilla::ipc::FileDescriptorShuffle shuffle_; std::vector argv_; diff --git a/ipc/chromium/src/base/process_util_linux.cc b/ipc/chromium/src/base/process_util_linux.cc index 6715e9f64212..cb4f30c728eb 100644 --- a/ipc/chromium/src/base/process_util_linux.cc +++ b/ipc/chromium/src/base/process_util_linux.cc @@ -14,18 +14,18 @@ #include "algorithm" #if defined(MOZ_ENABLE_FORKSERVER) -#include -#include -#include -#include +# include +# include +# include +# include # if defined(DEBUG) -#include "base/message_loop.h" +# include "base/message_loop.h" # endif -#include "mozilla/DebugOnly.h" -#include "mozilla/ipc/ForkServiceChild.h" +# include "mozilla/DebugOnly.h" +# include "mozilla/ipc/ForkServiceChild.h" -#include "mozilla/Unused.h" -#include "mozilla/ScopeExit.h" +# include "mozilla/Unused.h" +# include "mozilla/ScopeExit.h" using namespace mozilla::ipc; #endif @@ -51,16 +51,14 @@ namespace base { #if defined(MOZ_ENABLE_FORKSERVER) static mozilla::StaticAutoPtr > sNoCloseFDs; -void -RegisterForkServerNoCloseFD(int fd) { +void RegisterForkServerNoCloseFD(int fd) { if (!sNoCloseFDs) { sNoCloseFDs = new std::vector(); } sNoCloseFDs->push_back(fd); } -static bool -IsNoCloseFd(int fd) { +static bool IsNoCloseFd(int fd) { if (!sNoCloseFDs) { return false; } @@ -68,19 +66,17 @@ IsNoCloseFd(int fd) { [fd](int regfd) -> bool { return regfd == fd; }); } -AppProcessBuilder::AppProcessBuilder() { -} +AppProcessBuilder::AppProcessBuilder() {} -static void -ReplaceEnviroment(const LaunchOptions& options) { +static void ReplaceEnviroment(const LaunchOptions& options) { for (auto& elt : options.env_map) { setenv(elt.first.c_str(), elt.second.c_str(), 1); } } -bool -AppProcessBuilder::ForkProcess(const std::vector& argv, - const LaunchOptions& options, ProcessHandle* process_handle) { +bool AppProcessBuilder::ForkProcess(const std::vector& argv, + const LaunchOptions& options, + ProcessHandle* process_handle) { auto cleanFDs = mozilla::MakeScopeExit([&] { for (auto& elt : options.fds_to_remap) { auto fd = std::get<0>(elt); @@ -98,16 +94,16 @@ AppProcessBuilder::ForkProcess(const std::vector& argv, fflush(stdout); fflush(stderr); -#ifdef OS_LINUX +# ifdef OS_LINUX pid_t pid = options.fork_delegate ? options.fork_delegate->Fork() : fork(); // WARNING: if pid == 0, only async signal safe operations are permitted from // here until exec or _exit. // // Specifically, heap allocation is not safe: the sandbox's fork substitute // won't run the pthread_atfork handlers that fix up the malloc locks. -#else +# else pid_t pid = fork(); -#endif +# endif if (pid < 0) { return false; @@ -127,8 +123,7 @@ AppProcessBuilder::ForkProcess(const std::vector& argv, return true; } -void -AppProcessBuilder::ReplaceArguments(int *argcp, char*** argvp) { +void AppProcessBuilder::ReplaceArguments(int* argcp, char*** argvp) { // Change argc & argv of main() with the arguments passing // through IPC. char** argv = new char*[argv_.size() + 1]; @@ -141,8 +136,7 @@ AppProcessBuilder::ReplaceArguments(int *argcp, char*** argvp) { *argcp = argv_.size(); } -void -AppProcessBuilder::InitAppProcess(int *argcp, char*** argvp) { +void AppProcessBuilder::InitAppProcess(int* argcp, char*** argvp) { MOZ_ASSERT(MessageLoop::current() == nullptr, "The message loop of the main thread should have been destroyed"); @@ -157,8 +151,7 @@ AppProcessBuilder::InitAppProcess(int *argcp, char*** argvp) { } CloseSuperfluousFds(&shuffle_, [](void* ctx, int fd) { - return static_cast(ctx)->MapsTo(fd) || - IsNoCloseFd(fd); + return static_cast(ctx)->MapsTo(fd) || IsNoCloseFd(fd); }); // Without this, the destructor of |shuffle_| would try to close FDs // created by it, but they have been closed by @@ -168,21 +161,16 @@ AppProcessBuilder::InitAppProcess(int *argcp, char*** argvp) { ReplaceArguments(argcp, argvp); } -static void -handle_sigchld(int s) { - waitpid(-1, nullptr, WNOHANG); -} +static void handle_sigchld(int s) { waitpid(-1, nullptr, WNOHANG); } -static void -InstallChildSignalHandler() { +static void InstallChildSignalHandler() { // Since content processes are not children of the chrome process // any more, the fork server process has to handle SIGCHLD, or // content process would remain zombie after dead. signal(SIGCHLD, handle_sigchld); } -static void -ReserveFileDescriptors() { +static void ReserveFileDescriptors() { // Reserve the lower positions of the file descriptors to make sure // debug files and other files don't take these positions. So we // can keep their file descriptors during CloseSuperfluousFds() with @@ -193,16 +181,14 @@ ReserveFileDescriptors() { } } -void -InitForkServerProcess() { +void InitForkServerProcess() { InstallChildSignalHandler(); ReserveFileDescriptors(); } -static bool -LaunchAppWithForkServer(const std::vector& argv, - const LaunchOptions& options, - ProcessHandle* process_handle) { +static bool LaunchAppWithForkServer(const std::vector& argv, + const LaunchOptions& options, + ProcessHandle* process_handle) { MOZ_ASSERT(ForkServiceChild::Get()); nsTArray _argv(argv.size()); @@ -217,13 +203,12 @@ LaunchAppWithForkServer(const std::vector& argv, nsCString(vv.second.c_str()))); } for (auto& fdmapping : options.fds_to_remap) { - fdsremap.AppendElement(mozilla::FdMapping(mozilla::ipc::FileDescriptor(fdmapping.first), - fdmapping.second)); + fdsremap.AppendElement(mozilla::FdMapping( + mozilla::ipc::FileDescriptor(fdmapping.first), fdmapping.second)); } - return ForkServiceChild::Get()->SendForkNewSubprocess(_argv, env, - fdsremap, - process_handle); + return ForkServiceChild::Get()->SendForkNewSubprocess(_argv, env, fdsremap, + process_handle); } #endif // MOZ_ENABLE_FORKSERVER diff --git a/ipc/chromium/src/base/process_util_posix.cc b/ipc/chromium/src/base/process_util_posix.cc index d438c5ae2ed3..ea743685483a 100644 --- a/ipc/chromium/src/base/process_util_posix.cc +++ b/ipc/chromium/src/base/process_util_posix.cc @@ -213,7 +213,7 @@ bool DidProcessCrash(bool* child_exited, ProcessHandle handle) { // them. const int r = kill(handle, 0); if (r < 0 && errno == ESRCH) { - if (child_exited) *child_exited = true; + if (child_exited) *child_exited = true; } else { if (child_exited) *child_exited = false; } @@ -261,7 +261,7 @@ bool DidProcessCrash(bool* child_exited, ProcessHandle handle) { if (WIFEXITED(status)) return WEXITSTATUS(status) != 0; return false; -#endif // MOZ_ENABLE_FORKSERVER +#endif // MOZ_ENABLE_FORKSERVER } void FreeEnvVarsArray::operator()(char** array) { diff --git a/ipc/chromium/src/chrome/common/ipc_message.h b/ipc/chromium/src/chrome/common/ipc_message.h index c7c1eadb6b72..de7c6b9ddf96 100644 --- a/ipc/chromium/src/chrome/common/ipc_message.h +++ b/ipc/chromium/src/chrome/common/ipc_message.h @@ -33,7 +33,7 @@ namespace mozilla { namespace ipc { class MiniTransceiver; } -} +} // namespace mozilla class FileDescriptorSet; diff --git a/ipc/glue/FileDescriptorShuffle.h b/ipc/glue/FileDescriptorShuffle.h index 54aa12eadf2d..4afa8e047401 100644 --- a/ipc/glue/FileDescriptorShuffle.h +++ b/ipc/glue/FileDescriptorShuffle.h @@ -51,9 +51,7 @@ class FileDescriptorShuffle { // Forget the information, so that it's destructor will not try to // delete FDs duped by itself. - void Forget() { - mTempFds.Clear(); - } + void Forget() { mTempFds.Clear(); } private: nsTArray> mMapping; diff --git a/ipc/glue/ForkServer.cpp b/ipc/glue/ForkServer.cpp index eb8dc3181c56..4a69ec38a457 100644 --- a/ipc/glue/ForkServer.cpp +++ b/ipc/glue/ForkServer.cpp @@ -14,12 +14,11 @@ #include #if defined(XP_LINUX) && defined(MOZ_SANDBOX) -#include "mozilla/SandboxLaunch.h" +# include "mozilla/SandboxLaunch.h" #endif #include - namespace mozilla { namespace ipc { @@ -27,64 +26,59 @@ static const int sClientFd = 3; LazyLogModule gForkServiceLog("ForkService"); -ForkServer::ForkServer() { -} +ForkServer::ForkServer() {} /** * Prepare an environment for running a fork server. */ -void -ForkServer::InitProcess(int* aArgc, char*** aArgv) { - base::InitForkServerProcess(); +void ForkServer::InitProcess(int* aArgc, char*** aArgv) { + base::InitForkServerProcess(); - int fd = sClientFd; - int fd_flags = fcntl(sClientFd, F_GETFL, 0); - fcntl(fd, F_SETFL, fd_flags & ~O_NONBLOCK); - mTcver = MakeUnique(fd, DataBufferClear::AfterReceiving); + int fd = sClientFd; + int fd_flags = fcntl(sClientFd, F_GETFL, 0); + fcntl(fd, F_SETFL, fd_flags & ~O_NONBLOCK); + mTcver = MakeUnique(fd, DataBufferClear::AfterReceiving); } /** * Start providing the service at the IPC channel. */ -bool -ForkServer::HandleMessages() { - // |sClientFd| is created by an instance of |IPC::Channel|. - // It sends a HELLO automatically. - IPC::Message hello; - mTcver->RecvInfallible(hello, - "Expect to receive a HELLO message from the parent process!"); - MOZ_ASSERT(hello.type() == kHELLO_MESSAGE_TYPE); +bool ForkServer::HandleMessages() { + // |sClientFd| is created by an instance of |IPC::Channel|. + // It sends a HELLO automatically. + IPC::Message hello; + mTcver->RecvInfallible( + hello, "Expect to receive a HELLO message from the parent process!"); + MOZ_ASSERT(hello.type() == kHELLO_MESSAGE_TYPE); - // Send it back - mTcver->SendInfallible(hello, "Fail to ack the received HELLO!"); + // Send it back + mTcver->SendInfallible(hello, "Fail to ack the received HELLO!"); - while (true) { - IPC::Message msg; - if (!mTcver->Recv(msg)) { - break; - } - - OnMessageReceived(std::move(msg)); - - if (mAppProcBuilder) { - // New process - child - return false; - } + while (true) { + IPC::Message msg; + if (!mTcver->Recv(msg)) { + break; } - // Stop the server - return true; + + OnMessageReceived(std::move(msg)); + + if (mAppProcBuilder) { + // New process - child + return false; + } + } + // Stop the server + return true; } -inline void -CleanCString(nsCString& str) { - char* data; - int sz = str.GetMutableData(&data); +inline void CleanCString(nsCString& str) { + char* data; + int sz = str.GetMutableData(&data); - memset(data, ' ', sz); + memset(data, ' ', sz); } -inline void -CleanString(std::string& str) { +inline void CleanString(std::string& str) { const char deadbeef[] = "\xde\xad\xbe\xef\xde\xad\xbe\xef\xde\xad\xbe\xef\xde\xad\xbe\xef" "\xde\xad\xbe\xef\xde\xad\xbe\xef\xde\xad\xbe\xef\xde\xad\xbe\xef"; @@ -98,97 +92,91 @@ CleanString(std::string& str) { } } -inline void -PrepareArguments(std::vector& aArgv, - nsTArray& aArgvArray) { - for (auto& elt : aArgvArray) { - aArgv.push_back(elt.get()); - CleanCString(elt); - } +inline void PrepareArguments(std::vector& aArgv, + nsTArray& aArgvArray) { + for (auto& elt : aArgvArray) { + aArgv.push_back(elt.get()); + CleanCString(elt); + } } // Prepare aOptions->env_map -inline void -PrepareEnv(base::LaunchOptions* aOptions, nsTArray& aEnvMap) { - for (auto& elt : aEnvMap) { - nsCString &var = Get<0>(elt); - nsCString &val = Get<1>(elt); - aOptions->env_map[var.get()] = val.get(); - CleanCString(var); - CleanCString(val); - } +inline void PrepareEnv(base::LaunchOptions* aOptions, + nsTArray& aEnvMap) { + for (auto& elt : aEnvMap) { + nsCString& var = Get<0>(elt); + nsCString& val = Get<1>(elt); + aOptions->env_map[var.get()] = val.get(); + CleanCString(var); + CleanCString(val); + } } // Prepare aOptions->fds_to_remap -inline void -PrepareFdsRemap(base::LaunchOptions* aOptions, - nsTArray& aFdsRemap) { - MOZ_LOG(gForkServiceLog, LogLevel::Verbose, ("fds mapping:")); - for (auto& elt : aFdsRemap) { - // FDs are duplicated here. - int fd = Get<0>(elt).ClonePlatformHandle().release(); - std::pair fdmap(fd, Get<1>(elt)); - aOptions->fds_to_remap.push_back(fdmap); - MOZ_LOG(gForkServiceLog, LogLevel::Verbose, - ("\t%d => %d", fdmap.first, fdmap.second)); - } +inline void PrepareFdsRemap(base::LaunchOptions* aOptions, + nsTArray& aFdsRemap) { + MOZ_LOG(gForkServiceLog, LogLevel::Verbose, ("fds mapping:")); + for (auto& elt : aFdsRemap) { + // FDs are duplicated here. + int fd = Get<0>(elt).ClonePlatformHandle().release(); + std::pair fdmap(fd, Get<1>(elt)); + aOptions->fds_to_remap.push_back(fdmap); + MOZ_LOG(gForkServiceLog, LogLevel::Verbose, + ("\t%d => %d", fdmap.first, fdmap.second)); + } } /** * Parse a Message to get a list of arguments and fill a LaunchOptions. */ -inline bool -ParseForkNewSubprocess(IPC::Message& aMsg, - std::vector& aArgv, - base::LaunchOptions* aOptions) { - if (aMsg.type() != Msg_ForkNewSubprocess__ID) { - MOZ_LOG(gForkServiceLog, LogLevel::Verbose, - ("unknown message type %d\n", aMsg.type())); - return false; - } +inline bool ParseForkNewSubprocess(IPC::Message& aMsg, + std::vector& aArgv, + base::LaunchOptions* aOptions) { + if (aMsg.type() != Msg_ForkNewSubprocess__ID) { + MOZ_LOG(gForkServiceLog, LogLevel::Verbose, + ("unknown message type %d\n", aMsg.type())); + return false; + } - PickleIterator iter(aMsg); - nsTArray argv_array; - nsTArray env_map; - nsTArray fds_remap; + PickleIterator iter(aMsg); + nsTArray argv_array; + nsTArray env_map; + nsTArray fds_remap; - ReadIPDLParamInfallible(&aMsg, &iter, nullptr, &argv_array, - "Error deserializing 'nsCString[]'"); - ReadIPDLParamInfallible(&aMsg, &iter, nullptr, &env_map, - "Error deserializing 'EnvVar[]'"); - ReadIPDLParamInfallible(&aMsg, &iter, nullptr, &fds_remap, - "Error deserializing 'FdMapping[]'"); - aMsg.EndRead(iter, aMsg.type()); + ReadIPDLParamInfallible(&aMsg, &iter, nullptr, &argv_array, + "Error deserializing 'nsCString[]'"); + ReadIPDLParamInfallible(&aMsg, &iter, nullptr, &env_map, + "Error deserializing 'EnvVar[]'"); + ReadIPDLParamInfallible(&aMsg, &iter, nullptr, &fds_remap, + "Error deserializing 'FdMapping[]'"); + aMsg.EndRead(iter, aMsg.type()); - PrepareArguments(aArgv, argv_array); - PrepareEnv(aOptions, env_map); - PrepareFdsRemap(aOptions, fds_remap); + PrepareArguments(aArgv, argv_array); + PrepareEnv(aOptions, env_map); + PrepareFdsRemap(aOptions, fds_remap); - return true; + return true; } -inline void -SanitizeBuffers(IPC::Message& aMsg, - std::vector& aArgv, - base::LaunchOptions& aOptions) { - // Clean all buffers in the message to make sure content processes - // not peeking others. - auto& blist = aMsg.Buffers(); - for (auto itr = blist.Iter(); - !itr.Done(); - itr.Advance(blist, itr.RemainingInSegment())) { - memset(itr.Data(), 0, itr.RemainingInSegment()); - } +inline void SanitizeBuffers(IPC::Message& aMsg, std::vector& aArgv, + base::LaunchOptions& aOptions) { + // Clean all buffers in the message to make sure content processes + // not peeking others. + auto& blist = aMsg.Buffers(); + for (auto itr = blist.Iter(); !itr.Done(); + itr.Advance(blist, itr.RemainingInSegment())) { + memset(itr.Data(), 0, itr.RemainingInSegment()); + } - // clean all data string made from the message. - for (auto& var : aOptions.env_map) { - // Do it anyway since it is not going to be used anymore. - CleanString(*const_cast(&var.first)); - CleanString(var.second); - } - for (auto& arg : aArgv) { - CleanString(arg); - } + // clean all data string made from the message. + for (auto& var : aOptions.env_map) { + // Do it anyway since it is not going to be used anymore. + CleanString(*const_cast(&var.first)); + CleanString(var.second); + } + for (auto& arg : aArgv) { + CleanString(arg); + } } /** @@ -198,45 +186,43 @@ SanitizeBuffers(IPC::Message& aMsg, * It will return in both the fork server process and the new content * process. |mAppProcBuilder| is null for the fork server. */ -void -ForkServer::OnMessageReceived(IPC::Message&& message) { - IPC::Message msg(std::move(message)); +void ForkServer::OnMessageReceived(IPC::Message&& message) { + IPC::Message msg(std::move(message)); - std::vector argv; - base::LaunchOptions options; - if (!ParseForkNewSubprocess(msg, argv, &options)) { - return; - } + std::vector argv; + base::LaunchOptions options; + if (!ParseForkNewSubprocess(msg, argv, &options)) { + return; + } #if defined(XP_LINUX) && defined(MOZ_SANDBOX) - mozilla::SandboxLaunchForkServerPrepare(argv, options); + mozilla::SandboxLaunchForkServerPrepare(argv, options); #endif - base::ProcessHandle child_pid = -1; - mAppProcBuilder = MakeUnique(); - if (!mAppProcBuilder->ForkProcess(argv, options, &child_pid)) { - MOZ_CRASH("fail to fork"); - } - MOZ_ASSERT(child_pid >= 0); + base::ProcessHandle child_pid = -1; + mAppProcBuilder = MakeUnique(); + if (!mAppProcBuilder->ForkProcess(argv, options, &child_pid)) { + MOZ_CRASH("fail to fork"); + } + MOZ_ASSERT(child_pid >= 0); - if (child_pid == 0) { - // Content process - return; - } + if (child_pid == 0) { + // Content process + return; + } - // Fork server process + // Fork server process - mAppProcBuilder = nullptr; + mAppProcBuilder = nullptr; - IPC::Message reply(MSG_ROUTING_CONTROL, Reply_ForkNewSubprocess__ID); - WriteIPDLParam(&reply, nullptr, child_pid); - mTcver->SendInfallible(reply, - "failed to send a reply message"); + IPC::Message reply(MSG_ROUTING_CONTROL, Reply_ForkNewSubprocess__ID); + WriteIPDLParam(&reply, nullptr, child_pid); + mTcver->SendInfallible(reply, "failed to send a reply message"); - // Without this, the content processes that is forked later are - // able to read the content of buffers even the buffers have been - // released. - SanitizeBuffers(msg, argv, options); + // Without this, the content processes that is forked later are + // able to read the content of buffers even the buffers have been + // released. + SanitizeBuffers(msg, argv, options); } /** @@ -250,66 +236,69 @@ ForkServer::OnMessageReceived(IPC::Message&& message) { * For the later case, aArgc and aArgv are modified to pass the * arguments from the chrome process. */ -bool -ForkServer::RunForkServer(int* aArgc, char*** aArgv) { +bool ForkServer::RunForkServer(int* aArgc, char*** aArgv) { #ifdef DEBUG - if (getenv("MOZ_FORKSERVER_WAIT_GDB")) { - printf("Waiting for 30 seconds." - " Attach the fork server with gdb %s %d\n", - (*aArgv)[0], base::GetCurrentProcId()); - sleep(30); - } - bool sleep_newproc = !!getenv("MOZ_FORKSERVER_WAIT_GDB_NEWPROC"); + if (getenv("MOZ_FORKSERVER_WAIT_GDB")) { + printf( + "Waiting for 30 seconds." + " Attach the fork server with gdb %s %d\n", + (*aArgv)[0], base::GetCurrentProcId()); + sleep(30); + } + bool sleep_newproc = !!getenv("MOZ_FORKSERVER_WAIT_GDB_NEWPROC"); #endif - // Do this before NS_LogInit() to avoid log files taking lower - // FDs. - ForkServer forkserver; - forkserver.InitProcess(aArgc, aArgv); + // Do this before NS_LogInit() to avoid log files taking lower + // FDs. + ForkServer forkserver; + forkserver.InitProcess(aArgc, aArgv); - XRE_SetProcessType("forkserver"); - NS_LogInit(); - mozilla::LogModule::Init(0, nullptr); - MOZ_LOG(gForkServiceLog, LogLevel::Verbose, ("Start a fork server")); - { - DebugOnly forkserver_pid = base::GetCurrentProcId(); - if (forkserver.HandleMessages()) { - // In the fork server process - // The server has stopped. - MOZ_LOG(gForkServiceLog, LogLevel::Verbose, ("Terminate the fork server")); - NS_LogTerm(); - return true; - } - // Now, we are running in a content process just forked from - // the fork server process. - MOZ_ASSERT(base::GetCurrentProcId() != forkserver_pid); - MOZ_LOG(gForkServiceLog, LogLevel::Verbose, ("Fork a new content process")); + XRE_SetProcessType("forkserver"); + NS_LogInit(); + mozilla::LogModule::Init(0, nullptr); + MOZ_LOG(gForkServiceLog, LogLevel::Verbose, ("Start a fork server")); + { + DebugOnly forkserver_pid = base::GetCurrentProcId(); + if (forkserver.HandleMessages()) { + // In the fork server process + // The server has stopped. + MOZ_LOG(gForkServiceLog, LogLevel::Verbose, + ("Terminate the fork server")); + NS_LogTerm(); + return true; } + // Now, we are running in a content process just forked from + // the fork server process. + MOZ_ASSERT(base::GetCurrentProcId() != forkserver_pid); + MOZ_LOG(gForkServiceLog, LogLevel::Verbose, ("Fork a new content process")); + } #ifdef DEBUG - if (sleep_newproc) { - printf("Waiting for 30 seconds." - " Attach the new process with gdb %s %d\n", - (*aArgv)[0], base::GetCurrentProcId()); - sleep(30); - } + if (sleep_newproc) { + printf( + "Waiting for 30 seconds." + " Attach the new process with gdb %s %d\n", + (*aArgv)[0], base::GetCurrentProcId()); + sleep(30); + } #endif - NS_LogTerm(); + NS_LogTerm(); - MOZ_ASSERT(forkserver.mAppProcBuilder); - // |messageloop| has been destroyed. So, we can intialized the - // process safely. Message loops may allocates some file - // descriptors. If it is destroyed later, it may mess up this - // content process by closing wrong file descriptors. - forkserver.mAppProcBuilder->InitAppProcess(aArgc, aArgv); - forkserver.mAppProcBuilder.reset(); + MOZ_ASSERT(forkserver.mAppProcBuilder); + // |messageloop| has been destroyed. So, we can intialized the + // process safely. Message loops may allocates some file + // descriptors. If it is destroyed later, it may mess up this + // content process by closing wrong file descriptors. + forkserver.mAppProcBuilder->InitAppProcess(aArgc, aArgv); + forkserver.mAppProcBuilder.reset(); - MOZ_ASSERT(NS_LITERAL_CSTRING("tab") == (*aArgv)[*aArgc - 1], "Only |tab| is allowed!"); + MOZ_ASSERT(NS_LITERAL_CSTRING("tab") == (*aArgv)[*aArgc - 1], + "Only |tab| is allowed!"); - // Open log files again with right names and the new PID. - nsTraceRefcnt::ResetLogFiles((*aArgv)[*aArgc - 1]); + // Open log files again with right names and the new PID. + nsTraceRefcnt::ResetLogFiles((*aArgv)[*aArgc - 1]); - return false; + return false; } -} -} +} // namespace ipc +} // namespace mozilla diff --git a/ipc/glue/ForkServer.h b/ipc/glue/ForkServer.h index b3fa22deb0e9..e01e298f89f4 100644 --- a/ipc/glue/ForkServer.h +++ b/ipc/glue/ForkServer.h @@ -14,31 +14,31 @@ namespace mozilla { namespace ipc { class ForkServer { -public: - static const int kHELLO_MESSAGE_TYPE = 65535; + public: + static const int kHELLO_MESSAGE_TYPE = 65535; - ForkServer(); - ~ForkServer() {}; + ForkServer(); + ~ForkServer(){}; - void InitProcess(int* aArgc, char*** aArgv); - bool HandleMessages(); + void InitProcess(int* aArgc, char*** aArgv); + bool HandleMessages(); - // Called when a message is received. - void OnMessageReceived(IPC::Message&& message); + // Called when a message is received. + void OnMessageReceived(IPC::Message&& message); - static bool RunForkServer(int* aArgc, char*** aArgv); + static bool RunForkServer(int* aArgc, char*** aArgv); -private: - UniquePtr mTcver; - UniquePtr mAppProcBuilder; + private: + UniquePtr mTcver; + UniquePtr mAppProcBuilder; }; enum { - Msg_ForkNewSubprocess__ID = 0x7f0, // a random picked number - Reply_ForkNewSubprocess__ID, + Msg_ForkNewSubprocess__ID = 0x7f0, // a random picked number + Reply_ForkNewSubprocess__ID, }; -} -} +} // namespace ipc +} // namespace mozilla -#endif // __FORKSERVER_H_ +#endif // __FORKSERVER_H_ diff --git a/ipc/glue/ForkServiceChild.cpp b/ipc/glue/ForkServiceChild.cpp index a7eef20d77fe..86dc5cd5b590 100644 --- a/ipc/glue/ForkServiceChild.cpp +++ b/ipc/glue/ForkServiceChild.cpp @@ -19,97 +19,89 @@ extern LazyLogModule gForkServiceLog; mozilla::UniquePtr ForkServiceChild::sForkServiceChild; -void -ForkServiceChild::StartForkServer() { - std::vector extraArgs; +void ForkServiceChild::StartForkServer() { + std::vector extraArgs; - GeckoChildProcessHost *subprocess = - new GeckoChildProcessHost(GeckoProcessType_ForkServer, false); - subprocess->LaunchAndWaitForProcessHandle(std::move(extraArgs)); + GeckoChildProcessHost* subprocess = + new GeckoChildProcessHost(GeckoProcessType_ForkServer, false); + subprocess->LaunchAndWaitForProcessHandle(std::move(extraArgs)); - int fd = subprocess->GetChannel()->GetFileDescriptor(); - fd = dup(fd); // Dup it because the channel will close it. - int fs_flags = fcntl(fd, F_GETFL, 0); - fcntl(fd, F_SETFL, fs_flags & ~O_NONBLOCK); - int fd_flags = fcntl(fd, F_GETFD, 0); - fcntl(fd, F_SETFD, fd_flags | FD_CLOEXEC); + int fd = subprocess->GetChannel()->GetFileDescriptor(); + fd = dup(fd); // Dup it because the channel will close it. + int fs_flags = fcntl(fd, F_GETFL, 0); + fcntl(fd, F_SETFL, fs_flags & ~O_NONBLOCK); + int fd_flags = fcntl(fd, F_GETFD, 0); + fcntl(fd, F_SETFD, fd_flags | FD_CLOEXEC); - sForkServiceChild = mozilla::MakeUnique(fd, subprocess); + sForkServiceChild = mozilla::MakeUnique(fd, subprocess); - // Without doing this, IO thread may intercept messages since the - // IPC::Channel created by it is still open. - subprocess->GetChannel()->Close(); + // Without doing this, IO thread may intercept messages since the + // IPC::Channel created by it is still open. + subprocess->GetChannel()->Close(); } -void -ForkServiceChild::StopForkServer() { - sForkServiceChild = nullptr; -} +void ForkServiceChild::StopForkServer() { sForkServiceChild = nullptr; } ForkServiceChild::ForkServiceChild(int aFd, GeckoChildProcessHost* aProcess) - : mWaitForHello(true) - , mProcess(aProcess) { - mTcver = MakeUnique(aFd); + : mWaitForHello(true), mProcess(aProcess) { + mTcver = MakeUnique(aFd); } ForkServiceChild::~ForkServiceChild() { - mProcess->Destroy(); - close(mTcver->GetFD()); + mProcess->Destroy(); + close(mTcver->GetFD()); } -bool -ForkServiceChild::SendForkNewSubprocess(const nsTArray& aArgv, - const nsTArray& aEnvMap, - const nsTArray& aFdsRemap, - pid_t* aPid) { - if (mWaitForHello) { - // IPC::Channel created by the GeckoChildProcessHost has - // already send a HELLO. It is expected to receive a hello - // message from the fork server too. - IPC::Message hello; - mTcver->RecvInfallible(hello, "Fail to receive HELLO message"); - MOZ_ASSERT(hello.type() == ForkServer::kHELLO_MESSAGE_TYPE); - mWaitForHello = false; - } +bool ForkServiceChild::SendForkNewSubprocess( + const nsTArray& aArgv, const nsTArray& aEnvMap, + const nsTArray& aFdsRemap, pid_t* aPid) { + if (mWaitForHello) { + // IPC::Channel created by the GeckoChildProcessHost has + // already send a HELLO. It is expected to receive a hello + // message from the fork server too. + IPC::Message hello; + mTcver->RecvInfallible(hello, "Fail to receive HELLO message"); + MOZ_ASSERT(hello.type() == ForkServer::kHELLO_MESSAGE_TYPE); + mWaitForHello = false; + } - mRecvPid = -1; - IPC::Message msg(MSG_ROUTING_CONTROL, Msg_ForkNewSubprocess__ID); + mRecvPid = -1; + IPC::Message msg(MSG_ROUTING_CONTROL, Msg_ForkNewSubprocess__ID); - WriteIPDLParam(&msg, nullptr, aArgv); - WriteIPDLParam(&msg, nullptr, aEnvMap); - WriteIPDLParam(&msg, nullptr, aFdsRemap); - if (!mTcver->Send(msg)) { - MOZ_LOG(gForkServiceLog, LogLevel::Verbose, - ("the pipe to the fork server is closed or having errors")); - return false; - } + WriteIPDLParam(&msg, nullptr, aArgv); + WriteIPDLParam(&msg, nullptr, aEnvMap); + WriteIPDLParam(&msg, nullptr, aFdsRemap); + if (!mTcver->Send(msg)) { + MOZ_LOG(gForkServiceLog, LogLevel::Verbose, + ("the pipe to the fork server is closed or having errors")); + return false; + } - IPC::Message reply; - if (!mTcver->Recv(reply)) { - MOZ_LOG(gForkServiceLog, LogLevel::Verbose, - ("the pipe to the fork server is closed or having errors")); - return false; - } - OnMessageReceived(std::move(reply)); + IPC::Message reply; + if (!mTcver->Recv(reply)) { + MOZ_LOG(gForkServiceLog, LogLevel::Verbose, + ("the pipe to the fork server is closed or having errors")); + return false; + } + OnMessageReceived(std::move(reply)); - MOZ_ASSERT(mRecvPid != -1); - *aPid = mRecvPid; - return true; + MOZ_ASSERT(mRecvPid != -1); + *aPid = mRecvPid; + return true; } -void -ForkServiceChild::OnMessageReceived(IPC::Message&& message) { - if (message.type() != Reply_ForkNewSubprocess__ID) { - MOZ_LOG(gForkServiceLog, LogLevel::Verbose, - ("unknown reply type %d", message.type())); - return; - } - PickleIterator iter__(message); +void ForkServiceChild::OnMessageReceived(IPC::Message&& message) { + if (message.type() != Reply_ForkNewSubprocess__ID) { + MOZ_LOG(gForkServiceLog, LogLevel::Verbose, + ("unknown reply type %d", message.type())); + return; + } + PickleIterator iter__(message); - if (!ReadIPDLParam(&message, &iter__, nullptr, &mRecvPid)) { - MOZ_CRASH("Error deserializing 'pid_t'"); - } - message.EndRead(iter__, message.type()); + if (!ReadIPDLParam(&message, &iter__, nullptr, &mRecvPid)) { + MOZ_CRASH("Error deserializing 'pid_t'"); + } + message.EndRead(iter__, message.type()); } NS_IMPL_ISUPPORTS(ForkServerLauncher, nsIObserver) @@ -117,43 +109,41 @@ NS_IMPL_ISUPPORTS(ForkServerLauncher, nsIObserver) bool ForkServerLauncher::mHaveStartedClient = false; StaticRefPtr ForkServerLauncher::mSingleton; -ForkServerLauncher::ForkServerLauncher() { -} +ForkServerLauncher::ForkServerLauncher() {} -ForkServerLauncher::~ForkServerLauncher() { -} +ForkServerLauncher::~ForkServerLauncher() {} -already_AddRefed -ForkServerLauncher::Create() { - if (mSingleton == nullptr) { - mSingleton = new ForkServerLauncher(); - } - RefPtr launcher = mSingleton; - return launcher.forget(); +already_AddRefed ForkServerLauncher::Create() { + if (mSingleton == nullptr) { + mSingleton = new ForkServerLauncher(); + } + RefPtr launcher = mSingleton; + return launcher.forget(); } NS_IMETHODIMP -ForkServerLauncher::Observe(nsISupports* aSubject, - const char* aTopic, - const char16_t* aData) { - if (!mHaveStartedClient && strcmp(aTopic, NS_XPCOM_STARTUP_CATEGORY) == 0) { - mHaveStartedClient = true; - ForkServiceChild::StartForkServer(); +ForkServerLauncher::Observe(nsISupports* aSubject, const char* aTopic, + const char16_t* aData) { + if (!mHaveStartedClient && strcmp(aTopic, NS_XPCOM_STARTUP_CATEGORY) == 0) { + mHaveStartedClient = true; + ForkServiceChild::StartForkServer(); - nsCOMPtr obsSvc = mozilla::services::GetObserverService(); - MOZ_ASSERT(obsSvc != nullptr); - obsSvc->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); - } + nsCOMPtr obsSvc = + mozilla::services::GetObserverService(); + MOZ_ASSERT(obsSvc != nullptr); + obsSvc->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); + } - if (mHaveStartedClient && strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) { - mHaveStartedClient = false; - ForkServiceChild::StopForkServer(); + if (mHaveStartedClient && + strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) { + mHaveStartedClient = false; + ForkServiceChild::StopForkServer(); - // To make leak checker happy! - mSingleton = nullptr; - } - return NS_OK; + // To make leak checker happy! + mSingleton = nullptr; + } + return NS_OK; } -} -} +} // namespace ipc +} // namespace mozilla diff --git a/ipc/glue/ForkServiceChild.h b/ipc/glue/ForkServiceChild.h index 362e08803c1b..1e6de0b82fbb 100644 --- a/ipc/glue/ForkServiceChild.h +++ b/ipc/glue/ForkServiceChild.h @@ -26,72 +26,70 @@ class GeckoChildProcessHost; * pipe and get the PID of the new process from the reply. */ class ForkServiceChild { -public: - ForkServiceChild(int aFd, GeckoChildProcessHost* aProcess); - virtual ~ForkServiceChild(); + public: + ForkServiceChild(int aFd, GeckoChildProcessHost* aProcess); + virtual ~ForkServiceChild(); - /** - * Ask the fork server to create a new process with given parameters. - * - * The fork server uses |base::LaunchApp()| to create a new - * content process with the following parameters. - * - * \param aArgv assigns |argv| of the content process. - * \param aEnvMap sets |LaunchOptions::env_map|. - * \param aFdsRemap sets |LaunchOptions::fd_to_remap|. - * \param aPid returns the PID of the content process created. - * \return true if success. - */ - bool SendForkNewSubprocess( - const nsTArray& aArgv, - const nsTArray& aEnvMap, - const nsTArray& aFdsRemap, - pid_t* aPid); + /** + * Ask the fork server to create a new process with given parameters. + * + * The fork server uses |base::LaunchApp()| to create a new + * content process with the following parameters. + * + * \param aArgv assigns |argv| of the content process. + * \param aEnvMap sets |LaunchOptions::env_map|. + * \param aFdsRemap sets |LaunchOptions::fd_to_remap|. + * \param aPid returns the PID of the content process created. + * \return true if success. + */ + bool SendForkNewSubprocess(const nsTArray& aArgv, + const nsTArray& aEnvMap, + const nsTArray& aFdsRemap, pid_t* aPid); - /** - * Create a fork server process and the singleton of this class. - * - * This function uses |GeckoChildProcessHost| to launch the fork - * server, getting the fd of a pipe/socket to the fork server from - * it's |IPC::Channel|. - */ - static void StartForkServer(); - static void StopForkServer(); - /** - * Return the singleton. - */ - static ForkServiceChild* Get() { return sForkServiceChild.get(); } + /** + * Create a fork server process and the singleton of this class. + * + * This function uses |GeckoChildProcessHost| to launch the fork + * server, getting the fd of a pipe/socket to the fork server from + * it's |IPC::Channel|. + */ + static void StartForkServer(); + static void StopForkServer(); + /** + * Return the singleton. + */ + static ForkServiceChild* Get() { return sForkServiceChild.get(); } -private: - // Called when a message is received. - void OnMessageReceived(IPC::Message&& message); + private: + // Called when a message is received. + void OnMessageReceived(IPC::Message&& message); - UniquePtr mTcver; - static UniquePtr sForkServiceChild; - pid_t mRecvPid; - bool mWaitForHello; - GeckoChildProcessHost* mProcess; + UniquePtr mTcver; + static UniquePtr sForkServiceChild; + pid_t mRecvPid; + bool mWaitForHello; + GeckoChildProcessHost* mProcess; }; /** * Start a fork server at |xpcom-startup| from the chrome process. */ class ForkServerLauncher : public nsIObserver { -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIOBSERVER + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER - ForkServerLauncher(); - static already_AddRefed Create(); + ForkServerLauncher(); + static already_AddRefed Create(); -private: - virtual ~ForkServerLauncher(); + private: + virtual ~ForkServerLauncher(); - static bool mHaveStartedClient; - static StaticRefPtr mSingleton; + static bool mHaveStartedClient; + static StaticRefPtr mSingleton; }; -} -} +} // namespace ipc +} // namespace mozilla #endif /* __FORKSERVICE_CHILD_H_ */ diff --git a/ipc/glue/GeckoChildProcessHost.cpp b/ipc/glue/GeckoChildProcessHost.cpp index d744ff3531e8..5d8a64265e4e 100644 --- a/ipc/glue/GeckoChildProcessHost.cpp +++ b/ipc/glue/GeckoChildProcessHost.cpp @@ -831,7 +831,8 @@ void BaseProcessLauncher::GetChildLogName(const char* origLogName, // // Fork server needs a dedicated thread for accessing // |ForkServiceChild|. -#if defined(XP_WIN) || defined(MOZ_WIDGET_ANDROID) || defined(MOZ_ENABLE_FORKSERVER) +#if defined(XP_WIN) || defined(MOZ_WIDGET_ANDROID) || \ + defined(MOZ_ENABLE_FORKSERVER) static mozilla::StaticMutex gIPCLaunchThreadMutex; static mozilla::StaticRefPtr gIPCLaunchThread; @@ -884,7 +885,8 @@ nsCOMPtr GetIPCLauncher() { return thread; } -#else // defined(XP_WIN) || defined(MOZ_WIDGET_ANDROID) || defined(MOZ_ENABLE_FORKSERVER) +#else // defined(XP_WIN) || defined(MOZ_WIDGET_ANDROID) || + // defined(MOZ_ENABLE_FORKSERVER) // Other platforms use an on-demand thread pool. diff --git a/ipc/glue/IPDLParamTraits.h b/ipc/glue/IPDLParamTraits.h index f9cd67886714..da22d28601eb 100644 --- a/ipc/glue/IPDLParamTraits.h +++ b/ipc/glue/IPDLParamTraits.h @@ -69,10 +69,9 @@ static MOZ_NEVER_INLINE bool ReadIPDLParam(const IPC::Message* aMsg, } template -static MOZ_NEVER_INLINE bool ReadIPDLParamInfallible(const IPC::Message* aMsg, - PickleIterator* aIter, - IProtocol* aActor, P* aResult, - const char* aCrashMessage) { +static MOZ_NEVER_INLINE bool ReadIPDLParamInfallible( + const IPC::Message* aMsg, PickleIterator* aIter, IProtocol* aActor, + P* aResult, const char* aCrashMessage) { bool ok = ReadIPDLParam(aMsg, aIter, aActor, aResult); if (!ok) { MOZ_CRASH_UNSAFE(aCrashMessage); diff --git a/ipc/glue/MiniTransceiver.cpp b/ipc/glue/MiniTransceiver.cpp index 080dc9d9bf6e..11b376dcd4c7 100644 --- a/ipc/glue/MiniTransceiver.cpp +++ b/ipc/glue/MiniTransceiver.cpp @@ -32,214 +32,210 @@ MiniTransceiver::MiniTransceiver(int aFd, DataBufferClear aDataBufClear) namespace { /** - * Initialize the IO vector for sending data and the control buffer for sending FDs. + * Initialize the IO vector for sending data and the control buffer for sending + * FDs. */ -static void -InitMsgHdr(msghdr* aHdr, int aIOVSize, int aMaxNumFds) { - aHdr->msg_name = nullptr; - aHdr->msg_namelen = 0; - aHdr->msg_flags = 0; +static void InitMsgHdr(msghdr* aHdr, int aIOVSize, int aMaxNumFds) { + aHdr->msg_name = nullptr; + aHdr->msg_namelen = 0; + aHdr->msg_flags = 0; - // Prepare the IO vector to receive the content of message. - auto iov = new iovec[aIOVSize]; - aHdr->msg_iov = iov; - aHdr->msg_iovlen = aIOVSize; + // Prepare the IO vector to receive the content of message. + auto iov = new iovec[aIOVSize]; + aHdr->msg_iov = iov; + aHdr->msg_iovlen = aIOVSize; - // Prepare the control buffer to receive file descriptors. - auto cbuf = new char[CMSG_SPACE(sizeof(int) * aMaxNumFds)]; - aHdr->msg_control = cbuf; - aHdr->msg_controllen = CMSG_SPACE(sizeof(int) * aMaxNumFds); + // Prepare the control buffer to receive file descriptors. + auto cbuf = new char[CMSG_SPACE(sizeof(int) * aMaxNumFds)]; + aHdr->msg_control = cbuf; + aHdr->msg_controllen = CMSG_SPACE(sizeof(int) * aMaxNumFds); } /** * Delete resources allocated by InitMsgHdr(). */ -static void -DeinitMsgHdr(msghdr* aHdr) { - delete aHdr->msg_iov; - delete static_cast(aHdr->msg_control); +static void DeinitMsgHdr(msghdr* aHdr) { + delete aHdr->msg_iov; + delete static_cast(aHdr->msg_control); } +} // namespace + +void MiniTransceiver::PrepareFDs(msghdr* aHdr, IPC::Message& aMsg) { + // Set control buffer to send file descriptors of the Message. + int num_fds = aMsg.file_descriptor_set()->size(); + + cmsghdr* cmsg = CMSG_FIRSTHDR(aHdr); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = CMSG_LEN(sizeof(int) * num_fds); + aMsg.file_descriptor_set()->GetDescriptors( + reinterpret_cast(CMSG_DATA(cmsg))); + + // This number will be sent in the header of the message. So, we + // can check it at the other side. + aMsg.header()->num_fds = num_fds; } -void -MiniTransceiver::PrepareFDs(msghdr* aHdr, IPC::Message& aMsg) { - // Set control buffer to send file descriptors of the Message. - int num_fds = aMsg.file_descriptor_set()->size(); +size_t MiniTransceiver::PrepareBuffers(msghdr* aHdr, IPC::Message& aMsg) { + // Set iovec to send for all buffers of the Message. + iovec* iov = aHdr->msg_iov; + size_t iovlen = 0; + size_t bytes_to_send = 0; + for (Pickle::BufferList::IterImpl iter(aMsg.Buffers()); !iter.Done(); + iter.Advance(aMsg.Buffers(), iter.RemainingInSegment())) { + char* data = iter.Data(); + size_t size = iter.RemainingInSegment(); + iov[iovlen].iov_base = data; + iov[iovlen].iov_len = size; + iovlen++; + MOZ_ASSERT(iovlen <= kMaxIOVecSize); + bytes_to_send += size; + } + MOZ_ASSERT(bytes_to_send <= kMaxDataSize); + aHdr->msg_iovlen = iovlen; - cmsghdr *cmsg = CMSG_FIRSTHDR(aHdr); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - cmsg->cmsg_len = CMSG_LEN(sizeof(int) * num_fds); - aMsg.file_descriptor_set()->GetDescriptors( - reinterpret_cast(CMSG_DATA(cmsg))); - - // This number will be sent in the header of the message. So, we - // can check it at the other side. - aMsg.header()->num_fds = num_fds; + return bytes_to_send; } -size_t -MiniTransceiver::PrepareBuffers(msghdr* aHdr, IPC::Message& aMsg) { - // Set iovec to send for all buffers of the Message. - iovec *iov = aHdr->msg_iov; - size_t iovlen = 0; - size_t bytes_to_send = 0; - for (Pickle::BufferList::IterImpl iter(aMsg.Buffers()); - !iter.Done(); - iter.Advance(aMsg.Buffers(), iter.RemainingInSegment())) { - char* data = iter.Data(); - size_t size = iter.RemainingInSegment(); - iov[iovlen].iov_base = data; - iov[iovlen].iov_len = size; - iovlen++; - MOZ_ASSERT(iovlen <= kMaxIOVecSize); - bytes_to_send += size; - } - MOZ_ASSERT(bytes_to_send <= kMaxDataSize); - aHdr->msg_iovlen = iovlen; - - return bytes_to_send; -} - -bool -MiniTransceiver::Send(IPC::Message& aMsg) { +bool MiniTransceiver::Send(IPC::Message& aMsg) { #ifdef DEBUG - if (mState == STATE_SENDING) { - MOZ_CRASH("STATE_SENDING: It violates of request-response and no concurrent rules"); - } - mState = STATE_SENDING; + if (mState == STATE_SENDING) { + MOZ_CRASH( + "STATE_SENDING: It violates of request-response and no concurrent " + "rules"); + } + mState = STATE_SENDING; #endif - auto clean_fdset = MakeScopeExit([&] { - aMsg.file_descriptor_set()->CommitAll(); - }); + auto clean_fdset = + MakeScopeExit([&] { aMsg.file_descriptor_set()->CommitAll(); }); - int num_fds = aMsg.file_descriptor_set()->size(); - msghdr hdr; - InitMsgHdr(&hdr, kMaxIOVecSize, num_fds); + int num_fds = aMsg.file_descriptor_set()->size(); + msghdr hdr; + InitMsgHdr(&hdr, kMaxIOVecSize, num_fds); - UniquePtr uniq(&hdr, &DeinitMsgHdr); + UniquePtr uniq(&hdr, &DeinitMsgHdr); - PrepareFDs(&hdr, aMsg); - DebugOnly bytes_to_send = PrepareBuffers(&hdr, aMsg); + PrepareFDs(&hdr, aMsg); + DebugOnly bytes_to_send = PrepareBuffers(&hdr, aMsg); - ssize_t bytes_written = HANDLE_EINTR(sendmsg(mFd, &hdr, 0)); + ssize_t bytes_written = HANDLE_EINTR(sendmsg(mFd, &hdr, 0)); - if (bytes_written < 0) { - char error[128]; - SprintfLiteral(error, "sendmsg: %s", strerror(errno)); - NS_WARNING(error); - return false; - } - MOZ_ASSERT(bytes_written == (ssize_t)bytes_to_send, "The message is too big?!"); + if (bytes_written < 0) { + char error[128]; + SprintfLiteral(error, "sendmsg: %s", strerror(errno)); + NS_WARNING(error); + return false; + } + MOZ_ASSERT(bytes_written == (ssize_t)bytes_to_send, + "The message is too big?!"); - return true; + return true; } -unsigned -MiniTransceiver::RecvFDs(msghdr* aHdr, int* aAllFds, unsigned aMaxFds) { - if (aHdr->msg_controllen == 0) { - return 0; - } +unsigned MiniTransceiver::RecvFDs(msghdr* aHdr, int* aAllFds, + unsigned aMaxFds) { + if (aHdr->msg_controllen == 0) { + return 0; + } - unsigned num_all_fds = 0; - for (cmsghdr* cmsg = CMSG_FIRSTHDR(aHdr); - cmsg; - cmsg = CMSG_NXTHDR(aHdr, cmsg)) { - MOZ_ASSERT(cmsg->cmsg_level == SOL_SOCKET && - cmsg->cmsg_type == SCM_RIGHTS, - "Accept only SCM_RIGHTS to receive file descriptors"); + unsigned num_all_fds = 0; + for (cmsghdr* cmsg = CMSG_FIRSTHDR(aHdr); cmsg; + cmsg = CMSG_NXTHDR(aHdr, cmsg)) { + MOZ_ASSERT(cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS, + "Accept only SCM_RIGHTS to receive file descriptors"); - unsigned payload_sz = cmsg->cmsg_len - CMSG_LEN(0); - MOZ_ASSERT(payload_sz % sizeof(int) == 0); + unsigned payload_sz = cmsg->cmsg_len - CMSG_LEN(0); + MOZ_ASSERT(payload_sz % sizeof(int) == 0); - // Add fds to |aAllFds| - unsigned num_part_fds = payload_sz / sizeof(int); - int* part_fds = reinterpret_cast(CMSG_DATA(cmsg)); - MOZ_ASSERT(num_all_fds + num_part_fds <= aMaxFds); + // Add fds to |aAllFds| + unsigned num_part_fds = payload_sz / sizeof(int); + int* part_fds = reinterpret_cast(CMSG_DATA(cmsg)); + MOZ_ASSERT(num_all_fds + num_part_fds <= aMaxFds); - memcpy(aAllFds + num_all_fds, part_fds, num_part_fds * sizeof(int)); - num_all_fds += num_part_fds; - } - return num_all_fds; + memcpy(aAllFds + num_all_fds, part_fds, num_part_fds * sizeof(int)); + num_all_fds += num_part_fds; + } + return num_all_fds; } -bool -MiniTransceiver::RecvData(char* aDataBuf, size_t aBufSize, uint32_t* aMsgSize, - int* aFdsBuf, unsigned aMaxFds, unsigned* aNumFds) { - msghdr hdr; - InitMsgHdr(&hdr, 1, aMaxFds); +bool MiniTransceiver::RecvData(char* aDataBuf, size_t aBufSize, + uint32_t* aMsgSize, int* aFdsBuf, + unsigned aMaxFds, unsigned* aNumFds) { + msghdr hdr; + InitMsgHdr(&hdr, 1, aMaxFds); - UniquePtr uniq(&hdr, &DeinitMsgHdr); + UniquePtr uniq(&hdr, &DeinitMsgHdr); - // The buffer to collect all fds received from the socket. - int* all_fds = aFdsBuf; - unsigned num_all_fds = 0; + // The buffer to collect all fds received from the socket. + int* all_fds = aFdsBuf; + unsigned num_all_fds = 0; - size_t total_readed = 0; - uint32_t msgsz = 0; - while (msgsz == 0 || total_readed < msgsz) { - // Set IO vector with the begin of the unused buffer. - hdr.msg_iov->iov_base = aDataBuf + total_readed; - hdr.msg_iov->iov_len = (msgsz == 0 ? aBufSize : msgsz) - total_readed; + size_t total_readed = 0; + uint32_t msgsz = 0; + while (msgsz == 0 || total_readed < msgsz) { + // Set IO vector with the begin of the unused buffer. + hdr.msg_iov->iov_base = aDataBuf + total_readed; + hdr.msg_iov->iov_len = (msgsz == 0 ? aBufSize : msgsz) - total_readed; - // Read the socket - ssize_t bytes_readed = HANDLE_EINTR(recvmsg(mFd, &hdr, 0)); - if (bytes_readed <= 0) { - // Closed or error! - return false; - } - total_readed += bytes_readed; - MOZ_ASSERT(total_readed <= aBufSize); + // Read the socket + ssize_t bytes_readed = HANDLE_EINTR(recvmsg(mFd, &hdr, 0)); + if (bytes_readed <= 0) { + // Closed or error! + return false; + } + total_readed += bytes_readed; + MOZ_ASSERT(total_readed <= aBufSize); - if (msgsz == 0) { - // Parse the size of the message. - // Get 0 if data in the buffer is no enough to get message size. - msgsz = IPC::Message::MessageSize(aDataBuf, aDataBuf + total_readed); - } - - num_all_fds += RecvFDs(&hdr, all_fds + num_all_fds, aMaxFds - num_all_fds); + if (msgsz == 0) { + // Parse the size of the message. + // Get 0 if data in the buffer is no enough to get message size. + msgsz = IPC::Message::MessageSize(aDataBuf, aDataBuf + total_readed); } - *aMsgSize = msgsz; - *aNumFds = num_all_fds; - return true; + num_all_fds += RecvFDs(&hdr, all_fds + num_all_fds, aMaxFds - num_all_fds); + } + + *aMsgSize = msgsz; + *aNumFds = num_all_fds; + return true; } -bool -MiniTransceiver::Recv(IPC::Message& aMsg) { +bool MiniTransceiver::Recv(IPC::Message& aMsg) { #ifdef DEBUG - if (mState == STATE_RECEIVING) { - MOZ_CRASH("STATE_RECEIVING: It violates of request-response and no concurrent rules"); - } - mState = STATE_RECEIVING; + if (mState == STATE_RECEIVING) { + MOZ_CRASH( + "STATE_RECEIVING: It violates of request-response and no concurrent " + "rules"); + } + mState = STATE_RECEIVING; #endif - UniquePtr databuf = MakeUnique(kMaxDataSize); - uint32_t msgsz = 0; - int all_fds[kMaxNumFds]; - unsigned num_all_fds = 0; + UniquePtr databuf = MakeUnique(kMaxDataSize); + uint32_t msgsz = 0; + int all_fds[kMaxNumFds]; + unsigned num_all_fds = 0; - if (!RecvData(databuf.get(), kMaxDataSize, &msgsz, - all_fds, kMaxDataSize, &num_all_fds)) { - return false; - } + if (!RecvData(databuf.get(), kMaxDataSize, &msgsz, all_fds, kMaxDataSize, + &num_all_fds)) { + return false; + } - // Create Message from databuf & all_fds. - UniquePtr msg = MakeUnique(databuf.get(), msgsz); - msg->file_descriptor_set()->SetDescriptors(all_fds, num_all_fds); + // Create Message from databuf & all_fds. + UniquePtr msg = MakeUnique(databuf.get(), msgsz); + msg->file_descriptor_set()->SetDescriptors(all_fds, num_all_fds); - if (mDataBufClear == DataBufferClear::AfterReceiving) { - // Avoid content processes from reading the content of - // messages. - memset(databuf.get(), 0, msgsz); - } + if (mDataBufClear == DataBufferClear::AfterReceiving) { + // Avoid content processes from reading the content of + // messages. + memset(databuf.get(), 0, msgsz); + } - MOZ_ASSERT(msg->header()->num_fds == msg->file_descriptor_set()->size(), - "The number of file descriptors in the header is different from" - " the number actually received"); + MOZ_ASSERT(msg->header()->num_fds == msg->file_descriptor_set()->size(), + "The number of file descriptors in the header is different from" + " the number actually received"); - aMsg = std::move(*msg); - return true; + aMsg = std::move(*msg); + return true; } diff --git a/ipc/glue/MiniTransceiver.h b/ipc/glue/MiniTransceiver.h index 121ac50ee8f2..f7b482e3ca70 100644 --- a/ipc/glue/MiniTransceiver.h +++ b/ipc/glue/MiniTransceiver.h @@ -14,10 +14,7 @@ struct msghdr; namespace mozilla { namespace ipc { -enum class DataBufferClear { - None, - AfterReceiving -}; +enum class DataBufferClear { None, AfterReceiving }; /** * This simple implementation handles the transmissions of IPC @@ -31,89 +28,90 @@ enum class DataBufferClear { * complexity of asynchronous I/O. */ class MiniTransceiver { -public: - /** - * \param aFd should be a blocking, no O_NONBLOCK, fd. - * \param aClearDataBuf is true to clear data buffers after - * receiving a message. - */ - explicit MiniTransceiver(int aFd, DataBufferClear aDataBufClear = DataBufferClear::None); + public: + /** + * \param aFd should be a blocking, no O_NONBLOCK, fd. + * \param aClearDataBuf is true to clear data buffers after + * receiving a message. + */ + explicit MiniTransceiver( + int aFd, DataBufferClear aDataBufClear = DataBufferClear::None); - bool Send(IPC::Message& aMsg); - inline bool SendInfallible(IPC::Message& aMsg, const char* aCrashMessage) { - bool Ok = Send(aMsg); - if (!Ok) { - MOZ_CRASH_UNSAFE(aCrashMessage); - } - return Ok; + bool Send(IPC::Message& aMsg); + inline bool SendInfallible(IPC::Message& aMsg, const char* aCrashMessage) { + bool Ok = Send(aMsg); + if (!Ok) { + MOZ_CRASH_UNSAFE(aCrashMessage); } + return Ok; + } - /** - * \param aMsg will hold the content of the received message. - * \return false if the fd is closed or with an error. - */ - bool Recv(IPC::Message& aMsg); - inline bool RecvInfallible(IPC::Message& aMsg, const char* aCrashMessage) { - bool Ok = Recv(aMsg); - if (!Ok) { - MOZ_CRASH_UNSAFE(aCrashMessage); - } - return Ok; + /** + * \param aMsg will hold the content of the received message. + * \return false if the fd is closed or with an error. + */ + bool Recv(IPC::Message& aMsg); + inline bool RecvInfallible(IPC::Message& aMsg, const char* aCrashMessage) { + bool Ok = Recv(aMsg); + if (!Ok) { + MOZ_CRASH_UNSAFE(aCrashMessage); } + return Ok; + } - int GetFD() { return mFd; } + int GetFD() { return mFd; } -private: - /** - * Set control buffer to make file descriptors ready to be sent - * through a socket. - */ - void PrepareFDs(msghdr* aHdr, IPC::Message& aMsg); - /** - * Collect buffers of the message and make them ready to be sent. - * - * \param aHdr is the structure going to be passed to sendmsg(). - * \param aMsg is the Message to send. - */ - size_t PrepareBuffers(msghdr* aHdr, IPC::Message& aMsg); - /** - * Collect file descriptors received. - * - * \param aAllFds is where to store file descriptors. - * \param aMaxFds is how many file descriptors can be stored in aAllFds. - * \return the number of received file descriptors. - */ - unsigned RecvFDs(msghdr* aHdr, int* aAllFds, unsigned aMaxFds); - /** - * Received data from the socket. - * - * \param aDataBuf is where to store the data from the socket. - * \param aBufSize is the size of the buffer. - * \param aMsgSize returns how many bytes were readed from the socket. - * \param aFdsBuf is the buffer to return file desriptors received. - * \param aMaxFds is the number of file descriptors that can be held. - * \param aNumFds returns the number of file descriptors received. - * \return true if sucess, or false for error. - */ - bool RecvData(char* aDataBuf, size_t aBufSize, uint32_t* aMsgSize, - int* aFdsBuf, unsigned aMaxFds, unsigned* aNumFds); + private: + /** + * Set control buffer to make file descriptors ready to be sent + * through a socket. + */ + void PrepareFDs(msghdr* aHdr, IPC::Message& aMsg); + /** + * Collect buffers of the message and make them ready to be sent. + * + * \param aHdr is the structure going to be passed to sendmsg(). + * \param aMsg is the Message to send. + */ + size_t PrepareBuffers(msghdr* aHdr, IPC::Message& aMsg); + /** + * Collect file descriptors received. + * + * \param aAllFds is where to store file descriptors. + * \param aMaxFds is how many file descriptors can be stored in aAllFds. + * \return the number of received file descriptors. + */ + unsigned RecvFDs(msghdr* aHdr, int* aAllFds, unsigned aMaxFds); + /** + * Received data from the socket. + * + * \param aDataBuf is where to store the data from the socket. + * \param aBufSize is the size of the buffer. + * \param aMsgSize returns how many bytes were readed from the socket. + * \param aFdsBuf is the buffer to return file desriptors received. + * \param aMaxFds is the number of file descriptors that can be held. + * \param aNumFds returns the number of file descriptors received. + * \return true if sucess, or false for error. + */ + bool RecvData(char* aDataBuf, size_t aBufSize, uint32_t* aMsgSize, + int* aFdsBuf, unsigned aMaxFds, unsigned* aNumFds); - int mFd; // The file descriptor of the socket for IPC. + int mFd; // The file descriptor of the socket for IPC. #ifdef DEBUG - enum State { - STATE_NONE, - STATE_SENDING, - STATE_RECEIVING, - }; - State mState; + enum State { + STATE_NONE, + STATE_SENDING, + STATE_RECEIVING, + }; + State mState; #endif - // Clear all received data in temp buffers to avoid data leaking. - DataBufferClear mDataBufClear; + // Clear all received data in temp buffers to avoid data leaking. + DataBufferClear mDataBufClear; }; -} // ipc -} // mozilla +} // namespace ipc +} // namespace mozilla -#endif // __MINITRANSCEIVER_H_ +#endif // __MINITRANSCEIVER_H_ diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 6ddea839edf1..87117367b430 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -1099,7 +1099,8 @@ static bool GetDisplayPortImpl( result = GetDisplayPortFromRectData(aContent, rectData, aMultiplier); } else if (isDisplayportSuppressed || nsLayoutUtils::ShouldDisableApzForElement(aContent)) { - DisplayPortMarginsPropertyData noMargins(ScreenMargin(), 1, /*painted=*/false); + DisplayPortMarginsPropertyData noMargins(ScreenMargin(), 1, + /*painted=*/false); result = GetDisplayPortFromMarginsData(aContent, &noMargins, aMultiplier); } else { result = GetDisplayPortFromMarginsData(aContent, marginsData, aMultiplier); @@ -1143,8 +1144,7 @@ bool nsLayoutUtils::GetDisplayPort( bool usingDisplayPort = GetDisplayPortImpl(aContent, aResult, multiplier, MaxSizeExceededBehaviour::Assert, aOutPainted); - if (aResult && usingDisplayPort && - aRelativeTo == RelativeTo::ScrollFrame) { + if (aResult && usingDisplayPort && aRelativeTo == RelativeTo::ScrollFrame) { TranslateFromScrollPortToScrollFrame(aContent, aResult); } return usingDisplayPort; diff --git a/layout/forms/nsFieldSetFrame.cpp b/layout/forms/nsFieldSetFrame.cpp index 84ef24ddcc5e..6581b44799ea 100644 --- a/layout/forms/nsFieldSetFrame.cpp +++ b/layout/forms/nsFieldSetFrame.cpp @@ -915,7 +915,7 @@ void nsFieldSetFrame::EnsureChildContinuation(nsIFrame* aChild, } if (aStatus.IsOverflowIncomplete()) { if (nsFrameList* eoc = - GetPropTableFrames(ExcessOverflowContainersProperty())) { + GetPropTableFrames(ExcessOverflowContainersProperty())) { eoc->AppendFrames(nullptr, nifs); } else { SetPropTableFrames(new (PresShell()) nsFrameList(nifs), diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 7a1ade34ba37..dbd32051881e 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -485,8 +485,7 @@ bool nsImageFrame::UpdateIntrinsicSize() { return mIntrinsicSize != oldIntrinsicSize; } -static AspectRatio ComputeAspectRatio(imgIContainer* aImage, - bool aHasRequest, +static AspectRatio ComputeAspectRatio(imgIContainer* aImage, bool aHasRequest, const nsImageFrame& aFrame) { const ComputedStyle& style = *aFrame.Style(); if (style.StyleDisplay()->IsContainSize()) { @@ -718,8 +717,7 @@ void nsImageFrame::UpdateImage(imgIRequest* aRequest, imgIContainer* aImage) { } // NOTE(emilio): Intentionally using `|` instead of `||` to avoid // short-circuiting. - bool intrinsicSizeChanged = - UpdateIntrinsicSize() | UpdateIntrinsicRatio(); + bool intrinsicSizeChanged = UpdateIntrinsicSize() | UpdateIntrinsicRatio(); if (!GotInitialReflow()) { return; } diff --git a/layout/mathml/nsMathMLContainerFrame.h b/layout/mathml/nsMathMLContainerFrame.h index c00f8523dfff..4037e0ac69f1 100644 --- a/layout/mathml/nsMathMLContainerFrame.h +++ b/layout/mathml/nsMathMLContainerFrame.h @@ -71,8 +71,7 @@ class nsMathMLContainerFrame : public nsContainerFrame, public nsMathMLFrame { if (aFlags & (eLineParticipant | eSupportsContainLayoutAndPaint)) { return false; } - return nsContainerFrame::IsFrameOfType( - aFlags & ~eMathML); + return nsContainerFrame::IsFrameOfType(aFlags & ~eMathML); } virtual void AppendFrames(ChildListID aListID, @@ -419,8 +418,7 @@ class nsMathMLmathBlockFrame final : public nsBlockFrame { } virtual bool IsFrameOfType(uint32_t aFlags) const override { - return nsBlockFrame::IsFrameOfType( - aFlags & ~nsIFrame::eMathML); + return nsBlockFrame::IsFrameOfType(aFlags & ~nsIFrame::eMathML); } // See nsIMathMLFrame.h @@ -488,8 +486,7 @@ class nsMathMLmathInlineFrame final : public nsInlineFrame, } virtual bool IsFrameOfType(uint32_t aFlags) const override { - return nsInlineFrame::IsFrameOfType( - aFlags & ~nsIFrame::eMathML); + return nsInlineFrame::IsFrameOfType(aFlags & ~nsIFrame::eMathML); } bool IsMrowLike() override { diff --git a/layout/mathml/nsMathMLmtableFrame.h b/layout/mathml/nsMathMLmtableFrame.h index 1347bc4e83f0..8cf5c7651a93 100644 --- a/layout/mathml/nsMathMLmtableFrame.h +++ b/layout/mathml/nsMathMLmtableFrame.h @@ -272,8 +272,7 @@ class nsMathMLmtdInnerFrame final : public nsBlockFrame, public nsMathMLFrame { nsReflowStatus& aStatus) override; virtual bool IsFrameOfType(uint32_t aFlags) const override { - return nsBlockFrame::IsFrameOfType( - aFlags & ~nsIFrame::eMathML); + return nsBlockFrame::IsFrameOfType(aFlags & ~nsIFrame::eMathML); } virtual const nsStyleText* StyleTextForLineLayout() override; diff --git a/layout/xul/nsBoxFrame.h b/layout/xul/nsBoxFrame.h index 2a230c109374..1c3f520253e4 100644 --- a/layout/xul/nsBoxFrame.h +++ b/layout/xul/nsBoxFrame.h @@ -116,8 +116,8 @@ class nsBoxFrame : public nsContainerFrame { // that contains a block so ReflowInput doesn't tell us to be // NS_UNCONSTRAINEDSIZE wide.) return nsContainerFrame::IsFrameOfType( - aFlags & ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock | - eXULBox)); + aFlags & + ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock | eXULBox)); } #ifdef DEBUG_FRAME_DUMP diff --git a/media/webrtc/signaling/gtest/videoconduit_unittests.cpp b/media/webrtc/signaling/gtest/videoconduit_unittests.cpp index d6722e52f92c..707f44f9d51f 100644 --- a/media/webrtc/signaling/gtest/videoconduit_unittests.cpp +++ b/media/webrtc/signaling/gtest/videoconduit_unittests.cpp @@ -1407,7 +1407,7 @@ TEST_F(VideoConduitTest, TestVideoEncodeMaxFsNegotiatedThenSinkWants) { SendVideoFrame(1280, 720, frame++); ASSERT_EQ(sink->mVideoFrame.width(), 960); ASSERT_EQ(sink->mVideoFrame.height(), 540); - ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame-1)*1000); + ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame - 1) * 1000); ASSERT_EQ(sink->mOnFrameCount, frame); wants.max_pixel_count = 3600 * 16 * 16; @@ -1416,7 +1416,7 @@ TEST_F(VideoConduitTest, TestVideoEncodeMaxFsNegotiatedThenSinkWants) { SendVideoFrame(1280, 720, frame++); ASSERT_EQ(sink->mVideoFrame.width(), 960); ASSERT_EQ(sink->mVideoFrame.height(), 540); - ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame-1)*1000); + ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame - 1) * 1000); ASSERT_EQ(sink->mOnFrameCount, frame); mVideoConduit->StopTransmitting(); @@ -1445,7 +1445,7 @@ TEST_F(VideoConduitTest, TestVideoEncodeMaxFsCodecChange) { SendVideoFrame(1280, 720, frame++); ASSERT_EQ(sink->mVideoFrame.width(), 960); ASSERT_EQ(sink->mVideoFrame.height(), 540); - ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame-1)*1000); + ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame - 1) * 1000); ASSERT_EQ(sink->mOnFrameCount, frame); VideoCodecConfig codecConfigVP9(121, "VP9", constraints); @@ -1457,7 +1457,7 @@ TEST_F(VideoConduitTest, TestVideoEncodeMaxFsCodecChange) { SendVideoFrame(1280, 720, frame++); ASSERT_EQ(sink->mVideoFrame.width(), 960); ASSERT_EQ(sink->mVideoFrame.height(), 540); - ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame-1)*1000); + ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame - 1) * 1000); ASSERT_EQ(sink->mOnFrameCount, frame); mVideoConduit->StopTransmitting(); @@ -1486,7 +1486,7 @@ TEST_F(VideoConduitTest, TestVideoEncodeMaxFsSinkWantsThenCodecChange) { SendVideoFrame(1280, 720, frame++); ASSERT_EQ(sink->mVideoFrame.width(), 960); ASSERT_EQ(sink->mVideoFrame.height(), 540); - ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame-1)*1000); + ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame - 1) * 1000); ASSERT_EQ(sink->mOnFrameCount, frame); VideoCodecConfig codecConfigVP9(121, "VP9", constraints); @@ -1497,7 +1497,7 @@ TEST_F(VideoConduitTest, TestVideoEncodeMaxFsSinkWantsThenCodecChange) { SendVideoFrame(1280, 720, frame++); ASSERT_EQ(sink->mVideoFrame.width(), 960); ASSERT_EQ(sink->mVideoFrame.height(), 540); - ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame-1)*1000); + ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame - 1) * 1000); ASSERT_EQ(sink->mOnFrameCount, frame); mVideoConduit->StopTransmitting(); @@ -1524,7 +1524,7 @@ TEST_F(VideoConduitTest, TestVideoEncodeMaxFsNegotiated) { SendVideoFrame(1280, 720, frame++); ASSERT_EQ(sink->mVideoFrame.width(), 1280); ASSERT_EQ(sink->mVideoFrame.height(), 720); - ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame-1)*1000); + ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame - 1) * 1000); ASSERT_EQ(sink->mOnFrameCount, frame); // Ensure that negotiating a new max-fs works @@ -1535,7 +1535,7 @@ TEST_F(VideoConduitTest, TestVideoEncodeMaxFsNegotiated) { SendVideoFrame(1280, 720, frame++); ASSERT_EQ(sink->mVideoFrame.width(), 960); ASSERT_EQ(sink->mVideoFrame.height(), 540); - ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame-1)*1000); + ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame - 1) * 1000); ASSERT_EQ(sink->mOnFrameCount, frame); // Ensure that negotiating max-fs away works @@ -1546,7 +1546,7 @@ TEST_F(VideoConduitTest, TestVideoEncodeMaxFsNegotiated) { SendVideoFrame(1280, 720, frame++); ASSERT_EQ(sink->mVideoFrame.width(), 1280); ASSERT_EQ(sink->mVideoFrame.height(), 720); - ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame-1)*1000); + ASSERT_EQ(sink->mVideoFrame.timestamp_us(), (frame - 1) * 1000); ASSERT_EQ(sink->mOnFrameCount, frame); mVideoConduit->StopTransmitting(); diff --git a/media/webrtc/signaling/src/media-conduit/VideoConduit.h b/media/webrtc/signaling/src/media-conduit/VideoConduit.h index b0f052f9bf0c..be88701b630a 100644 --- a/media/webrtc/signaling/src/media-conduit/VideoConduit.h +++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.h @@ -208,8 +208,9 @@ class WebrtcVideoConduit */ void AddOrUpdateSink(rtc::VideoSinkInterface* sink, const rtc::VideoSinkWants& wants) override; - void AddOrUpdateSinkNotLocked(rtc::VideoSinkInterface* sink, - const rtc::VideoSinkWants& wants); + void AddOrUpdateSinkNotLocked( + rtc::VideoSinkInterface* sink, + const rtc::VideoSinkWants& wants); void RemoveSink(rtc::VideoSinkInterface* sink) override; void RemoveSinkNotLocked(rtc::VideoSinkInterface* sink); diff --git a/media/webrtc/signaling/src/peerconnection/RTCStatsIdGenerator.h b/media/webrtc/signaling/src/peerconnection/RTCStatsIdGenerator.h index d748e96ab220..aac451f75052 100644 --- a/media/webrtc/signaling/src/peerconnection/RTCStatsIdGenerator.h +++ b/media/webrtc/signaling/src/peerconnection/RTCStatsIdGenerator.h @@ -12,18 +12,19 @@ namespace mozilla { class RTCStatsIdGenerator { -public: - RTCStatsIdGenerator(); - nsString Id(const nsString& aKey); - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RTCStatsIdGenerator); -private: - virtual ~RTCStatsIdGenerator() {}; - nsString Generate(); + public: + RTCStatsIdGenerator(); + nsString Id(const nsString& aKey); + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RTCStatsIdGenerator); - const uint64_t mSalt; - uint64_t mCounter; - std::map mAllocated; + private: + virtual ~RTCStatsIdGenerator(){}; + nsString Generate(); + + const uint64_t mSalt; + uint64_t mCounter; + std::map mAllocated; }; -} +} // namespace mozilla #endif diff --git a/mfbt/RangedPtr.h b/mfbt/RangedPtr.h index 6e18a8d28a14..7f6e8c99de1f 100644 --- a/mfbt/RangedPtr.h +++ b/mfbt/RangedPtr.h @@ -120,7 +120,7 @@ class RangedPtr { } MOZ_IMPLICIT RangedPtr(const RangedPtr& aOther) - : mPtr(aOther.mPtr) + : mPtr(aOther.mPtr) #ifdef DEBUG , mRangeStart(aOther.mRangeStart), diff --git a/mozglue/misc/NativeNt.h b/mozglue/misc/NativeNt.h index a1814a2630c8..3d54bacd50b2 100644 --- a/mozglue/misc/NativeNt.h +++ b/mozglue/misc/NativeNt.h @@ -241,9 +241,7 @@ struct MemorySectionNameBuf : public _MEMORY_SECTION_NAME { mSectionFileName.Buffer = mBuf; } - MemorySectionNameBuf(const MemorySectionNameBuf& aOther) { - *this = aOther; - } + MemorySectionNameBuf(const MemorySectionNameBuf& aOther) { *this = aOther; } MemorySectionNameBuf(MemorySectionNameBuf&& aOther) { *this = std::move(aOther); diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index 920c2a99c653..4f6f567beead 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -1075,7 +1075,7 @@ class OutboundMessage { class OutboundEnqueuer final : public Runnable { public: OutboundEnqueuer(WebSocketChannel* aChannel, OutboundMessage* aMsg) - : Runnable("OutboundEnquerer"), mChannel(aChannel), mMessage(aMsg) {} + : Runnable("OutboundEnquerer"), mChannel(aChannel), mMessage(aMsg) {} NS_IMETHOD Run() override { mChannel->EnqueueOutgoingMessage(mChannel->mOutgoingMessages, mMessage); diff --git a/netwerk/system/android/nsAndroidNetworkLinkService.cpp b/netwerk/system/android/nsAndroidNetworkLinkService.cpp index 033354e9716c..10d15ebd0929 100644 --- a/netwerk/system/android/nsAndroidNetworkLinkService.cpp +++ b/netwerk/system/android/nsAndroidNetworkLinkService.cpp @@ -204,8 +204,8 @@ void nsAndroidNetworkLinkService::OnLinkStatusKnown() { mStatusIsKnown = true; } void nsAndroidNetworkLinkService::OnDnsSuffixListUpdated() { RefPtr self = this; - NS_DispatchToMainThread( - NS_NewRunnableFunction("nsAndroidNetworkLinkService::OnDnsSuffixListUpdated", [self]() { + NS_DispatchToMainThread(NS_NewRunnableFunction( + "nsAndroidNetworkLinkService::OnDnsSuffixListUpdated", [self]() { self->NotifyObservers(NS_DNS_SUFFIX_LIST_UPDATED_TOPIC, nullptr); })); } diff --git a/netwerk/system/linux/nsNetworkLinkService.cpp b/netwerk/system/linux/nsNetworkLinkService.cpp index 74d52838b975..07d4b994b01b 100644 --- a/netwerk/system/linux/nsNetworkLinkService.cpp +++ b/netwerk/system/linux/nsNetworkLinkService.cpp @@ -169,8 +169,8 @@ void nsNetworkLinkService::OnLinkStatusKnown() { mStatusIsKnown = true; } void nsNetworkLinkService::OnDnsSuffixListUpdated() { RefPtr self = this; - NS_DispatchToMainThread( - NS_NewRunnableFunction("nsNetworkLinkService::OnDnsSuffixListUpdated", [self]() { + NS_DispatchToMainThread(NS_NewRunnableFunction( + "nsNetworkLinkService::OnDnsSuffixListUpdated", [self]() { self->NotifyObservers(NS_DNS_SUFFIX_LIST_UPDATED_TOPIC, nullptr); })); } diff --git a/netwerk/test/fuzz/TestHttpFuzzing.cpp b/netwerk/test/fuzz/TestHttpFuzzing.cpp index e0028ffdf5dd..9cdb7896094e 100644 --- a/netwerk/test/fuzz/TestHttpFuzzing.cpp +++ b/netwerk/test/fuzz/TestHttpFuzzing.cpp @@ -221,9 +221,8 @@ static int FuzzingRunNetworkHttp(const uint8_t* data, size_t size) { bool mainPingBack = false; NS_DispatchBackgroundTask(NS_NewRunnableFunction("Dummy", [&]() { - NS_DispatchToMainThread(NS_NewRunnableFunction("Dummy", [&]() { - mainPingBack = true; - })); + NS_DispatchToMainThread( + NS_NewRunnableFunction("Dummy", [&]() { mainPingBack = true; })); })); SpinEventLoopUntil([&]() -> bool { return mainPingBack; }); diff --git a/security/sandbox/linux/launch/SandboxLaunch.cpp b/security/sandbox/linux/launch/SandboxLaunch.cpp index 5260c7350e4b..2a29756552ad 100644 --- a/security/sandbox/linux/launch/SandboxLaunch.cpp +++ b/security/sandbox/linux/launch/SandboxLaunch.cpp @@ -209,8 +209,7 @@ static void AttachSandboxReporter(base::file_handle_mapping_vector* aFdMap) { class SandboxFork : public base::LaunchOptions::ForkDelegate { public: - explicit SandboxFork(int aFlags, bool aChroot, - int aServerFd = -1, + explicit SandboxFork(int aFlags, bool aChroot, int aServerFd = -1, int aClientFd = -1); virtual ~SandboxFork(); @@ -335,7 +334,7 @@ void SandboxLaunchPrepare(GeckoProcessType aType, aOptions->fork_delegate = std::move(forker); // Pass to |SandboxLaunchForkServerPrepare()| in the fork server. aOptions->env_map[kSandboxChrootEnvFlag] = - std::to_string(canChroot ? 1 : 0) + std::to_string(flags); + std::to_string(canChroot ? 1 : 0) + std::to_string(flags); } } @@ -349,11 +348,9 @@ void SandboxLaunchPrepare(GeckoProcessType aType, */ void SandboxLaunchForkServerPrepare(const std::vector& aArgv, base::LaunchOptions& aOptions) { - auto chroot = std::find_if(aOptions.env_map.begin(), - aOptions.env_map.end(), - [](auto& elt) { - return elt.first == kSandboxChrootEnvFlag; - }); + auto chroot = std::find_if( + aOptions.env_map.begin(), aOptions.env_map.end(), + [](auto& elt) { return elt.first == kSandboxChrootEnvFlag; }); if (chroot == aOptions.env_map.end()) { return; } @@ -363,11 +360,9 @@ void SandboxLaunchForkServerPrepare(const std::vector& aArgv, // Find chroot server fd. It is supposed to be map to // kSandboxChrootServerFd so that we find it out from the mapping. - auto fdmap = std::find_if(aOptions.fds_to_remap.begin(), - aOptions.fds_to_remap.end(), - [](auto& elt) { - return elt.second == kSandboxChrootServerFd; - }); + auto fdmap = std::find_if( + aOptions.fds_to_remap.begin(), aOptions.fds_to_remap.end(), + [](auto& elt) { return elt.second == kSandboxChrootServerFd; }); MOZ_ASSERT(fdmap != aOptions.fds_to_remap.end(), "ChrootServerFd is not found with sandbox chroot"); int chrootserverfd = fdmap->first; diff --git a/toolkit/xre/nsEmbedFunctions.cpp b/toolkit/xre/nsEmbedFunctions.cpp index 7daeef3841ca..c1c3ed091c89 100644 --- a/toolkit/xre/nsEmbedFunctions.cpp +++ b/toolkit/xre/nsEmbedFunctions.cpp @@ -267,8 +267,7 @@ void XRE_SetAndroidChildFds(JNIEnv* env, const XRE_AndroidChildFds& fds) { void XRE_SetProcessType(const char* aProcessTypeString) { static bool called = false; - if (called && - sChildProcessType != GeckoProcessType_ForkServer) { + if (called && sChildProcessType != GeckoProcessType_ForkServer) { MOZ_CRASH(); } called = true; diff --git a/widget/windows/ToastNotificationHandler.cpp b/widget/windows/ToastNotificationHandler.cpp index 97cb0965e7e9..cf3087e9091e 100644 --- a/widget/windows/ToastNotificationHandler.cpp +++ b/widget/windows/ToastNotificationHandler.cpp @@ -29,15 +29,15 @@ namespace mozilla { namespace widget { typedef ABI::Windows::Foundation::ITypedEventHandler< - ABI::Windows::UI::Notifications::ToastNotification *, IInspectable *> + ABI::Windows::UI::Notifications::ToastNotification*, IInspectable*> ToastActivationHandler; typedef ABI::Windows::Foundation::ITypedEventHandler< - ABI::Windows::UI::Notifications::ToastNotification *, - ABI::Windows::UI::Notifications::ToastDismissedEventArgs *> + ABI::Windows::UI::Notifications::ToastNotification*, + ABI::Windows::UI::Notifications::ToastDismissedEventArgs*> ToastDismissedHandler; typedef ABI::Windows::Foundation::ITypedEventHandler< - ABI::Windows::UI::Notifications::ToastNotification *, - ABI::Windows::UI::Notifications::ToastFailedEventArgs *> + ABI::Windows::UI::Notifications::ToastNotification*, + ABI::Windows::UI::Notifications::ToastFailedEventArgs*> ToastFailedHandler; using namespace ABI::Windows::Data::Xml::Dom; @@ -49,11 +49,11 @@ using namespace mozilla; NS_IMPL_ISUPPORTS(ToastNotificationHandler, nsIAlertNotificationImageListener) -static bool SetNodeValueString(const nsString &aString, IXmlNode *node, - IXmlDocument *xml) { +static bool SetNodeValueString(const nsString& aString, IXmlNode* node, + IXmlDocument* xml) { ComPtr inputText; if (NS_WARN_IF(FAILED(xml->CreateTextNode( - HStringReference(static_cast(aString.get())).Get(), + HStringReference(static_cast(aString.get())).Get(), &inputText)))) { return false; } @@ -69,9 +69,9 @@ static bool SetNodeValueString(const nsString &aString, IXmlNode *node, return true; } -static bool SetAttribute(IXmlElement *element, const HSTRING name, - const nsAString &value) { - HSTRING valueStr = HStringReference(static_cast( +static bool SetAttribute(IXmlElement* element, const HSTRING name, + const nsAString& value) { + HSTRING valueStr = HStringReference(static_cast( PromiseFlatString(value).get())) .Get(); if (NS_WARN_IF(FAILED(element->SetAttribute(name, valueStr)))) { @@ -80,9 +80,9 @@ static bool SetAttribute(IXmlElement *element, const HSTRING name, return true; } -static bool AddActionNode(IXmlDocument *toastXml, IXmlNode *actionsNode, - const nsAString &actionTitle, - const nsAString &actionArgs) { +static bool AddActionNode(IXmlDocument* toastXml, IXmlNode* actionsNode, + const nsAString& actionTitle, + const nsAString& actionArgs) { ComPtr action; HRESULT hr = toastXml->CreateElement(HStringReference(L"action").Get(), &action); @@ -174,8 +174,8 @@ ComPtr ToastNotificationHandler::InitializeXmlForTemplate( return toastXml; } -nsresult -ToastNotificationHandler::InitAlertAsync(nsIAlertNotification *aAlert) { +nsresult ToastNotificationHandler::InitAlertAsync( + nsIAlertNotification* aAlert) { return aAlert->LoadImage(/* aTimeout = */ 0, this, /* aUserData = */ nullptr, getter_AddRefs(mImageRequest)); } @@ -341,7 +341,7 @@ bool ToastNotificationHandler::ShowAlert() { } bool ToastNotificationHandler::CreateWindowsNotificationFromXml( - IXmlDocument *aXml) { + IXmlDocument* aXml) { ComPtr factory; HRESULT hr = GetActivationFactory( HStringReference(RuntimeClass_Windows_UI_Notifications_ToastNotification) @@ -359,8 +359,8 @@ bool ToastNotificationHandler::CreateWindowsNotificationFromXml( RefPtr self = this; hr = mNotification->add_Activated( - Callback([self](IToastNotification *aNotification, - IInspectable *aInspectable) { + Callback([self](IToastNotification* aNotification, + IInspectable* aInspectable) { return self->OnActivate(aNotification, aInspectable); }).Get(), &mActivatedToken); @@ -369,8 +369,8 @@ bool ToastNotificationHandler::CreateWindowsNotificationFromXml( } hr = mNotification->add_Dismissed( - Callback([self](IToastNotification *aNotification, - IToastDismissedEventArgs *aArgs) { + Callback([self](IToastNotification* aNotification, + IToastDismissedEventArgs* aArgs) { return self->OnDismiss(aNotification, aArgs); }).Get(), &mDismissedToken); @@ -379,8 +379,8 @@ bool ToastNotificationHandler::CreateWindowsNotificationFromXml( } hr = mNotification->add_Failed( - Callback([self](IToastNotification *aNotification, - IToastFailedEventArgs *aArgs) { + Callback([self](IToastNotification* aNotification, + IToastFailedEventArgs* aArgs) { return self->OnFail(aNotification, aArgs); }).Get(), &mFailedToken); @@ -400,7 +400,7 @@ bool ToastNotificationHandler::CreateWindowsNotificationFromXml( } HSTRING uidStr = - HStringReference(static_cast(uid.get())).Get(); + HStringReference(static_cast(uid.get())).Get(); hr = toastNotificationManagerStatics->CreateToastNotifierWithId(uidStr, &mNotifier); if (NS_WARN_IF(FAILED(hr))) { @@ -419,8 +419,7 @@ bool ToastNotificationHandler::CreateWindowsNotificationFromXml( return true; } -void -ToastNotificationHandler::SendFinished() { +void ToastNotificationHandler::SendFinished() { if (!mSentFinished && mAlertListener) { mAlertListener->Observe(nullptr, "alertfinished", mCookie.get()); } @@ -429,20 +428,20 @@ ToastNotificationHandler::SendFinished() { } HRESULT -ToastNotificationHandler::OnActivate(IToastNotification *notification, - IInspectable *inspectable) { +ToastNotificationHandler::OnActivate(IToastNotification* notification, + IInspectable* inspectable) { if (mAlertListener) { nsAutoString argString; if (inspectable) { ComPtr eventArgs; HRESULT hr = inspectable->QueryInterface( - __uuidof(IToastActivatedEventArgs), (void **)&eventArgs); + __uuidof(IToastActivatedEventArgs), (void**)&eventArgs); if (SUCCEEDED(hr)) { HSTRING arguments; hr = eventArgs->get_Arguments(&arguments); if (SUCCEEDED(hr)) { uint32_t len = 0; - const wchar_t *buffer = WindowsGetStringRawBuffer(arguments, &len); + const wchar_t* buffer = WindowsGetStringRawBuffer(arguments, &len); if (buffer) { argString.Assign(buffer, len); } @@ -480,16 +479,16 @@ ToastNotificationHandler::OnActivate(IToastNotification *notification, } HRESULT -ToastNotificationHandler::OnDismiss(IToastNotification *notification, - IToastDismissedEventArgs *aArgs) { +ToastNotificationHandler::OnDismiss(IToastNotification* notification, + IToastDismissedEventArgs* aArgs) { SendFinished(); mBackend->RemoveHandler(mName, this); return S_OK; } HRESULT -ToastNotificationHandler::OnFail(IToastNotification *notification, - IToastFailedEventArgs *aArgs) { +ToastNotificationHandler::OnFail(IToastNotification* notification, + IToastFailedEventArgs* aArgs) { SendFinished(); mBackend->RemoveHandler(mName, this); return S_OK; @@ -504,12 +503,12 @@ nsresult ToastNotificationHandler::TryShowAlert() { } NS_IMETHODIMP -ToastNotificationHandler::OnImageMissing(nsISupports *) { +ToastNotificationHandler::OnImageMissing(nsISupports*) { return TryShowAlert(); } NS_IMETHODIMP -ToastNotificationHandler::OnImageReady(nsISupports *, imgIRequest *aRequest) { +ToastNotificationHandler::OnImageReady(nsISupports*, imgIRequest* aRequest) { nsresult rv = AsyncSaveImage(aRequest); if (NS_FAILED(rv)) { return TryShowAlert(); @@ -517,7 +516,7 @@ ToastNotificationHandler::OnImageReady(nsISupports *, imgIRequest *aRequest) { return rv; } -nsresult ToastNotificationHandler::AsyncSaveImage(imgIRequest *aRequest) { +nsresult ToastNotificationHandler::AsyncSaveImage(imgIRequest* aRequest) { nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(mImageFile)); if (NS_WARN_IF(NS_FAILED(rv))) { @@ -580,7 +579,7 @@ nsresult ToastNotificationHandler::AsyncSaveImage(imgIRequest *aRequest) { nsCOMPtr cbRunnable = NS_NewRunnableFunction( "ToastNotificationHandler::AsyncWriteBitmapCb", [self, rv]() -> void { - auto handler = const_cast(self.get()); + auto handler = const_cast(self.get()); handler->OnWriteBitmapFinished(rv); }); @@ -619,5 +618,5 @@ nsresult ToastNotificationHandler::OnWriteBitmapSuccess() { return NS_OK; } -} // namespace widget -} // namespace mozilla +} // namespace widget +} // namespace mozilla diff --git a/xpcom/base/nsTraceRefcnt.cpp b/xpcom/base/nsTraceRefcnt.cpp index 9db78b59af59..e0aecd3a7c3d 100644 --- a/xpcom/base/nsTraceRefcnt.cpp +++ b/xpcom/base/nsTraceRefcnt.cpp @@ -569,10 +569,11 @@ static void DoInitTraceLog(const char* aProcType) { return; } - bool defined = - InitLog(ENVVAR("XPCOM_MEM_BLOAT_LOG"), "bloat/leaks", &gBloatLog, aProcType); + bool defined = InitLog(ENVVAR("XPCOM_MEM_BLOAT_LOG"), "bloat/leaks", + &gBloatLog, aProcType); if (!defined) { - gLogLeaksOnly = InitLog(ENVVAR("XPCOM_MEM_LEAK_LOG"), "leaks", &gBloatLog, aProcType); + gLogLeaksOnly = + InitLog(ENVVAR("XPCOM_MEM_LEAK_LOG"), "leaks", &gBloatLog, aProcType); } if (defined || gLogLeaksOnly) { // Use the same bloat view, if there is, to keep it consistent @@ -1182,9 +1183,7 @@ static void ClearLogs(bool aKeepCounters) { maybeUnregisterAndCloseFile(gCOMPtrLog); } -void nsTraceRefcnt::Shutdown() { - ClearLogs(false); -} +void nsTraceRefcnt::Shutdown() { ClearLogs(false); } void nsTraceRefcnt::SetActivityIsLegal(bool aLegal) { if (gActivityTLS == BAD_TLS_INDEX) { diff --git a/xpcom/build/nsXULAppAPI.h b/xpcom/build/nsXULAppAPI.h index a82f0ac62be4..ad2881615f81 100644 --- a/xpcom/build/nsXULAppAPI.h +++ b/xpcom/build/nsXULAppAPI.h @@ -513,6 +513,6 @@ XRE_API(void, XRE_LibFuzzerSetDriver, (LibFuzzerDriver)) XRE_API(int, XRE_ForkServer, (int* aArgc, char*** aArgv)) -#endif // MOZ_ENABLE_FORKSERVER +#endif // MOZ_ENABLE_FORKSERVER #endif // _nsXULAppAPI_h__ diff --git a/xpcom/threads/nsThreadManager.h b/xpcom/threads/nsThreadManager.h index 55bbfa3a6b8d..c04c1b190497 100644 --- a/xpcom/threads/nsThreadManager.h +++ b/xpcom/threads/nsThreadManager.h @@ -58,7 +58,8 @@ class nsThreadManager : public nsIThreadManager { nsresult DispatchToBackgroundThread(nsIRunnable* aEvent, uint32_t aDispatchFlags); - already_AddRefed CreateBackgroundTaskQueue(const char* aName); + already_AddRefed CreateBackgroundTaskQueue( + const char* aName); // Returns the maximal number of threads that have been in existence // simultaneously during the execution of the thread manager. diff --git a/xpcom/threads/nsThreadUtils.cpp b/xpcom/threads/nsThreadUtils.cpp index 6437cb6b4c18..ffe0b6388d7d 100644 --- a/xpcom/threads/nsThreadUtils.cpp +++ b/xpcom/threads/nsThreadUtils.cpp @@ -534,7 +534,7 @@ nsresult NS_DispatchBackgroundTask(nsIRunnable* aEvent, nsresult NS_CreateBackgroundTaskQueue(const char* aName, nsISerialEventTarget** aTarget) { nsCOMPtr target = - nsThreadManager::get().CreateBackgroundTaskQueue(aName); + nsThreadManager::get().CreateBackgroundTaskQueue(aName); if (!target) { return NS_ERROR_FAILURE; }