| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ | 5 #ifndef CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ |
| 6 #define CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ | 6 #define CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "chrome/common/conflicts/module_event_win.mojom.h" | 11 #include "base/files/file_path.h" |
| 12 #include "chrome/common/conflicts/module_event_sink_win.mojom.h" |
| 12 | 13 |
| 13 class ModuleWatcherTest; | 14 class ModuleWatcherTest; |
| 14 | 15 |
| 15 union LDR_DLL_NOTIFICATION_DATA; | 16 union LDR_DLL_NOTIFICATION_DATA; |
| 16 | 17 |
| 17 // This class observes modules as they are loaded and unloaded into a process's | 18 // This class observes modules as they are loaded and unloaded into a process's |
| 18 // address space. | 19 // address space. |
| 19 // | 20 // |
| 20 // This class is safe to be created on any thread. Similarly, it is safe to be | 21 // This class is safe to be created on any thread. Similarly, it is safe to be |
| 21 // destroyed on any thread, independent of the thread on which the instance was | 22 // destroyed on any thread, independent of the thread on which the instance was |
| 22 // created. | 23 // created. |
| 23 class ModuleWatcher { | 24 class ModuleWatcher { |
| 24 public: | 25 public: |
| 26 // Houses information about a module load/unload event, and some module |
| 27 // metadata. |
| 28 struct ModuleEvent { |
| 29 ModuleEvent() = default; |
| 30 ModuleEvent(const ModuleEvent& other) = default; |
| 31 ModuleEvent(mojom::ModuleEventType event_type, |
| 32 const base::FilePath& module_path, |
| 33 void* module_load_address, |
| 34 size_t module_size); |
| 35 |
| 36 // The type of module event. |
| 37 mojom::ModuleEventType event_type; |
| 38 // The full path to the module on disk. |
| 39 base::FilePath module_path; |
| 40 // The load address of the module. |
| 41 void* module_load_address; |
| 42 // The size of the module in memory. |
| 43 size_t module_size; |
| 44 }; |
| 45 |
| 25 // The type of callback that will be invoked for each module event. This is | 46 // The type of callback that will be invoked for each module event. This is |
| 26 // invoked by the loader and potentially on any thread. The loader lock is not | 47 // invoked by the loader and potentially on any thread. The loader lock is not |
| 27 // held but the execution of this callback blocks the module from being bound. | 48 // held but the execution of this callback blocks the module from being bound. |
| 28 // Keep the amount of work performed here to an absolute minimum. Note that | 49 // Keep the amount of work performed here to an absolute minimum. Note that |
| 29 // it is possible for this callback to be invoked after the destruction of the | 50 // it is possible for this callback to be invoked after the destruction of the |
| 30 // watcher, but very unlikely. | 51 // watcher, but very unlikely. |
| 31 using OnModuleEventCallback = | 52 using OnModuleEventCallback = base::Callback<void(const ModuleEvent& event)>; |
| 32 base::Callback<void(const mojom::ModuleEvent& event)>; | |
| 33 | 53 |
| 34 // Creates and starts a watcher. This enumerates all loaded modules | 54 // Creates and starts a watcher. This enumerates all loaded modules |
| 35 // synchronously on the current thread during construction, and provides | 55 // synchronously on the current thread during construction, and provides |
| 36 // synchronous notifications as modules are loaded and unloaded. The callback | 56 // synchronous notifications as modules are loaded and unloaded. The callback |
| 37 // is invoked in the context of the thread that is loading a module, and as | 57 // is invoked in the context of the thread that is loading a module, and as |
| 38 // such may be invoked on any thread in the process. Note that it is possible | 58 // such may be invoked on any thread in the process. Note that it is possible |
| 39 // to receive two notifications for some modules as the initial loaded module | 59 // to receive two notifications for some modules as the initial loaded module |
| 40 // enumeration races briefly with the callback mechanism. In this case both a | 60 // enumeration races briefly with the callback mechanism. In this case both a |
| 41 // MODULE_LOADED and a MODULE_ALREADY_LOADED event will be received for the | 61 // MODULE_LOADED and a MODULE_ALREADY_LOADED event will be received for the |
| 42 // same module. Since the callback is installed first no modules can be | 62 // same module. Since the callback is installed first no modules can be |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 107 |
| 88 // The current callback. Can end up being invoked on any thread. | 108 // The current callback. Can end up being invoked on any thread. |
| 89 OnModuleEventCallback callback_; | 109 OnModuleEventCallback callback_; |
| 90 // Used by the DllNotification mechanism. | 110 // Used by the DllNotification mechanism. |
| 91 void* dll_notification_cookie_ = nullptr; | 111 void* dll_notification_cookie_ = nullptr; |
| 92 | 112 |
| 93 DISALLOW_COPY_AND_ASSIGN(ModuleWatcher); | 113 DISALLOW_COPY_AND_ASSIGN(ModuleWatcher); |
| 94 }; | 114 }; |
| 95 | 115 |
| 96 #endif // CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ | 116 #endif // CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ |
| OLD | NEW |