srv.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/common_types.h"
  5. #include "common/logging/log.h"
  6. #include "core/hle/kernel/event.h"
  7. #include "core/hle/service/srv.h"
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////
  9. // Namespace SRV
  10. namespace SRV {
  11. static Kernel::SharedPtr<Kernel::Event> event_handle;
  12. /**
  13. * SRV::RegisterClient service function
  14. * Inputs:
  15. * 0: 0x00010002
  16. * 1: ProcessId Header (must be 0x20)
  17. * Outputs:
  18. * 0: 0x00010040
  19. * 1: ResultCode
  20. */
  21. static void RegisterClient(Service::Interface* self) {
  22. u32* cmd_buff = Kernel::GetCommandBuffer();
  23. if (cmd_buff[1] != IPC::CallingPidDesc()) {
  24. cmd_buff[0] = IPC::MakeHeader(0x0, 0x1, 0); // 0x40
  25. cmd_buff[1] = ResultCode(ErrorDescription::OS_InvalidBufferDescriptor, ErrorModule::OS,
  26. ErrorSummary::WrongArgument, ErrorLevel::Permanent)
  27. .raw;
  28. return;
  29. }
  30. cmd_buff[0] = IPC::MakeHeader(0x1, 0x1, 0); // 0x10040
  31. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  32. LOG_WARNING(Service_SRV, "(STUBBED) called");
  33. }
  34. /**
  35. * SRV::EnableNotification service function
  36. * Inputs:
  37. * 0: 0x00020000
  38. * Outputs:
  39. * 0: 0x00020042
  40. * 1: ResultCode
  41. * 2: Translation descriptor: 0x20
  42. * 3: Handle to semaphore signaled on process notification
  43. */
  44. static void EnableNotification(Service::Interface* self) {
  45. u32* cmd_buff = Kernel::GetCommandBuffer();
  46. // TODO(bunnei): Change to a semaphore once these have been implemented
  47. event_handle = Kernel::Event::Create(Kernel::ResetType::OneShot, "SRV:Event");
  48. event_handle->Clear();
  49. cmd_buff[0] = IPC::MakeHeader(0x2, 0x1, 0x2); // 0x20042
  50. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  51. cmd_buff[2] = IPC::CopyHandleDesc(1);
  52. cmd_buff[3] = Kernel::g_handle_table.Create(event_handle).MoveFrom();
  53. LOG_WARNING(Service_SRV, "(STUBBED) called");
  54. }
  55. /**
  56. * SRV::GetServiceHandle service function
  57. * Inputs:
  58. * 0: 0x00050100
  59. * 1-2: 8-byte UTF-8 service name
  60. * 3: Name length
  61. * 4: Flags (bit0: if not set, return port-handle if session-handle unavailable)
  62. * Outputs:
  63. * 1: ResultCode
  64. * 3: Service handle
  65. */
  66. static void GetServiceHandle(Service::Interface* self) {
  67. ResultCode res = RESULT_SUCCESS;
  68. u32* cmd_buff = Kernel::GetCommandBuffer();
  69. std::string port_name = std::string((const char*)&cmd_buff[1], 0, Service::kMaxPortSize);
  70. auto it = Service::g_srv_services.find(port_name);
  71. if (it != Service::g_srv_services.end()) {
  72. cmd_buff[3] = Kernel::g_handle_table.Create(it->second).MoveFrom();
  73. LOG_TRACE(Service_SRV, "called port=%s, handle=0x%08X", port_name.c_str(), cmd_buff[3]);
  74. } else {
  75. LOG_ERROR(Service_SRV, "(UNIMPLEMENTED) called port=%s", port_name.c_str());
  76. res = UnimplementedFunction(ErrorModule::SRV);
  77. }
  78. cmd_buff[1] = res.raw;
  79. }
  80. /**
  81. * SRV::Subscribe service function
  82. * Inputs:
  83. * 0: 0x00090040
  84. * 1: Notification ID
  85. * Outputs:
  86. * 0: 0x00090040
  87. * 1: ResultCode
  88. */
  89. static void Subscribe(Service::Interface* self) {
  90. u32* cmd_buff = Kernel::GetCommandBuffer();
  91. u32 notification_id = cmd_buff[1];
  92. cmd_buff[0] = IPC::MakeHeader(0x9, 0x1, 0); // 0x90040
  93. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  94. LOG_WARNING(Service_SRV, "(STUBBED) called, notification_id=0x%X", notification_id);
  95. }
  96. /**
  97. * SRV::Unsubscribe service function
  98. * Inputs:
  99. * 0: 0x000A0040
  100. * 1: Notification ID
  101. * Outputs:
  102. * 0: 0x000A0040
  103. * 1: ResultCode
  104. */
  105. static void Unsubscribe(Service::Interface* self) {
  106. u32* cmd_buff = Kernel::GetCommandBuffer();
  107. u32 notification_id = cmd_buff[1];
  108. cmd_buff[0] = IPC::MakeHeader(0xA, 0x1, 0); // 0xA0040
  109. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  110. LOG_WARNING(Service_SRV, "(STUBBED) called, notification_id=0x%X", notification_id);
  111. }
  112. /**
  113. * SRV::PublishToSubscriber service function
  114. * Inputs:
  115. * 0: 0x000C0080
  116. * 1: Notification ID
  117. * 2: Flags (bit0: only fire if not fired, bit1: report errors)
  118. * Outputs:
  119. * 0: 0x000C0040
  120. * 1: ResultCode
  121. */
  122. static void PublishToSubscriber(Service::Interface* self) {
  123. u32* cmd_buff = Kernel::GetCommandBuffer();
  124. u32 notification_id = cmd_buff[1];
  125. u8 flags = cmd_buff[2] & 0xFF;
  126. cmd_buff[0] = IPC::MakeHeader(0xC, 0x1, 0); // 0xC0040
  127. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  128. LOG_WARNING(Service_SRV, "(STUBBED) called, notification_id=0x%X, flags=%u", notification_id,
  129. flags);
  130. }
  131. const Interface::FunctionInfo FunctionTable[] = {
  132. {0x00010002, RegisterClient, "RegisterClient"},
  133. {0x00020000, EnableNotification, "EnableNotification"},
  134. {0x00030100, nullptr, "RegisterService"},
  135. {0x000400C0, nullptr, "UnregisterService"},
  136. {0x00050100, GetServiceHandle, "GetServiceHandle"},
  137. {0x000600C2, nullptr, "RegisterPort"},
  138. {0x000700C0, nullptr, "UnregisterPort"},
  139. {0x00080100, nullptr, "GetPort"},
  140. {0x00090040, Subscribe, "Subscribe"},
  141. {0x000A0040, Unsubscribe, "Unsubscribe"},
  142. {0x000B0000, nullptr, "ReceiveNotification"},
  143. {0x000C0080, PublishToSubscriber, "PublishToSubscriber"},
  144. {0x000D0040, nullptr, "PublishAndGetSubscriber"},
  145. {0x000E00C0, nullptr, "IsServiceRegistered"},
  146. };
  147. ////////////////////////////////////////////////////////////////////////////////////////////////////
  148. // Interface class
  149. Interface::Interface() {
  150. Register(FunctionTable);
  151. event_handle = nullptr;
  152. }
  153. Interface::~Interface() {
  154. event_handle = nullptr;
  155. }
  156. } // namespace SRV