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