Bug 1492121 - Run BaseProfiler's InitializeWin64ProfilerHooks once from either profiler - r=njn

Running identical (but separate) InitializeWin64ProfilerHooks in both profilers
confuses the DLL interceptor and the 2nd one crashes because of unexpected
opcodes introduced by the 1st one.
If MOZ_BASE_PROFILER is defined, Gecko Profiler will use that implementation of
InitializeWin64ProfilerHooks instead of its own; and that code also has a guard
so that it effectively only run once even if called from both profilers.

Differential Revision: https://phabricator.services.mozilla.com/D31931

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gerald Squelart 2019-06-06 06:20:07 +00:00
Родитель 511b46dfbe
Коммит a54d246a96
3 изменённых файлов: 29 добавлений и 2 удалений

Просмотреть файл

@ -314,7 +314,15 @@ static PVOID WINAPI patched_LdrResolveDelayLoadedAPI(
ThunkAddress, Flags);
}
void InitializeWin64ProfilerHooks() {
MFBT_API void InitializeWin64ProfilerHooks() {
// This function could be called by both profilers, but we only want to run
// it once.
static bool ran = false;
if (ran) {
return;
}
ran = true;
NtDllIntercept.Init("ntdll.dll");
stub_LdrUnloadDll.Set(NtDllIntercept, "LdrUnloadDll", &patched_LdrUnloadDll);
if (IsWin8OrLater()) { // LdrResolveDelayLoadedAPI was introduced in Win8

Просмотреть файл

@ -269,6 +269,10 @@ void Registers::SyncPopulate() {
#endif
#if defined(GP_PLAT_amd64_windows)
# ifndef MOZ_BASE_PROFILER
// If MOZ_BASE_PROFILER is *not* #defined, we need to implement this here, as
// the one in mozglue/baseprofiler will not even be built.
static WindowsDllInterceptor NtDllIntercept;
typedef NTSTATUS(NTAPI* LdrUnloadDll_func)(HMODULE module);
@ -308,4 +312,18 @@ void InitializeWin64ProfilerHooks() {
&patched_LdrResolveDelayLoadedAPI);
}
}
#endif // defined(GP_PLAT_amd64_windows)
# else // ndef MOZ_BASE_PROFILER
// If MOZ_BASE_PROFILER is #defined, we just use InitializeWin64ProfilerHooks
// that it implements.
namespace mozilla {
namespace baseprofiler {
MFBT_API void InitializeWin64ProfilerHooks();
} // namespace baseprofiler
} // namespace mozilla
using mozilla::baseprofiler::InitializeWin64ProfilerHooks;
# endif // ndef MOZ_BASE_PROFILER else
#endif // defined(GP_PLAT_amd64_windows)

Просмотреть файл

@ -59,6 +59,7 @@
#include "mozilla/Tuple.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Vector.h"
#include "BaseProfiler.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsIHttpProtocolHandler.h"