2019-11-27 04:58:39 +00:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-11-27 04:58:39 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include "amsmitm_debug.hpp"
|
|
|
|
|
|
|
|
namespace ams::mitm {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-04-08 10:21:35 +01:00
|
|
|
os::Mutex g_throw_lock(false);
|
2019-11-27 04:58:39 +00:00
|
|
|
bool g_threw;
|
|
|
|
Result g_throw_result;
|
|
|
|
|
|
|
|
|
|
|
|
void DebugThrowThreadFunc(void *arg);
|
|
|
|
|
|
|
|
constexpr size_t DebugThrowThreadStackSize = 0x4000;
|
2020-04-08 10:21:35 +01:00
|
|
|
constexpr int DebugThrowThreadPriority = 21;
|
|
|
|
os::ThreadType g_debug_throw_thread;
|
|
|
|
|
|
|
|
alignas(os::ThreadStackAlignment) u8 g_debug_throw_thread_stack[DebugThrowThreadStackSize];
|
2019-11-27 04:58:39 +00:00
|
|
|
|
|
|
|
void DebugThrowThreadFunc(void *arg) {
|
|
|
|
/* TODO: Better heuristic for fatal startup than sleep. */
|
2020-04-08 10:21:35 +01:00
|
|
|
os::SleepThread(TimeSpan::FromSeconds(10));
|
2019-11-27 04:58:39 +00:00
|
|
|
fatalThrow(g_throw_result.GetValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThrowResultForDebug(Result res) {
|
|
|
|
std::scoped_lock lk(g_throw_lock);
|
|
|
|
|
|
|
|
if (g_threw) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_throw_result = res;
|
|
|
|
g_threw = true;
|
2020-04-08 10:21:35 +01:00
|
|
|
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));
|
|
|
|
os::StartThread(std::addressof(g_debug_throw_thread));
|
2019-11-27 04:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|