mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 12:21:18 +00:00
strat: automatic program id detection
This commit is contained in:
parent
9ecec1b935
commit
18825866ac
28 changed files with 88 additions and 129 deletions
|
@ -36,7 +36,7 @@ namespace ams::os {
|
|||
}
|
||||
|
||||
IoRegion(size_t size, Handle handle, bool managed) {
|
||||
this->Attach(size, handle, managed);
|
||||
this->AttachHandle(size, handle, managed);
|
||||
}
|
||||
|
||||
~IoRegion() {
|
||||
|
|
|
@ -16,13 +16,17 @@
|
|||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_managed_handle.hpp>
|
||||
#include <stratosphere/ncm/ncm_program_id.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
::Handle GetCurrentProcessHandle();
|
||||
|
||||
NX_INLINE ProcessId GetCurrentProcessId() {
|
||||
ALWAYS_INLINE ProcessId GetCurrentProcessId() {
|
||||
return GetProcessId(GetCurrentProcessHandle());
|
||||
}
|
||||
|
||||
/* TODO: Another header? */
|
||||
ncm::ProgramId GetCurrentProgramId();
|
||||
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ namespace ams {
|
|||
|
||||
}
|
||||
|
||||
extern ncm::ProgramId CurrentProgramId;
|
||||
|
||||
void InitializeForBoot() {
|
||||
R_ABORT_UNLESS(amsBpcInitialize());
|
||||
}
|
||||
|
@ -56,7 +54,7 @@ namespace ams {
|
|||
{
|
||||
ams_ctx.magic = FatalErrorContext::Magic;
|
||||
ams_ctx.error_desc = ctx->error_desc;
|
||||
ams_ctx.program_id = static_cast<u64>(CurrentProgramId);
|
||||
ams_ctx.program_id = os::GetCurrentProgramId().value;
|
||||
for (size_t i = 0; i < FatalErrorContext::NumGprs; i++) {
|
||||
ams_ctx.gprs[i] = ctx->cpu_gprs[i].x;
|
||||
}
|
||||
|
|
|
@ -15,12 +15,6 @@
|
|||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams {
|
||||
|
||||
extern ncm::ProgramId CurrentProgramId;
|
||||
|
||||
}
|
||||
|
||||
namespace ams::diag {
|
||||
|
||||
namespace {
|
||||
|
@ -69,7 +63,7 @@ namespace ams::diag {
|
|||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) {
|
||||
DebugLog("%016lx: Assertion Failure\n", static_cast<u64>(ams::CurrentProgramId));
|
||||
DebugLog("%016lx: Assertion Failure\n", os::GetCurrentProgramId().value);
|
||||
DebugLog(" Location: %s:%d\n", file, line);
|
||||
DebugLog(" Function: %s\n", func);
|
||||
DebugLog(" Expression: %s\n", expr);
|
||||
|
@ -89,7 +83,7 @@ namespace ams::diag {
|
|||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value) {
|
||||
DebugLog("%016lx: Assertion Failure\n", static_cast<u64>(ams::CurrentProgramId));
|
||||
DebugLog("%016lx: Assertion Failure\n", os::GetCurrentProgramId().value);
|
||||
DebugLog(" Location: %s:%d\n", file, line);
|
||||
DebugLog(" Function: %s\n", func);
|
||||
DebugLog(" Expression: %s\n", expr);
|
||||
|
@ -101,7 +95,7 @@ namespace ams::diag {
|
|||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) {
|
||||
DebugLog("%016lx: Abort Called\n", static_cast<u64>(ams::CurrentProgramId));
|
||||
DebugLog("%016lx: Abort Called\n", os::GetCurrentProgramId().value);
|
||||
DebugLog(" Location: %s:%d\n", file, line);
|
||||
DebugLog(" Function: %s\n", func);
|
||||
DebugLog(" Expression: %s\n", expr);
|
||||
|
@ -121,7 +115,7 @@ namespace ams::diag {
|
|||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value) {
|
||||
DebugLog("%016lx: Abort Called\n", static_cast<u64>(ams::CurrentProgramId));
|
||||
DebugLog("%016lx: Abort Called\n", os::GetCurrentProgramId().value);
|
||||
DebugLog(" Location: %s:%d\n", file, line);
|
||||
DebugLog(" Function: %s\n", func);
|
||||
DebugLog(" Expression: %s\n", expr);
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 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 {
|
||||
|
||||
ncm::ProgramId GetCurrentProgramId();
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "os_program_id_impl.hpp"
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
ncm::ProgramId GetCurrentProgramId() {
|
||||
u64 value;
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), svc::InfoType_ProgramId, svc::PseudoHandle::CurrentProcess, 0));
|
||||
return {value};
|
||||
}
|
||||
|
||||
}
|
26
libraries/libstratosphere/source/os/os_program_id.cpp
Normal file
26
libraries/libstratosphere/source/os/os_program_id.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "impl/os_program_id_impl.hpp"
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
ncm::ProgramId GetCurrentProgramId() {
|
||||
return ::ams::os::impl::GetCurrentProgramId();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -34,12 +34,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::AtmosphereProgramId::AtmosphereLogManager;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
#define AMS_LM_USE_FATAL_ERROR 1
|
||||
|
|
|
@ -35,12 +35,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::DevServer;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
#define AMS_TIO_SERVER_USE_FATAL_ERROR 1
|
||||
|
|
|
@ -45,8 +45,6 @@ extern "C" {
|
|||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::AtmosphereProgramId::Mitm;
|
||||
|
||||
/* Override. */
|
||||
void ExceptionHandler(FatalErrorContext *ctx) {
|
||||
/* We're bpc-mitm (or ams_mitm, anyway), so manually reboot to fatal error. */
|
||||
|
|
|
@ -56,8 +56,6 @@ extern "C" {
|
|||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Boot;
|
||||
|
||||
void ExceptionHandler(FatalErrorContext *ctx) {
|
||||
/* We're boot sysmodule, so manually reboot to fatal error. */
|
||||
boot::RebootForFatalError(ctx);
|
||||
|
|
|
@ -39,12 +39,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Boot2;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
|
|
|
@ -42,12 +42,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Creport;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
|
|
|
@ -34,12 +34,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Cs;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
#define AMS_CS_SERVER_USE_FATAL_ERROR 1
|
||||
|
|
|
@ -36,12 +36,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::DmntGen2;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
#define AMS_DMNT2_SERVER_USE_FATAL_ERROR 1
|
||||
|
|
|
@ -36,12 +36,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Dmnt;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
void __libnx_initheap(void) {
|
||||
|
|
|
@ -34,12 +34,6 @@ extern "C" {
|
|||
void __libnx_exception_handler(ThreadExceptionDump *ctx);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Eclct;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
|
|
|
@ -39,12 +39,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Erpt;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
|
|
|
@ -46,12 +46,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Fatal;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
namespace ams::fatal {
|
||||
|
|
|
@ -34,12 +34,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Htc;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
#define AMS_HTC_USE_FATAL_ERROR 1
|
||||
|
|
|
@ -36,11 +36,6 @@ extern "C" {
|
|||
void __libnx_exception_handler(ThreadExceptionDump *ctx);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::JpegDec;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
|
|
|
@ -41,12 +41,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Loader;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
|
|
|
@ -39,12 +39,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Ncm;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -39,12 +39,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Pgl;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
|
|
|
@ -44,12 +44,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Pm;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
|
@ -81,7 +75,7 @@ namespace {
|
|||
/* Doing this here works around a bug fixed in 6.0.0. */
|
||||
/* Not doing so will cause svcDebugActiveProcess to deadlock on lower firmwares if called for it's own process. */
|
||||
if (process_id == os::GetCurrentProcessId()) {
|
||||
return ams::CurrentProgramId;
|
||||
return os::GetCurrentProgramId();
|
||||
}
|
||||
|
||||
/* Get a debug handle. */
|
||||
|
|
|
@ -36,12 +36,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Ro;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
namespace ams::ro {
|
||||
|
|
|
@ -51,8 +51,6 @@ namespace {
|
|||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Sm;
|
||||
|
||||
void NORETURN Exit(int rc) {
|
||||
AMS_ABORT("Exit called by immortal process");
|
||||
}
|
||||
|
|
|
@ -49,12 +49,6 @@ extern "C" {
|
|||
void __libnx_free(void *mem);
|
||||
}
|
||||
|
||||
namespace ams {
|
||||
|
||||
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Spl;
|
||||
|
||||
}
|
||||
|
||||
using namespace ams;
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
||||
|
|
Loading…
Reference in a new issue