summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core.cpp5
-rw-r--r--src/core/file_sys/registered_cache.cpp2
-rw-r--r--src/core/file_sys/vfs_real.cpp6
-rw-r--r--src/core/file_sys/vfs_real.h20
-rw-r--r--src/core/file_sys/xts_archive.cpp1
-rw-r--r--src/core/hle/kernel/kernel.cpp24
-rw-r--r--src/core/hle/kernel/kernel.h18
-rw-r--r--src/core/hle/kernel/svc.cpp12
-rw-r--r--src/core/hle/service/filesystem/filesystem.cpp7
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp30
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.h2
-rw-r--r--src/core/hle/service/service.cpp9
-rw-r--r--src/core/hle/service/service.h7
-rw-r--r--src/core/loader/loader.cpp5
-rw-r--r--src/core/loader/loader.h6
15 files changed, 117 insertions, 37 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 2cfae18df..29983b9b4 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -14,6 +14,9 @@
#include "core/core.h"
#include "core/core_cpu.h"
#include "core/core_timing.h"
+#include "core/file_sys/mode.h"
+#include "core/file_sys/vfs_concat.h"
+#include "core/file_sys/vfs_real.h"
#include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/kernel.h"
@@ -27,8 +30,6 @@
#include "core/perf_stats.h"
#include "core/settings.h"
#include "core/telemetry_session.h"
-#include "file_sys/vfs_concat.h"
-#include "file_sys/vfs_real.h"
#include "video_core/debug_utils/debug_utils.h"
#include "video_core/gpu.h"
#include "video_core/renderer_base.h"
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp
index dacf8568b..fe5d36930 100644
--- a/src/core/file_sys/registered_cache.cpp
+++ b/src/core/file_sys/registered_cache.cpp
@@ -5,9 +5,9 @@
#include <regex>
#include <mbedtls/sha256.h>
#include "common/assert.h"
+#include "common/file_util.h"
#include "common/hex_util.h"
#include "common/logging/log.h"
-#include "core/crypto/encryption_layer.h"
#include "core/file_sys/card_image.h"
#include "core/file_sys/nca_metadata.h"
#include "core/file_sys/registered_cache.h"
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp
index 2b8ac7103..89b101145 100644
--- a/src/core/file_sys/vfs_real.cpp
+++ b/src/core/file_sys/vfs_real.cpp
@@ -8,6 +8,7 @@
#include <utility>
#include "common/assert.h"
#include "common/common_paths.h"
+#include "common/file_util.h"
#include "common/logging/log.h"
#include "core/file_sys/vfs_real.h"
@@ -39,6 +40,7 @@ static std::string ModeFlagsToString(Mode mode) {
}
RealVfsFilesystem::RealVfsFilesystem() : VfsFilesystem(nullptr) {}
+RealVfsFilesystem::~RealVfsFilesystem() = default;
std::string RealVfsFilesystem::GetName() const {
return "Real";
@@ -219,6 +221,8 @@ RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::shared_ptr<FileUtil::IOF
parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)),
perms(perms_) {}
+RealVfsFile::~RealVfsFile() = default;
+
std::string RealVfsFile::GetName() const {
return path_components.back();
}
@@ -312,6 +316,8 @@ RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string&
FileUtil::CreateDir(path);
}
+RealVfsDirectory::~RealVfsDirectory() = default;
+
std::shared_ptr<VfsFile> RealVfsDirectory::GetFileRelative(std::string_view path) const {
const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path));
if (!FileUtil::Exists(full_path) || FileUtil::IsDirectory(full_path))
diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h
index 989803d43..7db86691f 100644
--- a/src/core/file_sys/vfs_real.h
+++ b/src/core/file_sys/vfs_real.h
@@ -6,15 +6,19 @@
#include <string_view>
#include <boost/container/flat_map.hpp>
-#include "common/file_util.h"
#include "core/file_sys/mode.h"
#include "core/file_sys/vfs.h"
+namespace FileUtil {
+class IOFile;
+}
+
namespace FileSys {
class RealVfsFilesystem : public VfsFilesystem {
public:
RealVfsFilesystem();
+ ~RealVfsFilesystem() override;
std::string GetName() const override;
bool IsReadable() const override;
@@ -40,10 +44,9 @@ class RealVfsFile : public VfsFile {
friend class RealVfsDirectory;
friend class RealVfsFilesystem;
- RealVfsFile(RealVfsFilesystem& base, std::shared_ptr<FileUtil::IOFile> backing,
- const std::string& path, Mode perms = Mode::Read);
-
public:
+ ~RealVfsFile() override;
+
std::string GetName() const override;
size_t GetSize() const override;
bool Resize(size_t new_size) override;
@@ -55,6 +58,9 @@ public:
bool Rename(std::string_view name) override;
private:
+ RealVfsFile(RealVfsFilesystem& base, std::shared_ptr<FileUtil::IOFile> backing,
+ const std::string& path, Mode perms = Mode::Read);
+
bool Close();
RealVfsFilesystem& base;
@@ -70,9 +76,9 @@ private:
class RealVfsDirectory : public VfsDirectory {
friend class RealVfsFilesystem;
- RealVfsDirectory(RealVfsFilesystem& base, const std::string& path, Mode perms = Mode::Read);
-
public:
+ ~RealVfsDirectory() override;
+
std::shared_ptr<VfsFile> GetFileRelative(std::string_view path) const override;
std::shared_ptr<VfsDirectory> GetDirectoryRelative(std::string_view path) const override;
std::shared_ptr<VfsFile> GetFile(std::string_view name) const override;
@@ -97,6 +103,8 @@ protected:
bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override;
private:
+ RealVfsDirectory(RealVfsFilesystem& base, const std::string& path, Mode perms = Mode::Read);
+
template <typename T, typename R>
std::vector<std::shared_ptr<R>> IterateEntries() const;
diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp
index 552835738..4dbc25c55 100644
--- a/src/core/file_sys/xts_archive.cpp
+++ b/src/core/file_sys/xts_archive.cpp
@@ -10,6 +10,7 @@
#include <mbedtls/md.h>
#include <mbedtls/sha256.h>
#include "common/assert.h"
+#include "common/file_util.h"
#include "common/hex_util.h"
#include "common/logging/log.h"
#include "core/crypto/aes_util.h"
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 615d7901a..7902c2882 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -13,6 +13,7 @@
#include "core/core.h"
#include "core/core_timing.h"
+#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/process.h"
@@ -124,6 +125,8 @@ struct KernelCore::Impl {
timer_callback_handle_table.Clear();
timer_callback_event_type = nullptr;
+
+ named_ports.clear();
}
void InitializeResourceLimits(KernelCore& kernel) {
@@ -217,6 +220,10 @@ struct KernelCore::Impl {
// TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future,
// allowing us to simply use a pool index or similar.
Kernel::HandleTable thread_wakeup_callback_handle_table;
+
+ /// Map of named ports managed by the kernel, which can be retrieved using
+ /// the ConnectToPort SVC.
+ NamedPortTable named_ports;
};
KernelCore::KernelCore() : impl{std::make_unique<Impl>()} {}
@@ -257,6 +264,23 @@ void KernelCore::AppendNewProcess(SharedPtr<Process> process) {
impl->process_list.push_back(std::move(process));
}
+void KernelCore::AddNamedPort(std::string name, SharedPtr<ClientPort> port) {
+ impl->named_ports.emplace(std::move(name), std::move(port));
+}
+
+KernelCore::NamedPortTable::iterator KernelCore::FindNamedPort(const std::string& name) {
+ return impl->named_ports.find(name);
+}
+
+KernelCore::NamedPortTable::const_iterator KernelCore::FindNamedPort(
+ const std::string& name) const {
+ return impl->named_ports.find(name);
+}
+
+bool KernelCore::IsValidNamedPort(NamedPortTable::const_iterator port) const {
+ return port != impl->named_ports.cend();
+}
+
u32 KernelCore::CreateNewObjectID() {
return impl->next_object_id++;
}
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 089e959ac..ab2e9bffa 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -4,6 +4,8 @@
#pragma once
+#include <string>
+#include <unordered_map>
#include "core/hle/kernel/object.h"
template <typename T>
@@ -15,6 +17,7 @@ struct EventType;
namespace Kernel {
+class ClientPort;
class HandleTable;
class Process;
class ResourceLimit;
@@ -25,6 +28,9 @@ enum class ResourceLimitCategory : u8;
/// Represents a single instance of the kernel.
class KernelCore {
+private:
+ using NamedPortTable = std::unordered_map<std::string, SharedPtr<ClientPort>>;
+
public:
KernelCore();
~KernelCore();
@@ -59,6 +65,18 @@ public:
/// Adds the given shared pointer to an internal list of active processes.
void AppendNewProcess(SharedPtr<Process> process);
+ /// Adds a port to the named port table
+ void AddNamedPort(std::string name, SharedPtr<ClientPort> port);
+
+ /// Finds a port within the named port table with the given name.
+ NamedPortTable::iterator FindNamedPort(const std::string& name);
+
+ /// Finds a port within the named port table with the given name.
+ NamedPortTable::const_iterator FindNamedPort(const std::string& name) const;
+
+ /// Determines whether or not the given port is a valid named port.
+ bool IsValidNamedPort(NamedPortTable::const_iterator port) const;
+
private:
friend class Object;
friend class Process;
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 5da71cff0..1c9373ed8 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -68,19 +68,22 @@ static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
/// Connect to an OS service given the port name, returns the handle to the port to out
static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address) {
- if (!Memory::IsValidVirtualAddress(port_name_address))
+ if (!Memory::IsValidVirtualAddress(port_name_address)) {
return ERR_NOT_FOUND;
+ }
static constexpr std::size_t PortNameMaxLength = 11;
// Read 1 char beyond the max allowed port name to detect names that are too long.
std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1);
- if (port_name.size() > PortNameMaxLength)
+ if (port_name.size() > PortNameMaxLength) {
return ERR_PORT_NAME_TOO_LONG;
+ }
LOG_TRACE(Kernel_SVC, "called port_name={}", port_name);
- auto it = Service::g_kernel_named_ports.find(port_name);
- if (it == Service::g_kernel_named_ports.end()) {
+ auto& kernel = Core::System::GetInstance().Kernel();
+ auto it = kernel.FindNamedPort(port_name);
+ if (!kernel.IsValidNamedPort(it)) {
LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: {}", port_name);
return ERR_NOT_FOUND;
}
@@ -91,7 +94,6 @@ static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address
CASCADE_RESULT(client_session, client_port->Connect());
// Return the client session
- auto& kernel = Core::System::GetInstance().Kernel();
CASCADE_RESULT(*out_handle, kernel.HandleTable().Create(client_session));
return RESULT_SUCCESS;
}
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp
index 881c39e31..a4426af96 100644
--- a/src/core/hle/service/filesystem/filesystem.cpp
+++ b/src/core/hle/service/filesystem/filesystem.cpp
@@ -60,17 +60,20 @@ ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64
ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) const {
std::string path(FileUtil::SanitizePath(path_));
- auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
if (path.empty()) {
// TODO(DarkLordZach): Why do games call this and what should it do? Works as is but...
return RESULT_SUCCESS;
}
- if (dir->GetFile(FileUtil::GetFilename(path)) == nullptr)
+
+ auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
+ if (dir->GetFile(FileUtil::GetFilename(path)) == nullptr) {
return FileSys::ERROR_PATH_NOT_FOUND;
+ }
if (!dir->DeleteFile(FileUtil::GetFilename(path))) {
// TODO(DarkLordZach): Find a better error code for this
return ResultCode(-1);
}
+
return RESULT_SUCCESS;
}
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index 5759299fe..3f8ff67e8 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -26,6 +26,17 @@
namespace Service::FileSystem {
+enum class FileSystemType : u8 {
+ Invalid0 = 0,
+ Invalid1 = 1,
+ Logo = 2,
+ ContentControl = 3,
+ ContentManual = 4,
+ ContentMeta = 5,
+ ContentData = 6,
+ ApplicationPackage = 7,
+};
+
class IStorage final : public ServiceFramework<IStorage> {
public:
explicit IStorage(FileSys::VirtualFile backend_)
@@ -420,7 +431,7 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") {
{0, nullptr, "MountContent"},
{1, &FSP_SRV::Initialize, "Initialize"},
{2, nullptr, "OpenDataFileSystemByCurrentProcess"},
- {7, nullptr, "OpenFileSystemWithPatch"},
+ {7, &FSP_SRV::OpenFileSystemWithPatch, "OpenFileSystemWithPatch"},
{8, nullptr, "OpenFileSystemWithId"},
{9, nullptr, "OpenDataFileSystemByApplicationId"},
{11, nullptr, "OpenBisFileSystem"},
@@ -444,7 +455,7 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") {
{34, nullptr, "GetCacheStorageSize"},
{51, &FSP_SRV::MountSaveData, "MountSaveData"},
{52, nullptr, "OpenSaveDataFileSystemBySystemSaveDataId"},
- {53, nullptr, "OpenReadOnlySaveDataFileSystem"},
+ {53, &FSP_SRV::OpenReadOnlySaveDataFileSystem, "OpenReadOnlySaveDataFileSystem"},
{57, nullptr, "ReadSaveDataFileSystemExtraDataBySaveDataSpaceId"},
{58, nullptr, "ReadSaveDataFileSystemExtraData"},
{59, nullptr, "WriteSaveDataFileSystemExtraData"},
@@ -516,6 +527,16 @@ void FSP_SRV::Initialize(Kernel::HLERequestContext& ctx) {
rb.Push(RESULT_SUCCESS);
}
+void FSP_SRV::OpenFileSystemWithPatch(Kernel::HLERequestContext& ctx) {
+ IPC::RequestParser rp{ctx};
+
+ const auto type = rp.PopRaw<FileSystemType>();
+ const auto title_id = rp.PopRaw<u64>();
+
+ IPC::ResponseBuilder rb{ctx, 2, 0, 0};
+ rb.Push(ResultCode(-1));
+}
+
void FSP_SRV::MountSdCard(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_FS, "called");
@@ -563,6 +584,11 @@ void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) {
rb.PushIpcInterface<IFileSystem>(std::move(filesystem));
}
+void FSP_SRV::OpenReadOnlySaveDataFileSystem(Kernel::HLERequestContext& ctx) {
+ LOG_WARNING(Service_FS, "(STUBBED) called, delegating to 51 OpenSaveDataFilesystem");
+ MountSaveData(ctx);
+}
+
void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_FS, "(STUBBED) called");
diff --git a/src/core/hle/service/filesystem/fsp_srv.h b/src/core/hle/service/filesystem/fsp_srv.h
index f073ac523..2b5c21abb 100644
--- a/src/core/hle/service/filesystem/fsp_srv.h
+++ b/src/core/hle/service/filesystem/fsp_srv.h
@@ -20,9 +20,11 @@ public:
private:
void Initialize(Kernel::HLERequestContext& ctx);
+ void OpenFileSystemWithPatch(Kernel::HLERequestContext& ctx);
void MountSdCard(Kernel::HLERequestContext& ctx);
void CreateSaveData(Kernel::HLERequestContext& ctx);
void MountSaveData(Kernel::HLERequestContext& ctx);
+ void OpenReadOnlySaveDataFileSystem(Kernel::HLERequestContext& ctx);
void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx);
void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx);
void OpenDataStorageByDataId(Kernel::HLERequestContext& ctx);
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 8fb907072..9d804652e 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -12,6 +12,7 @@
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/handle_table.h"
+#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/process.h"
#include "core/hle/kernel/server_port.h"
#include "core/hle/kernel/thread.h"
@@ -114,7 +115,7 @@ void ServiceFrameworkBase::InstallAsNamedPort() {
std::tie(server_port, client_port) =
ServerPort::CreatePortPair(kernel, max_sessions, service_name);
server_port->SetHleHandler(shared_from_this());
- AddNamedPort(service_name, std::move(client_port));
+ kernel.AddNamedPort(service_name, std::move(client_port));
}
Kernel::SharedPtr<Kernel::ClientPort> ServiceFrameworkBase::CreatePort() {
@@ -197,11 +198,6 @@ ResultCode ServiceFrameworkBase::HandleSyncRequest(Kernel::HLERequestContext& co
////////////////////////////////////////////////////////////////////////////////////////////////////
// Module interface
-// TODO(yuriks): Move to kernel
-void AddNamedPort(std::string name, SharedPtr<ClientPort> port) {
- g_kernel_named_ports.emplace(std::move(name), std::move(port));
-}
-
/// Initialize ServiceManager
void Init(std::shared_ptr<SM::ServiceManager>& sm, const FileSys::VirtualFilesystem& rfs) {
// NVFlinger needs to be accessed by several services like Vi and AppletOE so we instantiate it
@@ -264,7 +260,6 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm, const FileSys::VirtualFilesys
/// Shutdown ServiceManager
void Shutdown() {
- g_kernel_named_ports.clear();
LOG_DEBUG(Service, "shutdown OK");
}
} // namespace Service
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index cd9c74f3d..7a051523e 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -6,7 +6,6 @@
#include <cstddef>
#include <string>
-#include <unordered_map>
#include <boost/container/flat_map.hpp>
#include "common/common_types.h"
#include "core/hle/kernel/hle_ipc.h"
@@ -187,10 +186,4 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm,
/// Shutdown ServiceManager
void Shutdown();
-/// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort SVC.
-extern std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> g_kernel_named_ports;
-
-/// Adds a port to the named port table
-void AddNamedPort(std::string name, Kernel::SharedPtr<Kernel::ClientPort> port);
-
} // namespace Service
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index c13fb49b8..5980cdb25 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -5,9 +5,9 @@
#include <memory>
#include <ostream>
#include <string>
+#include "common/file_util.h"
#include "common/logging/log.h"
#include "common/string_util.h"
-#include "core/file_sys/vfs_real.h"
#include "core/hle/kernel/process.h"
#include "core/loader/deconstructed_rom_directory.h"
#include "core/loader/elf.h"
@@ -144,6 +144,9 @@ std::ostream& operator<<(std::ostream& os, ResultStatus status) {
return os;
}
+AppLoader::AppLoader(FileSys::VirtualFile file) : file(std::move(file)) {}
+AppLoader::~AppLoader() = default;
+
/**
* Get a loader for a file with a specific type
* @param file The file to load
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index 885fee84c..5a8540b0e 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -4,7 +4,6 @@
#pragma once
-#include <algorithm>
#include <iosfwd>
#include <memory>
#include <string>
@@ -12,7 +11,6 @@
#include <vector>
#include <boost/optional.hpp>
#include "common/common_types.h"
-#include "common/file_util.h"
#include "core/file_sys/vfs.h"
#include "core/hle/kernel/object.h"
@@ -114,8 +112,8 @@ std::ostream& operator<<(std::ostream& os, ResultStatus status);
/// Interface for loading an application
class AppLoader : NonCopyable {
public:
- explicit AppLoader(FileSys::VirtualFile file) : file(std::move(file)) {}
- virtual ~AppLoader() {}
+ explicit AppLoader(FileSys::VirtualFile file);
+ virtual ~AppLoader();
/**
* Returns the type of this file