#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< ThreadingManager > | initialize (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< Arion > | arion |
| 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. | |
This class is used to manage threading operations. It is responsible for creating, managing, and synchronizing threads and processes.
| arion::ThreadingManager::ThreadingManager | ( | std::weak_ptr< Arion > | arion | ) |
Builder for ThreadingManager instances.
| [in] | arion | The Arion instance associated with this instance. |
| arion::ThreadingManager::~ThreadingManager | ( | ) |
Destructor for ThreadingManager instances.
| pid_t arion::ThreadingManager::add_thread_entry | ( | std::unique_ptr< ARION_THREAD > | thread | ) |
Adds a new thread entry to the internal tracking structures.
| [in] | thread | The ARION_THREAD instance to register. |
| void arion::ThreadingManager::clear_threads | ( | ) |
Removes all thread entries and clears the internal structures.
| 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.
| [in] | flags | Clone flags defining thread sharing behavior. |
| [in] | new_sp | New stack pointer for the thread. |
| [in] | new_tls | New TLS (Thread-Local Storage) address. |
| [in] | child_tid_addr | Address where the child TID will be written. |
| [in] | parent_tid_addr | Address where the parent TID will be written. |
| [in] | exit_signal | Signal to send when the thread exits. |
| 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.
| [in] | flags | Fork flags defining process creation behavior. |
| [in] | new_sp | New stack pointer for the process. |
| [in] | new_tls | New TLS (Thread-Local Storage) address. |
| [in] | child_tid_addr | Address where the child TID will be written. |
| [in] | parent_tid_addr | Address where the parent TID will be written. |
| [in] | exit_signal | Signal to send when the process exits. |
| void arion::ThreadingManager::futex_wait | ( | pid_t | tid, |
| ADDR | futex_addr, | ||
| uint32_t | futex_bitmask | ||
| ) |
Makes the specified thread wait on a futex.
| [in] | tid | The thread ID that will wait. |
| [in] | futex_addr | Address of the futex being waited on. |
| [in] | futex_bitmask | Bitmask used for wake filtering. |
| void arion::ThreadingManager::futex_wait_curr | ( | ADDR | futex_addr, |
| uint32_t | futex_bitmask | ||
| ) |
Makes the currently running thread wait on a futex.
| [in] | futex_addr | Address of the futex being waited on. |
| [in] | futex_bitmask | Bitmask used for wake filtering. |
| size_t arion::ThreadingManager::futex_wake | ( | ADDR | futex_addr, |
| uint32_t | futex_bitmask | ||
| ) |
Wakes up threads waiting on a futex.
| [in] | futex_addr | Address of the futex being signaled. |
| [in] | futex_bitmask | Bitmask used for filtering which threads to wake. |
|
private |
Generates the next available Thread ID.
| pid_t arion::ThreadingManager::get_running_tid | ( | ) |
Retrieves the ID of the currently running thread.
| size_t arion::ThreadingManager::get_threads_count | ( | ) |
Retrieves the total number of threads currently managed by this instance.
|
static |
Instanciates and initializes new ThreadingManager objects with some parameters.
| [in] | arion | The Arion instance associated with this instance. |
| bool arion::ThreadingManager::is_curr_locked | ( | ) |
Checks whether the currently running thread is locked.
| void arion::ThreadingManager::remove_thread_entry | ( | pid_t | tid | ) |
Removes a thread entry from the ThreadingManager.
| [in] | tid | The thread ID to remove. |
|
private |
Removes a thread entry, used internally by other methods.
| [in] | tid | The Thread ID to remove. |
| [in] | clearing | Whether this removal is part of a global clear operation. |
| void arion::ThreadingManager::set_all_tgid | ( | pid_t | tgid, |
| bool | init = false |
||
| ) |
Sets the same thread group ID (TGID) for all managed threads.
| [in] | tgid | The thread group ID to assign. |
| [in] | init | Whether this is part of an initialization sequence. |
| void arion::ThreadingManager::set_running_tid | ( | pid_t | tid | ) |
Sets the currently running thread ID.
| [in] | tid | The TID of the thread to mark as running. |
| void arion::ThreadingManager::set_tgid | ( | pid_t | tid, |
| pid_t | tgid, | ||
| bool | init = false |
||
| ) |
Sets the thread group ID (TGID) for a specific thread.
| [in] | tid | The thread ID. |
| [in] | tgid | The thread group ID. |
| [in] | init | Whether this is part of an initialization sequence. |
| 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.
| [in] | target_tid | The thread ID that will wait. |
| [in] | source_pid | The PID of the process sending the signal. |
| [in] | wait_status_addr | Address where the wait status will be stored. |
| 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.
| [in] | source_pid | The PID of the process sending the signal. |
| [in] | wait_status_addr | Address where the wait status will be stored. |
| void arion::ThreadingManager::switch_to_next_thread | ( | ) |
Switches execution context to the next available thread.
| void arion::ThreadingManager::switch_to_thread | ( | pid_t | tid | ) |
Switches execution context to the thread identified by tid.
| [in] | tid | The target thread ID to switch to. |
|
private |
The Arion instance associated with this instance.
|
private |
The next thread ID to assign when creating new threads.
|
private |
Stack of reusable thread IDs from previously terminated threads.
| 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.
|
private |
The thread ID of the currently running thread.
|
static |
A map identifying a thread group given its associated Thread ID.
| 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.