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_LoaderAPIInterfaces_h
8 #define mozilla_LoaderAPIInterfaces_h
9 
10 #include "mozilla/ModuleLoadInfo.h"
11 
12 namespace mozilla {
13 namespace nt {
14 
15 class NS_NO_VTABLE LoaderObserver {
16  public:
17   /**
18    * Notification that a DLL load has begun.
19    *
20    * @param aContext Outparam that allows this observer to store any context
21    *                 information pertaining to the current load.
22    * @param aRequestedDllName The DLL name requested by whatever invoked the
23    *                          loader. This name may not match the effective
24    *                          name of the DLL once the loader has completed
25    *                          its path search.
26    */
27   virtual void OnBeginDllLoad(void** aContext,
28                               PCUNICODE_STRING aRequestedDllName) = 0;
29 
30   /**
31    * Query the observer to determine whether the DLL named |aLSPLeafName| needs
32    * to be substituted with another module, and substitute the module handle
33    * when necessary.
34    *
35    * @return true when substitution occurs, otherwise false
36    */
37   virtual bool SubstituteForLSP(PCUNICODE_STRING aLSPLeafName,
38                                 PHANDLE aOutHandle) = 0;
39 
40   /**
41    * Notification that a DLL load has ended.
42    *
43    * @param aContext The context that was set by the corresponding call to
44    *                 OnBeginDllLoad
45    * @param aNtStatus The NTSTATUS returned by LdrLoadDll
46    * @param aModuleLoadInfo Telemetry information that was gathered about the
47    *                        load.
48    */
49   virtual void OnEndDllLoad(void* aContext, NTSTATUS aNtStatus,
50                             ModuleLoadInfo&& aModuleLoadInfo) = 0;
51 
52   /**
53    * Called to inform the observer that it is no longer active and, if
54    * necessary, call aNext->OnForward() with any accumulated telemetry
55    * information.
56    */
57   virtual void Forward(LoaderObserver* aNext) = 0;
58 
59   /**
60    * Receives a vector of module load telemetry from a previous LoaderObserver.
61    */
62   virtual void OnForward(ModuleLoadInfoVec&& aInfo) = 0;
63 };
64 
65 class NS_NO_VTABLE LoaderAPI {
66  public:
67   /**
68    * Construct a new ModuleLoadInfo structure and notify the LoaderObserver
69    * that a library load is beginning.
70    */
71   virtual ModuleLoadInfo ConstructAndNotifyBeginDllLoad(
72       void** aContext, PCUNICODE_STRING aRequestedDllName) = 0;
73 
74   /**
75    * Query to determine whether the DLL named |aLSPLeafName| needs to be
76    * substituted with another module, and substitute the module handle when
77    * necessary.
78    *
79    * @return true when substitution occurs, otherwise false
80    */
81   virtual bool SubstituteForLSP(PCUNICODE_STRING aLSPLeafName,
82                                 PHANDLE aOutHandle) = 0;
83 
84   /**
85    * Notification that a DLL load has ended.
86    */
87   virtual void NotifyEndDllLoad(void* aContext, NTSTATUS aLoadNtStatus,
88                                 ModuleLoadInfo&& aModuleLoadInfo) = 0;
89 
90   /**
91    * Given the address of a mapped section, obtain the name of the file that is
92    * backing it.
93    */
94   virtual AllocatedUnicodeString GetSectionName(void* aSectionAddr) = 0;
95 
96   using InitDllBlocklistOOPFnPtr = LauncherVoidResultWithLineInfo (*)(
97       const wchar_t*, HANDLE, const IMAGE_THUNK_DATA*);
98 
99   /**
100    * Return a pointer to the cross-process DLL Blocklist Init function.
101    * Used by sandboxBroker::LaunchApp.
102    */
103   virtual InitDllBlocklistOOPFnPtr GetDllBlocklistInitFn() = 0;
104 };
105 
106 }  // namespace nt
107 }  // namespace mozilla
108 
109 #endif  // mozilla_LoaderAPIInterfaces_h
110