strat: statically allocate additional threads
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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)));
|
||||
|
||||
@@ -31,9 +31,10 @@ extern "C" {
|
||||
|
||||
u32 __nx_applet_type = AppletType_None;
|
||||
u32 __nx_fs_num_sessions = 1;
|
||||
u32 __nx_fsdev_direntry_cache_size = 1;
|
||||
|
||||
/* TODO: Evaluate how much this can be reduced by. */
|
||||
#define INNER_HEAP_SIZE 0xC0000
|
||||
#define INNER_HEAP_SIZE 0x20000
|
||||
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
|
||||
char nx_inner_heap[INNER_HEAP_SIZE];
|
||||
|
||||
@@ -118,6 +119,14 @@ namespace {
|
||||
g_server_manager.LoopProcess();
|
||||
}
|
||||
|
||||
constexpr size_t TotalThreads = DebugMonitorMaxSessions + 1;
|
||||
static_assert(TotalThreads >= 1, "TotalThreads");
|
||||
constexpr size_t NumExtraThreads = TotalThreads - 1;
|
||||
constexpr size_t ThreadStackSize = 0x4000;
|
||||
alignas(0x1000) u8 g_extra_thread_stacks[NumExtraThreads][ThreadStackSize];
|
||||
|
||||
os::Thread g_extra_threads[NumExtraThreads];
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -130,25 +139,19 @@ int main(int argc, char **argv)
|
||||
/* Loop forever, servicing our services. */
|
||||
/* Nintendo loops four threads processing on the manager -- we'll loop an extra fifth for our cheat service. */
|
||||
{
|
||||
constexpr size_t TotalThreads = DebugMonitorMaxSessions + 1;
|
||||
constexpr size_t NumExtraThreads = TotalThreads - 1;
|
||||
static_assert(TotalThreads >= 1, "TotalThreads");
|
||||
|
||||
os::Thread extra_threads[NumExtraThreads];
|
||||
|
||||
/* Initialize threads. */
|
||||
if constexpr (NumExtraThreads > 0) {
|
||||
constexpr size_t ThreadStackSize = 0x4000;
|
||||
const u32 priority = os::GetCurrentThreadPriority();
|
||||
for (size_t i = 0; i < NumExtraThreads; i++) {
|
||||
R_ASSERT(extra_threads[i].Initialize(LoopServerThread, nullptr, ThreadStackSize, priority));
|
||||
R_ASSERT(g_extra_threads[i].Initialize(LoopServerThread, nullptr, g_extra_thread_stacks[i], ThreadStackSize, priority));
|
||||
}
|
||||
}
|
||||
|
||||
/* Start extra threads. */
|
||||
if constexpr (NumExtraThreads > 0) {
|
||||
for (size_t i = 0; i < NumExtraThreads; i++) {
|
||||
R_ASSERT(extra_threads[i].Start());
|
||||
R_ASSERT(g_extra_threads[i].Start());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +161,7 @@ int main(int argc, char **argv)
|
||||
/* Wait for extra threads to finish. */
|
||||
if constexpr (NumExtraThreads > 0) {
|
||||
for (size_t i = 0; i < NumExtraThreads; i++) {
|
||||
R_ASSERT(extra_threads[i].Join());
|
||||
R_ASSERT(g_extra_threads[i].Join());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user