From 073653e858abf377fd1ebbdb071809c8830ce99d Mon Sep 17 00:00:00 2001 From: Subv Date: Tue, 14 Jun 2016 18:03:30 -0500 Subject: Kernel/IPC: Use Ports and Sessions as the fundamental building block of Inter Process Communication. All handles obtained via srv::GetServiceHandle or svcConnectToPort are references to ClientSessions. Service modules will wait on the counterpart of those ClientSessions (Called ServerSessions) using svcReplyAndReceive or svcWaitSynchronization[1|N], and will be awoken when a SyncRequest is performed. HLE Interfaces are now ClientPorts which override the HandleSyncRequest virtual member function to perform command handling immediately. --- src/core/hle/service/fs/archive.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core/hle/service/fs/archive.cpp') diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 4c29784e8..da009df91 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -92,7 +92,7 @@ File::File(std::unique_ptr&& backend, const FileSys::Path& File::~File() {} -ResultVal File::SyncRequest() { +ResultCode File::HandleSyncRequest() { u32* cmd_buff = Kernel::GetCommandBuffer(); FileCommand cmd = static_cast(cmd_buff[0]); switch (cmd) { @@ -193,10 +193,10 @@ ResultVal File::SyncRequest() { LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd); ResultCode error = UnimplementedFunction(ErrorModule::FS); cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. - return error; + return ServerSession::HandleSyncRequest(); } cmd_buff[1] = RESULT_SUCCESS.raw; // No error - return MakeResult(false); + return ServerSession::HandleSyncRequest(); } Directory::Directory(std::unique_ptr&& backend, @@ -205,7 +205,7 @@ Directory::Directory(std::unique_ptr&& backend, Directory::~Directory() {} -ResultVal Directory::SyncRequest() { +ResultCode Directory::HandleSyncRequest() { u32* cmd_buff = Kernel::GetCommandBuffer(); DirectoryCommand cmd = static_cast(cmd_buff[0]); switch (cmd) { @@ -236,10 +236,10 @@ ResultVal Directory::SyncRequest() { LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd); ResultCode error = UnimplementedFunction(ErrorModule::FS); cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. - return MakeResult(false); + return ServerSession::HandleSyncRequest(); } cmd_buff[1] = RESULT_SUCCESS.raw; // No error - return MakeResult(false); + return ServerSession::HandleSyncRequest(); } //////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 009b15b3aa9858930f461d825f7dd030fc963801 Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 30 Nov 2016 22:50:13 -0500 Subject: A bit of a redesign. Sessions and Ports are now detached from each other. HLE services are handled by means of a SessionRequestHandler class, Interface now inherits from this class. The File and Directory classes are no longer kernel objects, but SessionRequestHandlers instead, bound to a ServerSession when requested. File::OpenLinkFile now creates a new session pair and binds the File instance to it. --- src/core/hle/service/fs/archive.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/core/hle/service/fs/archive.cpp') diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index da009df91..e40483c72 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -23,10 +23,11 @@ #include "core/file_sys/directory_backend.h" #include "core/file_sys/file_backend.h" #include "core/hle/hle.h" +#include "core/hle/kernel/client_session.h" #include "core/hle/result.h" +#include "core/hle/service/service.h" #include "core/hle/service/fs/archive.h" #include "core/hle/service/fs/fs_user.h" -#include "core/hle/service/service.h" #include "core/memory.h" // Specializes std::hash for ArchiveIdCode, so that we can use it in std::unordered_map. @@ -92,11 +93,10 @@ File::File(std::unique_ptr&& backend, const FileSys::Path& File::~File() {} -ResultCode File::HandleSyncRequest() { +ResultCode File::HandleSyncRequest(Kernel::SharedPtr server_session) { u32* cmd_buff = Kernel::GetCommandBuffer(); FileCommand cmd = static_cast(cmd_buff[0]); switch (cmd) { - // Read from file... case FileCommand::Read: { u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32; @@ -170,9 +170,11 @@ ResultCode File::HandleSyncRequest() { break; } - case FileCommand::OpenLinkFile: { + case FileCommand::OpenLinkFile: + { LOG_WARNING(Service_FS, "(STUBBED) File command OpenLinkFile %s", GetName().c_str()); - cmd_buff[3] = Kernel::g_handle_table.Create(this).ValueOr(INVALID_HANDLE); + auto sessions = Kernel::ServerSession::CreateSessionPair(GetName(), shared_from_this()); + cmd_buff[3] = Kernel::g_handle_table.Create(std::get>(sessions)).ValueOr(INVALID_HANDLE); break; } @@ -193,10 +195,10 @@ ResultCode File::HandleSyncRequest() { LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd); ResultCode error = UnimplementedFunction(ErrorModule::FS); cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. - return ServerSession::HandleSyncRequest(); + return RESULT_SUCCESS; } cmd_buff[1] = RESULT_SUCCESS.raw; // No error - return ServerSession::HandleSyncRequest(); + return RESULT_SUCCESS; } Directory::Directory(std::unique_ptr&& backend, @@ -205,11 +207,10 @@ Directory::Directory(std::unique_ptr&& backend, Directory::~Directory() {} -ResultCode Directory::HandleSyncRequest() { +ResultCode Directory::HandleSyncRequest(Kernel::SharedPtr server_session) { u32* cmd_buff = Kernel::GetCommandBuffer(); DirectoryCommand cmd = static_cast(cmd_buff[0]); switch (cmd) { - // Read from directory... case DirectoryCommand::Read: { u32 count = cmd_buff[1]; @@ -236,10 +237,10 @@ ResultCode Directory::HandleSyncRequest() { LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd); ResultCode error = UnimplementedFunction(ErrorModule::FS); cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. - return ServerSession::HandleSyncRequest(); + return RESULT_SUCCESS; } cmd_buff[1] = RESULT_SUCCESS.raw; // No error - return ServerSession::HandleSyncRequest(); + return RESULT_SUCCESS; } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -306,7 +307,7 @@ ResultCode RegisterArchiveType(std::unique_ptr&& factor return RESULT_SUCCESS; } -ResultVal> OpenFileFromArchive(ArchiveHandle archive_handle, +ResultVal> OpenFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path, const FileSys::Mode mode) { ArchiveBackend* archive = GetArchive(archive_handle); @@ -317,8 +318,8 @@ ResultVal> OpenFileFromArchive(ArchiveHandle archive_han if (backend.Failed()) return backend.Code(); - auto file = Kernel::SharedPtr(new File(backend.MoveFrom(), path)); - return MakeResult>(std::move(file)); + auto file = std::shared_ptr(new File(backend.MoveFrom(), path)); + return MakeResult>(std::move(file)); } ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { @@ -397,7 +398,7 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, } } -ResultVal> OpenDirectoryFromArchive(ArchiveHandle archive_handle, +ResultVal> OpenDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { ArchiveBackend* archive = GetArchive(archive_handle); if (archive == nullptr) @@ -407,8 +408,8 @@ ResultVal> OpenDirectoryFromArchive(ArchiveHandle a if (backend.Failed()) return backend.Code(); - auto directory = Kernel::SharedPtr(new Directory(backend.MoveFrom(), path)); - return MakeResult>(std::move(directory)); + auto directory = std::shared_ptr(new Directory(backend.MoveFrom(), path)); + return MakeResult>(std::move(directory)); } ResultVal GetFreeBytesInArchive(ArchiveHandle archive_handle) { -- cgit v1.2.3 From 2eceee3a4cc2786dae4e9b80a8b5f3bb666d3fc6 Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 30 Nov 2016 23:28:31 -0500 Subject: Fixed the rebase mistakes. --- src/core/hle/service/fs/archive.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core/hle/service/fs/archive.cpp') diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index e40483c72..a9f457726 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -25,9 +25,9 @@ #include "core/hle/hle.h" #include "core/hle/kernel/client_session.h" #include "core/hle/result.h" -#include "core/hle/service/service.h" #include "core/hle/service/fs/archive.h" #include "core/hle/service/fs/fs_user.h" +#include "core/hle/service/service.h" #include "core/memory.h" // Specializes std::hash for ArchiveIdCode, so that we can use it in std::unordered_map. @@ -97,6 +97,7 @@ ResultCode File::HandleSyncRequest(Kernel::SharedPtr serv u32* cmd_buff = Kernel::GetCommandBuffer(); FileCommand cmd = static_cast(cmd_buff[0]); switch (cmd) { + // Read from file... case FileCommand::Read: { u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32; @@ -170,8 +171,7 @@ ResultCode File::HandleSyncRequest(Kernel::SharedPtr serv break; } - case FileCommand::OpenLinkFile: - { + case FileCommand::OpenLinkFile: { LOG_WARNING(Service_FS, "(STUBBED) File command OpenLinkFile %s", GetName().c_str()); auto sessions = Kernel::ServerSession::CreateSessionPair(GetName(), shared_from_this()); cmd_buff[3] = Kernel::g_handle_table.Create(std::get>(sessions)).ValueOr(INVALID_HANDLE); @@ -195,7 +195,7 @@ ResultCode File::HandleSyncRequest(Kernel::SharedPtr serv LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd); ResultCode error = UnimplementedFunction(ErrorModule::FS); cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. - return RESULT_SUCCESS; + return error; } cmd_buff[1] = RESULT_SUCCESS.raw; // No error return RESULT_SUCCESS; -- cgit v1.2.3 From 00f0c775702af4145a4a81ec5d357c3586a5c6c3 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 5 Dec 2016 12:05:00 -0500 Subject: Split SessionRequestHandler::HandleSyncRequest into HandleSyncRequest, TranslateRequest and HandleSyncRequestImpl. HandleSyncRequest now takes care of calling the command buffer translate function before actually invoking the command handler for HLE services. --- src/core/hle/service/fs/archive.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/core/hle/service/fs/archive.cpp') diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index a9f457726..c10d6a3a9 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -93,7 +93,7 @@ File::File(std::unique_ptr&& backend, const FileSys::Path& File::~File() {} -ResultCode File::HandleSyncRequest(Kernel::SharedPtr server_session) { +void File::HandleSyncRequestImpl(Kernel::SharedPtr server_session) { u32* cmd_buff = Kernel::GetCommandBuffer(); FileCommand cmd = static_cast(cmd_buff[0]); switch (cmd) { @@ -116,7 +116,7 @@ ResultCode File::HandleSyncRequest(Kernel::SharedPtr serv ResultVal read = backend->Read(offset, data.size(), data.data()); if (read.Failed()) { cmd_buff[1] = read.Code().raw; - return read.Code(); + return; } Memory::WriteBlock(address, data.data(), *read); cmd_buff[2] = static_cast(*read); @@ -137,7 +137,7 @@ ResultCode File::HandleSyncRequest(Kernel::SharedPtr serv ResultVal written = backend->Write(offset, data.size(), flush != 0, data.data()); if (written.Failed()) { cmd_buff[1] = written.Code().raw; - return written.Code(); + return; } cmd_buff[2] = static_cast(*written); break; @@ -195,10 +195,9 @@ ResultCode File::HandleSyncRequest(Kernel::SharedPtr serv LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd); ResultCode error = UnimplementedFunction(ErrorModule::FS); cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. - return error; + return; } cmd_buff[1] = RESULT_SUCCESS.raw; // No error - return RESULT_SUCCESS; } Directory::Directory(std::unique_ptr&& backend, @@ -207,7 +206,7 @@ Directory::Directory(std::unique_ptr&& backend, Directory::~Directory() {} -ResultCode Directory::HandleSyncRequest(Kernel::SharedPtr server_session) { +void Directory::HandleSyncRequestImpl(Kernel::SharedPtr server_session) { u32* cmd_buff = Kernel::GetCommandBuffer(); DirectoryCommand cmd = static_cast(cmd_buff[0]); switch (cmd) { @@ -237,10 +236,9 @@ ResultCode Directory::HandleSyncRequest(Kernel::SharedPtr LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd); ResultCode error = UnimplementedFunction(ErrorModule::FS); cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. - return RESULT_SUCCESS; + return; } cmd_buff[1] = RESULT_SUCCESS.raw; // No error - return RESULT_SUCCESS; } //////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 386112da3265d111595329508b860800e5cf14e8 Mon Sep 17 00:00:00 2001 From: Subv Date: Thu, 8 Dec 2016 15:01:10 -0500 Subject: Added a framework for partially handling Session disconnections. Further implementation will happen in a future commit. Fixes a regression. --- src/core/hle/service/fs/archive.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core/hle/service/fs/archive.cpp') diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index c10d6a3a9..b63c6eaac 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -174,6 +174,7 @@ void File::HandleSyncRequestImpl(Kernel::SharedPtr server case FileCommand::OpenLinkFile: { LOG_WARNING(Service_FS, "(STUBBED) File command OpenLinkFile %s", GetName().c_str()); auto sessions = Kernel::ServerSession::CreateSessionPair(GetName(), shared_from_this()); + ClientConnected(std::get>(sessions)); cmd_buff[3] = Kernel::g_handle_table.Create(std::get>(sessions)).ValueOr(INVALID_HANDLE); break; } -- cgit v1.2.3 From ebbb55ec8f827096f1c743cc4b7f4a2aa05a3ed3 Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 9 Dec 2016 12:52:12 -0500 Subject: Moved the HLE command buffer translation task to ServerSession instead of the HLE handler superclass. --- src/core/hle/service/fs/archive.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service/fs/archive.cpp') diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index b63c6eaac..bca57061e 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -93,7 +93,7 @@ File::File(std::unique_ptr&& backend, const FileSys::Path& File::~File() {} -void File::HandleSyncRequestImpl(Kernel::SharedPtr server_session) { +void File::HandleSyncRequest(Kernel::SharedPtr server_session) { u32* cmd_buff = Kernel::GetCommandBuffer(); FileCommand cmd = static_cast(cmd_buff[0]); switch (cmd) { @@ -207,7 +207,7 @@ Directory::Directory(std::unique_ptr&& backend, Directory::~Directory() {} -void Directory::HandleSyncRequestImpl(Kernel::SharedPtr server_session) { +void Directory::HandleSyncRequest(Kernel::SharedPtr server_session) { u32* cmd_buff = Kernel::GetCommandBuffer(); DirectoryCommand cmd = static_cast(cmd_buff[0]); switch (cmd) { -- cgit v1.2.3 From 016307ae656afc85ab59a5c2598205ef81f99231 Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 14 Dec 2016 12:33:49 -0500 Subject: Fixed the codestyle to match our clang-format rules. --- src/core/hle/service/fs/archive.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/core/hle/service/fs/archive.cpp') diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index bca57061e..6184e6f1b 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -175,7 +175,9 @@ void File::HandleSyncRequest(Kernel::SharedPtr server_ses LOG_WARNING(Service_FS, "(STUBBED) File command OpenLinkFile %s", GetName().c_str()); auto sessions = Kernel::ServerSession::CreateSessionPair(GetName(), shared_from_this()); ClientConnected(std::get>(sessions)); - cmd_buff[3] = Kernel::g_handle_table.Create(std::get>(sessions)).ValueOr(INVALID_HANDLE); + cmd_buff[3] = Kernel::g_handle_table + .Create(std::get>(sessions)) + .ValueOr(INVALID_HANDLE); break; } @@ -307,8 +309,8 @@ ResultCode RegisterArchiveType(std::unique_ptr&& factor } ResultVal> OpenFileFromArchive(ArchiveHandle archive_handle, - const FileSys::Path& path, - const FileSys::Mode mode) { + const FileSys::Path& path, + const FileSys::Mode mode) { ArchiveBackend* archive = GetArchive(archive_handle); if (archive == nullptr) return ERR_INVALID_ARCHIVE_HANDLE; @@ -398,7 +400,7 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, } ResultVal> OpenDirectoryFromArchive(ArchiveHandle archive_handle, - const FileSys::Path& path) { + const FileSys::Path& path) { ArchiveBackend* archive = GetArchive(archive_handle); if (archive == nullptr) return ERR_INVALID_ARCHIVE_HANDLE; -- cgit v1.2.3