Arion 1.0.2-alpha
A high-performance C++ framework for emulating executable binaries.
 
Loading...
Searching...
No Matches
arion::ThreadingManager Class Reference

#include <threading_manager.hpp>

Public Member Functions

 ThreadingManager (std::weak_ptr< Arion > arion)
 
 ~ThreadingManager ()
 
pid_t add_thread_entry (std::unique_ptr< ARION_THREAD > thread)
 
void remove_thread_entry (pid_t tid)
 
void clear_threads ()
 
pid_t clone_thread (uint64_t flags, ADDR new_sp, ADDR new_tls, ADDR child_tid_addr, ADDR parent_tid_addr, int exit_signal)
 
pid_t fork_process (uint64_t flags, ADDR new_sp, ADDR new_tls, ADDR child_tid_addr, ADDR parent_tid_addr, int exit_signal)
 
void switch_to_thread (pid_t tid)
 
void switch_to_next_thread ()
 
void futex_wait (pid_t tid, ADDR futex_addr, uint32_t futex_bitmask)
 
void futex_wait_curr (ADDR futex_addr, uint32_t futex_bitmask)
 
bool signal_wait (pid_t target_tid, pid_t source_pid, ADDR wait_status_addr)
 
bool signal_wait_curr (pid_t source_pid, ADDR wait_status_addr)
 
size_t futex_wake (ADDR futex_addr, uint32_t futex_bitmask)
 
bool is_curr_locked ()
 
size_t get_threads_count ()
 
pid_t get_running_tid ()
 
void set_running_tid (pid_t tid)
 
void set_tgid (pid_t tid, pid_t tgid, bool init=false)
 
void set_all_tgid (pid_t tgid, bool init=false)
 

Static Public Member Functions

static std::unique_ptr< ThreadingManagerinitialize (std::weak_ptr< Arion > arion)
 

Public Attributes

std::map< pid_t, std::unique_ptr< ARION_THREAD > > threads_map
 A map identifying an ARION_THREAD instance given its associated Thread ID.
 
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.
 

Static Public Attributes

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.
 

Private Member Functions

pid_t gen_next_id ()
 
void remove_thread_entry_internal (pid_t tid, bool clearing=false)
 

Private Attributes

std::weak_ptr< Arionarion
 The Arion instance associated with this instance.
 
pid_t curr_id = 1
 The next thread ID to assign when creating new threads.
 
pid_t running_tid = 1
 The thread ID of the currently running thread.
 
std::stack< pid_t > free_thread_ids
 Stack of reusable thread IDs from previously terminated threads.
 

Detailed Description

This class is used to manage threading operations. It is responsible for creating, managing, and synchronizing threads and processes.

Constructor & Destructor Documentation

◆ ThreadingManager()

arion::ThreadingManager::ThreadingManager ( std::weak_ptr< Arion arion)

Builder for ThreadingManager instances.

Parameters
[in]arionThe Arion instance associated with this instance.

◆ ~ThreadingManager()

arion::ThreadingManager::~ThreadingManager ( )

Destructor for ThreadingManager instances.

Member Function Documentation

◆ add_thread_entry()

pid_t arion::ThreadingManager::add_thread_entry ( std::unique_ptr< ARION_THREAD thread)

Adds a new thread entry to the internal tracking structures.

Parameters
[in]threadThe ARION_THREAD instance to register.
Returns
The newly assigned thread ID (TID).

◆ clear_threads()

void arion::ThreadingManager::clear_threads ( )

Removes all thread entries and clears the internal structures.

◆ clone_thread()

pid_t arion::ThreadingManager::clone_thread ( uint64_t  flags,
ADDR  new_sp,
ADDR  new_tls,
ADDR  child_tid_addr,
ADDR  parent_tid_addr,
int  exit_signal 
)

Creates a new thread by emulating the clone() system call.

Parameters
[in]flagsClone flags defining thread sharing behavior.
[in]new_spNew stack pointer for the thread.
[in]new_tlsNew TLS (Thread-Local Storage) address.
[in]child_tid_addrAddress where the child TID will be written.
[in]parent_tid_addrAddress where the parent TID will be written.
[in]exit_signalSignal to send when the thread exits.
Returns
The newly created thread's TID.

◆ fork_process()

pid_t arion::ThreadingManager::fork_process ( uint64_t  flags,
ADDR  new_sp,
ADDR  new_tls,
ADDR  child_tid_addr,
ADDR  parent_tid_addr,
int  exit_signal 
)

Creates a new process by emulating the fork() system call.

Parameters
[in]flagsFork flags defining process creation behavior.
[in]new_spNew stack pointer for the process.
[in]new_tlsNew TLS (Thread-Local Storage) address.
[in]child_tid_addrAddress where the child TID will be written.
[in]parent_tid_addrAddress where the parent TID will be written.
[in]exit_signalSignal to send when the process exits.
Returns
The newly created process's PID.

◆ futex_wait()

void arion::ThreadingManager::futex_wait ( pid_t  tid,
ADDR  futex_addr,
uint32_t  futex_bitmask 
)

Makes the specified thread wait on a futex.

Parameters
[in]tidThe thread ID that will wait.
[in]futex_addrAddress of the futex being waited on.
[in]futex_bitmaskBitmask used for wake filtering.

◆ futex_wait_curr()

void arion::ThreadingManager::futex_wait_curr ( ADDR  futex_addr,
uint32_t  futex_bitmask 
)

Makes the currently running thread wait on a futex.

Parameters
[in]futex_addrAddress of the futex being waited on.
[in]futex_bitmaskBitmask used for wake filtering.

◆ futex_wake()

size_t arion::ThreadingManager::futex_wake ( ADDR  futex_addr,
uint32_t  futex_bitmask 
)

Wakes up threads waiting on a futex.

Parameters
[in]futex_addrAddress of the futex being signaled.
[in]futex_bitmaskBitmask used for filtering which threads to wake.
Returns
The number of threads woken up.

◆ gen_next_id()

pid_t arion::ThreadingManager::gen_next_id ( )
private

Generates the next available Thread ID.

Returns
The next unique Thread ID.

◆ get_running_tid()

pid_t arion::ThreadingManager::get_running_tid ( )

Retrieves the ID of the currently running thread.

Returns
The running thread's TID.

◆ get_threads_count()

size_t arion::ThreadingManager::get_threads_count ( )

Retrieves the total number of threads currently managed by this instance.

Returns
The number of active threads.

◆ initialize()

static std::unique_ptr< ThreadingManager > arion::ThreadingManager::initialize ( std::weak_ptr< Arion arion)
static

Instanciates and initializes new ThreadingManager objects with some parameters.

Parameters
[in]arionThe Arion instance associated with this instance.
Returns
A new ThreadingManager instance.

◆ is_curr_locked()

bool arion::ThreadingManager::is_curr_locked ( )

Checks whether the currently running thread is locked.

Returns
True if the thread is locked, false otherwise.

◆ remove_thread_entry()

void arion::ThreadingManager::remove_thread_entry ( pid_t  tid)

Removes a thread entry from the ThreadingManager.

Parameters
[in]tidThe thread ID to remove.

◆ remove_thread_entry_internal()

void arion::ThreadingManager::remove_thread_entry_internal ( pid_t  tid,
bool  clearing = false 
)
private

Removes a thread entry, used internally by other methods.

Parameters
[in]tidThe Thread ID to remove.
[in]clearingWhether this removal is part of a global clear operation.

◆ set_all_tgid()

void arion::ThreadingManager::set_all_tgid ( pid_t  tgid,
bool  init = false 
)

Sets the same thread group ID (TGID) for all managed threads.

Parameters
[in]tgidThe thread group ID to assign.
[in]initWhether this is part of an initialization sequence.

◆ set_running_tid()

void arion::ThreadingManager::set_running_tid ( pid_t  tid)

Sets the currently running thread ID.

Parameters
[in]tidThe TID of the thread to mark as running.

◆ set_tgid()

void arion::ThreadingManager::set_tgid ( pid_t  tid,
pid_t  tgid,
bool  init = false 
)

Sets the thread group ID (TGID) for a specific thread.

Parameters
[in]tidThe thread ID.
[in]tgidThe thread group ID.
[in]initWhether this is part of an initialization sequence.

◆ signal_wait()

bool arion::ThreadingManager::signal_wait ( pid_t  target_tid,
pid_t  source_pid,
ADDR  wait_status_addr 
)

Makes a target thread wait for a signal from a source process.

Parameters
[in]target_tidThe thread ID that will wait.
[in]source_pidThe PID of the process sending the signal.
[in]wait_status_addrAddress where the wait status will be stored.
Returns
True if the wait was successful, false otherwise.

◆ signal_wait_curr()

bool arion::ThreadingManager::signal_wait_curr ( pid_t  source_pid,
ADDR  wait_status_addr 
)

Makes the currently running thread wait for a signal from a source process.

Parameters
[in]source_pidThe PID of the process sending the signal.
[in]wait_status_addrAddress where the wait status will be stored.
Returns
True if the wait was successful, false otherwise.

◆ switch_to_next_thread()

void arion::ThreadingManager::switch_to_next_thread ( )

Switches execution context to the next available thread.

◆ switch_to_thread()

void arion::ThreadingManager::switch_to_thread ( pid_t  tid)

Switches execution context to the thread identified by tid.

Parameters
[in]tidThe target thread ID to switch to.

Member Data Documentation

◆ arion

std::weak_ptr<Arion> arion::ThreadingManager::arion
private

The Arion instance associated with this instance.

◆ curr_id

pid_t arion::ThreadingManager::curr_id = 1
private

The next thread ID to assign when creating new threads.

◆ free_thread_ids

std::stack<pid_t> arion::ThreadingManager::free_thread_ids
private

Stack of reusable thread IDs from previously terminated threads.

◆ futex_list

std::map<ADDR, std::vector<std::unique_ptr<ARION_FUTEX> > *> arion::ThreadingManager::futex_list

A map identifying an ARION_FUTEX instance given the address of the futex.

◆ running_tid

pid_t arion::ThreadingManager::running_tid = 1
private

The thread ID of the currently running thread.

◆ thread_groups

std::map<pid_t, std::vector<std::unique_ptr<ARION_TGROUP_ENTRY> > > arion::ThreadingManager::thread_groups
static

A map identifying a thread group given its associated Thread ID.

◆ threads_map

std::map<pid_t, std::unique_ptr<ARION_THREAD> > arion::ThreadingManager::threads_map

A map identifying an ARION_THREAD instance given its associated Thread ID.


The documentation for this class was generated from the following file: