ipc: add MapAlias processing logic for Receive

This commit is contained in:
Michael Scire 2020-07-10 08:49:10 -07:00
parent 9d57783aa8
commit 804aa0e55d
6 changed files with 155 additions and 2 deletions

View file

@ -17,6 +17,47 @@
namespace ams::kern {
Result KSessionRequest::SessionMappings::PushMap(KProcessAddress client, KProcessAddress server, size_t size, KMemoryState state, size_t index) {
/* At most 15 buffers of each type (4-bit descriptor counts). */
MESOSPHERE_ASSERT(index < ((1ul << 4) - 1) * 3);
/* Get the mapping. */
Mapping *mapping;
if (index < NumStaticMappings) {
mapping = std::addressof(this->static_mappings[index]);
} else {
/* Allocate a page for the extra mappings. */
if (this->mappings == nullptr) {
KPageBuffer *page_buffer = KPageBuffer::Allocate();
R_UNLESS(page_buffer != nullptr, svc::ResultOutOfMemory());
this->mappings = reinterpret_cast<Mapping *>(page_buffer);
}
mapping = std::addressof(this->mappings[index - NumStaticMappings]);
}
/* Set the mapping. */
mapping->Set(client, server, size, state);
return ResultSuccess();
}
Result KSessionRequest::SessionMappings::PushSend(KProcessAddress client, KProcessAddress server, size_t size, KMemoryState state) {
MESOSPHERE_ASSERT(this->num_recv == 0);
MESOSPHERE_ASSERT(this->num_exch == 0);
return this->PushMap(client, server, size, state, this->num_send++);
}
Result KSessionRequest::SessionMappings::PushReceive(KProcessAddress client, KProcessAddress server, size_t size, KMemoryState state) {
MESOSPHERE_ASSERT(this->num_exch == 0);
return this->PushMap(client, server, size, state, this->num_send + this->num_recv++);
}
Result KSessionRequest::SessionMappings::PushExchange(KProcessAddress client, KProcessAddress server, size_t size, KMemoryState state) {
return this->PushMap(client, server, size, state, this->num_send + this->num_recv + this->num_exch++);
}
void KSessionRequest::SessionMappings::Finalize() {
if (this->mappings) {
KPageBuffer::Free(reinterpret_cast<KPageBuffer *>(this->mappings));