diff options
author | Mary <me@thog.eu> | 2021-10-24 23:52:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-24 18:52:59 -0300 |
commit | b4dc33efc2890bc0d60e99f715425d6af4a72b3d (patch) | |
tree | 6b5a712903a20d23db5a2be70b6c1d03c8d0f019 /Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs | |
parent | 8c4e4ab3b32eb2dfe5e26fab95648b7872fe2c28 (diff) |
kernel: Clear pages allocated with SetHeapSize (#2776)
* kernel: Clear pages allocated with SetHeapSize
Before this commit, all new pages allocated by SetHeapSize were not
cleared by the kernel.
This would cause undefined data to be pass to the userland and possibly
resulting in weird memory corruption.
This commit also add support for custom fill heap and ipc value (that is also
supported by the official kernel)
* Remove dots at the end of KPageTableBase.MapPages new documentation
* Remove unused _stackFillValue
Diffstat (limited to 'Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs')
-rw-r--r-- | Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs index 965e03d9..ff87ecb7 100644 --- a/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs +++ b/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs @@ -75,6 +75,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory public abstract bool SupportsMemoryAliasing { get; } + private MemoryFillValue _heapFillValue; + private MemoryFillValue _ipcFillValue; + public KPageTableBase(KernelContext context) { Context = context; @@ -82,6 +85,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory _blockManager = new KMemoryBlockManager(); _isKernel = false; + + _heapFillValue = MemoryFillValue.Zero; + _ipcFillValue = MemoryFillValue.Zero; } private static readonly int[] AddrSpaceSizes = new int[] { 32, 36, 32, 39 }; @@ -299,6 +305,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory TlsIoRegionStart = tlsIoRegion.Start; TlsIoRegionEnd = tlsIoRegion.End; + // TODO: Check kernel configuration via secure monitor call when implemented to set memory fill values. + _currentHeapAddr = HeapRegionStart; _heapCapacity = 0; PhysicalMemoryUsage = 0; @@ -738,7 +746,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory return KernelResult.InvalidMemState; } - result = MapPages(_currentHeapAddr, pageList, KMemoryPermission.ReadAndWrite); + result = MapPages(_currentHeapAddr, pageList, KMemoryPermission.ReadAndWrite, true, (byte)_heapFillValue); if (result != KernelResult.Success) { @@ -1783,7 +1791,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { ulong unusedSizeBefore = address - addressTruncated; - Context.Memory.ZeroFill(GetDramAddressFromPa(dstFirstPagePa), unusedSizeBefore); + Context.Memory.Fill(GetDramAddressFromPa(dstFirstPagePa), unusedSizeBefore, (byte)_ipcFillValue); ulong copySize = addressRounded <= endAddr ? addressRounded - address : size; var data = srcPageTable.GetSpan(addressTruncated + unusedSizeBefore, (int)copySize); @@ -1801,7 +1809,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory if (unusedSizeAfter != 0) { - Context.Memory.ZeroFill(GetDramAddressFromPa(firstPageFillAddress), unusedSizeAfter); + Context.Memory.Fill(GetDramAddressFromPa(firstPageFillAddress), unusedSizeAfter, (byte)_ipcFillValue); } KernelResult result = MapPages(currentVa, 1, dstFirstPagePa, permission); @@ -1853,7 +1861,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory unusedSizeAfter = PageSize; } - Context.Memory.ZeroFill(GetDramAddressFromPa(lastPageFillAddr), unusedSizeAfter); + Context.Memory.Fill(GetDramAddressFromPa(lastPageFillAddr), unusedSizeAfter, (byte)_ipcFillValue); KernelResult result = MapPages(currentVa, 1, dstLastPagePa, permission); @@ -2779,8 +2787,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory /// <param name="pagesCount">Number of pages to map</param> /// <param name="srcPa">Physical address where the pages should be mapped. May be ignored if aliasing is not supported</param> /// <param name="permission">Permission of the region to be mapped</param> + /// <param name="shouldFillPages">Indicate if the pages should be filled with the <paramref name="fillValue"/> value</param> + /// <param name="fillValue">The value used to fill pages when <paramref name="shouldFillPages"/> is set to true</param> /// <returns>Result of the mapping operation</returns> - protected abstract KernelResult MapPages(ulong dstVa, ulong pagesCount, ulong srcPa, KMemoryPermission permission); + protected abstract KernelResult MapPages(ulong dstVa, ulong pagesCount, ulong srcPa, KMemoryPermission permission, bool shouldFillPages = false, byte fillValue = 0); /// <summary> /// Maps a region of memory into the specified physical memory region. @@ -2788,8 +2798,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory /// <param name="address">Destination virtual address that should be mapped</param> /// <param name="pageList">List of physical memory pages where the pages should be mapped. May be ignored if aliasing is not supported</param> /// <param name="permission">Permission of the region to be mapped</param> + /// <param name="shouldFillPages">Indicate if the pages should be filled with the <paramref name="fillValue"/> value</param> + /// <param name="fillValue">The value used to fill pages when <paramref name="shouldFillPages"/> is set to true</param> /// <returns>Result of the mapping operation</returns> - protected abstract KernelResult MapPages(ulong address, KPageList pageList, KMemoryPermission permission); + protected abstract KernelResult MapPages(ulong address, KPageList pageList, KMemoryPermission permission, bool shouldFillPages = false, byte fillValue = 0); /// <summary> /// Maps a region of memory into the specified host memory ranges. |