ILibraryAppletCreator.cs 3.1 KB

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