From 8ee2d8bffb18dcf7bc5d0693d09cf19556e8b1bd Mon Sep 17 00:00:00 2001 From: Smertig <akaraevz@mail.ru> Date: Mon, 20 Mar 2023 11:29:42 +0200 Subject: [PATCH] Remove `generic_hook_function` overload that accepts compile-time address (it should be injected directly in `Policy` as a `Tag` to provide state uniqueness) --- include/rcmp/codegen.hpp | 11 ----------- include/rcmp/detail/hook_policy/indirect_policy.hpp | 2 +- include/rcmp/detail/hook_policy/prolog_policy.hpp | 2 +- test/test_hooks.cpp | 10 ++++++++++ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/include/rcmp/codegen.hpp b/include/rcmp/codegen.hpp index aa9d93c..473bbb7 100644 --- a/include/rcmp/codegen.hpp +++ b/include/rcmp/codegen.hpp @@ -17,17 +17,6 @@ void generic_hook_function(rcmp::address_t original_address, Hook&& hook) { >::template install_hook<Policy>(original_address, std::forward<Hook>(hook)); } -// TODO: remove this overload -template <template <class> class Policy, auto Address, class Signature, class Hook> -void generic_hook_function(Hook&& hook) { - static_assert(std::is_constructible_v<rcmp::address_t, decltype(Address)>); - - return rcmp::generic_hook_function< - Policy, - Signature - >(Address, std::forward<Hook>(hook)); -} - } // namespace rcmp #include "detail/hook_policy/prolog_policy.hpp" diff --git a/include/rcmp/detail/hook_policy/indirect_policy.hpp b/include/rcmp/detail/hook_policy/indirect_policy.hpp index 0f14df2..b0557e1 100644 --- a/include/rcmp/detail/hook_policy/indirect_policy.hpp +++ b/include/rcmp/detail/hook_policy/indirect_policy.hpp @@ -38,7 +38,7 @@ void hook_indirect_function(F&& hook) { detail::HookIndirectPolicy, std::integral_constant<decltype(IndirectFunctionAddress), IndirectFunctionAddress> >; - rcmp::generic_hook_function<wrapped_policy_t::Policy, IndirectFunctionAddress, Signature>(std::forward<F>(hook)); + rcmp::generic_hook_function<wrapped_policy_t::template Policy, Signature>(IndirectFunctionAddress, std::forward<F>(hook)); } template <class Tag, class Signature, class F> diff --git a/include/rcmp/detail/hook_policy/prolog_policy.hpp b/include/rcmp/detail/hook_policy/prolog_policy.hpp index 6c10bf9..2ac66ff 100644 --- a/include/rcmp/detail/hook_policy/prolog_policy.hpp +++ b/include/rcmp/detail/hook_policy/prolog_policy.hpp @@ -35,7 +35,7 @@ void hook_function(F&& hook) { detail::HookPrologPolicy, std::integral_constant<decltype(FunctionAddress), FunctionAddress> >; - rcmp::generic_hook_function<wrapped_policy_t::template Policy, FunctionAddress, Signature>(std::forward<F>(hook)); + rcmp::generic_hook_function<wrapped_policy_t::template Policy, Signature>(FunctionAddress, std::forward<F>(hook)); } template <auto Function, class F> diff --git a/test/test_hooks.cpp b/test/test_hooks.cpp index 4bce48c..d3f9feb 100644 --- a/test/test_hooks.cpp +++ b/test/test_hooks.cpp @@ -312,3 +312,13 @@ TEST_CASE("hook with different tags") { rcmp::hook_function<class Tag2, decltype(f4)>(rcmp::bit_cast<const void*>(&f4), l); CHECK(f4(42) == 44); } + +TEST_CASE("compile-time addresses") { + if ([[maybe_unused]] auto always_true = []{ return true; }()) { + return; + } + + // Just to check compilation, should not be called + rcmp::hook_indirect_function<0x0, void()>([](auto) {}); + rcmp::hook_function<0x0, void()>([](auto) {}); +}