diff --git a/libstratosphere/include/stratosphere/os/os_io_region.hpp b/libstratosphere/include/stratosphere/os/os_io_region.hpp index 0f3b00f1..fa3f0543 100644 --- a/libstratosphere/include/stratosphere/os/os_io_region.hpp +++ b/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/libstratosphere/include/stratosphere/os/os_process_handle.hpp b/libstratosphere/include/stratosphere/os/os_process_handle.hpp index 25b49d04..d5b0ae48 100644 --- a/libstratosphere/include/stratosphere/os/os_process_handle.hpp +++ b/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/libstratosphere/source/ams/ams_environment.cpp b/libstratosphere/source/ams/ams_environment.cpp index 04f8f4d1..60873e70 100644 --- a/libstratosphere/source/ams/ams_environment.cpp +++ b/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/libstratosphere/source/diag/diag_assertion_impl.cpp b/libstratosphere/source/diag/diag_assertion_impl.cpp index d075194a..c8b1356d 100644 --- a/libstratosphere/source/diag/diag_assertion_impl.cpp +++ b/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/libstratosphere/source/os/impl/os_program_id_impl.hpp b/libstratosphere/source/os/impl/os_program_id_impl.hpp new file mode 100644 index 00000000..b06105ba --- /dev/null +++ b/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/libstratosphere/source/os/impl/os_program_id_impl.os.horizon.cpp b/libstratosphere/source/os/impl/os_program_id_impl.os.horizon.cpp new file mode 100644 index 00000000..2d722ff5 --- /dev/null +++ b/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/libstratosphere/source/os/os_program_id.cpp b/libstratosphere/source/os/os_program_id.cpp new file mode 100644 index 00000000..323d901a --- /dev/null +++ b/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(); + } + + +}