hle: kernel: hle_ipc: Simplify incoming/outgoing move/copy/domain objects.
This commit is contained in:
parent
342170fcd3
commit
f4fe71c1c9
|
@ -80,8 +80,6 @@ public:
|
||||||
|
|
||||||
memset(cmdbuf, 0, sizeof(u32) * IPC::COMMAND_BUFFER_LENGTH);
|
memset(cmdbuf, 0, sizeof(u32) * IPC::COMMAND_BUFFER_LENGTH);
|
||||||
|
|
||||||
ctx.ClearIncomingObjects();
|
|
||||||
|
|
||||||
IPC::CommandHeader header{};
|
IPC::CommandHeader header{};
|
||||||
|
|
||||||
// The entire size of the raw data section in u32 units, including the 16 bytes of mandatory
|
// The entire size of the raw data section in u32 units, including the 16 bytes of mandatory
|
||||||
|
@ -170,24 +168,6 @@ public:
|
||||||
PushIpcInterface<T>(std::make_shared<T>(std::forward<Args>(args)...));
|
PushIpcInterface<T>(std::make_shared<T>(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidateHeader() {
|
|
||||||
const std::size_t num_domain_objects = context->NumDomainObjects();
|
|
||||||
const std::size_t num_move_objects = context->NumMoveObjects();
|
|
||||||
ASSERT_MSG(!num_domain_objects || !num_move_objects,
|
|
||||||
"cannot move normal handles and domain objects");
|
|
||||||
ASSERT_MSG((index - data_payload_index) == normal_params_size,
|
|
||||||
"normal_params_size value is incorrect");
|
|
||||||
ASSERT_MSG((num_domain_objects + num_move_objects) == num_objects_to_move,
|
|
||||||
"num_objects_to_move value is incorrect");
|
|
||||||
ASSERT_MSG(context->NumCopyObjects() == num_handles_to_copy,
|
|
||||||
"num_handles_to_copy value is incorrect");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate on destruction, as there shouldn't be any case where we don't want it
|
|
||||||
~ResponseBuilder() {
|
|
||||||
ValidateHeader();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PushImpl(s8 value);
|
void PushImpl(s8 value);
|
||||||
void PushImpl(s16 value);
|
void PushImpl(s16 value);
|
||||||
void PushImpl(s32 value);
|
void PushImpl(s32 value);
|
||||||
|
|
|
@ -69,14 +69,10 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32
|
||||||
if (incoming) {
|
if (incoming) {
|
||||||
// Populate the object lists with the data in the IPC request.
|
// Populate the object lists with the data in the IPC request.
|
||||||
for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_copy; ++handle) {
|
for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_copy; ++handle) {
|
||||||
const u32 copy_handle{rp.Pop<Handle>()};
|
incoming_copy_handles.push_back(rp.Pop<Handle>());
|
||||||
copy_handles.push_back(copy_handle);
|
|
||||||
copy_objects.push_back(handle_table.GetObject(copy_handle).GetPointerUnsafe());
|
|
||||||
}
|
}
|
||||||
for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_move; ++handle) {
|
for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_move; ++handle) {
|
||||||
const u32 move_handle{rp.Pop<Handle>()};
|
incoming_move_handles.push_back(rp.Pop<Handle>());
|
||||||
move_handles.push_back(move_handle);
|
|
||||||
move_objects.push_back(handle_table.GetObject(move_handle).GetPointerUnsafe());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// For responses we just ignore the handles, they're empty and will be populated when
|
// For responses we just ignore the handles, they're empty and will be populated when
|
||||||
|
@ -186,14 +182,14 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_t
|
||||||
auto& owner_process = *requesting_thread.GetOwnerProcess();
|
auto& owner_process = *requesting_thread.GetOwnerProcess();
|
||||||
auto& handle_table = owner_process.GetHandleTable();
|
auto& handle_table = owner_process.GetHandleTable();
|
||||||
|
|
||||||
for (auto& object : copy_objects) {
|
for (auto& object : outgoing_copy_objects) {
|
||||||
Handle handle{};
|
Handle handle{};
|
||||||
if (object) {
|
if (object) {
|
||||||
R_TRY(handle_table.Add(&handle, object));
|
R_TRY(handle_table.Add(&handle, object));
|
||||||
}
|
}
|
||||||
cmd_buf[current_offset++] = handle;
|
cmd_buf[current_offset++] = handle;
|
||||||
}
|
}
|
||||||
for (auto& object : move_objects) {
|
for (auto& object : outgoing_move_objects) {
|
||||||
Handle handle{};
|
Handle handle{};
|
||||||
if (object) {
|
if (object) {
|
||||||
R_TRY(handle_table.Add(&handle, object));
|
R_TRY(handle_table.Add(&handle, object));
|
||||||
|
@ -208,8 +204,8 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_t
|
||||||
// TODO(Subv): This completely ignores C buffers.
|
// TODO(Subv): This completely ignores C buffers.
|
||||||
|
|
||||||
if (Session()->IsDomain()) {
|
if (Session()->IsDomain()) {
|
||||||
current_offset = domain_offset - static_cast<u32>(domain_objects.size());
|
current_offset = domain_offset - static_cast<u32>(outgoing_domain_objects.size());
|
||||||
for (const auto& object : domain_objects) {
|
for (const auto& object : outgoing_domain_objects) {
|
||||||
server_session->AppendDomainHandler(object);
|
server_session->AppendDomainHandler(object);
|
||||||
cmd_buf[current_offset++] =
|
cmd_buf[current_offset++] =
|
||||||
static_cast<u32_le>(server_session->NumDomainRequestHandlers());
|
static_cast<u32_le>(server_session->NumDomainRequestHandlers());
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/container/small_vector.hpp>
|
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
@ -289,23 +288,23 @@ public:
|
||||||
bool CanWriteBuffer(std::size_t buffer_index = 0) const;
|
bool CanWriteBuffer(std::size_t buffer_index = 0) const;
|
||||||
|
|
||||||
Handle GetCopyHandle(std::size_t index) const {
|
Handle GetCopyHandle(std::size_t index) const {
|
||||||
return copy_handles.at(index);
|
return incoming_copy_handles.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle GetMoveHandle(std::size_t index) const {
|
Handle GetMoveHandle(std::size_t index) const {
|
||||||
return move_handles.at(index);
|
return incoming_move_handles.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddMoveObject(KAutoObject* object) {
|
void AddMoveObject(KAutoObject* object) {
|
||||||
move_objects.emplace_back(object);
|
outgoing_move_objects.emplace_back(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddCopyObject(KAutoObject* object) {
|
void AddCopyObject(KAutoObject* object) {
|
||||||
copy_objects.emplace_back(object);
|
outgoing_copy_objects.emplace_back(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddDomainObject(SessionRequestHandlerPtr object) {
|
void AddDomainObject(SessionRequestHandlerPtr object) {
|
||||||
domain_objects.emplace_back(std::move(object));
|
outgoing_domain_objects.emplace_back(std::move(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -317,26 +316,6 @@ public:
|
||||||
manager = std::move(manager_);
|
manager = std::move(manager_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clears the list of objects so that no lingering objects are written accidentally to the
|
|
||||||
/// response buffer.
|
|
||||||
void ClearIncomingObjects() {
|
|
||||||
move_objects.clear();
|
|
||||||
copy_objects.clear();
|
|
||||||
domain_objects.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t NumMoveObjects() const {
|
|
||||||
return move_objects.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t NumCopyObjects() const {
|
|
||||||
return copy_objects.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t NumDomainObjects() const {
|
|
||||||
return domain_objects.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Description() const;
|
std::string Description() const;
|
||||||
|
|
||||||
KThread& GetThread() {
|
KThread& GetThread() {
|
||||||
|
@ -356,12 +335,12 @@ private:
|
||||||
Kernel::KServerSession* server_session{};
|
Kernel::KServerSession* server_session{};
|
||||||
KThread* thread;
|
KThread* thread;
|
||||||
|
|
||||||
// TODO(yuriks): Check common usage of this and optimize size accordingly
|
std::vector<Handle> incoming_move_handles;
|
||||||
boost::container::small_vector<Handle, 8> move_handles;
|
std::vector<Handle> incoming_copy_handles;
|
||||||
boost::container::small_vector<Handle, 8> copy_handles;
|
|
||||||
boost::container::small_vector<KAutoObject*, 8> move_objects;
|
std::vector<KAutoObject*> outgoing_move_objects;
|
||||||
boost::container::small_vector<KAutoObject*, 8> copy_objects;
|
std::vector<KAutoObject*> outgoing_copy_objects;
|
||||||
boost::container::small_vector<SessionRequestHandlerPtr, 8> domain_objects;
|
std::vector<SessionRequestHandlerPtr> outgoing_domain_objects;
|
||||||
|
|
||||||
std::optional<IPC::CommandHeader> command_header;
|
std::optional<IPC::CommandHeader> command_header;
|
||||||
std::optional<IPC::HandleDescriptorHeader> handle_descriptor_header;
|
std::optional<IPC::HandleDescriptorHeader> handle_descriptor_header;
|
||||||
|
|
Reference in New Issue