2020-07-10 06:30:29 +02:00
|
|
|
/*
|
2021-10-04 21:59:10 +02:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-07-10 06:30:29 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <mesosphere.hpp>
|
|
|
|
|
|
|
|
namespace ams::kern {
|
|
|
|
|
2020-07-10 17:49:10 +02:00
|
|
|
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). */
|
2022-10-12 09:36:32 +02:00
|
|
|
MESOSPHERE_ASSERT(index < NumMappings);
|
2020-07-10 17:49:10 +02:00
|
|
|
|
|
|
|
/* Get the mapping. */
|
|
|
|
Mapping *mapping;
|
|
|
|
if (index < NumStaticMappings) {
|
2020-12-18 02:18:47 +01:00
|
|
|
mapping = std::addressof(m_static_mappings[index]);
|
2020-07-10 17:49:10 +02:00
|
|
|
} else {
|
2022-10-12 09:36:32 +02:00
|
|
|
/* Allocate dynamic mappings as necessary. */
|
|
|
|
if (m_dynamic_mappings == nullptr) {
|
|
|
|
m_dynamic_mappings = DynamicMappings::Allocate();
|
|
|
|
R_UNLESS(m_dynamic_mappings != nullptr, svc::ResultOutOfMemory());
|
2020-07-10 17:49:10 +02:00
|
|
|
}
|
|
|
|
|
2022-10-12 09:36:32 +02:00
|
|
|
mapping = std::addressof(m_dynamic_mappings->Get(index - NumStaticMappings));
|
2020-07-10 17:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the mapping. */
|
|
|
|
mapping->Set(client, server, size, state);
|
|
|
|
|
2022-02-14 23:45:32 +01:00
|
|
|
R_SUCCEED();
|
2020-07-10 17:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result KSessionRequest::SessionMappings::PushSend(KProcessAddress client, KProcessAddress server, size_t size, KMemoryState state) {
|
2020-12-18 02:18:47 +01:00
|
|
|
MESOSPHERE_ASSERT(m_num_recv == 0);
|
|
|
|
MESOSPHERE_ASSERT(m_num_exch == 0);
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(this->PushMap(client, server, size, state, m_num_send++));
|
2020-07-10 17:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result KSessionRequest::SessionMappings::PushReceive(KProcessAddress client, KProcessAddress server, size_t size, KMemoryState state) {
|
2020-12-18 02:18:47 +01:00
|
|
|
MESOSPHERE_ASSERT(m_num_exch == 0);
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(this->PushMap(client, server, size, state, m_num_send + m_num_recv++));
|
2020-07-10 17:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result KSessionRequest::SessionMappings::PushExchange(KProcessAddress client, KProcessAddress server, size_t size, KMemoryState state) {
|
2022-02-14 23:45:32 +01:00
|
|
|
R_RETURN(this->PushMap(client, server, size, state, m_num_send + m_num_recv + m_num_exch++));
|
2020-07-10 17:49:10 +02:00
|
|
|
}
|
|
|
|
|
2020-07-10 06:30:29 +02:00
|
|
|
void KSessionRequest::SessionMappings::Finalize() {
|
2022-10-12 09:36:32 +02:00
|
|
|
if (m_dynamic_mappings) {
|
|
|
|
DynamicMappings::Free(m_dynamic_mappings);
|
|
|
|
m_dynamic_mappings = nullptr;
|
2020-07-10 06:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|