26#include <log4cxx/logger.h>
31#include <unordered_set>
40 std::shared_ptr<Breakpoint>
bp;
47 static inline const log4cxx::LoggerPtr logger =
48 log4cxx::Logger::getLogger(
"introvirt.FunctionCallFactory");
53 if (filter_ && !filter_(event))
57 std::unique_ptr<T> handler;
60 LOG4CXX_DEBUG(logger,
"Entered TRY block");
61 handler = std::make_unique<T>(event);
63 auto* guest =
event.domain().guest();
65 LOG4CXX_DEBUG(logger, ex);
78 callback_(event, *handler);
80 LOG4CXX_WARN(logger,
"Exception during callback: " << ex);
85 if (handler->hook_return()) {
86 auto&
domain =
event.domain();
89 auto return_address = handler->return_address();
92 auto return_data = std::make_shared<FunctionCallReturnData<T>>(std::move(handler));
94 auto return_bp =
domain.create_breakpoint(
96 this, std::placeholders::_1, return_data));
98 return_data->bp = std::move(return_bp);
105 if (return_data->handler->is_return_event(event)) {
107 return_data->handler->handle_return(event);
111 return_callback_(event, *(return_data->handler));
113 LOG4CXX_WARN(logger,
"Exception during callback: " << ex);
117 return_data->bp.reset();
122 std::function<
void(
Event&, T&)> return_callback,
123 std::function<
bool(
Event&)> filter =
nullptr)
124 : callback_(callback), return_callback_(return_callback), filter_(filter) {
128 func_bp_ =
domain.create_breakpoint(
130 std::placeholders::_1));
136 const std::function<void(
Event&, T&)> callback_;
137 const std::function<void(
Event&, T&)> return_callback_;
138 const std::function<bool(
Event&)> filter_;
140 std::shared_ptr<Breakpoint> func_bp_;
A class representing a single Domain.
Definition Domain.hh:44
Interface class for hypervisor events.
Definition Event.hh:43
Definition FunctionCallFactory.hh:45
~FunctionCallFactory()
Definition FunctionCallFactory.hh:133
void function_breakpoint_hit(Event &event)
Definition FunctionCallFactory.hh:51
void function_ret_breakpoint_hit(Event &event, std::shared_ptr< FunctionCallReturnData< T > > return_data)
Definition FunctionCallFactory.hh:102
FunctionCallFactory(const guest_ptr< void > &address, std::function< void(Event &, T &)> callback, std::function< void(Event &, T &)> return_callback, std::function< bool(Event &)> filter=nullptr)
Definition FunctionCallFactory.hh:121
Definition FunctionCallFactory.hh:36
std::unique_ptr< T > handler
Definition FunctionCallFactory.hh:41
FunctionCallReturnData(std::unique_ptr< T > &&handler)
Definition FunctionCallFactory.hh:38
std::shared_ptr< Breakpoint > bp
Definition FunctionCallFactory.hh:40
Base class for exceptions with stack unwinding.
Definition TraceableException.hh:31
Thrown when translating a guest virtual address is marked as not present.
Definition VirtualAddressNotPresentException.hh:31
uint64_t virtual_address() const
Get the guest virtual address that was marked as not present.
Definition guest_ptr.hh:88
const Domain & domain() const
Definition guest_ptr.hh:144
Core IntroVirt classes.
Definition Cr0.hh:20
std::string n2hexstr(I w, size_t hex_len=sizeof(I)<< 1)
Definition n2hexstr.hh:23
unique_ptr< Domain > domain
Definition vmcall_interface.cc:48