mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-31 14:58:22 -04:00
abort/error: print backtrace, abuse templates, overhaul result/diag (macos not done yet)
This commit is contained in:
parent
18168d54c3
commit
646f84bad1
118 changed files with 2843 additions and 369 deletions
|
@ -23,7 +23,7 @@
|
|||
#elif defined(ATMOSPHERE_OS_LINUX)
|
||||
#include "os_cache_impl.os.linux.hpp"
|
||||
#elif defined(ATMOSPHERE_OS_MACOS)
|
||||
#include "os_cache_impl.os.linux.hpp"
|
||||
#include "os_cache_impl.os.macos.hpp"
|
||||
#else
|
||||
#error "Unknown OS for CacheImpl"
|
||||
#endif
|
||||
|
|
29
libraries/libstratosphere/source/os/impl/os_debug_impl.hpp
Normal file
29
libraries/libstratosphere/source/os/impl/os_debug_impl.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
#include "os_debug_impl.os.horizon.hpp"
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS)
|
||||
#include "os_debug_impl.os.windows.hpp"
|
||||
#elif defined(ATMOSPHERE_OS_LINUX)
|
||||
#include "os_debug_impl.os.linux.hpp"
|
||||
#elif defined(ATMOSPHERE_OS_MACOS)
|
||||
#include "os_debug_impl.os.macos.hpp"
|
||||
#else
|
||||
#error "Unknown OS for DebugImpl"
|
||||
#endif
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "os_thread_manager.hpp"
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class DebugHorizonImpl {
|
||||
public:
|
||||
static uintptr_t GetCurrentStackPointer() {
|
||||
uintptr_t v;
|
||||
__asm__ __volatile__("mov %[v], sp" : [v]"=&r"(v) :: "memory");
|
||||
return v;
|
||||
}
|
||||
|
||||
static void GetCurrentStackInfo(uintptr_t *out_stack, size_t *out_size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(out_stack != nullptr);
|
||||
AMS_ASSERT(out_size != nullptr);
|
||||
|
||||
/* Get the current thread. */
|
||||
auto *cur_thread = os::impl::GetCurrentThread();
|
||||
auto *cur_fiber = cur_thread->current_fiber;
|
||||
|
||||
/* Get the current stack pointer. */
|
||||
uintptr_t cur_sp = GetCurrentStackPointer();
|
||||
|
||||
/* Determine current stack extents, TODO Fiber */
|
||||
uintptr_t stack_top = reinterpret_cast<uintptr_t>(cur_fiber == nullptr ? cur_thread->stack : /* TODO: cur_fiber->stack */ nullptr);
|
||||
size_t stack_size = reinterpret_cast<size_t>(cur_fiber == nullptr ? cur_thread->stack_size : /* TODO: cur_fiber->stack_size */ 0);
|
||||
|
||||
uintptr_t stack_bottom = stack_top + stack_size;
|
||||
|
||||
/* TODO: User exception handler, check if stack is out of range and use exception stack. */
|
||||
|
||||
/* Check that the stack pointer is in bounds. */
|
||||
AMS_ABORT_UNLESS((stack_top <= cur_sp) && (cur_sp < stack_bottom));
|
||||
|
||||
/* Set the output. */
|
||||
*out_stack = stack_top;
|
||||
*out_size = stack_size;
|
||||
}
|
||||
|
||||
static void QueryMemoryInfo(os::MemoryInfo *out) {
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO: Horizon QueryMemoryInfo");
|
||||
}
|
||||
|
||||
static Tick GetIdleTickCount() {
|
||||
u64 value;
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), svc::InfoType_IdleTickCount, svc::InvalidHandle, static_cast<u64>(-1)));
|
||||
|
||||
return os::Tick(value);
|
||||
}
|
||||
|
||||
static Tick GetThreadTickCount() {
|
||||
u64 value;
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), svc::InfoType_ThreadTickCount, svc::PseudoHandle::CurrentThread, static_cast<u64>(-1)));
|
||||
|
||||
return os::Tick(value);
|
||||
}
|
||||
|
||||
static int GetFreeThreadCount() {
|
||||
u64 value;
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), svc::InfoType_FreeThreadCount, svc::PseudoHandle::CurrentProcess, 0));
|
||||
|
||||
AMS_ASSERT(value <= static_cast<u64>(std::numeric_limits<int>::max()));
|
||||
|
||||
return static_cast<int>(value);
|
||||
}
|
||||
};
|
||||
|
||||
using DebugImpl = DebugHorizonImpl;
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class DebugLinuxImpl {
|
||||
public:
|
||||
static void GetCurrentStackInfo(uintptr_t *out_stack, size_t *out_size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(out_stack != nullptr);
|
||||
AMS_ASSERT(out_size != nullptr);
|
||||
|
||||
/* Get the current stack by pthread */
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(std::addressof(attr));
|
||||
ON_SCOPE_EXIT { pthread_attr_destroy(std::addressof(attr)); };
|
||||
|
||||
const auto getattr_res = pthread_getattr_np(pthread_self(), std::addressof(attr));
|
||||
AMS_ABORT_UNLESS(getattr_res == 0);
|
||||
|
||||
/* Get the thread satck. */
|
||||
void *base = nullptr;
|
||||
size_t size = 0;
|
||||
const auto getstack_res = pthread_getattr_np(pthread_self(), std::addressof(attr));
|
||||
AMS_ABORT_UNLESS(getstack_res == 0);
|
||||
|
||||
*out_stack = reinterpret_cast<uintptr_t>(base);
|
||||
*out_size = size;
|
||||
}
|
||||
|
||||
static void QueryMemoryInfo(os::MemoryInfo *out) {
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO: Linux QueryMemoryInfo");
|
||||
}
|
||||
|
||||
static Tick GetIdleTickCount() {
|
||||
return os::Tick(0);
|
||||
}
|
||||
|
||||
static Tick GetThreadTickCount() {
|
||||
return os::Tick(0);
|
||||
}
|
||||
|
||||
static int GetFreeThreadCount() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
using DebugImpl = DebugLinuxImpl;
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class DebugMacosImpl {
|
||||
public:
|
||||
static void GetCurrentStackInfo(uintptr_t *out_stack, size_t *out_size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(out_stack != nullptr);
|
||||
AMS_ASSERT(out_size != nullptr);
|
||||
|
||||
/* Get the current stack by pthread */
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(std::addressof(attr));
|
||||
ON_SCOPE_EXIT { pthread_attr_destroy(std::addressof(attr)); };
|
||||
|
||||
const auto getattr_res = pthread_getattr_np(pthread_self(), std::addressof(attr));
|
||||
AMS_ABORT_UNLESS(getattr_res == 0);
|
||||
|
||||
/* Get the thread satck. */
|
||||
void *base = nullptr;
|
||||
size_t size = 0;
|
||||
const auto getstack_res = pthread_getattr_np(pthread_self(), std::addressof(attr));
|
||||
AMS_ABORT_UNLESS(getstack_res == 0);
|
||||
|
||||
*out_stack = reinterpret_cast<uintptr_t>(base);
|
||||
*out_size = size;
|
||||
}
|
||||
|
||||
static void QueryMemoryInfo(os::MemoryInfo *out) {
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO: macOS QueryMemoryInfo");
|
||||
}
|
||||
|
||||
static Tick GetIdleTickCount() {
|
||||
return os::Tick(0);
|
||||
}
|
||||
|
||||
static Tick GetThreadTickCount() {
|
||||
return os::Tick(0);
|
||||
}
|
||||
|
||||
static int GetFreeThreadCount() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
using DebugImpl = DebugMacosImpl;
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class DebugWindowsImpl {
|
||||
public:
|
||||
static void GetCurrentStackInfo(uintptr_t *out_stack, size_t *out_size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(out_stack != nullptr);
|
||||
AMS_ASSERT(out_size != nullptr);
|
||||
|
||||
/* Get the current stack by NT_TIB */
|
||||
auto *tib = reinterpret_cast<NT_TIB *>(::NtCurrentTeb());
|
||||
|
||||
*out_stack = reinterpret_cast<uintptr_t>(tib->StackLimit);
|
||||
*out_size = reinterpret_cast<uintptr_t>(tib->StackBase) - reinterpret_cast<uintptr_t>(tib->StackLimit);
|
||||
}
|
||||
|
||||
static void QueryMemoryInfo(os::MemoryInfo *out) {
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO: Windows QueryMemoryInfo");
|
||||
}
|
||||
|
||||
static Tick GetIdleTickCount() {
|
||||
return os::Tick(0);
|
||||
}
|
||||
|
||||
static Tick GetThreadTickCount() {
|
||||
return os::Tick(0);
|
||||
}
|
||||
|
||||
static int GetFreeThreadCount() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
using DebugImpl = DebugWindowsImpl;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue