k_session_request.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "core/hle/kernel/k_page_buffer.h"
  4. #include "core/hle/kernel/k_session_request.h"
  5. namespace Kernel {
  6. Result KSessionRequest::SessionMappings::PushMap(KProcessAddress client, KProcessAddress server,
  7. size_t size, KMemoryState state, size_t index) {
  8. // At most 15 buffers of each type (4-bit descriptor counts).
  9. ASSERT(index < ((1ul << 4) - 1) * 3);
  10. // Get the mapping.
  11. Mapping* mapping;
  12. if (index < NumStaticMappings) {
  13. mapping = std::addressof(m_static_mappings[index]);
  14. } else {
  15. // Allocate a page for the extra mappings.
  16. if (m_mappings == nullptr) {
  17. KPageBuffer* page_buffer = KPageBuffer::Allocate(m_kernel);
  18. R_UNLESS(page_buffer != nullptr, ResultOutOfMemory);
  19. m_mappings = reinterpret_cast<Mapping*>(page_buffer);
  20. }
  21. mapping = std::addressof(m_mappings[index - NumStaticMappings]);
  22. }
  23. // Set the mapping.
  24. mapping->Set(client, server, size, state);
  25. R_SUCCEED();
  26. }
  27. Result KSessionRequest::SessionMappings::PushSend(KProcessAddress client, KProcessAddress server,
  28. size_t size, KMemoryState state) {
  29. ASSERT(m_num_recv == 0);
  30. ASSERT(m_num_exch == 0);
  31. R_RETURN(this->PushMap(client, server, size, state, m_num_send++));
  32. }
  33. Result KSessionRequest::SessionMappings::PushReceive(KProcessAddress client, KProcessAddress server,
  34. size_t size, KMemoryState state) {
  35. ASSERT(m_num_exch == 0);
  36. R_RETURN(this->PushMap(client, server, size, state, m_num_send + m_num_recv++));
  37. }
  38. Result KSessionRequest::SessionMappings::PushExchange(KProcessAddress client,
  39. KProcessAddress server, size_t size,
  40. KMemoryState state) {
  41. R_RETURN(this->PushMap(client, server, size, state, m_num_send + m_num_recv + m_num_exch++));
  42. }
  43. void KSessionRequest::SessionMappings::Finalize() {
  44. if (m_mappings) {
  45. KPageBuffer::Free(m_kernel, reinterpret_cast<KPageBuffer*>(m_mappings));
  46. m_mappings = nullptr;
  47. }
  48. }
  49. } // namespace Kernel