strat: automatic program id detection

This commit is contained in:
Michael Scire 2021-10-01 17:18:50 -07:00
parent 57f439afe7
commit 28756234d9
7 changed files with 87 additions and 15 deletions

View File

@ -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() {

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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();
}

View File

@ -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};
}
}

View 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();
}
}