git subrepo clone https://github.com/Atmosphere-NX/Atmosphere-libs libraries
subrepo: subdir: "libraries" merged: "07af583b" upstream: origin: "https://github.com/Atmosphere-NX/Atmosphere-libs" branch: "master" commit: "07af583b" git-subrepo: version: "0.4.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "5d6aba9"
This commit is contained in:
92
libraries/libstratosphere/source/pm/pm_ams.c
Normal file
92
libraries/libstratosphere/source/pm/pm_ams.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 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 <switch.h>
|
||||
#include "pm_ams.h"
|
||||
|
||||
Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 program_id) {
|
||||
return serviceDispatchInOut(pminfoGetServiceSession(), 65000, program_id, *out_pid);
|
||||
}
|
||||
|
||||
Result pminfoAtmosphereHasLaunchedProgram(bool *out, u64 program_id) {
|
||||
u8 tmp;
|
||||
Result rc = serviceDispatchInOut(pminfoGetServiceSession(), 65001, program_id, tmp);
|
||||
if (R_SUCCEEDED(rc) && out) *out = tmp & 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result pminfoAtmosphereGetProcessInfo(NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid) {
|
||||
struct {
|
||||
NcmProgramLocation loc;
|
||||
CfgOverrideStatus status;
|
||||
} out;
|
||||
|
||||
Result rc = serviceDispatchInOut(pminfoGetServiceSession(), 65002, pid, out);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
if (loc_out) *loc_out = out.loc;
|
||||
if (status_out) *status_out = out.status;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result pmdmntAtmosphereGetProcessInfo(Handle* handle_out, NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid) {
|
||||
Handle tmp_handle;
|
||||
|
||||
struct {
|
||||
NcmProgramLocation loc;
|
||||
CfgOverrideStatus status;
|
||||
} out;
|
||||
|
||||
Result rc = serviceDispatchInOut(pmdmntGetServiceSession(), 65000, pid, out,
|
||||
.out_handle_attrs = { SfOutHandleAttr_HipcCopy },
|
||||
.out_handles = &tmp_handle,
|
||||
);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
if (handle_out) {
|
||||
*handle_out = tmp_handle;
|
||||
} else {
|
||||
svcCloseHandle(tmp_handle);
|
||||
}
|
||||
|
||||
if (loc_out) *loc_out = out.loc;
|
||||
if (status_out) *status_out = out.status;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result pmdmntAtmosphereGetCurrentLimitInfo(u64 *out_cur, u64 *out_lim, u32 group, u32 resource) {
|
||||
const struct {
|
||||
u32 group;
|
||||
u32 resource;
|
||||
} in = { group, resource };
|
||||
struct {
|
||||
u64 cur;
|
||||
u64 lim;
|
||||
} out;
|
||||
|
||||
Result rc = serviceDispatchInOut(pmdmntGetServiceSession(), 65001, in, out);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
if (out_cur) *out_cur = out.cur;
|
||||
if (out_lim) *out_lim = out.lim;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
28
libraries/libstratosphere/source/pm/pm_ams.h
Normal file
28
libraries/libstratosphere/source/pm/pm_ams.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @file pm_ams.h
|
||||
* @brief Process Manager (pm:*) IPC wrapper for Atmosphere extensions.
|
||||
* @author SciresM
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
u64 keys_held;
|
||||
u64 flags;
|
||||
} CfgOverrideStatus;
|
||||
|
||||
Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 program_id);
|
||||
Result pminfoAtmosphereHasLaunchedProgram(bool *out, u64 program_id);
|
||||
Result pminfoAtmosphereGetProcessInfo(NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid);
|
||||
|
||||
Result pmdmntAtmosphereGetProcessInfo(Handle *out, NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid);
|
||||
Result pmdmntAtmosphereGetCurrentLimitInfo(u64 *out_cur, u64 *out_lim, u32 group, u32 resource);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
32
libraries/libstratosphere/source/pm/pm_boot_mode_api.cpp
Normal file
32
libraries/libstratosphere/source/pm/pm_boot_mode_api.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 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>
|
||||
|
||||
namespace ams::pm::bm {
|
||||
|
||||
/* Boot Mode API. */
|
||||
/* Both functions should be weakly linked, so that they can be overridden by ams::boot2 as needed. */
|
||||
BootMode WEAK GetBootMode() {
|
||||
PmBootMode boot_mode = PmBootMode_Normal;
|
||||
R_ASSERT(pmbmGetBootMode(&boot_mode));
|
||||
return static_cast<BootMode>(boot_mode);
|
||||
}
|
||||
|
||||
void WEAK SetMaintenanceBoot() {
|
||||
R_ASSERT(pmbmSetMaintenanceBoot());
|
||||
}
|
||||
|
||||
}
|
||||
56
libraries/libstratosphere/source/pm/pm_dmnt_api.cpp
Normal file
56
libraries/libstratosphere/source/pm/pm_dmnt_api.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 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 "pm_ams.h"
|
||||
|
||||
namespace ams::pm::dmnt {
|
||||
|
||||
/* Debug Monitor API. */
|
||||
Result StartProcess(os::ProcessId process_id) {
|
||||
return pmdmntStartProcess(static_cast<u64>(process_id));
|
||||
}
|
||||
|
||||
Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id) {
|
||||
return pmdmntGetProcessId(reinterpret_cast<u64 *>(out_process_id), static_cast<u64>(program_id));
|
||||
}
|
||||
|
||||
Result GetApplicationProcessId(os::ProcessId *out_process_id) {
|
||||
return pmdmntGetApplicationProcessId(reinterpret_cast<u64 *>(out_process_id));
|
||||
}
|
||||
|
||||
Result HookToCreateApplicationProcess(Handle *out_handle) {
|
||||
Event evt;
|
||||
R_TRY(pmdmntHookToCreateApplicationProcess(&evt));
|
||||
*out_handle = evt.revent;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) {
|
||||
*out_handle = INVALID_HANDLE;
|
||||
*out_loc = {};
|
||||
*out_status = {};
|
||||
static_assert(sizeof(*out_status) == sizeof(CfgOverrideStatus));
|
||||
return pmdmntAtmosphereGetProcessInfo(out_handle, reinterpret_cast<NcmProgramLocation *>(out_loc), reinterpret_cast<CfgOverrideStatus *>(out_status), static_cast<u64>(process_id));
|
||||
}
|
||||
|
||||
Result AtmosphereGetCurrentLimitInfo(u64 *out_current_value, u64 *out_limit_value, ResourceLimitGroup group, LimitableResource resource) {
|
||||
*out_current_value = 0;
|
||||
*out_limit_value = 0;
|
||||
return pmdmntAtmosphereGetCurrentLimitInfo(out_current_value, out_limit_value, group, resource);
|
||||
}
|
||||
|
||||
}
|
||||
93
libraries/libstratosphere/source/pm/pm_info_api.cpp
Normal file
93
libraries/libstratosphere/source/pm/pm_info_api.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 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 "pm_ams.h"
|
||||
|
||||
namespace ams::pm::info {
|
||||
|
||||
namespace {
|
||||
|
||||
/* Global lock. */
|
||||
os::Mutex g_info_lock;
|
||||
/* TODO: Less memory-intensive storage? */
|
||||
std::set<u64> g_cached_launched_programs;
|
||||
|
||||
}
|
||||
|
||||
/* Information API. */
|
||||
Result GetProgramId(ncm::ProgramId *out_program_id, os::ProcessId process_id) {
|
||||
std::scoped_lock lk(g_info_lock);
|
||||
|
||||
return pminfoGetProgramId(reinterpret_cast<u64 *>(out_program_id), static_cast<u64>(process_id));
|
||||
}
|
||||
|
||||
Result GetProcessId(os::ProcessId *out_process_id, ncm::ProgramId program_id) {
|
||||
std::scoped_lock lk(g_info_lock);
|
||||
|
||||
return pminfoAtmosphereGetProcessId(reinterpret_cast<u64 *>(out_process_id), static_cast<u64>(program_id));
|
||||
}
|
||||
|
||||
Result GetProcessInfo(ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) {
|
||||
std::scoped_lock lk(g_info_lock);
|
||||
|
||||
*out_loc = {};
|
||||
*out_status = {};
|
||||
static_assert(sizeof(*out_status) == sizeof(CfgOverrideStatus));
|
||||
return pminfoAtmosphereGetProcessInfo(reinterpret_cast<NcmProgramLocation *>(out_loc), reinterpret_cast<CfgOverrideStatus *>(out_status), static_cast<u64>(process_id));
|
||||
}
|
||||
|
||||
Result WEAK HasLaunchedProgram(bool *out, ncm::ProgramId program_id) {
|
||||
std::scoped_lock lk(g_info_lock);
|
||||
|
||||
if (g_cached_launched_programs.find(static_cast<u64>(program_id)) != g_cached_launched_programs.end()) {
|
||||
*out = true;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
bool has_launched = false;
|
||||
R_TRY(pminfoAtmosphereHasLaunchedProgram(&has_launched, static_cast<u64>(program_id)));
|
||||
if (has_launched) {
|
||||
g_cached_launched_programs.insert(static_cast<u64>(program_id));
|
||||
}
|
||||
|
||||
*out = has_launched;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
bool HasLaunchedProgram(ncm::ProgramId program_id) {
|
||||
bool has_launched = false;
|
||||
R_ASSERT(HasLaunchedProgram(&has_launched, program_id));
|
||||
return has_launched;
|
||||
}
|
||||
|
||||
|
||||
Result IsHblProcessId(bool *out, os::ProcessId process_id) {
|
||||
ncm::ProgramLocation loc;
|
||||
cfg::OverrideStatus override_status;
|
||||
R_TRY(GetProcessInfo(&loc, &override_status, process_id));
|
||||
|
||||
*out = override_status.IsHbl();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result IsHblProgramId(bool *out, ncm::ProgramId program_id) {
|
||||
os::ProcessId process_id;
|
||||
R_TRY(GetProcessId(&process_id, program_id));
|
||||
|
||||
return IsHblProcessId(out, process_id);
|
||||
}
|
||||
|
||||
}
|
||||
27
libraries/libstratosphere/source/pm/pm_shell_api.cpp
Normal file
27
libraries/libstratosphere/source/pm/pm_shell_api.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 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>
|
||||
|
||||
namespace ams::pm::shell {
|
||||
|
||||
/* Shell API. */
|
||||
Result WEAK LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags) {
|
||||
static_assert(sizeof(ncm::ProgramLocation) == sizeof(NcmProgramLocation));
|
||||
static_assert(alignof(ncm::ProgramLocation) == alignof(NcmProgramLocation));
|
||||
return pmshellLaunchProgram(launch_flags, reinterpret_cast<const NcmProgramLocation *>(&loc), reinterpret_cast<u64 *>(out_process_id));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user