2017-12-05 04:08:17 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2018-01-31 00:23:10 +03:00
|
|
|
#ifndef mozilla_glue_WindowsDllServices_h
|
|
|
|
#define mozilla_glue_WindowsDllServices_h
|
2017-12-05 04:08:17 +03:00
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2018-08-23 00:23:04 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
2018-01-31 01:08:03 +03:00
|
|
|
#include "mozilla/Authenticode.h"
|
2019-09-23 23:18:41 +03:00
|
|
|
#include "mozilla/LoaderAPIInterfaces.h"
|
2018-11-02 11:01:52 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
|
|
|
#include "mozilla/Vector.h"
|
2019-12-07 01:03:45 +03:00
|
|
|
#include "mozilla/WinHeaderOnlyUtils.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/WindowsDllBlocklist.h"
|
|
|
|
#include "mozilla/mozalloc.h"
|
2017-12-05 04:08:17 +03:00
|
|
|
|
|
|
|
#if defined(MOZILLA_INTERNAL_API)
|
2018-08-23 00:23:04 +03:00
|
|
|
# include "MainThreadUtils.h"
|
2017-12-05 04:08:17 +03:00
|
|
|
# include "nsISupportsImpl.h"
|
|
|
|
# include "nsString.h"
|
|
|
|
# include "nsThreadUtils.h"
|
2019-09-23 23:18:41 +03:00
|
|
|
# include "prthread.h"
|
2020-04-07 18:16:33 +03:00
|
|
|
# include "mozilla/SchedulerGroup.h"
|
2017-12-05 04:08:17 +03:00
|
|
|
#endif // defined(MOZILLA_INTERNAL_API)
|
|
|
|
|
|
|
|
// For PCUNICODE_STRING
|
|
|
|
#include <winternl.h>
|
|
|
|
|
|
|
|
namespace mozilla {
|
2018-01-31 00:23:10 +03:00
|
|
|
namespace glue {
|
2017-12-05 04:08:17 +03:00
|
|
|
namespace detail {
|
|
|
|
|
2018-01-31 01:08:03 +03:00
|
|
|
class DllServicesBase : public Authenticode {
|
2017-12-05 04:08:17 +03:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* WARNING: This method is called from within an unsafe context that holds
|
|
|
|
* multiple locks inside the Windows loader. The only thing that
|
|
|
|
* this function should be used for is dispatching the event to our
|
|
|
|
* event loop so that it may be handled in a safe context.
|
|
|
|
*/
|
2019-09-23 23:18:41 +03:00
|
|
|
virtual void DispatchDllLoadNotification(ModuleLoadInfo&& aModLoadInfo) = 0;
|
2017-12-05 04:08:17 +03:00
|
|
|
|
2018-11-02 11:01:52 +03:00
|
|
|
/**
|
|
|
|
* This function accepts module load events to be processed later for
|
|
|
|
* the untrusted modules telemetry ping.
|
|
|
|
*
|
|
|
|
* WARNING: This method is run from within the Windows loader and should
|
2019-09-23 23:18:41 +03:00
|
|
|
* only perform trivial, loader-friendly operations.
|
2018-11-02 11:01:52 +03:00
|
|
|
*/
|
2019-09-23 23:18:41 +03:00
|
|
|
virtual void DispatchModuleLoadBacklogNotification(
|
|
|
|
ModuleLoadInfoVec&& aEvents) = 0;
|
2018-11-02 11:01:52 +03:00
|
|
|
|
2018-01-31 01:08:03 +03:00
|
|
|
void SetAuthenticodeImpl(Authenticode* aAuthenticode) {
|
|
|
|
mAuthenticode = aAuthenticode;
|
|
|
|
}
|
|
|
|
|
2020-08-26 22:01:40 +03:00
|
|
|
void SetWinLauncherFunctions(const nt::WinLauncherFunctions& aFunctions) {
|
|
|
|
mWinLauncherFunctions = aFunctions;
|
2019-12-07 01:03:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
LauncherVoidResultWithLineInfo InitDllBlocklistOOP(Args&&... aArgs) {
|
2020-08-26 22:01:40 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mWinLauncherFunctions.mInitDllBlocklistOOP);
|
|
|
|
return mWinLauncherFunctions.mInitDllBlocklistOOP(
|
|
|
|
std::forward<Args>(aArgs)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
void HandleLauncherError(Args&&... aArgs) {
|
|
|
|
MOZ_RELEASE_ASSERT(mWinLauncherFunctions.mHandleLauncherError);
|
|
|
|
mWinLauncherFunctions.mHandleLauncherError(std::forward<Args>(aArgs)...);
|
2019-12-07 01:03:45 +03:00
|
|
|
}
|
|
|
|
|
2019-09-23 23:18:41 +03:00
|
|
|
// In debug builds we override GetBinaryOrgName to add a Gecko-specific
|
2018-08-23 00:23:04 +03:00
|
|
|
// assertion. OTOH, we normally do not want people overriding this function,
|
|
|
|
// so we'll make it final in the release case, thus covering all bases.
|
|
|
|
#if defined(DEBUG)
|
2019-10-29 00:58:49 +03:00
|
|
|
UniquePtr<wchar_t[]> GetBinaryOrgName(
|
|
|
|
const wchar_t* aFilePath,
|
|
|
|
AuthenticodeFlags aFlags = AuthenticodeFlags::Default) override
|
2018-08-23 00:23:04 +03:00
|
|
|
#else
|
2019-10-29 00:58:49 +03:00
|
|
|
UniquePtr<wchar_t[]> GetBinaryOrgName(
|
|
|
|
const wchar_t* aFilePath,
|
|
|
|
AuthenticodeFlags aFlags = AuthenticodeFlags::Default) final
|
2018-08-23 00:23:04 +03:00
|
|
|
#endif // defined(DEBUG)
|
2018-01-31 01:08:03 +03:00
|
|
|
{
|
|
|
|
if (!mAuthenticode) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-10-29 00:58:49 +03:00
|
|
|
return mAuthenticode->GetBinaryOrgName(aFilePath, aFlags);
|
2018-01-31 01:08:03 +03:00
|
|
|
}
|
|
|
|
|
2019-12-07 01:06:26 +03:00
|
|
|
virtual void DisableFull() { DllBlocklist_SetFullDllServices(nullptr); }
|
2017-12-05 04:08:17 +03:00
|
|
|
|
|
|
|
DllServicesBase(const DllServicesBase&) = delete;
|
|
|
|
DllServicesBase(DllServicesBase&&) = delete;
|
|
|
|
DllServicesBase& operator=(const DllServicesBase&) = delete;
|
|
|
|
DllServicesBase& operator=(DllServicesBase&&) = delete;
|
|
|
|
|
|
|
|
protected:
|
2020-08-26 22:01:40 +03:00
|
|
|
DllServicesBase() : mAuthenticode(nullptr) {}
|
2018-01-31 01:08:03 +03:00
|
|
|
|
2017-12-05 04:08:17 +03:00
|
|
|
virtual ~DllServicesBase() = default;
|
|
|
|
|
2019-02-20 09:18:45 +03:00
|
|
|
void EnableFull() { DllBlocklist_SetFullDllServices(this); }
|
|
|
|
void EnableBasic() { DllBlocklist_SetBasicDllServices(this); }
|
2018-01-31 01:08:03 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
Authenticode* mAuthenticode;
|
2020-08-26 22:01:40 +03:00
|
|
|
nt::WinLauncherFunctions mWinLauncherFunctions;
|
2017-12-05 04:08:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
#if defined(MOZILLA_INTERNAL_API)
|
|
|
|
|
2019-09-23 23:18:41 +03:00
|
|
|
struct EnhancedModuleLoadInfo final {
|
|
|
|
explicit EnhancedModuleLoadInfo(ModuleLoadInfo&& aModLoadInfo)
|
|
|
|
: mNtLoadInfo(std::move(aModLoadInfo)) {
|
|
|
|
// Only populate mThreadName when we're on the same thread as the event
|
|
|
|
if (mNtLoadInfo.mThreadId == ::GetCurrentThreadId()) {
|
|
|
|
mThreadName = PR_GetThreadName(PR_GetCurrentThread());
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(!mNtLoadInfo.mSectionName.IsEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
EnhancedModuleLoadInfo(EnhancedModuleLoadInfo&&) = default;
|
|
|
|
EnhancedModuleLoadInfo& operator=(EnhancedModuleLoadInfo&&) = default;
|
|
|
|
|
|
|
|
EnhancedModuleLoadInfo(const EnhancedModuleLoadInfo&) = delete;
|
|
|
|
EnhancedModuleLoadInfo& operator=(const EnhancedModuleLoadInfo&) = delete;
|
|
|
|
|
|
|
|
nsDependentString GetSectionName() const {
|
|
|
|
return mNtLoadInfo.mSectionName.AsString();
|
|
|
|
}
|
|
|
|
|
|
|
|
using BacktraceType = decltype(ModuleLoadInfo::mBacktrace);
|
|
|
|
|
|
|
|
ModuleLoadInfo mNtLoadInfo;
|
|
|
|
nsCString mThreadName;
|
|
|
|
};
|
|
|
|
|
2017-12-05 04:08:17 +03:00
|
|
|
class DllServices : public detail::DllServicesBase {
|
|
|
|
public:
|
2019-09-23 23:18:41 +03:00
|
|
|
void DispatchDllLoadNotification(ModuleLoadInfo&& aModLoadInfo) final {
|
|
|
|
nsCOMPtr<nsIRunnable> runnable(
|
|
|
|
NewRunnableMethod<StoreCopyPassByRRef<EnhancedModuleLoadInfo>>(
|
|
|
|
"DllServices::NotifyDllLoad", this, &DllServices::NotifyDllLoad,
|
|
|
|
std::move(aModLoadInfo)));
|
2017-12-05 04:08:17 +03:00
|
|
|
|
2020-04-07 18:16:33 +03:00
|
|
|
SchedulerGroup::Dispatch(TaskCategory::Other, runnable.forget());
|
2019-09-23 23:18:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchModuleLoadBacklogNotification(
|
|
|
|
ModuleLoadInfoVec&& aEvents) final {
|
|
|
|
nsCOMPtr<nsIRunnable> runnable(
|
|
|
|
NewRunnableMethod<StoreCopyPassByRRef<ModuleLoadInfoVec>>(
|
|
|
|
"DllServices::NotifyModuleLoadBacklog", this,
|
|
|
|
&DllServices::NotifyModuleLoadBacklog, std::move(aEvents)));
|
2017-12-05 04:08:17 +03:00
|
|
|
|
2020-04-07 18:16:33 +03:00
|
|
|
SchedulerGroup::Dispatch(TaskCategory::Other, runnable.forget());
|
2017-12-05 04:08:17 +03:00
|
|
|
}
|
|
|
|
|
2018-08-23 00:23:04 +03:00
|
|
|
# if defined(DEBUG)
|
2019-10-29 00:58:49 +03:00
|
|
|
UniquePtr<wchar_t[]> GetBinaryOrgName(
|
|
|
|
const wchar_t* aFilePath,
|
|
|
|
AuthenticodeFlags aFlags = AuthenticodeFlags::Default) final {
|
2018-08-23 00:23:04 +03:00
|
|
|
// This function may perform disk I/O, so we should never call it on the
|
|
|
|
// main thread.
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
2019-10-29 00:58:49 +03:00
|
|
|
return detail::DllServicesBase::GetBinaryOrgName(aFilePath, aFlags);
|
2018-08-23 00:23:04 +03:00
|
|
|
}
|
|
|
|
# endif // defined(DEBUG)
|
|
|
|
|
2017-12-05 04:08:17 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_VIRTUAL_REFCOUNTING(DllServices)
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DllServices() = default;
|
|
|
|
~DllServices() = default;
|
|
|
|
|
2019-09-23 23:18:41 +03:00
|
|
|
virtual void NotifyDllLoad(EnhancedModuleLoadInfo&& aModLoadInfo) = 0;
|
|
|
|
virtual void NotifyModuleLoadBacklog(ModuleLoadInfoVec&& aEvents) = 0;
|
2017-12-05 04:08:17 +03:00
|
|
|
};
|
|
|
|
|
2018-02-14 02:03:11 +03:00
|
|
|
#else
|
|
|
|
|
2019-02-20 09:18:45 +03:00
|
|
|
class BasicDllServices final : public detail::DllServicesBase {
|
2018-02-14 02:03:11 +03:00
|
|
|
public:
|
2019-02-20 09:18:45 +03:00
|
|
|
BasicDllServices() { EnableBasic(); }
|
2018-02-14 02:03:11 +03:00
|
|
|
|
2019-02-20 09:18:45 +03:00
|
|
|
~BasicDllServices() = default;
|
2018-02-14 02:03:11 +03:00
|
|
|
|
2019-02-20 09:18:45 +03:00
|
|
|
// Not useful in this class, so provide a default implementation
|
2019-09-23 23:18:41 +03:00
|
|
|
virtual void DispatchDllLoadNotification(
|
|
|
|
ModuleLoadInfo&& aModLoadInfo) override {}
|
2018-11-02 11:01:52 +03:00
|
|
|
|
2019-09-23 23:18:41 +03:00
|
|
|
virtual void DispatchModuleLoadBacklogNotification(
|
|
|
|
ModuleLoadInfoVec&& aEvents) override {}
|
2018-02-14 02:03:11 +03:00
|
|
|
};
|
|
|
|
|
2017-12-05 04:08:17 +03:00
|
|
|
#endif // defined(MOZILLA_INTERNAL_API)
|
|
|
|
|
2018-01-31 00:23:10 +03:00
|
|
|
} // namespace glue
|
2017-12-05 04:08:17 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-01-31 00:23:10 +03:00
|
|
|
#endif // mozilla_glue_WindowsDllServices_h
|