controller.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/assert.h"
  5. #include "common/logging/log.h"
  6. #include "core/hle/ipc_helpers.h"
  7. #include "core/hle/kernel/k_client_session.h"
  8. #include "core/hle/kernel/k_server_session.h"
  9. #include "core/hle/kernel/k_session.h"
  10. #include "core/hle/service/sm/controller.h"
  11. namespace Service::SM {
  12. void Controller::ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx) {
  13. ASSERT_MSG(ctx.Session()->IsSession(), "Session is already a domain");
  14. LOG_DEBUG(Service, "called, server_session={}", ctx.Session()->GetId());
  15. ctx.Session()->ConvertToDomain();
  16. IPC::ResponseBuilder rb{ctx, 3};
  17. rb.Push(RESULT_SUCCESS);
  18. rb.Push<u32>(1); // Converted sessions start with 1 request handler
  19. }
  20. void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) {
  21. // TODO(bunnei): This is just creating a new handle to the same Session. I assume this is wrong
  22. // and that we probably want to actually make an entirely new Session, but we still need to
  23. // verify this on hardware.
  24. LOG_DEBUG(Service, "called");
  25. IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
  26. rb.Push(RESULT_SUCCESS);
  27. rb.PushMoveObjects(ctx.Session()->GetParent()->GetClientSession());
  28. }
  29. void Controller::CloneCurrentObjectEx(Kernel::HLERequestContext& ctx) {
  30. LOG_WARNING(Service, "(STUBBED) called, using CloneCurrentObject");
  31. CloneCurrentObject(ctx);
  32. }
  33. void Controller::QueryPointerBufferSize(Kernel::HLERequestContext& ctx) {
  34. LOG_WARNING(Service, "(STUBBED) called");
  35. IPC::ResponseBuilder rb{ctx, 3};
  36. rb.Push(RESULT_SUCCESS);
  37. rb.Push<u16>(0x8000);
  38. }
  39. // https://switchbrew.org/wiki/IPC_Marshalling
  40. Controller::Controller(Core::System& system_) : ServiceFramework{system_, "IpcController"} {
  41. static const FunctionInfo functions[] = {
  42. {0, &Controller::ConvertCurrentObjectToDomain, "ConvertCurrentObjectToDomain"},
  43. {1, nullptr, "CopyFromCurrentDomain"},
  44. {2, &Controller::CloneCurrentObject, "CloneCurrentObject"},
  45. {3, &Controller::QueryPointerBufferSize, "QueryPointerBufferSize"},
  46. {4, &Controller::CloneCurrentObjectEx, "CloneCurrentObjectEx"},
  47. };
  48. RegisterHandlers(functions);
  49. }
  50. Controller::~Controller() = default;
  51. } // namespace Service::SM