strat: statically allocate additional threads

This commit is contained in:
Michael Scire 2019-10-18 20:31:15 -07:00 committed by SciresM
parent fbb5730369
commit 535e49a38d
17 changed files with 123 additions and 42 deletions

View file

@ -30,6 +30,11 @@ namespace sts::dmnt::cheat::impl {
/* Manager class. */
class CheatProcessManager {
private:
static constexpr size_t ThreadStackSize = 0x4000;
static constexpr int DetectThreadPriority = 39;
static constexpr int VirtualMachineThreadPriority = 48;
static constexpr int DebugEventsThreadPriority = 24;
private:
os::Mutex cheat_lock;
os::Event debug_events_event; /* Autoclear. */
@ -47,6 +52,10 @@ namespace sts::dmnt::cheat::impl {
bool should_save_cheat_toggles = false;
CheatEntry cheat_entries[MaxCheatCount] = {};
std::map<u64, FrozenAddressValue> frozen_addresses_map;
alignas(0x1000) u8 detect_thread_stack[ThreadStackSize] = {};
alignas(0x1000) u8 debug_events_thread_stack[ThreadStackSize] = {};
alignas(0x1000) u8 vm_thread_stack[ThreadStackSize] = {};
private:
static void DetectLaunchThread(void *_this);
static void VirtualMachineThread(void *_this);
@ -200,9 +209,9 @@ namespace sts::dmnt::cheat::impl {
}
/* Spawn application detection thread, spawn cheat vm thread. */
R_ASSERT(this->detect_thread.Initialize(&CheatProcessManager::DetectLaunchThread, this, 0x4000, 39));
R_ASSERT(this->vm_thread.Initialize(&CheatProcessManager::VirtualMachineThread, this, 0x4000, 48));
R_ASSERT(this->debug_events_thread.Initialize(&CheatProcessManager::DebugEventsThread, this, 0x4000, 24));
R_ASSERT(this->detect_thread.Initialize(&CheatProcessManager::DetectLaunchThread, this, this->detect_thread_stack, ThreadStackSize, DetectThreadPriority));
R_ASSERT(this->vm_thread.Initialize(&CheatProcessManager::VirtualMachineThread, this, this->vm_thread_stack, ThreadStackSize, VirtualMachineThreadPriority));
R_ASSERT(this->debug_events_thread.Initialize(&CheatProcessManager::DebugEventsThread, this, this->debug_events_thread_stack, ThreadStackSize, DebugEventsThreadPriority));
/* Start threads. */
R_ASSERT(this->detect_thread.Start());

View file

@ -25,10 +25,14 @@ namespace sts::dmnt::cheat::impl {
class DebugEventsManager {
public:
static constexpr size_t NumCores = 4;
static constexpr size_t ThreadStackSize = 0x1000;
static constexpr size_t ThreadPriority = 24;
private:
std::array<os::MessageQueue, NumCores> message_queues;
std::array<os::Thread, NumCores> threads;
os::Event continued_event;
alignas(0x1000) u8 thread_stacks[NumCores][ThreadStackSize];
private:
static void PerCoreThreadFunction(void *_this) {
/* This thread will wait on the appropriate message queue. */
@ -88,10 +92,10 @@ namespace sts::dmnt::cheat::impl {
}
public:
DebugEventsManager() : message_queues{os::MessageQueue(1), os::MessageQueue(1), os::MessageQueue(1), os::MessageQueue(1)} {
DebugEventsManager() : message_queues{os::MessageQueue(1), os::MessageQueue(1), os::MessageQueue(1), os::MessageQueue(1)}, thread_stacks{} {
for (size_t i = 0; i < NumCores; i++) {
/* Create thread. */
R_ASSERT(this->threads[i].Initialize(&DebugEventsManager::PerCoreThreadFunction, reinterpret_cast<void *>(this), 0x1000, 24, i));
R_ASSERT(this->threads[i].Initialize(&DebugEventsManager::PerCoreThreadFunction, reinterpret_cast<void *>(this), this->thread_stacks[i], ThreadStackSize, ThreadPriority, i));
/* Set core mask. */
R_ASSERT(svcSetThreadCoreMask(this->threads[i].GetHandle(), i, (1u << i)));