Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 200eb77

Browse files
committed
Bug 1430857: Part 1 - Refactor DllServices to make it possible to obtain them from anywhere in Gecko; r=jimm
MozReview-Commit-ID: GfWata0eCc5 --HG-- extra : rebase_source : 3a5b4a6f0412311f0b9080a2b3b3a31e45d15b75
1 parent 4a583a2 commit 200eb77

13 files changed

Lines changed: 117 additions & 52 deletions

File tree

browser/app/nsBrowserApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
#ifdef MOZ_SANDBOX
2929
#include "mozilla/sandboxing/SandboxInitialization.h"
3030
#endif
31+
#include "mozilla/WindowsDllBlocklist.h"
3132
#endif
3233
#include "BinaryPath.h"
3334

3435
#include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
3536

3637
#include "mozilla/Sprintf.h"
3738
#include "mozilla/StartupTimeline.h"
38-
#include "mozilla/WindowsDllBlocklist.h"
3939

4040
#ifdef LIBFUZZER
4141
#include "FuzzerDefs.h"

ipc/app/MozillaRuntimeMain.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
#include "../contentproc/plugin-container.cpp"
88

99
#include "mozilla/Bootstrap.h"
10+
11+
#if defined(XP_WIN)
1012
#include "mozilla/WindowsDllBlocklist.h"
13+
#endif // defined(XP_WIN)
1114

1215
using namespace mozilla;
1316

js/xpconnect/shell/xpcshell.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <stdio.h>
1010

11-
#include "mozilla/WindowsDllBlocklist.h"
1211
#include "mozilla/Bootstrap.h"
1312

1413
#include "nsXULAppAPI.h"
@@ -26,6 +25,7 @@
2625
#ifdef MOZ_SANDBOX
2726
#include "mozilla/sandboxing/SandboxInitialization.h"
2827
#endif
28+
#include "mozilla/WindowsDllBlocklist.h"
2929
#endif
3030

3131
#ifdef MOZ_WIDGET_GTK

mozglue/build/WindowsDllBlocklist.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#pragma warning( pop )
2525

2626
#include "nsAutoPtr.h"
27-
2827
#include "nsWindowsDllInterceptor.h"
2928
#include "mozilla/Sprintf.h"
3029
#include "mozilla/StackWalk_windows.h"
@@ -33,7 +32,7 @@
3332
#include "nsWindowsHelpers.h"
3433
#include "WindowsDllBlocklist.h"
3534
#include "mozilla/AutoProfilerLabel.h"
36-
#include "mozilla/WindowsDllServices.h"
35+
#include "mozilla/glue/WindowsDllServices.h"
3736

3837
using namespace mozilla;
3938

@@ -938,7 +937,7 @@ DllBlocklist_CheckStatus()
938937

939938

940939
static SRWLOCK gDllServicesLock = SRWLOCK_INIT;
941-
static mozilla::detail::DllServicesBase* gDllServices;
940+
static mozilla::glue::detail::DllServicesBase* gDllServices;
942941

943942
class MOZ_RAII AutoSharedLock final
944943
{
@@ -1048,7 +1047,7 @@ DllLoadNotification(ULONG aReason, PCLDR_DLL_NOTIFICATION_DATA aNotificationData
10481047
}
10491048

10501049
MFBT_API void
1051-
DllBlocklist_SetDllServices(mozilla::detail::DllServicesBase* aSvc)
1050+
DllBlocklist_SetDllServices(mozilla::glue::detail::DllServicesBase* aSvc)
10521051
{
10531052
AutoExclusiveLock lock(gDllServicesLock);
10541053

mozglue/build/WindowsDllBlocklist.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ MFBT_API bool DllBlocklist_CheckStatus();
2626

2727
// Forward declaration
2828
namespace mozilla {
29+
namespace glue {
2930
namespace detail {
3031
class DllServicesBase;
3132
} // namespace detail
33+
} // namespace glue
3234
} // namespace mozilla
3335

34-
MFBT_API void DllBlocklist_SetDllServices(mozilla::detail::DllServicesBase* aSvc);
36+
MFBT_API void DllBlocklist_SetDllServices(mozilla::glue::detail::DllServicesBase* aSvc);
3537

3638
#endif // defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
3739
#endif // mozilla_windowsdllblocklist_h

mozglue/build/WindowsDllServices.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66

7-
#ifndef mozilla_WindowsDllServices_h
8-
#define mozilla_WindowsDllServices_h
7+
#ifndef mozilla_glue_WindowsDllServices_h
8+
#define mozilla_glue_WindowsDllServices_h
99

1010
#include "mozilla/WindowsDllBlocklist.h"
1111

@@ -22,6 +22,7 @@
2222
#include <winternl.h>
2323

2424
namespace mozilla {
25+
namespace glue {
2526
namespace detail {
2627

2728
class DllServicesBase
@@ -86,6 +87,7 @@ class DllServices : public detail::DllServicesBase
8687

8788
#endif // defined(MOZILLA_INTERNAL_API)
8889

90+
} // namespace glue
8991
} // namespace mozilla
9092

91-
#endif // mozilla_WindowsDllServices_h
93+
#endif // mozilla_glue_WindowsDllServices_h

mozglue/build/moz.build

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,18 @@ if CONFIG['MOZ_WIDGET_TOOLKIT']:
6363
OS_LIBS += [
6464
'version',
6565
]
66+
EXPORTS.mozilla += [
67+
'WindowsDllBlocklist.h',
68+
]
69+
EXPORTS.mozilla.glue += [
70+
'WindowsDllServices.h',
71+
]
6672

6773
EXPORTS.mozilla += [
6874
'arm.h',
6975
'mips.h',
7076
'SSE.h',
7177
'WindowsCFGStatus.h',
72-
'WindowsDllBlocklist.h',
73-
'WindowsDllServices.h',
7478
]
7579

7680
if CONFIG['CPU_ARCH'].startswith('x86'):

toolkit/crashreporter/nsExceptionHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "nsDirectoryServiceUtils.h"
4343

4444
#include "nsWindowsDllInterceptor.h"
45+
#include "mozilla/WindowsDllBlocklist.h"
4546
#include "mozilla/WindowsVersion.h"
4647
#elif defined(XP_MACOSX)
4748
#include "breakpad-client/mac/crash_generation/client_info.h"
@@ -91,7 +92,6 @@ using mozilla::InjectCrashRunnable;
9192

9293
#include "mozilla/IOInterposer.h"
9394
#include "mozilla/mozalloc_oom.h"
94-
#include "mozilla/WindowsDllBlocklist.h"
9595

9696
#if defined(XP_MACOSX)
9797
CFStringRef reporterClientAppID = CFSTR("org.mozilla.crashreporter");

toolkit/xre/WinDllServices.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3+
/* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6+
7+
#include "mozilla/WinDllServices.h"
8+
9+
#include "mozilla/ClearOnShutdown.h"
10+
#include "mozilla/Services.h"
11+
#include "nsIObserverService.h"
12+
#include "nsString.h"
13+
14+
namespace mozilla {
15+
16+
const char* DllServices::kTopicDllLoadedMainThread = "dll-loaded-main-thread";
17+
const char* DllServices::kTopicDllLoadedNonMainThread = "dll-loaded-non-main-thread";
18+
19+
static StaticRefPtr<DllServices> sInstance;
20+
21+
DllServices*
22+
DllServices::Get()
23+
{
24+
if (sInstance) {
25+
return sInstance;
26+
}
27+
28+
sInstance = new DllServices();
29+
ClearOnShutdown(&sInstance);
30+
return sInstance;
31+
}
32+
33+
DllServices::DllServices()
34+
{
35+
Enable();
36+
}
37+
38+
void
39+
DllServices::NotifyDllLoad(const bool aIsMainThread, const nsString& aDllName)
40+
{
41+
const char* topic;
42+
43+
if (aIsMainThread) {
44+
topic = kTopicDllLoadedMainThread;
45+
} else {
46+
topic = kTopicDllLoadedNonMainThread;
47+
}
48+
49+
nsCOMPtr<nsIObserverService> obsServ(mozilla::services::GetObserverService());
50+
obsServ->NotifyObservers(nullptr, topic, aDllName.get());
51+
}
52+
53+
} // namespace mozilla
54+

toolkit/xre/WinDllServices.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3+
/* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
6+
7+
#ifndef mozilla_WinDllServices_h
8+
#define mozilla_WinDllServices_h
9+
10+
#include "mozilla/glue/WindowsDllServices.h"
11+
12+
namespace mozilla {
13+
14+
class DllServices : public mozilla::glue::DllServices
15+
{
16+
public:
17+
static DllServices* Get();
18+
19+
static const char* kTopicDllLoadedMainThread;
20+
static const char* kTopicDllLoadedNonMainThread;
21+
22+
private:
23+
DllServices();
24+
~DllServices() = default;
25+
26+
void NotifyDllLoad(const bool aIsMainThread, const nsString& aDllName) override;
27+
};
28+
29+
} // namespace mozilla
30+
31+
#endif // mozilla_WinDllServices_h

0 commit comments

Comments
 (0)