1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-18 01:46:47 +00:00
Atmosphere/libraries/libstratosphere/source/fssystem/fssystem_external_code.cpp

94 lines
2.9 KiB
C++
Raw Normal View History

2020-03-09 10:10:12 +00:00
/*
* Copyright (c) Atmosphère-NX
2020-03-09 10:10:12 +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::fssystem {
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
2020-03-09 10:10:12 +00:00
namespace {
constexpr inline size_t MaxExternalCodeFileSystem = 0x10;
util::BoundedMap<ncm::ProgramId, fs::RemoteFileSystem, MaxExternalCodeFileSystem> g_ecs_map;
util::BoundedMap<ncm::ProgramId, os::NativeHandle, MaxExternalCodeFileSystem> g_hnd_map;
2020-03-09 10:10:12 +00:00
}
fs::fsa::IFileSystem *GetExternalCodeFileSystem(ncm::ProgramId program_id) {
/* Return a fs from the map if one exists. */
if (auto *fs = g_ecs_map.Find(program_id); fs != nullptr) {
return fs;
}
/* Otherwise, we may have a handle. */
if (auto *hnd = g_hnd_map.Find(program_id); hnd != nullptr) {
/* Create a service using libnx bindings. */
Service srv;
serviceCreate(std::addressof(srv), *hnd);
2020-03-09 10:10:12 +00:00
g_hnd_map.Remove(program_id);
/* Create a remote filesystem. */
const FsFileSystem fs = { srv };
g_ecs_map.Emplace(program_id, fs);
/* Return the created filesystem. */
return g_ecs_map.Find(program_id);
}
/* Otherwise, we have no filesystem. */
return nullptr;
}
2021-10-04 22:54:13 +01:00
Result CreateExternalCode(os::NativeHandle *out, ncm::ProgramId program_id) {
2020-03-09 10:10:12 +00:00
/* Create a handle pair. */
2021-10-04 22:54:13 +01:00
os::NativeHandle server, client;
R_TRY(svc::CreateSession(std::addressof(server), std::addressof(client), false, 0));
2020-03-09 10:10:12 +00:00
/* Insert the handle into the map. */
g_hnd_map.Emplace(program_id, client);
*out = server;
2022-03-26 07:14:36 +00:00
R_SUCCEED();
2020-03-09 10:10:12 +00:00
}
void DestroyExternalCode(ncm::ProgramId program_id) {
g_ecs_map.Remove(program_id);
if (auto *hnd = g_hnd_map.Find(program_id); hnd != nullptr) {
os::CloseNativeHandle(*hnd);
g_hnd_map.Remove(program_id);
}
2020-03-09 10:10:12 +00:00
}
#else
fs::fsa::IFileSystem *GetExternalCodeFileSystem(ncm::ProgramId program_id) {
AMS_UNUSED(program_id);
return nullptr;
}
Result CreateExternalCode(os::NativeHandle *out, ncm::ProgramId program_id) {
AMS_UNUSED(out, program_id);
R_THROW(fs::ResultNotImplemented());
}
void DestroyExternalCode(ncm::ProgramId program_id) {
AMS_UNUSED(program_id);
}
#endif
2020-03-09 10:10:12 +00:00
}