src/internal/hook_publication.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef DETOURMODKIT_INTERNAL_HOOK_PUBLICATION_HPP | ||
| 2 | #define DETOURMODKIT_INTERNAL_HOOK_PUBLICATION_HPP | ||
| 3 | |||
| 4 | /** | ||
| 5 | * @file hook_publication.hpp | ||
| 6 | * @brief The hook loader-lock veto and test-seam vocabulary for publication and loader-veto boundaries. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "DetourModKit/error.hpp" | ||
| 10 | |||
| 11 | #include "platform.hpp" | ||
| 12 | |||
| 13 | #include <cstdint> | ||
| 14 | #include <optional> | ||
| 15 | |||
| 16 | namespace DetourModKit::detail | ||
| 17 | { | ||
| 18 | /// Identifies a completed boundary in the inline/mid publication transaction. | ||
| 19 | enum class HookPublishStep : std::uint8_t | ||
| 20 | { | ||
| 21 | BackendCreated, | ||
| 22 | ImplConstructed, | ||
| 23 | GatePublished, | ||
| 24 | LedgerCommitted | ||
| 25 | }; | ||
| 26 | |||
| 27 | #if defined(DMK_ENABLE_TEST_SEAMS) | ||
| 28 | /// Identifies one hook mutation entry at its first boundary after the loader-lock veto. | ||
| 29 | enum class HookLoaderEntry : std::uint8_t | ||
| 30 | { | ||
| 31 | InlineAt, | ||
| 32 | MidAt, | ||
| 33 | InstallAll, | ||
| 34 | VmtFor, | ||
| 35 | Enable, | ||
| 36 | Disable, | ||
| 37 | VmtApply, | ||
| 38 | VmtRemove, | ||
| 39 | VmtHookMethod, | ||
| 40 | VmtRemoveMethod, | ||
| 41 | Count | ||
| 42 | }; | ||
| 43 | |||
| 44 | /// Fires after the loader-lock check permits a mutation entry and before that entry performs other work. | ||
| 45 | extern void (*g_hook_post_loader_veto_probe)(HookLoaderEntry) noexcept; | ||
| 46 | |||
| 47 | /// HookTogglePublicationOrder.* owns this proof seam. | ||
| 48 | extern void (*g_hook_toggle_publication_probe)( | ||
| 49 | bool armed, | ||
| 50 | bool owns_lock, | ||
| 51 | bool status_matches, | ||
| 52 | bool callable_matches | ||
| 53 | ) noexcept; | ||
| 54 | #endif | ||
| 55 | } // namespace DetourModKit::detail | ||
| 56 | |||
| 57 | namespace DetourModKit::hook | ||
| 58 | { | ||
| 59 | /** | ||
| 60 | * @brief Implements the hook.hpp loader-lock precondition. | ||
| 61 | * @details T-HOOK-LOADER pins this gate before each mutation boundary. | ||
| 62 | */ | ||
| 63 | 8240 | [[nodiscard]] inline std::optional<Error> refuse_on_loader_lock(const char *operation) noexcept | |
| 64 | { | ||
| 65 |
2/2✓ Branch 3 → 4 taken 10 times.
✓ Branch 3 → 6 taken 8230 times.
|
8240 | if (DetourModKit::detail::is_loader_lock_held()) |
| 66 | { | ||
| 67 | 10 | return Error{ErrorCode::LoaderLockActive, operation}; | |
| 68 | } | ||
| 69 | 8230 | return std::nullopt; | |
| 70 | } | ||
| 71 | |||
| 72 | #if defined(DMK_ENABLE_TEST_SEAMS) | ||
| 73 | 8230 | inline void note_loader_veto_passed(DetourModKit::detail::HookLoaderEntry entry) noexcept | |
| 74 | { | ||
| 75 |
2/2✓ Branch 2 → 3 taken 10 times.
✓ Branch 2 → 4 taken 8220 times.
|
8230 | if (auto *probe = DetourModKit::detail::g_hook_post_loader_veto_probe) |
| 76 | { | ||
| 77 | 10 | probe(entry); | |
| 78 | } | ||
| 79 | 8230 | } | |
| 80 | #endif | ||
| 81 | } // namespace DetourModKit::hook | ||
| 82 | |||
| 83 | #endif // DETOURMODKIT_INTERNAL_HOOK_PUBLICATION_HPP | ||
| 84 |