1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-22 20:06:40 +00:00

fssrv: skeleton more program registry logic

This commit is contained in:
Michael Scire 2021-12-07 02:04:39 -08:00 committed by SciresM
parent 33701bb387
commit e8d14eb77d
13 changed files with 448 additions and 3 deletions

View file

@ -31,4 +31,5 @@
#include <stratosphere/fssrv/fssrv_file_system_proxy_server_session_resource_manager.hpp>
#include <stratosphere/fssrv/impl/fssrv_file_system_proxy_service_object.hpp>
#include <stratosphere/fssrv/fssrv_program_registry_impl.hpp>
#include <stratosphere/fssrv/fssrv_program_registry_service.hpp>
#include <stratosphere/fssrv/fssrv_file_system_proxy_api.hpp>

View file

@ -27,12 +27,16 @@ namespace ams::fssrv {
}
class NcaFileSystemService;
class SaveDataFileSystemService;
class FileSystemProxyImpl {
NON_COPYABLE(FileSystemProxyImpl);
NON_MOVEABLE(FileSystemProxyImpl);
private:
impl::FileSystemProxyCoreImpl *m_impl;
/* TODO: service pointers. */
std::shared_ptr<NcaFileSystemService> m_nca_service;
std::shared_ptr<SaveDataFileSystemService> m_save_data_service;
u64 m_process_id;
public:
FileSystemProxyImpl();

View file

@ -19,6 +19,8 @@
namespace ams::fssrv {
class ProgramRegistryServiceImpl;
namespace impl {
class ProgramInfo;
@ -33,6 +35,8 @@ namespace ams::fssrv {
public:
ProgramRegistryImpl();
~ProgramRegistryImpl();
public:
static void Initialize(ProgramRegistryServiceImpl *service);
public:
Result 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);
Result UnregisterProgram(u64 process_id);

View file

@ -0,0 +1,46 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/fssystem/fssystem_pimpl.hpp>
namespace ams::fssrv {
namespace impl {
class ProgramInfo;
class ProgramRegistryManager;
class ProgramIndexMapInfoManager;
}
class ProgramRegistryServiceImpl {
public:
struct Configuration {
/* ... */
};
private:
Configuration m_config;
fssystem::Pimpl<impl::ProgramRegistryManager, 0x40> m_registry_manager;
fssystem::Pimpl<impl::ProgramIndexMapInfoManager, 0x50> m_index_map_info_manager;
public:
ProgramRegistryServiceImpl(const Configuration &cfg) : m_config(cfg) { /* ... */ }
Result RegisterProgramInfo(u64 process_id, u64 program_id, u8 storage_id, const void *data, s64 data_size, const void *desc, s64 desc_size);
Result UnregisterProgramInfo(u64 process_id);
};
}

View file

@ -18,6 +18,7 @@
#include <stratosphere/ncm/ncm_ids.hpp>
#include <stratosphere/fs/impl/fs_newable.hpp>
#include <stratosphere/fs/fs_program_index_map_info.hpp>
#include <stratosphere/fssystem/fssystem_pimpl.hpp>
namespace ams::fssrv::impl {
@ -156,3 +157,5 @@ namespace ams::fssrv::impl {
}
AMS_FSSYSTEM_ENABLE_PIMPL(::ams::fssrv::impl::ProgramIndexMapInfoManager)

View file

@ -0,0 +1,62 @@
/*
* 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 <vapours.hpp>
namespace ams::fssystem {
namespace impl {
template<typename T, size_t Size>
struct PimplHelper {
static void Construct(void *);
static void Destroy(void *);
};
}
template<typename T, size_t Size>
class Pimpl {
private:
alignas(0x10) u8 m_storage[Size];
public:
ALWAYS_INLINE Pimpl() { impl::PimplHelper<T, Size>::Construct(m_storage); }
ALWAYS_INLINE ~Pimpl() { impl::PimplHelper<T, Size>::Destroy(m_storage); }
ALWAYS_INLINE T *Get() { return reinterpret_cast<T *>(m_storage + 0); }
ALWAYS_INLINE T *operator->() { return reinterpret_cast<T *>(m_storage + 0); }
};
#define AMS_FSSYSTEM_ENABLE_PIMPL(_CLASSNAME_) \
namespace ams::fssystem::impl { \
\
template<size_t Size> \
struct PimplHelper<_CLASSNAME_, Size> { \
static ALWAYS_INLINE void Construct(void *p) { \
static_assert(sizeof(_CLASSNAME_) <= Size); \
static_assert(alignof(_CLASSNAME_) <= 0x10); \
\
std::construct_at(static_cast<_CLASSNAME_ *>(p)); \
} \
\
static ALWAYS_INLINE void Destroy(void *p) { \
std::destroy_at(static_cast<_CLASSNAME_ *>(p)); \
} \
}; \
\
}
}

View file

@ -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");
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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. */