diff --git a/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs b/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs index 922ce4e38..f35dbec7f 100644 --- a/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs +++ b/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs @@ -23,7 +23,7 @@ namespace Ryujinx.Audio.Renderer.Common if (size != 0) { - ulong alignedOffset = BitUtils.AlignUp(Offset, align); + ulong alignedOffset = BitUtils.AlignUp(Offset, (ulong)align); if (alignedOffset + size <= (ulong)BackingMemory.Length) { @@ -55,7 +55,7 @@ namespace Ryujinx.Audio.Renderer.Common public static ulong GetTargetSize(ulong currentSize, ulong count, int align) where T : unmanaged { - return BitUtils.AlignUp(currentSize, align) + (ulong)Unsafe.SizeOf() * count; + return BitUtils.AlignUp(currentSize, (ulong)align) + (ulong)Unsafe.SizeOf() * count; } } } \ No newline at end of file diff --git a/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs b/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs index 5116f7ca8..53570243d 100644 --- a/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs +++ b/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs @@ -167,7 +167,7 @@ namespace Ryujinx.Audio.Renderer.Server return ResultCode.WorkBufferTooSmall; } - _depopBuffer = workBufferAllocator.Allocate((ulong)BitUtils.AlignUp(parameter.MixBufferCount, Constants.BufferAlignment), Constants.BufferAlignment); + _depopBuffer = workBufferAllocator.Allocate(BitUtils.AlignUp(parameter.MixBufferCount, Constants.BufferAlignment), Constants.BufferAlignment); if (_depopBuffer.IsEmpty) { @@ -772,7 +772,7 @@ namespace Ryujinx.Audio.Renderer.Server size = WorkBufferAllocator.GetTargetSize(size, Constants.TargetSampleCount * (Constants.VoiceChannelCountMax + parameter.MixBufferCount) * (parameter.SinkCount + parameter.SubMixBufferCount), 0x10); // Depop buffer - size = WorkBufferAllocator.GetTargetSize(size, (ulong)BitUtils.AlignUp(parameter.MixBufferCount, Constants.BufferAlignment), Constants.BufferAlignment); + size = WorkBufferAllocator.GetTargetSize(size, BitUtils.AlignUp(parameter.MixBufferCount, Constants.BufferAlignment), Constants.BufferAlignment); // Voice size = WorkBufferAllocator.GetTargetSize(size, parameter.VoiceCount, VoiceState.Alignment); @@ -804,10 +804,10 @@ namespace Ryujinx.Audio.Renderer.Server { ulong performanceMetricsPerFramesSize = PerformanceManager.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter, ref behaviourContext) * (parameter.PerformanceMetricFramesCount + 1) + 0xC; - size += BitUtils.AlignUp(performanceMetricsPerFramesSize, Constants.PerformanceMetricsPerFramesSizeAlignment); + size += BitUtils.AlignUp(performanceMetricsPerFramesSize, Constants.PerformanceMetricsPerFramesSizeAlignment); } - return BitUtils.AlignUp(size, Constants.WorkBufferAlignment); + return BitUtils.AlignUp(size, Constants.WorkBufferAlignment); } public ResultCode QuerySystemEvent(out IWritableEvent systemEvent) diff --git a/Ryujinx.Common/Utilities/BitUtils.cs b/Ryujinx.Common/Utilities/BitUtils.cs index a42e2cc7d..f885ce844 100644 --- a/Ryujinx.Common/Utilities/BitUtils.cs +++ b/Ryujinx.Common/Utilities/BitUtils.cs @@ -1,82 +1,26 @@ +using System; using System.Numerics; namespace Ryujinx.Common { public static class BitUtils { - public static uint AlignUp(uint value, int size) + public static T AlignUp(T value, T size) + where T : IBinaryInteger { - return (uint)AlignUp((int)value, size); + return (value + (size - T.One)) & -size; } - public static int AlignUp(int value, int size) - { - return (value + (size - 1)) & -size; - } - - public static ulong AlignUp(ulong value, int size) - { - return (ulong)AlignUp((long)value, size); - } - - public static long AlignUp(long value, int size) - { - return AlignUp(value, (long)size); - } - - public static ulong AlignUp(ulong value, ulong size) - { - return (ulong)AlignUp((long)value, (long)size); - } - - public static long AlignUp(long value, long size) - { - return (value + (size - 1)) & -size; - } - - public static uint AlignDown(uint value, int size) - { - return (uint)AlignDown((int)value, size); - } - - public static int AlignDown(int value, int size) + public static T AlignDown(T value, T size) + where T : IBinaryInteger { return value & -size; } - public static ulong AlignDown(ulong value, int size) + public static T DivRoundUp(T value, T dividend) + where T : IBinaryInteger { - return (ulong)AlignDown((long)value, size); - } - - public static long AlignDown(long value, int size) - { - return AlignDown(value, (long)size); - } - - public static ulong AlignDown(ulong value, ulong size) - { - return (ulong)AlignDown((long)value, (long)size); - } - - public static long AlignDown(long value, long size) - { - return value & -size; - } - - public static int DivRoundUp(int value, int dividend) - { - return (value + dividend - 1) / dividend; - } - - public static ulong DivRoundUp(ulong value, uint dividend) - { - return (value + dividend - 1) / dividend; - } - - public static long DivRoundUp(long value, int dividend) - { - return (value + dividend - 1) / dividend; + return (value + (dividend - T.One)) / dividend; } public static int Pow2RoundUp(int value) diff --git a/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs b/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs index 6120d2950..f6effe2ed 100644 --- a/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs +++ b/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs @@ -100,7 +100,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory _isLinear = (argument & 1) != 0; _offset = 0; - _size = (int)(BitUtils.AlignUp(state.LineLengthIn, 4) * state.LineCount); + _size = (int)(BitUtils.AlignUp(state.LineLengthIn, 4) * state.LineCount); int count = _size / 4; diff --git a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs index 1728cdb58..e20e1bb68 100644 --- a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs @@ -252,7 +252,7 @@ namespace Ryujinx.Graphics.Gpu.Memory RecordStorageAlignment(_cpStorageBuffers, index, gpuVa); - gpuVa = BitUtils.AlignDown(gpuVa, _context.Capabilities.StorageBufferOffsetAlignment); + gpuVa = BitUtils.AlignDown(gpuVa, (ulong)_context.Capabilities.StorageBufferOffsetAlignment); ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size); @@ -276,7 +276,7 @@ namespace Ryujinx.Graphics.Gpu.Memory RecordStorageAlignment(buffers, index, gpuVa); - gpuVa = BitUtils.AlignDown(gpuVa, _context.Capabilities.StorageBufferOffsetAlignment); + gpuVa = BitUtils.AlignDown(gpuVa, (ulong)_context.Capabilities.StorageBufferOffsetAlignment); ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size); diff --git a/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs b/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs index 66d339b8c..dc3eb598a 100644 --- a/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs +++ b/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs @@ -53,7 +53,7 @@ namespace Ryujinx.Graphics.Vulkan { var range = _freeRanges[i]; - ulong alignedOffset = BitUtils.AlignUp(range.Offset, (int)alignment); + ulong alignedOffset = BitUtils.AlignUp(range.Offset, alignment); ulong sizeDelta = alignedOffset - range.Offset; ulong usableSize = range.Size - sizeDelta; @@ -196,7 +196,7 @@ namespace Ryujinx.Graphics.Vulkan } } - ulong blockAlignedSize = BitUtils.AlignUp(size, _blockAlignment); + ulong blockAlignedSize = BitUtils.AlignUp(size, (ulong)_blockAlignment); var memoryAllocateInfo = new MemoryAllocateInfo() { diff --git a/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs b/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs index a4e7f5895..5726299ba 100644 --- a/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs +++ b/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs @@ -81,8 +81,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc attributeMask |= MemoryAttribute.DeviceMapped; } - ulong clientAddrTruncated = BitUtils.AlignDown(desc.ClientAddress, KPageTableBase.PageSize); - ulong clientAddrRounded = BitUtils.AlignUp (desc.ClientAddress, KPageTableBase.PageSize); + ulong clientAddrTruncated = BitUtils.AlignDown(desc.ClientAddress, KPageTableBase.PageSize); + ulong clientAddrRounded = BitUtils.AlignUp(desc.ClientAddress, KPageTableBase.PageSize); // Check if address is not aligned, in this case we need to perform 2 copies. if (clientAddrTruncated != clientAddrRounded) @@ -113,9 +113,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc ulong clientEndAddr = desc.ClientAddress + desc.Size; ulong serverEndAddr = desc.ServerAddress + desc.Size; - ulong clientEndAddrTruncated = BitUtils.AlignDown(clientEndAddr, KPageTableBase.PageSize); - ulong clientEndAddrRounded = BitUtils.AlignUp (clientEndAddr, KPageTableBase.PageSize); - ulong serverEndAddrTruncated = BitUtils.AlignDown(serverEndAddr, KPageTableBase.PageSize); + ulong clientEndAddrTruncated = BitUtils.AlignDown(clientEndAddr, (ulong)KPageTableBase.PageSize); + ulong clientEndAddrRounded = BitUtils.AlignUp(clientEndAddr, KPageTableBase.PageSize); + ulong serverEndAddrTruncated = BitUtils.AlignDown(serverEndAddr, (ulong)KPageTableBase.PageSize); if (clientEndAddrTruncated < clientEndAddrRounded && (clientAddrTruncated == clientAddrRounded || clientAddrTruncated < clientEndAddrTruncated)) diff --git a/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs b/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs index dc5ad7177..199e78dc6 100644 --- a/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs +++ b/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs @@ -1005,7 +1005,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc recvListEndAddr = recvListBaseAddr + size; } - recvListBufferAddress = BitUtils.AlignUp(recvListBaseAddr + dstOffset, 0x10); + recvListBufferAddress = BitUtils.AlignUp(recvListBaseAddr + dstOffset, 0x10); ulong endAddress = recvListBufferAddress + descriptor.BufferSize; diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs index 2df93d789..05cf4a4f9 100644 --- a/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs +++ b/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs @@ -44,7 +44,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory public KernelResult Map(ulong address, ulong size, KMemoryPermission perm) { - if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) + if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, (ulong)KPageTableBase.PageSize)) { return KernelResult.InvalidSize; } @@ -73,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory public KernelResult MapToOwner(ulong address, ulong size, KMemoryPermission permission) { - if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) + if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, (ulong)KPageTableBase.PageSize)) { return KernelResult.InvalidSize; } @@ -102,7 +102,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory public KernelResult Unmap(ulong address, ulong size) { - if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) + if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, (ulong)KPageTableBase.PageSize)) { return KernelResult.InvalidSize; } @@ -128,7 +128,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory public KernelResult UnmapFromOwner(ulong address, ulong size) { - if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) + if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) { return KernelResult.InvalidSize; } diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs index 0568325ad..fa090b02c 100644 --- a/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs +++ b/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs @@ -101,7 +101,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory for (int depth = HighestDepthIndex; depth >= 0; depth--) { _bitStorages[depth] = storage; - size = BitUtils.DivRoundUp(size, UInt64BitSize); + size = BitUtils.DivRoundUp(size, (ulong)UInt64BitSize); storage = storage.Slice((int)size); } @@ -288,7 +288,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory for (int depth = GetRequiredDepth(regionSize) - 1; depth >= 0; depth--) { - regionSize = BitUtils.DivRoundUp(regionSize, UInt64BitSize); + regionSize = BitUtils.DivRoundUp(regionSize, UInt64BitSize); overheadBits += (int)regionSize; } diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs index 39ecfdeae..c3586ed78 100644 --- a/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs +++ b/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs @@ -48,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { int diff = 1 << (NextShift - Shift); - offset = BitUtils.AlignDown(offset, diff); + offset = BitUtils.AlignDown(offset, (ulong)diff); if (_bitmap.ClearRange(offset, diff)) { diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs index 501d1cc42..2c94cba22 100644 --- a/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs +++ b/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs @@ -203,8 +203,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory heapRegion.Size = 0x180000000; stackRegion.Size = 0x80000000; tlsIoRegion.Size = 0x1000000000; - CodeRegionStart = BitUtils.AlignDown(address, 0x200000); - codeRegionSize = BitUtils.AlignUp(endAddr, 0x200000) - CodeRegionStart; + CodeRegionStart = BitUtils.AlignDown(address, 0x200000); + codeRegionSize = BitUtils.AlignUp(endAddr, 0x200000) - CodeRegionStart; stackAndTlsIoStart = 0; stackAndTlsIoEnd = 0; baseAddress = 0x8000000; @@ -1584,8 +1584,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory return KernelResult.OutOfResource; } - ulong srcMapAddress = BitUtils.AlignUp(src, PageSize); - ulong srcMapEndAddr = BitUtils.AlignDown(src + size, PageSize); + ulong srcMapAddress = BitUtils.AlignUp(src, PageSize); + ulong srcMapEndAddr = BitUtils.AlignDown(src + size, PageSize); ulong srcMapSize = srcMapEndAddr - srcMapAddress; result = MapPagesFromClientProcess(size, src, permission, state, srcPageTable, send, out ulong va); @@ -1659,10 +1659,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory attributeMask |= MemoryAttribute.DeviceMapped; } - ulong addressRounded = BitUtils.AlignUp(address, PageSize); - ulong addressTruncated = BitUtils.AlignDown(address, PageSize); - ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize); - ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize); + ulong addressRounded = BitUtils.AlignUp(address, PageSize); + ulong addressTruncated = BitUtils.AlignDown(address, PageSize); + ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize); + ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize); if (!_slabManager.CanAllocate(MaxBlocksNeededForInsertion)) { @@ -1769,10 +1769,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory ulong endAddr = address + size; - ulong addressTruncated = BitUtils.AlignDown(address, PageSize); - ulong addressRounded = BitUtils.AlignUp(address, PageSize); - ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize); - ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize); + ulong addressTruncated = BitUtils.AlignDown(address, PageSize); + ulong addressRounded = BitUtils.AlignUp(address, PageSize); + ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize); + ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize); ulong neededSize = endAddrRounded - addressTruncated; @@ -1983,10 +1983,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory return KernelResult.OutOfResource; } - ulong addressTruncated = BitUtils.AlignDown(address, PageSize); - ulong addressRounded = BitUtils.AlignUp(address, PageSize); - ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize); - ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize); + ulong addressTruncated = BitUtils.AlignDown(address, PageSize); + ulong addressRounded = BitUtils.AlignUp(address, PageSize); + ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize); + ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize); ulong pagesCount = (endAddrRounded - addressTruncated) / PageSize; @@ -2010,10 +2010,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { ulong endAddr = address + size; - ulong addressRounded = BitUtils.AlignUp(address, PageSize); - ulong addressTruncated = BitUtils.AlignDown(address, PageSize); - ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize); - ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize); + ulong addressRounded = BitUtils.AlignUp(address, PageSize); + ulong addressTruncated = BitUtils.AlignDown(address, PageSize); + ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize); + ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize); ulong pagesCount = addressRounded < endAddrTruncated ? (endAddrTruncated - addressRounded) / PageSize : 0; @@ -2540,7 +2540,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory for (int attempt = 0; attempt < 8; attempt++) { - ulong aslrAddress = BitUtils.AlignDown(regionStart + GetRandomValue(0, aslrMaxOffset) * (ulong)alignment, alignment); + ulong aslrAddress = BitUtils.AlignDown(regionStart + GetRandomValue(0, aslrMaxOffset) * (ulong)alignment, (ulong)alignment); ulong aslrEndAddr = aslrAddress + totalNeededSize; KMemoryInfo info = _blockManager.FindBlock(aslrAddress).GetInfo(); @@ -2618,7 +2618,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory currBaseAddr += reservedSize; - ulong address = BitUtils.AlignDown(currBaseAddr, alignment) + reservedStart; + ulong address = BitUtils.AlignDown(currBaseAddr, (ulong)alignment) + reservedStart; if (currBaseAddr > address) { @@ -2834,7 +2834,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory { lock (_blockManager) { - return BitUtils.DivRoundUp(GetMmUsedSize(), PageSize); + return BitUtils.DivRoundUp(GetMmUsedSize(), PageSize); } } diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs index 3711b9dfa..3af627505 100644 --- a/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs +++ b/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs @@ -33,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory KProcess process, KMemoryPermission permission) { - if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) + if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) { return KernelResult.InvalidSize; } @@ -52,7 +52,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory public KernelResult UnmapFromProcess(KPageTableBase memoryManager, ulong address, ulong size, KProcess process) { - if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) + if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) { return KernelResult.InvalidSize; } diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs index 107f04c91..2888efb83 100644 --- a/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs +++ b/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs @@ -67,7 +67,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory KProcess process, KMemoryPermission permission) { - if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) + if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) { return KernelResult.InvalidSize; } @@ -95,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory ulong size, KProcess process) { - if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize)) + if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, (ulong)KPageTableBase.PageSize)) { return KernelResult.InvalidSize; } diff --git a/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs b/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs index 4c95821c1..6a2d45ea4 100644 --- a/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs +++ b/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs @@ -472,7 +472,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public KernelResult FreeThreadLocalStorage(ulong tlsSlotAddr) { - ulong tlsPageAddr = BitUtils.AlignDown(tlsSlotAddr, KPageTableBase.PageSize); + ulong tlsPageAddr = BitUtils.AlignDown(tlsSlotAddr, KPageTableBase.PageSize); KernelContext.CriticalSection.Enter(); @@ -554,7 +554,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process throw new InvalidOperationException("Trying to start a process with a invalid state!"); } - ulong stackSizeRounded = BitUtils.AlignUp(stackSize, KPageTableBase.PageSize); + ulong stackSizeRounded = BitUtils.AlignUp(stackSize, KPageTableBase.PageSize); ulong neededSize = stackSizeRounded + _imageSize; diff --git a/Ryujinx.HLE/HOS/ProgramLoader.cs b/Ryujinx.HLE/HOS/ProgramLoader.cs index 66fa20fad..beeb5ad60 100644 --- a/Ryujinx.HLE/HOS/ProgramLoader.cs +++ b/Ryujinx.HLE/HOS/ProgramLoader.cs @@ -47,7 +47,7 @@ namespace Ryujinx.HLE.HOS endOffset = kip.BssOffset + kip.BssSize; } - uint codeSize = BitUtils.AlignUp(kip.TextOffset + endOffset, KPageTableBase.PageSize); + uint codeSize = BitUtils.AlignUp(kip.TextOffset + endOffset, KPageTableBase.PageSize); int codePagesCount = (int)(codeSize / KPageTableBase.PageSize); @@ -195,7 +195,7 @@ namespace Ryujinx.HLE.HOS nsoSize = dataEnd; } - nsoSize = BitUtils.AlignUp(nsoSize, KPageTableBase.PageSize); + nsoSize = BitUtils.AlignUp(nsoSize, KPageTableBase.PageSize); nsoBase[index] = codeStart + (ulong)codeSize; @@ -349,7 +349,7 @@ namespace Ryujinx.HLE.HOS return KernelResult.Success; } - size = BitUtils.AlignUp(size, KPageTableBase.PageSize); + size = BitUtils.AlignUp(size, KPageTableBase.PageSize); return process.MemoryManager.SetProcessMemoryPermission(address, size, permission); } diff --git a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs index a111d5d65..36e1078fd 100644 --- a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs +++ b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs @@ -321,7 +321,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro ulong bssStart = dataStart + (ulong)relocatableObject.Data.Length; - ulong bssEnd = BitUtils.AlignUp(bssStart + (ulong)relocatableObject.BssSize, KPageTableBase.PageSize); + ulong bssEnd = BitUtils.AlignUp(bssStart + relocatableObject.BssSize, KPageTableBase.PageSize); process.CpuMemory.Write(textStart, relocatableObject.Text); process.CpuMemory.Write(roStart, relocatableObject.Ro); diff --git a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs index fbe38c08a..19b221571 100644 --- a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs +++ b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs @@ -36,7 +36,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger { uint headerSize = (uint)Unsafe.SizeOf(); - _rawData = new byte[BitUtils.AlignUp(headerSize + payloadSize + objectsSize, 4)]; + _rawData = new byte[BitUtils.AlignUp(headerSize + payloadSize + objectsSize, 4)]; Header.PayloadSize = payloadSize; Header.ObjectsSize = objectsSize;