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.
This commit is contained in:
Subv 2016-06-14 18:03:30 -05:00
parent 68c00ee771
commit 073653e858
16 changed files with 315 additions and 89 deletions

View file

@ -92,7 +92,7 @@ File::File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path&
File::~File() {}
ResultVal<bool> File::SyncRequest() {
ResultCode File::HandleSyncRequest() {
u32* cmd_buff = Kernel::GetCommandBuffer();
FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]);
switch (cmd) {
@ -193,10 +193,10 @@ ResultVal<bool> 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<bool>(false);
return ServerSession::HandleSyncRequest();
}
Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend,
@ -205,7 +205,7 @@ Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend,
Directory::~Directory() {}
ResultVal<bool> Directory::SyncRequest() {
ResultCode Directory::HandleSyncRequest() {
u32* cmd_buff = Kernel::GetCommandBuffer();
DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]);
switch (cmd) {
@ -236,10 +236,10 @@ ResultVal<bool> 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<bool>(false);
return ServerSession::HandleSyncRequest();
}
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
return MakeResult<bool>(false);
return ServerSession::HandleSyncRequest();
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -8,7 +8,7 @@
#include <string>
#include "common/common_types.h"
#include "core/file_sys/archive_backend.h"
#include "core/hle/kernel/session.h"
#include "core/hle/kernel/server_session.h"
#include "core/hle/result.h"
namespace FileSys {
@ -41,7 +41,7 @@ enum class MediaType : u32 { NAND = 0, SDMC = 1 };
typedef u64 ArchiveHandle;
class File : public Kernel::Session {
class File : public Kernel::ServerSession {
public:
File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path);
~File();
@ -49,14 +49,15 @@ public:
std::string GetName() const override {
return "Path: " + path.DebugStr();
}
ResultVal<bool> SyncRequest() override;
ResultCode HandleSyncRequest() override;
FileSys::Path path; ///< Path of the file
u32 priority; ///< Priority of the file. TODO(Subv): Find out what this means
std::unique_ptr<FileSys::FileBackend> backend; ///< File backend interface
};
class Directory : public Kernel::Session {
class Directory : public Kernel::ServerSession {
public:
Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path& path);
~Directory();
@ -64,7 +65,8 @@ public:
std::string GetName() const override {
return "Directory: " + path.DebugStr();
}
ResultVal<bool> SyncRequest() override;
ResultCode HandleSyncRequest() override;
FileSys::Path path; ///< Path of the directory
std::unique_ptr<FileSys::DirectoryBackend> backend; ///< File backend interface

View file

@ -8,6 +8,7 @@
#include "common/logging/log.h"
#include "common/scope_exit.h"
#include "common/string_util.h"
#include "core/hle/kernel/client_session.h"
#include "core/hle/result.h"
#include "core/hle/service/fs/archive.h"
#include "core/hle/service/fs/fs_user.h"
@ -17,7 +18,7 @@
// Namespace FS_User
using Kernel::SharedPtr;
using Kernel::Session;
using Kernel::ServerSession;
namespace Service {
namespace FS {
@ -70,7 +71,7 @@ static void OpenFile(Service::Interface* self) {
ResultVal<SharedPtr<File>> file_res = OpenFileFromArchive(archive_handle, file_path, mode);
cmd_buff[1] = file_res.Code().raw;
if (file_res.Succeeded()) {
cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom();
cmd_buff[3] = Kernel::g_handle_table.Create((*file_res)->CreateClientSession()).MoveFrom();
} else {
cmd_buff[3] = 0;
LOG_ERROR(Service_FS, "failed to get a handle for file %s", file_path.DebugStr().c_str());
@ -130,7 +131,7 @@ static void OpenFileDirectly(Service::Interface* self) {
ResultVal<SharedPtr<File>> file_res = OpenFileFromArchive(*archive_handle, file_path, mode);
cmd_buff[1] = file_res.Code().raw;
if (file_res.Succeeded()) {
cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom();
cmd_buff[3] = Kernel::g_handle_table.Create((*file_res)->CreateClientSession()).MoveFrom();
} else {
cmd_buff[3] = 0;
LOG_ERROR(Service_FS, "failed to get a handle for file %s mode=%u attributes=%u",
@ -391,7 +392,7 @@ static void OpenDirectory(Service::Interface* self) {
ResultVal<SharedPtr<Directory>> dir_res = OpenDirectoryFromArchive(archive_handle, dir_path);
cmd_buff[1] = dir_res.Code().raw;
if (dir_res.Succeeded()) {
cmd_buff[3] = Kernel::g_handle_table.Create(*dir_res).MoveFrom();
cmd_buff[3] = Kernel::g_handle_table.Create((*dir_res)->CreateClientSession()).MoveFrom();
} else {
LOG_ERROR(Service_FS, "failed to get a handle for directory type=%d size=%d data=%s",
dirname_type, dirname_size, dir_path.DebugStr().c_str());