diff options
author | Davide Beatrici <git@davidebeatrici.dev> | 2020-11-06 23:37:06 +0300 |
---|---|---|
committer | Davide Beatrici <git@davidebeatrici.dev> | 2020-11-06 23:37:06 +0300 |
commit | 988b8417acfc4ca4b19283afe7e1973d05a39be8 (patch) | |
tree | 160e79e9d7dc57ac27e02279775ea29418a537ae /plugins/Module.h | |
parent | a3480a2a6b432b247821add175f725714692ef1e (diff) |
REFAC(positional-audio): Proper functions/classes for module-related operations
Previously, only module() was present: it retrieved the base address of the specified module.
It worked fine, but it iterated through the process' modules every time it was called.
This commit replaces it with modules(), which returns an std::unordered_map containing all modules.
The map uses the module name as key and Module as value.
Aside from the performance improvement, the new code also provides info for each module region:
- Start address.
- Size.
- Whether it's readable, writable and/or executable.
Diffstat (limited to 'plugins/Module.h')
-rw-r--r-- | plugins/Module.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/Module.h b/plugins/Module.h new file mode 100644 index 000000000..d3d54af38 --- /dev/null +++ b/plugins/Module.h @@ -0,0 +1,48 @@ +// Copyright 2020 The Mumble Developers. All rights reserved. +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file at the root of the +// Mumble source tree or at <https://www.mumble.info/LICENSE>. + +#ifndef MODULE_H +#define MODULE_H + +#include <set> +#include <string> +#include <unordered_map> + +typedef uint64_t procptr_t; + +struct MemoryRegion { + procptr_t address; + size_t size; + + bool readable; + bool writable; + bool executable; + + bool operator<(const MemoryRegion ®ion) const { return address < region.address; } + + MemoryRegion() : address(0), size(0), readable(false), writable(false), executable(false) {} +}; + +typedef std::set< MemoryRegion > MemoryRegions; + +class Module { +protected: + std::string m_name; + MemoryRegions m_regions; + +public: + inline std::string name() const { return m_name; } + inline MemoryRegions regions() const { return m_regions; } + + inline bool addRegion(const MemoryRegion ®ion) { return m_regions.insert(region).second; } + + procptr_t baseAddress() const; + + Module(const std::string &name); +}; + +typedef std::unordered_map< std::string, Module > Modules; + +#endif // MODULE_H |