2019-12-09 11:57:37 +00:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-12-09 11:57:37 +00:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
namespace ams::cfg {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2021-09-30 05:52:50 +00:00
|
|
|
constinit os::SdkMutex g_lock;
|
|
|
|
constinit bool g_got_privileged_process_status = false;
|
|
|
|
constinit os::ProcessId g_min_initial_process_id = os::InvalidProcessId, g_max_initial_process_id = os::InvalidProcessId;
|
|
|
|
constinit os::ProcessId g_cur_process_id = os::InvalidProcessId;
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2021-10-02 00:37:39 +00:00
|
|
|
ALWAYS_INLINE void EnsurePrivilegedProcessStatusCached() {
|
|
|
|
if (AMS_LIKELY(g_got_privileged_process_status)) {
|
|
|
|
return;
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-02 00:37:39 +00:00
|
|
|
std::scoped_lock lk(g_lock);
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2021-10-02 00:37:39 +00:00
|
|
|
if (AMS_LIKELY(!g_got_privileged_process_status)) {
|
|
|
|
R_ABORT_UNLESS(svc::GetSystemInfo(std::addressof(g_min_initial_process_id.value), svc::SystemInfoType_InitialProcessIdRange, svc::InvalidHandle, svc::InitialProcessIdRangeInfo_Minimum));
|
|
|
|
R_ABORT_UNLESS(svc::GetSystemInfo(std::addressof(g_max_initial_process_id.value), svc::SystemInfoType_InitialProcessIdRange, svc::InvalidHandle, svc::InitialProcessIdRangeInfo_Maximum));
|
|
|
|
g_cur_process_id = os::GetCurrentProcessId();
|
|
|
|
|
|
|
|
g_got_privileged_process_status = true;
|
|
|
|
}
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsInitialProcess() {
|
2021-10-02 00:37:39 +00:00
|
|
|
/* Cache initial process range and extents. */
|
|
|
|
EnsurePrivilegedProcessStatusCached();
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2021-10-02 00:37:39 +00:00
|
|
|
/* Determine if we're Initial. */
|
2019-12-09 11:57:37 +00:00
|
|
|
return g_min_initial_process_id <= g_cur_process_id && g_cur_process_id <= g_max_initial_process_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetInitialProcessRange(os::ProcessId *out_min, os::ProcessId *out_max) {
|
2021-10-02 00:37:39 +00:00
|
|
|
/* Cache initial process range and extents. */
|
|
|
|
EnsurePrivilegedProcessStatusCached();
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2021-10-02 00:37:39 +00:00
|
|
|
/* Set output. */
|
2019-12-09 11:57:37 +00:00
|
|
|
*out_min = g_min_initial_process_id;
|
|
|
|
*out_max = g_max_initial_process_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|