diff --git a/libraries/libstratosphere/include/stratosphere/os/os_io_region.hpp b/libraries/libstratosphere/include/stratosphere/os/os_io_region.hpp index 0f3b00f1a..fa3f05430 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_io_region.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_io_region.hpp @@ -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() { diff --git a/libraries/libstratosphere/include/stratosphere/os/os_process_handle.hpp b/libraries/libstratosphere/include/stratosphere/os/os_process_handle.hpp index 25b49d044..d5b0ae48e 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_process_handle.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_process_handle.hpp @@ -16,13 +16,17 @@ #pragma once #include +#include namespace ams::os { ::Handle GetCurrentProcessHandle(); - NX_INLINE ProcessId GetCurrentProcessId() { + ALWAYS_INLINE ProcessId GetCurrentProcessId() { return GetProcessId(GetCurrentProcessHandle()); } + /* TODO: Another header? */ + ncm::ProgramId GetCurrentProgramId(); + } diff --git a/libraries/libstratosphere/source/ams/ams_environment.cpp b/libraries/libstratosphere/source/ams/ams_environment.cpp index 04f8f4d1f..60873e702 100644 --- a/libraries/libstratosphere/source/ams/ams_environment.cpp +++ b/libraries/libstratosphere/source/ams/ams_environment.cpp @@ -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(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; } diff --git a/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp b/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp index d075194ab..c8b1356d9 100644 --- a/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp +++ b/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp @@ -15,12 +15,6 @@ */ #include -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(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(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(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(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); diff --git a/libraries/libstratosphere/source/os/impl/os_program_id_impl.hpp b/libraries/libstratosphere/source/os/impl/os_program_id_impl.hpp new file mode 100644 index 000000000..b06105ba4 --- /dev/null +++ b/libraries/libstratosphere/source/os/impl/os_program_id_impl.hpp @@ -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 . + */ +#pragma once +#include + +namespace ams::os::impl { + + ncm::ProgramId GetCurrentProgramId(); + +} \ No newline at end of file diff --git a/libraries/libstratosphere/source/os/impl/os_program_id_impl.os.horizon.cpp b/libraries/libstratosphere/source/os/impl/os_program_id_impl.os.horizon.cpp new file mode 100644 index 000000000..2d722ff5a --- /dev/null +++ b/libraries/libstratosphere/source/os/impl/os_program_id_impl.os.horizon.cpp @@ -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 . + */ +#include +#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}; + } + +} diff --git a/libraries/libstratosphere/source/os/os_program_id.cpp b/libraries/libstratosphere/source/os/os_program_id.cpp new file mode 100644 index 000000000..323d901aa --- /dev/null +++ b/libraries/libstratosphere/source/os/os_program_id.cpp @@ -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 . + */ +#include +#include "impl/os_program_id_impl.hpp" + +namespace ams::os { + + ncm::ProgramId GetCurrentProgramId() { + return ::ams::os::impl::GetCurrentProgramId(); + } + + +} diff --git a/stratosphere/LogManager/source/lm_main.cpp b/stratosphere/LogManager/source/lm_main.cpp index 6fbd28412..fe94d8dff 100644 --- a/stratosphere/LogManager/source/lm_main.cpp +++ b/stratosphere/LogManager/source/lm_main.cpp @@ -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 diff --git a/stratosphere/TioServer/source/tio_main.cpp b/stratosphere/TioServer/source/tio_main.cpp index a56b1b107..5de604755 100644 --- a/stratosphere/TioServer/source/tio_main.cpp +++ b/stratosphere/TioServer/source/tio_main.cpp @@ -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 diff --git a/stratosphere/ams_mitm/source/amsmitm_main.cpp b/stratosphere/ams_mitm/source/amsmitm_main.cpp index 0a30d0cc0..33a29d357 100644 --- a/stratosphere/ams_mitm/source/amsmitm_main.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_main.cpp @@ -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. */ diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index 32e3eca32..bcae7dde1 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -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); diff --git a/stratosphere/boot2/source/boot2_main.cpp b/stratosphere/boot2/source/boot2_main.cpp index a1333ea92..4cf576a80 100644 --- a/stratosphere/boot2/source/boot2_main.cpp +++ b/stratosphere/boot2/source/boot2_main.cpp @@ -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) { diff --git a/stratosphere/creport/source/creport_main.cpp b/stratosphere/creport/source/creport_main.cpp index d26616b3a..0c2470a6b 100644 --- a/stratosphere/creport/source/creport_main.cpp +++ b/stratosphere/creport/source/creport_main.cpp @@ -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) { diff --git a/stratosphere/cs/source/cs_main.cpp b/stratosphere/cs/source/cs_main.cpp index 86d882cb8..2abc323ae 100644 --- a/stratosphere/cs/source/cs_main.cpp +++ b/stratosphere/cs/source/cs_main.cpp @@ -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 diff --git a/stratosphere/dmnt.gen2/source/dmnt2_main.cpp b/stratosphere/dmnt.gen2/source/dmnt2_main.cpp index bcfae3223..fd3e9fbe2 100644 --- a/stratosphere/dmnt.gen2/source/dmnt2_main.cpp +++ b/stratosphere/dmnt.gen2/source/dmnt2_main.cpp @@ -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 diff --git a/stratosphere/dmnt/source/dmnt_main.cpp b/stratosphere/dmnt/source/dmnt_main.cpp index 48b1c98aa..5015a8e19 100644 --- a/stratosphere/dmnt/source/dmnt_main.cpp +++ b/stratosphere/dmnt/source/dmnt_main.cpp @@ -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) { diff --git a/stratosphere/eclct.stub/source/eclct_stub.cpp b/stratosphere/eclct.stub/source/eclct_stub.cpp index 172e308e9..e0f687cd1 100644 --- a/stratosphere/eclct.stub/source/eclct_stub.cpp +++ b/stratosphere/eclct.stub/source/eclct_stub.cpp @@ -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) { diff --git a/stratosphere/erpt/source/erpt_main.cpp b/stratosphere/erpt/source/erpt_main.cpp index 9905d2eb8..60f037a13 100644 --- a/stratosphere/erpt/source/erpt_main.cpp +++ b/stratosphere/erpt/source/erpt_main.cpp @@ -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) { diff --git a/stratosphere/fatal/source/fatal_main.cpp b/stratosphere/fatal/source/fatal_main.cpp index b2531b40b..00178842e 100644 --- a/stratosphere/fatal/source/fatal_main.cpp +++ b/stratosphere/fatal/source/fatal_main.cpp @@ -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 { diff --git a/stratosphere/htc/source/htc_main.cpp b/stratosphere/htc/source/htc_main.cpp index 14347e342..8f463813f 100644 --- a/stratosphere/htc/source/htc_main.cpp +++ b/stratosphere/htc/source/htc_main.cpp @@ -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 diff --git a/stratosphere/jpegdec/source/jpegdec_main.cpp b/stratosphere/jpegdec/source/jpegdec_main.cpp index ad7d8aa4b..5403c4cdb 100644 --- a/stratosphere/jpegdec/source/jpegdec_main.cpp +++ b/stratosphere/jpegdec/source/jpegdec_main.cpp @@ -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) { diff --git a/stratosphere/loader/source/ldr_main.cpp b/stratosphere/loader/source/ldr_main.cpp index 09900851f..8cb947add 100644 --- a/stratosphere/loader/source/ldr_main.cpp +++ b/stratosphere/loader/source/ldr_main.cpp @@ -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) { diff --git a/stratosphere/ncm/source/ncm_main.cpp b/stratosphere/ncm/source/ncm_main.cpp index 16065c4f2..4aaf83eb8 100644 --- a/stratosphere/ncm/source/ncm_main.cpp +++ b/stratosphere/ncm/source/ncm_main.cpp @@ -39,12 +39,6 @@ extern "C" { void __libnx_free(void *mem); } -namespace ams { - - ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Ncm; - -} - using namespace ams; namespace { diff --git a/stratosphere/pgl/source/pgl_main.cpp b/stratosphere/pgl/source/pgl_main.cpp index 2330e29b7..24ce1d6b1 100644 --- a/stratosphere/pgl/source/pgl_main.cpp +++ b/stratosphere/pgl/source/pgl_main.cpp @@ -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) { diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index 6cd95e5e2..177dbfeeb 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -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. */ diff --git a/stratosphere/ro/source/ro_main.cpp b/stratosphere/ro/source/ro_main.cpp index 47249e885..33631290b 100644 --- a/stratosphere/ro/source/ro_main.cpp +++ b/stratosphere/ro/source/ro_main.cpp @@ -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 { diff --git a/stratosphere/sm/source/sm_main.cpp b/stratosphere/sm/source/sm_main.cpp index b30f9a7a4..7dfd22331 100644 --- a/stratosphere/sm/source/sm_main.cpp +++ b/stratosphere/sm/source/sm_main.cpp @@ -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"); } diff --git a/stratosphere/spl/source/spl_main.cpp b/stratosphere/spl/source/spl_main.cpp index dbd48321e..e74e37c32 100644 --- a/stratosphere/spl/source/spl_main.cpp +++ b/stratosphere/spl/source/spl_main.cpp @@ -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) {