1#ifndef ARION_THREADING_MANAGER_HPP
2#define ARION_THREADING_MANAGER_HPP
5#include <arion/unicorn/unicorn.h>
76 std::unique_ptr<std::map<REG, RVAL>> regs_state =
nullptr;
88 uint32_t rseq_len = 0;
90 uint32_t rseq_sig = 0;
110 ADDR parent_tid_addr, std::unique_ptr<std::map<REG, RVAL>> regs_state,
ADDR tls_addr)
111 : exit_signal(exit_signal), flags(flags), child_cleartid_addr(child_cleartid_addr),
112 child_settid_addr(child_settid_addr), parent_tid_addr(parent_tid_addr), regs_state(std::move(regs_state)),
113 tls_addr(tls_addr) {};
119 : tid(arion_t->tid), tgid(arion_t->tgid), exit_signal(arion_t->exit_signal), flags(arion_t->flags),
120 child_cleartid_addr(arion_t->child_cleartid_addr), child_settid_addr(arion_t->child_settid_addr),
121 parent_tid_addr(arion_t->parent_tid_addr),
122 regs_state(arion_t->regs_state ? std::make_unique<std::map<
REG,
RVAL>>(*arion_t->regs_state) : nullptr),
123 tls_addr(arion_t->tls_addr), wait_status_addr(arion_t->wait_status_addr), stopped(arion_t->stopped) {};
167 pid_t running_tid = 1;
184 static std::map<pid_t, std::vector<std::unique_ptr<ARION_TGROUP_ENTRY>>>
thread_groups;
188 std::map<ADDR, std::vector<std::unique_ptr<ARION_FUTEX>> *>
futex_list;
313 void set_tgid(pid_t tid, pid_t tgid,
bool init =
false);
Definition threading_manager.hpp:160
void remove_thread_entry_internal(pid_t tid, bool clearing=false)
void switch_to_thread(pid_t tid)
std::map< pid_t, std::unique_ptr< ARION_THREAD > > threads_map
A map identifying an ARION_THREAD instance given its associated Thread ID.
Definition threading_manager.hpp:186
static std::unique_ptr< ThreadingManager > initialize(std::weak_ptr< Arion > arion)
void set_tgid(pid_t tid, pid_t tgid, bool init=false)
std::weak_ptr< Arion > arion
The Arion instance associated with this instance.
Definition threading_manager.hpp:163
pid_t fork_process(uint64_t flags, ADDR new_sp, ADDR new_tls, ADDR child_tid_addr, ADDR parent_tid_addr, int exit_signal)
size_t futex_wake(ADDR futex_addr, uint32_t futex_bitmask)
size_t get_threads_count()
void futex_wait_curr(ADDR futex_addr, uint32_t futex_bitmask)
void remove_thread_entry(pid_t tid)
pid_t clone_thread(uint64_t flags, ADDR new_sp, ADDR new_tls, ADDR child_tid_addr, ADDR parent_tid_addr, int exit_signal)
void set_all_tgid(pid_t tgid, bool init=false)
std::stack< pid_t > free_thread_ids
Stack of reusable thread IDs from previously terminated threads.
Definition threading_manager.hpp:169
static std::map< pid_t, std::vector< std::unique_ptr< ARION_TGROUP_ENTRY > > > thread_groups
A map identifying a thread group given its associated Thread ID.
Definition threading_manager.hpp:184
ThreadingManager(std::weak_ptr< Arion > arion)
std::map< ADDR, std::vector< std::unique_ptr< ARION_FUTEX > > * > futex_list
A map identifying an ARION_FUTEX instance given the address of the futex.
Definition threading_manager.hpp:188
pid_t add_thread_entry(std::unique_ptr< ARION_THREAD > thread)
bool signal_wait_curr(pid_t source_pid, ADDR wait_status_addr)
bool signal_wait(pid_t target_tid, pid_t source_pid, ADDR wait_status_addr)
void set_running_tid(pid_t tid)
void futex_wait(pid_t tid, ADDR futex_addr, uint32_t futex_bitmask)
void switch_to_next_thread()
#define ARION_EXPORT
Defines which symbols should be exported from the library.
Definition global_defs.hpp:13
Definition arch_x86-64.hpp:11
uint64_t REG
Identifies a Unicorn register.
Definition global_defs.hpp:42
uint64_t ADDR
Identifies a memory address.
Definition global_defs.hpp:36
std::vector< BYTE > serialize_arion_futex(ARION_FUTEX *arion_f)
ARION_THREAD * deserialize_arion_thread(std::vector< BYTE > srz_thread)
ARION_FUTEX * deserialize_arion_futex(std::vector< BYTE > srz_futex)
std::vector< BYTE > serialize_arion_thread(ARION_THREAD *arion_t)
This structure holds data about a Fast Userspace muTEX.
Definition threading_manager.hpp:18
ARION_FUTEX(ARION_FUTEX *arion_f)
Definition threading_manager.hpp:41
uint32_t futex_bitmask
Bitmask of the futex, used to encode various states or conditions.
Definition threading_manager.hpp:22
ARION_FUTEX()
Definition threading_manager.hpp:28
ARION_FUTEX(ADDR futex_addr, uint32_t futex_bitmask, pid_t tid)
Definition threading_manager.hpp:35
ADDR futex_addr
Memory address of the futex.
Definition threading_manager.hpp:20
pid_t tid
The Thread ID associated with the futex.
Definition threading_manager.hpp:24
Definition threading_manager.hpp:141
ARION_TGROUP_ENTRY(pid_t tid, pid_t tgid, pid_t pid)
Definition threading_manager.hpp:154
pid_t tgid
The Thread Group ID (TGID) associated with the thread.
Definition threading_manager.hpp:145
pid_t pid
The Process ID (PID) associated with the thread.
Definition threading_manager.hpp:147
pid_t tid
The Thread ID (TID) of the thread.
Definition threading_manager.hpp:143
This structure holds data about a UNIX thread.
Definition threading_manager.hpp:59
ADDR child_settid_addr
The address of the child_tid variable to be set when the thread starts (used with CLONE_CHILD_SETTID)...
Definition threading_manager.hpp:71
ARION_THREAD(int exit_signal, uint64_t flags, ADDR child_cleartid_addr, ADDR child_settid_addr, ADDR parent_tid_addr, std::unique_ptr< std::map< REG, RVAL > > regs_state, ADDR tls_addr)
Definition threading_manager.hpp:109
ADDR tls_addr
The address of the thread’s thread-local storage (TLS) block.
Definition threading_manager.hpp:78
ARION_THREAD(ARION_THREAD *arion_t)
Definition threading_manager.hpp:118
pid_t tgid
The thread group ID (TGID) associated with this thread.
Definition threading_manager.hpp:63
ADDR parent_tid_addr
Definition threading_manager.hpp:74
ADDR child_cleartid_addr
The address of the child_tid variable to be cleared when the thread exits (used with CLONE_CHILD_CLEA...
Definition threading_manager.hpp:69
ARION_THREAD()
Definition threading_manager.hpp:94
int exit_signal
The signal to be sent to the parent process when the thread terminates.
Definition threading_manager.hpp:65
uint64_t flags
The clone flags used when the thread was created.
Definition threading_manager.hpp:67
pid_t tid
The thread ID (TID) associated with this thread.
Definition threading_manager.hpp:61
Identifies a size-agnostic register value.
Definition global_defs.hpp:64