2 #ifndef __MESSAGE_HPP__
3 #define __MESSAGE_HPP__
7 #include <sys/socket.h>
21 #define POINTER_SIZE ( sizeof( void * ) )
24 #define MESSAGE_HEADER_LENGTH 4
27 #define MESSAGE_SIZE ( POINTER_SIZE + MESSAGE_HEADER_LENGTH )
47 #define MESSAGE_INTERNALS( HEADER_ONLY ) \
49 static const constexpr bool header_only = HEADER_ONLY; \
51 static const constexpr int size = MESSAGE_SIZE; \
53 static const constexpr char *const header = Info::header; \
58 static_assert( strlen( Info::header ) == MESSAGE_HEADER_LENGTH, \
59 "Header is of wrong size." ); \
61 MessageType<HEADER_ONLY, Info>() = delete;
67 static const char *
set_length(
char *
const dst,
const char *
const src,
72 template <
bool only_header,
typename Info>
struct MessageType;
78 template <
typename Info>
struct MessageType<true, Info> final {
85 static const
char *const message;
89 static
char internal[size];
93 template <typename Info> struct
MessageType<false, Info> final {
110 #undef MESSAGE_INTERNALS
126 static constexpr
const char *
const header =
"CONT";
132 static const constexpr
char *
const header =
"CALL";
138 static const constexpr
char *
const header =
"RET-";
145 static constexpr
const char *
const header =
"NEWS";
151 static constexpr
const char *
const header =
"EXEC";
157 static const constexpr
char *
const header =
"FORK";
163 static const constexpr
char *
const header =
"THRD";
168 template <
class T>
static bool is_a_valid(
const char *
const buffer ) {
194 template <
typename T>
210 static_assert( Msg::header_only ==
true,
"wrong send_msg called." );
211 const int bytes_sent = write( sock, Msg::header, Msg::size );
216 template <
typename Msg>
void send_msg(
const int sock,
const char *
const bdy ) {
217 static_assert( Msg::header_only ==
false,
"wrong send_msg called." );
219 const int bytes_sent = write( sock, to_send.message, to_send.size );
225 static_assert( Msg::header_only ==
true,
"wrong recv_msg called." );
226 char buffer[Msg::size];
227 const int bytes_recv = recv( sock, buffer, Msg::size, MSG_WAITALL );
229 const constexpr
auto is_msg = Message::is_a_valid<Message::Continue>;
236 static_assert( Msg::header_only ==
false,
"wrong recv_msg called." );
237 static char buffer[Msg::size];
238 const int bytes_recv = recv( sock, buffer, Msg::size, MSG_WAITALL );
240 const constexpr
auto is_msg = Message::is_a_valid<Message::Continue>;
A class containing the header of Call message.
Definition: message.hpp:136
#define POINTER_SIZE
The size of a pointer in the target program Note: 64 bit can stil handle 32 bit programs.
Definition: message.hpp:21
A class containing the header of NewSignal message.
Definition: message.hpp:143
const Msg::WithBody< CallInfo > Call
A typedef for the call message.
Definition: message.hpp:175
const Msg::HeaderOnly< ForkInfo > Fork
A typedef for the fork message.
Definition: message.hpp:184
const Msg::HeaderOnly< ExecveInfo > Execve
A typedef for the execve message.
Definition: message.hpp:182
A class containing the header of Execve message.
Definition: message.hpp:149
A class containing the header of Fork message.
Definition: message.hpp:155
const Msg::HeaderOnly< ContinueInfo > Continue
A typedef for the continue message.
Definition: message.hpp:173
const Msg::HeaderOnly< NewSignalInfo > NewSignal
A typedef for the new signal message.
Definition: message.hpp:180
#define MESSAGE_HEADER_LENGTH
The number of characters a message header can be.
Definition: message.hpp:24
static void assert(const bool b, const char *const s)
assert b, if false call program_err(s)
Definition: utilities.cpp:89
A class containing the header of Call message.
Definition: message.hpp:130
Defines the types of messages which can be sent.
Definition: message.hpp:43
A class containing the header of Continue message.
Definition: message.hpp:124
const char * recv_msg_and_body(const int sock)
Reads a only Msg from sock This function is NOT re-entrant.
Definition: message.hpp:235
static int sock
Definition: dr_external_ss_events.cpp:14
void recv_msg(const int sock)
Reads a header only Msg from sock.
Definition: message.hpp:224
A class containing the header of Thread message.
Definition: message.hpp:161
static bool is_a_valid(const char *const buffer)
A function used to check if a char * may represent a message of type T.
Definition: message.hpp:168
void send_msg(const int sock)
Sends a header only Msg to sock.
Definition: message.hpp:209
const Msg::WithBody< RetInfo > Ret
A typedef for the ret message.
Definition: message.hpp:177
A class used for defining all message types Messages come in two forms.
Definition: message.hpp:40
A templated message class A valid message is defined by constructing a MessageType around it...
Definition: message.hpp:72
#define MESSAGE_INTERNALS(HEADER_ONLY)
The internals of a message.
Definition: message.hpp:47
const Msg::HeaderOnly< ThreadInfo > Thread
A typedef for the thread message.
Definition: message.hpp:186
static const char * set_length(char *const dst, const char *const src, const int n)
Copies n bytes from src into dst during static initilization If src is less than n bytes...
Definition: message.cpp:9