erreula.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/string_util.h"
  5. #include "core/hle/applets/erreula.h"
  6. #include "core/hle/service/apt/apt.h"
  7. namespace HLE {
  8. namespace Applets {
  9. ResultCode ErrEula::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
  10. if (parameter.signal != static_cast<u32>(Service::APT::SignalType::LibAppJustStarted)) {
  11. LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal);
  12. UNIMPLEMENTED();
  13. // TODO(Subv): Find the right error code
  14. return ResultCode(-1);
  15. }
  16. // The LibAppJustStarted message contains a buffer with the size of the framebuffer shared memory.
  17. // Create the SharedMemory that will hold the framebuffer data
  18. Service::APT::CaptureBufferInfo capture_info;
  19. ASSERT(sizeof(capture_info) == parameter.buffer.size());
  20. memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info));
  21. // TODO: allocated memory never released
  22. using Kernel::MemoryPermission;
  23. // Allocate a heap block of the required size for this applet.
  24. heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
  25. // Create a SharedMemory that directly points to this heap block.
  26. framebuffer_memory = Kernel::SharedMemory::CreateForApplet(heap_memory, 0, heap_memory->size(),
  27. MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
  28. "ErrEula Memory");
  29. // Send the response message with the newly created SharedMemory
  30. Service::APT::MessageParameter result;
  31. result.signal = static_cast<u32>(Service::APT::SignalType::LibAppFinished);
  32. result.buffer.clear();
  33. result.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
  34. result.sender_id = static_cast<u32>(id);
  35. result.object = framebuffer_memory;
  36. Service::APT::SendParameter(result);
  37. return RESULT_SUCCESS;
  38. }
  39. ResultCode ErrEula::StartImpl(const Service::APT::AppletStartupParameter& parameter) {
  40. started = true;
  41. // TODO(Subv): Set the expected fields in the response buffer before resending it to the application.
  42. // TODO(Subv): Reverse the parameter format for the ErrEula applet
  43. // Let the application know that we're closing
  44. Service::APT::MessageParameter message;
  45. message.buffer.resize(parameter.buffer.size());
  46. std::fill(message.buffer.begin(), message.buffer.end(), 0);
  47. message.signal = static_cast<u32>(Service::APT::SignalType::LibAppClosed);
  48. message.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
  49. message.sender_id = static_cast<u32>(id);
  50. Service::APT::SendParameter(message);
  51. started = false;
  52. return RESULT_SUCCESS;
  53. }
  54. void ErrEula::Update() {
  55. }
  56. } // namespace Applets
  57. } // namespace HLE