Bug 1529726 [wpt PR 15414] - HTML: window.length and named access, a=testonly
[gecko.git] / mozglue / build / UntrustedDllsHandler.h
blobd2daa751bd30d864ca14250949026e484a723791
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 http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_glue_UntrustedDllsHandler_h
8 #define mozilla_glue_UntrustedDllsHandler_h
10 #include <windows.h>
11 #include <winternl.h> // For PUNICODE_STRING
13 #include "mozilla/Attributes.h"
14 #include "mozilla/glue/WindowsDllServices.h" // For ModuleLoadEvent
15 #include "mozilla/Vector.h"
17 namespace mozilla {
18 namespace glue {
20 // This class examines successful module loads, converts them to a
21 // glue::ModuleLoadEvent, and stores them for consumption by the caller.
22 // In the process, we capture data about the event that is later used to
23 // evaluate trustworthiness of the module.
24 class UntrustedDllsHandler {
25 public:
26 static void Init();
28 #ifdef DEBUG
29 static void Shutdown();
30 #endif // DEBUG
32 /**
33 * To prevent issues with re-entrancy, we only capture module load events at
34 * the top-level call. Recursive module loads get bundled with the top-level
35 * module load. In order to do that, we must track when LdrLoadDLL() enters
36 * and exits, to detect recursion.
38 * EnterLoaderCall() must be called at the top of LdrLoadDLL(), and
39 * ExitLoaderCall() must be called when LdrLoadDLL() exits.
41 * These methods may be called even outside of Init() / Shutdown().
43 static void EnterLoaderCall();
44 static void ExitLoaderCall();
46 /**
47 * OnAfterModuleLoad should be called between calls to EnterLoaderCall() and
48 * ExitLoaderCall(). This handles the successful module load and records it
49 * internally if needed. To handle the resulting recorded event, call
50 * TakePendingEvents().
52 * This method may be called even outside of Init() / Shutdown().
54 static void OnAfterModuleLoad(uintptr_t aBaseAddr,
55 PUNICODE_STRING aLdrModuleName,
56 double aLoadDurationMS);
58 /**
59 * Call TakePendingEvents to get any events that have been recorded since
60 * the last call to TakePendingEvents().
62 * This method may be called even outside of Init() / Shutdown().
64 * @param aOut [out] Receives a list of events.
65 * @return true if aOut now contains elements.
67 static bool TakePendingEvents(
68 Vector<ModuleLoadEvent, 0, InfallibleAllocPolicy>& aOut);
71 } // namespace glue
72 } // namespace mozilla
74 #endif // mozilla_glue_UntrustedDllsHandler_h