service: populate pid and handle table from client

This commit is contained in:
Liam 2023-12-09 11:25:21 -05:00
parent 34e4012998
commit 5feda37688
3 changed files with 19 additions and 13 deletions

View File

@ -462,8 +462,7 @@ Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext
std::make_shared<Service::HLERequestContext>(m_kernel, memory, this, client_thread); std::make_shared<Service::HLERequestContext>(m_kernel, memory, this, client_thread);
(*out_context)->SetSessionRequestManager(manager); (*out_context)->SetSessionRequestManager(manager);
(*out_context) (*out_context)
->PopulateFromIncomingCommandBuffer(client_thread->GetOwnerProcess()->GetHandleTable(), ->PopulateFromIncomingCommandBuffer(*client_thread->GetOwnerProcess(), cmd_buf);
cmd_buf);
} else { } else {
KThread* server_thread = GetCurrentThreadPointer(m_kernel); KThread* server_thread = GetCurrentThreadPointer(m_kernel);
KProcess& src_process = *client_thread->GetOwnerProcess(); KProcess& src_process = *client_thread->GetOwnerProcess();

View File

@ -146,8 +146,10 @@ HLERequestContext::HLERequestContext(Kernel::KernelCore& kernel_, Core::Memory::
HLERequestContext::~HLERequestContext() = default; HLERequestContext::~HLERequestContext() = default;
void HLERequestContext::ParseCommandBuffer(const Kernel::KHandleTable& handle_table, void HLERequestContext::ParseCommandBuffer(Kernel::KProcess& process, u32_le* src_cmdbuf,
u32_le* src_cmdbuf, bool incoming) { bool incoming) {
client_handle_table = &process.GetHandleTable();
IPC::RequestParser rp(src_cmdbuf); IPC::RequestParser rp(src_cmdbuf);
command_header = rp.PopRaw<IPC::CommandHeader>(); command_header = rp.PopRaw<IPC::CommandHeader>();
@ -160,7 +162,8 @@ void HLERequestContext::ParseCommandBuffer(const Kernel::KHandleTable& handle_ta
if (command_header->enable_handle_descriptor) { if (command_header->enable_handle_descriptor) {
handle_descriptor_header = rp.PopRaw<IPC::HandleDescriptorHeader>(); handle_descriptor_header = rp.PopRaw<IPC::HandleDescriptorHeader>();
if (handle_descriptor_header->send_current_pid) { if (handle_descriptor_header->send_current_pid) {
pid = rp.Pop<u64>(); pid = process.GetProcessId();
rp.Skip(2, false);
} }
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.
@ -267,9 +270,9 @@ void HLERequestContext::ParseCommandBuffer(const Kernel::KHandleTable& handle_ta
rp.Skip(1, false); // The command is actually an u64, but we don't use the high part. rp.Skip(1, false); // The command is actually an u64, but we don't use the high part.
} }
Result HLERequestContext::PopulateFromIncomingCommandBuffer( Result HLERequestContext::PopulateFromIncomingCommandBuffer(Kernel::KProcess& process,
const Kernel::KHandleTable& handle_table, u32_le* src_cmdbuf) { u32_le* src_cmdbuf) {
ParseCommandBuffer(handle_table, src_cmdbuf, true); ParseCommandBuffer(process, src_cmdbuf, true);
if (command_header->IsCloseCommand()) { if (command_header->IsCloseCommand()) {
// Close does not populate the rest of the IPC header // Close does not populate the rest of the IPC header

View File

@ -38,6 +38,7 @@ namespace Kernel {
class KAutoObject; class KAutoObject;
class KernelCore; class KernelCore;
class KHandleTable; class KHandleTable;
class KProcess;
class KServerSession; class KServerSession;
class KThread; class KThread;
} // namespace Kernel } // namespace Kernel
@ -195,8 +196,7 @@ public:
} }
/// Populates this context with data from the requesting process/thread. /// Populates this context with data from the requesting process/thread.
Result PopulateFromIncomingCommandBuffer(const Kernel::KHandleTable& handle_table, Result PopulateFromIncomingCommandBuffer(Kernel::KProcess& process, u32_le* src_cmdbuf);
u32_le* src_cmdbuf);
/// Writes data from this context back to the requesting process/thread. /// Writes data from this context back to the requesting process/thread.
Result WriteToOutgoingCommandBuffer(Kernel::KThread& requesting_thread); Result WriteToOutgoingCommandBuffer(Kernel::KThread& requesting_thread);
@ -359,6 +359,10 @@ public:
return *thread; return *thread;
} }
Kernel::KHandleTable& GetClientHandleTable() {
return *client_handle_table;
}
[[nodiscard]] std::shared_ptr<SessionRequestManager> GetManager() const { [[nodiscard]] std::shared_ptr<SessionRequestManager> GetManager() const {
return manager.lock(); return manager.lock();
} }
@ -374,12 +378,12 @@ public:
private: private:
friend class IPC::ResponseBuilder; friend class IPC::ResponseBuilder;
void ParseCommandBuffer(const Kernel::KHandleTable& handle_table, u32_le* src_cmdbuf, void ParseCommandBuffer(Kernel::KProcess& process, u32_le* src_cmdbuf, bool incoming);
bool incoming);
std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf;
Kernel::KServerSession* server_session{}; Kernel::KServerSession* server_session{};
Kernel::KThread* thread; Kernel::KHandleTable* client_handle_table{};
Kernel::KThread* thread{};
std::vector<Handle> incoming_move_handles; std::vector<Handle> incoming_move_handles;
std::vector<Handle> incoming_copy_handles; std::vector<Handle> incoming_copy_handles;