mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-30 06:25:20 -04:00
fssrv: skeleton more program registry logic
This commit is contained in:
parent
33701bb387
commit
e8d14eb77d
13 changed files with 448 additions and 3 deletions
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 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/fssrv_program_info.hpp"
|
||||
|
||||
namespace ams::fssrv {
|
||||
|
||||
FileSystemProxyImpl::FileSystemProxyImpl() {
|
||||
/* TODO: Set core impl. */
|
||||
m_process_id = os::InvalidProcessId.value;
|
||||
}
|
||||
|
||||
FileSystemProxyImpl::~FileSystemProxyImpl() {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
Result FileSystemProxyImpl::OpenCodeFileSystemDeprecated(ams::sf::Out<ams::sf::SharedPointer<fssrv::sf::IFileSystem>> out_fs, const fssrv::sf::Path &path, ncm::ProgramId program_id) {
|
||||
AMS_ABORT("TODO");
|
||||
AMS_UNUSED(out_fs, path, program_id);
|
||||
}
|
||||
|
||||
Result FileSystemProxyImpl::OpenCodeFileSystem(ams::sf::Out<ams::sf::SharedPointer<fssrv::sf::IFileSystem>> out_fs, ams::sf::Out<fs::CodeVerificationData> out_verif, const fssrv::sf::Path &path, ncm::ProgramId program_id) {
|
||||
AMS_ABORT("TODO");
|
||||
AMS_UNUSED(out_fs, out_verif, path, program_id);
|
||||
}
|
||||
|
||||
Result FileSystemProxyImpl::IsArchivedProgram(ams::sf::Out<bool> out, u64 process_id) {
|
||||
AMS_ABORT("TODO");
|
||||
AMS_UNUSED(out, process_id);
|
||||
}
|
||||
|
||||
Result FileSystemProxyImpl::SetCurrentProcess(const ams::sf::ClientProcessId &client_pid) {
|
||||
/* Set current process. */
|
||||
m_process_id = client_pid.GetValue().value;
|
||||
|
||||
/* TODO: Allocate NcaFileSystemService. */
|
||||
AMS_ABORT("TODO");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 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/fssrv_program_info.hpp"
|
||||
|
||||
namespace ams::fssrv {
|
||||
|
||||
namespace {
|
||||
|
||||
constinit ProgramRegistryServiceImpl *g_impl = nullptr;
|
||||
|
||||
}
|
||||
|
||||
ProgramRegistryImpl::ProgramRegistryImpl() : m_process_id(os::InvalidProcessId.value) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
ProgramRegistryImpl::~ProgramRegistryImpl() {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
void ProgramRegistryImpl::Initialize(ProgramRegistryServiceImpl *service) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(g_impl != nullptr);
|
||||
AMS_ASSERT(g_impl == nullptr);
|
||||
|
||||
/* Set the global service. */
|
||||
g_impl = service;
|
||||
}
|
||||
|
||||
Result ProgramRegistryImpl::RegisterProgram(u64 process_id, u64 program_id, u8 storage_id, const ams::sf::InBuffer &data, s64 data_size, const ams::sf::InBuffer &desc, s64 desc_size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(g_impl != nullptr);
|
||||
|
||||
/* Check that we're allowed to register. */
|
||||
R_UNLESS(fssrv::impl::IsInitialProgram(m_process_id), fs::ResultPermissionDenied());
|
||||
|
||||
/* Check buffer sizes. */
|
||||
R_UNLESS(data.GetSize() >= static_cast<size_t>(data_size), fs::ResultInvalidSize());
|
||||
R_UNLESS(desc.GetSize() >= static_cast<size_t>(desc_size), fs::ResultInvalidSize());
|
||||
|
||||
/* Register the program. */
|
||||
return g_impl->RegisterProgramInfo(process_id, program_id, storage_id, data.GetPointer(), data_size, desc.GetPointer(), desc_size);
|
||||
}
|
||||
|
||||
Result ProgramRegistryImpl::UnregisterProgram(u64 process_id) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(g_impl != nullptr);
|
||||
|
||||
/* Check that we're allowed to register. */
|
||||
R_UNLESS(fssrv::impl::IsInitialProgram(m_process_id), fs::ResultPermissionDenied());
|
||||
|
||||
/* Unregister the program. */
|
||||
return g_impl->UnregisterProgramInfo(process_id);
|
||||
}
|
||||
|
||||
Result ProgramRegistryImpl::SetCurrentProcess(const ams::sf::ClientProcessId &client_pid) {
|
||||
/* Set our process id. */
|
||||
m_process_id = client_pid.GetValue().value;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ProgramRegistryImpl::SetEnabledProgramVerification(bool en) {
|
||||
/* TODO: How to deal with this backwards compat? */
|
||||
AMS_ABORT("TODO: SetEnabledProgramVerification");
|
||||
AMS_UNUSED(en);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 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/fssrv_program_info.hpp"
|
||||
|
||||
namespace ams::fssrv {
|
||||
|
||||
Result ProgramRegistryServiceImpl::RegisterProgramInfo(u64 process_id, u64 program_id, u8 storage_id, const void *data, s64 data_size, const void *desc, s64 desc_size) {
|
||||
AMS_ABORT("TODO");
|
||||
AMS_UNUSED(process_id, program_id, storage_id, data, data_size, desc, desc_size);
|
||||
}
|
||||
|
||||
Result ProgramRegistryServiceImpl::UnregisterProgramInfo(u64 process_id) {
|
||||
AMS_ABORT("TODO");
|
||||
AMS_UNUSED(process_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 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 "fssrv_program_info.hpp"
|
||||
|
||||
namespace ams::fssrv::impl {
|
||||
|
||||
namespace {
|
||||
|
||||
constinit os::SdkMutex g_mutex;
|
||||
constinit bool g_initialized = false;
|
||||
|
||||
constinit u64 g_initial_process_id_min = 0;
|
||||
constinit u64 g_initial_process_id_max = 0;
|
||||
|
||||
constinit u64 g_current_process_id = 0;
|
||||
|
||||
ALWAYS_INLINE void InitializeInitialAndCurrentProcessId() {
|
||||
if (AMS_UNLIKELY(!g_initialized)) {
|
||||
std::scoped_lock lk(g_mutex);
|
||||
if (AMS_LIKELY(!g_initialized)) {
|
||||
/* Get initial process id range. */
|
||||
R_ABORT_UNLESS(svc::GetSystemInfo(std::addressof(g_initial_process_id_min), svc::SystemInfoType_InitialProcessIdRange, svc::InvalidHandle, svc::InitialProcessIdRangeInfo_Minimum));
|
||||
R_ABORT_UNLESS(svc::GetSystemInfo(std::addressof(g_initial_process_id_max), svc::SystemInfoType_InitialProcessIdRange, svc::InvalidHandle, svc::InitialProcessIdRangeInfo_Maximum));
|
||||
|
||||
AMS_ABORT_UNLESS(0 < g_initial_process_id_min);
|
||||
AMS_ABORT_UNLESS(g_initial_process_id_min <= g_initial_process_id_max);
|
||||
|
||||
/* Get current procss id. */
|
||||
R_ABORT_UNLESS(svc::GetProcessId(std::addressof(g_current_process_id), svc::PseudoHandle::CurrentProcess));
|
||||
|
||||
/* Set initialized. */
|
||||
g_initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool IsInitialProgram(u64 process_id) {
|
||||
/* Initialize/sanity check. */
|
||||
InitializeInitialAndCurrentProcessId();
|
||||
AMS_ABORT_UNLESS(g_initial_process_id_min > 0);
|
||||
|
||||
/* Check process id in range. */
|
||||
return g_initial_process_id_min <= process_id && process_id <= g_initial_process_id_max;
|
||||
}
|
||||
|
||||
bool IsCurrentProcess(u64 process_id) {
|
||||
/* Initialize. */
|
||||
InitializeInitialAndCurrentProcessId();
|
||||
|
||||
return process_id == g_current_process_id;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 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::fssrv::impl {
|
||||
|
||||
class ProgramInfo : public ::ams::fs::impl::Newable {
|
||||
private:
|
||||
u64 m_process_id;
|
||||
ncm::ProgramId m_program_id;
|
||||
ncm::StorageId m_storage_id;
|
||||
/* TODO: AccessControl m_access_control; */
|
||||
public:
|
||||
ProgramInfo(u64 process_id, u64 program_id, u8 storage_id, const void *data, s64 data_size, const void *desc, s64 desc_size) : m_process_id(process_id) /* TODO: m_access_control */ {
|
||||
m_program_id.value = program_id;
|
||||
m_storage_id = static_cast<ncm::StorageId>(storage_id);
|
||||
|
||||
/* TODO */
|
||||
AMS_UNUSED(data, data_size, desc, desc_size);
|
||||
}
|
||||
};
|
||||
|
||||
struct ProgramInfoNode : public util::IntrusiveListBaseNode<ProgramInfoNode>, public ::ams::fs::impl::Newable {
|
||||
std::shared_ptr<ProgramInfo> program_info;
|
||||
};
|
||||
|
||||
bool IsInitialProgram(u64 process_id);
|
||||
bool IsCurrentProcess(u64 process_id);
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 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>
|
||||
#include "fssrv_program_info.hpp"
|
||||
|
||||
namespace ams::fssrv::impl {
|
||||
|
||||
class ProgramRegistryManager {
|
||||
NON_COPYABLE(ProgramRegistryManager);
|
||||
NON_MOVEABLE(ProgramRegistryManager);
|
||||
private:
|
||||
using ProgramInfoList = util::IntrusiveListBaseTraits<ProgramInfoNode>::ListType;
|
||||
private:
|
||||
ProgramInfoList m_program_info_list{};
|
||||
os::SdkMutex m_mutex{};
|
||||
public:
|
||||
constexpr ProgramRegistryManager() = default;
|
||||
|
||||
Result RegisterProgram(u64 process_id, u64 program_id, u8 storage_id, const void *data, s64 data_size, const void *desc, s64 desc_size);
|
||||
Result UnregisterProgram(u64 process_id);
|
||||
|
||||
Result GetProgramInfo(std::shared_ptr<ProgramInfo> *out, u64 process_id);
|
||||
Result GetProgramInfoByProgramId(std::shared_ptr<ProgramInfo> *out, u64 program_id);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
AMS_FSSYSTEM_ENABLE_PIMPL(::ams::fssrv::impl::ProgramRegistryManager);
|
|
@ -14,6 +14,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "../fssrv/impl/fssrv_program_registry_manager.hpp"
|
||||
|
||||
namespace ams::fssystem {
|
||||
|
||||
|
@ -22,7 +23,7 @@ namespace ams::fssystem {
|
|||
|
||||
namespace {
|
||||
|
||||
constexpr inline auto FileSystemProxyServerThreadCount = 5;
|
||||
constexpr inline auto FileSystemProxyServerThreadCount = fssrv::FileSystemProxyServerActiveSessionCount;
|
||||
|
||||
/* TODO: Heap sizes need to match FS, when this is FS in master rather than ams.mitm. */
|
||||
|
||||
|
@ -152,6 +153,8 @@ namespace ams::fssystem {
|
|||
};
|
||||
|
||||
/* TODO FS-REIMPL: Revise above for latest firmware, all the new Services creation. */
|
||||
fssrv::ProgramRegistryServiceImpl program_registry_service(fssrv::ProgramRegistryServiceImpl::Configuration{});
|
||||
fssrv::ProgramRegistryImpl::Initialize(std::addressof(program_registry_service));
|
||||
|
||||
/* TODO FS-REIMPL: Memory Report Creators, fssrv::SetMemoryReportCreator */
|
||||
|
||||
|
@ -166,7 +169,7 @@ namespace ams::fssystem {
|
|||
fs::SetEnabledAutoAbort(false);
|
||||
|
||||
/* Initialize fsp server. */
|
||||
fssrv::InitializeFileSystemProxyServer(fssrv::FileSystemProxyServerActiveSessionCount);
|
||||
fssrv::InitializeFileSystemProxyServer(FileSystemProxyServerThreadCount);
|
||||
|
||||
/* TODO FS-REIMPL: Cleanup calls. */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue