ams: centralize system thread definitions

This commit is contained in:
Michael Scire 2020-04-17 01:06:07 -07:00
parent d77fe98203
commit 3da0cda4ae
32 changed files with 254 additions and 40 deletions

View file

@ -28,7 +28,6 @@ namespace ams::mitm {
void DebugThrowThreadFunc(void *arg);
constexpr size_t DebugThrowThreadStackSize = 0x4000;
constexpr int DebugThrowThreadPriority = 21;
os::ThreadType g_debug_throw_thread;
alignas(os::ThreadStackAlignment) u8 g_debug_throw_thread_stack[DebugThrowThreadStackSize];
@ -50,7 +49,8 @@ namespace ams::mitm {
g_throw_result = res;
g_threw = true;
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_debug_throw_thread), DebugThrowThreadFunc, nullptr, g_debug_throw_thread_stack, sizeof(g_debug_throw_thread_stack), DebugThrowThreadPriority));
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_debug_throw_thread), DebugThrowThreadFunc, nullptr, g_debug_throw_thread_stack, sizeof(g_debug_throw_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(mitm, DebugThrowThread)));
os::SetThreadNamePointer(std::addressof(g_debug_throw_thread), AMS_GET_SYSTEM_THREAD_NAME(mitm, DebugThrowThread));
os::StartThread(std::addressof(g_debug_throw_thread));
}

View file

@ -50,7 +50,6 @@ namespace ams::mitm {
void InitializeThreadFunc(void *arg);
constexpr size_t InitializeThreadStackSize = 0x4000;
constexpr int InitializeThreadPriority = -7;
/* Globals. */
os::Event g_init_event(os::EventClearMode_ManualClear);
@ -223,7 +222,8 @@ namespace ams::mitm {
}
void StartInitialize() {
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_initialize_thread), InitializeThreadFunc, nullptr, g_initialize_thread_stack, sizeof(g_initialize_thread_stack), InitializeThreadPriority));
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_initialize_thread), InitializeThreadFunc, nullptr, g_initialize_thread_stack, sizeof(g_initialize_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(mitm, InitializeThread)));
os::SetThreadNamePointer(std::addressof(g_initialize_thread), AMS_GET_SYSTEM_THREAD_NAME(mitm, InitializeThread));
os::StartThread(std::addressof(g_initialize_thread));
}

View file

@ -19,6 +19,6 @@
namespace ams::mitm::bpc {
DEFINE_MITM_MODULE_CLASS(0x8000, 4);
DEFINE_MITM_MODULE_CLASS(0x8000, AMS_GET_SYSTEM_THREAD_PRIORITY(bpc, IpcServer));
}

View file

@ -39,7 +39,6 @@ namespace ams::mitm::fs {
}
constexpr size_t RomfsInitializerThreadStackSize = 0x8000;
constexpr int RomfsInitializerThreadPriority = 16;
os::ThreadType g_romfs_initializer_thread;
alignas(os::ThreadStackAlignment) u8 g_romfs_initializer_thread_stack[RomfsInitializerThreadStackSize];
@ -47,7 +46,8 @@ namespace ams::mitm::fs {
std::scoped_lock lk(g_mq_lock);
if (AMS_UNLIKELY(!g_started_req_thread)) {
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_romfs_initializer_thread), RomfsInitializerThreadFunction, nullptr, g_romfs_initializer_thread_stack, sizeof(g_romfs_initializer_thread_stack), RomfsInitializerThreadPriority));
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_romfs_initializer_thread), RomfsInitializerThreadFunction, nullptr, g_romfs_initializer_thread_stack, sizeof(g_romfs_initializer_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(mitm_fs, RomFileSystemInitializeThread)));
os::SetThreadNamePointer(std::addressof(g_romfs_initializer_thread), AMS_GET_SYSTEM_THREAD_NAME(mitm_fs, RomFileSystemInitializeThread));
os::StartThread(std::addressof(g_romfs_initializer_thread));
g_started_req_thread = true;
}

View file

@ -19,6 +19,6 @@
namespace ams::mitm::fs {
DEFINE_MITM_MODULE_CLASS(0x8000, 15);
DEFINE_MITM_MODULE_CLASS(0x8000, AMS_GET_SYSTEM_THREAD_PRIORITY(fs, WorkerThreadPool) - 1);
}

View file

@ -19,6 +19,6 @@
namespace ams::mitm::hid {
DEFINE_MITM_MODULE_CLASS(0x8000, 19);
DEFINE_MITM_MODULE_CLASS(0x8000, AMS_GET_SYSTEM_THREAD_PRIORITY(hid, IpcServer));
}

View file

@ -19,6 +19,6 @@
namespace ams::mitm::ns {
DEFINE_MITM_MODULE_CLASS(0x4000, 20);
DEFINE_MITM_MODULE_CLASS(0x4000, AMS_GET_SYSTEM_THREAD_PRIORITY(ns, ApplicationManagerIpcSession) - 1);
}

View file

@ -19,6 +19,6 @@
namespace ams::mitm::settings {
DEFINE_MITM_MODULE_CLASS(0x8000, 20);
DEFINE_MITM_MODULE_CLASS(0x8000, AMS_GET_SYSTEM_THREAD_PRIORITY(settings, IpcServer) - 1);
}

View file

@ -107,6 +107,10 @@ void __appExit(void) {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(boot, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(boot, Main));
/* Change voltage from 3.3v to 1.8v for select devices. */
boot::ChangeGpioVoltageTo1_8v();

View file

@ -96,6 +96,10 @@ void __appExit(void) {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(boot2, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(boot2, Main));
/* Launch all programs off of SYSTEM/the SD. */
boot2::LaunchPostSdCardBootPrograms();
}

View file

@ -85,6 +85,10 @@ void __appExit(void) {
static creport::CrashReport g_crash_report;
int main(int argc, char **argv) {
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(creport, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(creport, Main));
/* Validate arguments. */
if (argc < 2) {
return EXIT_FAILURE;

View file

@ -29,9 +29,6 @@ namespace ams::dmnt::cheat::impl {
class CheatProcessManager {
private:
static constexpr size_t ThreadStackSize = 0x4000;
static constexpr s32 DetectThreadPriority = 11;
static constexpr s32 VirtualMachineThreadPriority = 20;
static constexpr s32 DebugEventsThreadPriority = -1;
private:
os::Mutex cheat_lock;
os::Event debug_events_event; /* Autoclear. */
@ -200,9 +197,12 @@ namespace ams::dmnt::cheat::impl {
}
/* Spawn application detection thread, spawn cheat vm thread. */
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->detect_thread), DetectLaunchThread, this, this->detect_thread_stack, ThreadStackSize, DetectThreadPriority));
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->vm_thread), VirtualMachineThread, this, this->vm_thread_stack, ThreadStackSize, VirtualMachineThreadPriority));
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->debug_events_thread), DebugEventsThread, this, this->debug_events_thread_stack, ThreadStackSize, DebugEventsThreadPriority));
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->detect_thread), DetectLaunchThread, this, this->detect_thread_stack, ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, CheatDetect)));
os::SetThreadNamePointer(std::addressof(this->detect_thread), AMS_GET_SYSTEM_THREAD_NAME(dmnt, CheatDetect));
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->vm_thread), VirtualMachineThread, this, this->vm_thread_stack, ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, CheatVirtualMachine)));
os::SetThreadNamePointer(std::addressof(this->vm_thread), AMS_GET_SYSTEM_THREAD_NAME(dmnt, CheatVirtualMachine));
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->debug_events_thread), DebugEventsThread, this, this->debug_events_thread_stack, ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, CheatDebugEvents)));
os::SetThreadNamePointer(std::addressof(this->debug_events_thread), AMS_GET_SYSTEM_THREAD_NAME(dmnt, CheatDebugEvents));
/* Start threads. */
os::StartThread(std::addressof(this->detect_thread));

View file

@ -25,7 +25,6 @@ namespace ams::dmnt::cheat::impl {
public:
static constexpr size_t NumCores = 4;
static constexpr size_t ThreadStackSize = os::MemoryPageSize;
static constexpr s32 ThreadPriority = -3;
private:
std::array<uintptr_t, NumCores> message_queue_buffers;
std::array<os::MessageQueue, NumCores> message_queues;
@ -103,7 +102,8 @@ namespace ams::dmnt::cheat::impl {
{
for (size_t i = 0; i < NumCores; i++) {
/* Create thread. */
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->threads[i]), PerCoreThreadFunction, this, this->thread_stacks[i], ThreadStackSize, ThreadPriority, i));
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->threads[i]), PerCoreThreadFunction, this, this->thread_stacks[i], ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, MultiCoreEventManager), i));
os::SetThreadNamePointer(std::addressof(this->threads[i]), AMS_GET_SYSTEM_THREAD_NAME(dmnt, MultiCoreEventManager));
/* Set core mask. */
os::SetThreadCoreMask(std::addressof(this->threads[i]), i, (1u << i));

View file

@ -129,6 +129,10 @@ namespace {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(dmnt, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, Main));
/* Initialize the cheat manager. */
ams::dmnt::cheat::impl::InitializeCheatManager();
@ -143,9 +147,10 @@ int main(int argc, char **argv)
/* Initialize threads. */
if constexpr (NumExtraThreads > 0) {
const s32 priority = os::GetThreadCurrentPriority(os::GetCurrentThread());
static_assert(AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, Main) == AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, Ipc));
for (size_t i = 0; i < NumExtraThreads; i++) {
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_extra_threads[i]), LoopServerThread, nullptr, g_extra_thread_stacks[i], ThreadStackSize, priority));
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_extra_threads[i]), LoopServerThread, nullptr, g_extra_thread_stacks[i], ThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(dmnt, Ipc)));
os::SetThreadNamePointer(std::addressof(g_extra_threads[i]), AMS_GET_SYSTEM_THREAD_NAME(dmnt, Ipc));
}
}

View file

@ -120,6 +120,10 @@ namespace ams::erpt {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(erpt, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(erpt, Main));
/* Set the memory heap for erpt::srv namespace. */
R_ABORT_UNLESS(erpt::srv::Initialize(erpt::g_memory_heap, erpt::MemoryHeapSize));

View file

@ -90,7 +90,7 @@ void __appInit(void) {
R_ABORT_UNLESS(lblInitialize());
R_ABORT_UNLESS(psmInitialize());
R_ABORT_UNLESS(spsmInitialize());
R_ABORT_UNLESS(plInitialize());
R_ABORT_UNLESS(plInitialize(::PlServiceType_User));
R_ABORT_UNLESS(gpioInitialize());
R_ABORT_UNLESS(fsInitialize());
});
@ -141,6 +141,10 @@ namespace {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(fatal, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(fatal, Main));
/* Load shared font. */
R_ABORT_UNLESS(fatal::srv::font::InitializeSharedFont());

View file

@ -27,8 +27,6 @@ namespace ams::fatal::srv {
class TaskThread {
NON_COPYABLE(TaskThread);
private:
static constexpr s32 TaskThreadPriority = -13;
private:
os::ThreadType thread;
private:
@ -42,7 +40,8 @@ namespace ams::fatal::srv {
public:
TaskThread() { /* ... */ }
void StartTask(ITask *task) {
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->thread), RunTaskImpl, task, task->GetStack(), task->GetStackSize(), TaskThreadPriority, 3));
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->thread), RunTaskImpl, task, task->GetStack(), task->GetStackSize(), AMS_GET_SYSTEM_THREAD_PRIORITY(fatalsrv, FatalTaskThread), 3));
os::SetThreadNamePointer(std::addressof(this->thread), AMS_GET_SYSTEM_THREAD_NAME(fatalsrv, FatalTaskThread));
os::StartThread(std::addressof(this->thread));
}
};

View file

@ -115,6 +115,10 @@ namespace {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(ldr, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(ldr, Main));
/* Configure development. */
/* NOTE: Nintendo really does call the getter function three times instead of caching the value. */
ldr::SetDevelopmentForAcidProductionCheck(spl::IsDevelopmentHardware());

View file

@ -174,7 +174,8 @@ namespace {
}
ams::Result StartThreads() {
R_TRY(os::CreateThread(std::addressof(this->thread), ThreadFunction, this, g_content_manager_thread_stack, sizeof(g_content_manager_thread_stack), 21));
R_TRY(os::CreateThread(std::addressof(this->thread), ThreadFunction, this, g_content_manager_thread_stack, sizeof(g_content_manager_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(ncm, ContentManagerServerIpcSession)));
os::SetThreadNamePointer(std::addressof(this->thread), AMS_GET_SYSTEM_THREAD_NAME(ncm, ContentManagerServerIpcSession));
os::StartThread(std::addressof(this->thread));
return ResultSuccess();
}
@ -219,7 +220,8 @@ namespace {
}
ams::Result StartThreads() {
R_TRY(os::CreateThread(std::addressof(this->thread), ThreadFunction, this, g_location_resolver_thread_stack, sizeof(g_location_resolver_thread_stack), 21));
R_TRY(os::CreateThread(std::addressof(this->thread), ThreadFunction, this, g_location_resolver_thread_stack, sizeof(g_location_resolver_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(ncm, LocationResolverServerIpcSession)));
os::SetThreadNamePointer(std::addressof(this->thread), AMS_GET_SYSTEM_THREAD_NAME(ncm, LocationResolverServerIpcSession));
os::StartThread(std::addressof(this->thread));
return ResultSuccess();
}
@ -260,6 +262,10 @@ namespace {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(ncm, MainWaitThreads));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(ncm, MainWaitThreads));
/* Create and initialize the content manager. */
auto content_manager = GetSharedPointerToContentManager();
R_ABORT_UNLESS(content_manager->Initialize(ManagerConfig));

View file

@ -145,6 +145,10 @@ void __appExit(void) {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(pgl, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(pgl, Main));
/* Register the pgl service. */
pgl::RegisterServiceSession();

View file

@ -117,7 +117,6 @@ namespace ams::pm::impl {
/* Process Tracking globals. */
void ProcessTrackingMain(void *arg);
constexpr int ProcessTrackThreadPriority = 21;
os::ThreadType g_process_track_thread;
alignas(os::ThreadStackAlignment) u8 g_process_track_thread_stack[16_KB];
@ -405,7 +404,8 @@ namespace ams::pm::impl {
R_TRY(resource::InitializeResourceManager());
/* Create thread. */
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_process_track_thread), ProcessTrackingMain, nullptr, g_process_track_thread_stack, sizeof(g_process_track_thread_stack), ProcessTrackThreadPriority));
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_process_track_thread), ProcessTrackingMain, nullptr, g_process_track_thread_stack, sizeof(g_process_track_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(pm, ProcessTrack)));
os::SetThreadNamePointer(std::addressof(g_process_track_thread), AMS_GET_SYSTEM_THREAD_NAME(pm, ProcessTrack));
/* Start thread. */
os::StartThread(std::addressof(g_process_track_thread));

View file

@ -184,6 +184,10 @@ namespace {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(pm, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(pm, Main));
/* Initialize process manager implementation. */
R_ABORT_UNLESS(pm::impl::InitializeProcessManager());

View file

@ -107,6 +107,10 @@ namespace {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(ro, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(ro, Main));
/* Initialize Debug config. */
{
ON_SCOPE_EXIT { splExit(); };

View file

@ -89,6 +89,10 @@ namespace {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(sm, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(sm, Main));
/* NOTE: These handles are manually managed, but we don't save references to them to close on exit. */
/* This is fine, because if SM crashes we have much bigger issues. */

View file

@ -129,6 +129,10 @@ namespace {
int main(int argc, char **argv)
{
/* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(spl, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(spl, Main));
/* Initialize global context. */
spl::impl::Initialize();