forked from Ryan-rsm-McKenzie/CommonLibF4
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from qudix/dev
feat: improve `REL` and `Relocation`
- Loading branch information
Showing
23 changed files
with
947 additions
and
791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Main CI | ||
name: build | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "REL/IDDB.h" | ||
#include "REL/Module.h" | ||
|
||
namespace REL | ||
{ | ||
class ID | ||
{ | ||
public: | ||
constexpr ID() noexcept = default; | ||
|
||
explicit constexpr ID(std::uint64_t a_id) noexcept : | ||
_id(a_id) | ||
{} | ||
|
||
constexpr ID& operator=(std::uint64_t a_id) noexcept | ||
{ | ||
_id = a_id; | ||
return *this; | ||
} | ||
|
||
[[nodiscard]] std::uintptr_t address() const { return base() + offset(); } | ||
[[nodiscard]] constexpr std::uint64_t id() const noexcept { return _id; } | ||
[[nodiscard]] std::size_t offset() const { return IDDB::get().id2offset(_id); } | ||
|
||
private: | ||
[[nodiscard]] static std::uintptr_t base() { return Module::get().base(); } | ||
|
||
std::uint64_t _id{ static_cast<std::uint64_t>(-1) }; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
|
||
namespace REL | ||
{ | ||
class IDDB | ||
{ | ||
private: | ||
struct mapping_t | ||
{ | ||
std::uint64_t id; | ||
std::uint64_t offset; | ||
}; | ||
|
||
public: | ||
IDDB(const IDDB&) = delete; | ||
IDDB(IDDB&&) = delete; | ||
|
||
IDDB& operator=(const IDDB&) = delete; | ||
IDDB& operator=(IDDB&&) = delete; | ||
|
||
[[nodiscard]] static IDDB& get() | ||
{ | ||
static IDDB singleton; | ||
return singleton; | ||
} | ||
|
||
[[nodiscard]] std::size_t id2offset(std::uint64_t a_id) const | ||
{ | ||
if (_id2offset.empty()) { | ||
stl::report_and_fail("data is empty"sv); | ||
} | ||
|
||
const mapping_t elem{ a_id, 0 }; | ||
const auto it = std::lower_bound( | ||
_id2offset.begin(), | ||
_id2offset.end(), | ||
elem, | ||
[](auto&& a_lhs, auto&& a_rhs) { | ||
return a_lhs.id < a_rhs.id; | ||
}); | ||
if (it == _id2offset.end()) { | ||
stl::report_and_fail("id not found"sv); | ||
} | ||
|
||
return static_cast<std::size_t>(it->offset); | ||
} | ||
|
||
protected: | ||
friend class Offset2ID; | ||
|
||
[[nodiscard]] std::span<const mapping_t> get_id2offset() const noexcept { return _id2offset; } | ||
|
||
private: | ||
IDDB(); | ||
~IDDB() = default; | ||
|
||
mmio::mapped_file_source _mmap; | ||
std::span<const mapping_t> _id2offset; | ||
}; | ||
} |
Oops, something went wrong.