SharedMemoryStorage.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. namespace Ryujinx.HLE.HOS.Kernel.Memory
  3. {
  4. class SharedMemoryStorage
  5. {
  6. private readonly KernelContext _context;
  7. private readonly KPageList _pageList;
  8. private readonly ulong _size;
  9. public SharedMemoryStorage(KernelContext context, KPageList pageList)
  10. {
  11. _context = context;
  12. _pageList = pageList;
  13. _size = pageList.GetPagesCount() * KPageTableBase.PageSize;
  14. foreach (KPageNode pageNode in pageList)
  15. {
  16. ulong address = pageNode.Address - DramMemoryMap.DramBase;
  17. ulong size = pageNode.PagesCount * KPageTableBase.PageSize;
  18. context.Memory.Commit(address, size);
  19. }
  20. }
  21. public void ZeroFill()
  22. {
  23. for (ulong offset = 0; offset < _size; offset += sizeof(ulong))
  24. {
  25. GetRef<ulong>(offset) = 0;
  26. }
  27. }
  28. public ref T GetRef<T>(ulong offset) where T : unmanaged
  29. {
  30. if (_pageList.Nodes.Count == 1)
  31. {
  32. ulong address = _pageList.Nodes.First.Value.Address - DramMemoryMap.DramBase;
  33. return ref _context.Memory.GetRef<T>(address + offset);
  34. }
  35. throw new NotImplementedException("Non-contiguous shared memory is not yet supported.");
  36. }
  37. public KPageList GetPageList()
  38. {
  39. return _pageList;
  40. }
  41. }
  42. }