srv.cpp 5.7 KB

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