ILibraryAppletCreator.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Ryujinx.HLE.HOS.Kernel.Memory;
  2. using Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.LibraryAppletCreator;
  3. namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
  4. {
  5. class ILibraryAppletCreator : IpcService
  6. {
  7. public ILibraryAppletCreator() { }
  8. [CommandHipc(0)]
  9. // CreateLibraryApplet(u32, u32) -> object<nn::am::service::ILibraryAppletAccessor>
  10. public ResultCode CreateLibraryApplet(ServiceCtx context)
  11. {
  12. AppletId appletId = (AppletId)context.RequestData.ReadInt32();
  13. int libraryAppletMode = context.RequestData.ReadInt32();
  14. MakeObject(context, new ILibraryAppletAccessor(appletId, context.Device.System));
  15. return ResultCode.Success;
  16. }
  17. [CommandHipc(10)]
  18. // CreateStorage(u64) -> object<nn::am::service::IStorage>
  19. public ResultCode CreateStorage(ServiceCtx context)
  20. {
  21. long size = context.RequestData.ReadInt64();
  22. if (size <= 0)
  23. {
  24. return ResultCode.ObjectInvalid;
  25. }
  26. MakeObject(context, new IStorage(new byte[size]));
  27. // NOTE: Returns ResultCode.MemoryAllocationFailed if IStorage is null, it doesn't occur in our case.
  28. return ResultCode.Success;
  29. }
  30. [CommandHipc(11)]
  31. // CreateTransferMemoryStorage(b8, u64, handle<copy>) -> object<nn::am::service::IStorage>
  32. public ResultCode CreateTransferMemoryStorage(ServiceCtx context)
  33. {
  34. bool isReadOnly = (context.RequestData.ReadInt64() & 1) == 0;
  35. long size = context.RequestData.ReadInt64();
  36. int handle = context.Request.HandleDesc.ToCopy[0];
  37. KTransferMemory transferMem = context.Process.HandleTable.GetObject<KTransferMemory>(handle);
  38. if (size <= 0)
  39. {
  40. return ResultCode.ObjectInvalid;
  41. }
  42. byte[] data = new byte[transferMem.Size];
  43. transferMem.Creator.CpuMemory.Read(transferMem.Address, data);
  44. context.Device.System.KernelContext.Syscall.CloseHandle(handle);
  45. MakeObject(context, new IStorage(data, isReadOnly));
  46. return ResultCode.Success;
  47. }
  48. [CommandHipc(12)] // 2.0.0+
  49. // CreateHandleStorage(u64, handle<copy>) -> object<nn::am::service::IStorage>
  50. public ResultCode CreateHandleStorage(ServiceCtx context)
  51. {
  52. long size = context.RequestData.ReadInt64();
  53. int handle = context.Request.HandleDesc.ToCopy[0];
  54. KTransferMemory transferMem = context.Process.HandleTable.GetObject<KTransferMemory>(handle);
  55. if (size <= 0)
  56. {
  57. return ResultCode.ObjectInvalid;
  58. }
  59. byte[] data = new byte[transferMem.Size];
  60. transferMem.Creator.CpuMemory.Read(transferMem.Address, data);
  61. context.Device.System.KernelContext.Syscall.CloseHandle(handle);
  62. MakeObject(context, new IStorage(data));
  63. return ResultCode.Success;
  64. }
  65. }
  66. }