Misc cleanup (#708)

* Fix typos

* Remove unneeded using statements

* Enforce var style more

* Remove redundant qualifiers

* Fix some indentation

* Disable naming warnings on files with external enum names

* Fix build

* Mass find & replace for comments with no spacing

* Standardize todo capitalization and for/if spacing
This commit is contained in:
Alex Barney 2019-07-01 21:39:22 -05:00 committed by Ac_K
parent 10c74182ba
commit b2b736abc2
205 changed files with 1020 additions and 1041 deletions

View file

@ -114,9 +114,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
nvServicesRg = new KMemoryArrangeRegion(nvServicesRgEnd - nvServicesRgSize, nvServicesRgSize);
appletRg = new KMemoryArrangeRegion(nvServicesRgEnd, appletRgSize);
//Note: There is an extra region used by the kernel, however
//since we are doing HLE we are not going to use that memory, so give all
//the remaining memory space to services.
// Note: There is an extra region used by the kernel, however
// since we are doing HLE we are not going to use that memory, so give all
// the remaining memory space to services.
ulong serviceRgSize = nvServicesRg.Address - DramMemoryMap.SlabHeapEnd;
serviceRg = new KMemoryArrangeRegion(DramMemoryMap.SlabHeapEnd, serviceRgSize);

View file

@ -34,16 +34,16 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
if (range == -1)
{
//Increment would cause a overflow, special case.
// Increment would cause a overflow, special case.
return GenRandomNumber(2, 2, 32, 0xffffffffu, 0xffffffffu);
}
range++;
//This is log2(Range) plus one.
// This is log2(Range) plus one.
int nextRangeLog2 = 64 - BitUtils.CountLeadingZeros64(range);
//If Range is already power of 2, subtract one to use log2(Range) directly.
// If Range is already power of 2, subtract one to use log2(Range) directly.
int rangeLog2 = nextRangeLog2 - (BitUtils.IsPowerOfTwo64(range) ? 1 : 0);
int parts = rangeLog2 > 32 ? 2 : 1;

View file

@ -84,7 +84,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
ulong clientAddrTruncated = BitUtils.AlignDown(desc.ClientAddress, KMemoryManager.PageSize);
ulong clientAddrRounded = BitUtils.AlignUp (desc.ClientAddress, KMemoryManager.PageSize);
//Check if address is not aligned, in this case we need to perform 2 copies.
// Check if address is not aligned, in this case we need to perform 2 copies.
if (clientAddrTruncated != clientAddrRounded)
{
ulong copySize = clientAddrRounded - desc.ClientAddress;

View file

@ -16,8 +16,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
private object _countIncLock;
//TODO: Remove that, we need it for now to allow HLE
//SM implementation to work with the new IPC system.
// TODO: Remove that, we need it for now to allow HLE
// SM implementation to work with the new IPC system.
public IpcService Service { get; set; }
public KClientPort(Horizon system, KPort parent, int maxSessions) : base(system)

View file

@ -13,8 +13,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
public ChannelState State { get; set; }
//TODO: Remove that, we need it for now to allow HLE
//services implementation to work with the new IPC system.
// TODO: Remove that, we need it for now to allow HLE
// services implementation to work with the new IPC system.
public IpcService Service { get; set; }
public KClientSession(Horizon system, KSession parent) : base(system)

View file

@ -327,7 +327,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
uint offset;
//Copy handles.
// Copy handles.
if (clientHeader.HasHandles)
{
if (clientHeader.MoveHandlesCount != 0)
@ -399,7 +399,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
offset = 2;
}
//Copy pointer/receive list buffers.
// Copy pointer/receive list buffers.
uint recvListDstOffset = 0;
for (int index = 0; index < clientHeader.PointerBuffersCount; index++)
@ -455,7 +455,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
offset += 2;
}
//Copy send, receive and exchange buffers.
// Copy send, receive and exchange buffers.
uint totalBuffersCount =
clientHeader.SendBuffersCount +
clientHeader.ReceiveBuffersCount +
@ -551,7 +551,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
offset += 3;
}
//Copy raw data.
// Copy raw data.
if (clientHeader.RawDataSizeInWords != 0)
{
ulong copySrc = clientMsg.Address + offset * 4;
@ -683,13 +683,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return KernelResult.InvalidCombination;
}
//Read receive list.
// Read receive list.
ulong[] receiveList = GetReceiveList(
clientMsg,
clientHeader.ReceiveListType,
clientHeader.ReceiveListOffset);
//Copy receive and exchange buffers.
// Copy receive and exchange buffers.
clientResult = request.BufferDescriptorTable.CopyBuffersToClient(clientProcess.MemoryManager);
if (clientResult != KernelResult.Success)
@ -699,11 +699,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return serverResult;
}
//Copy header.
// Copy header.
System.Device.Memory.WriteUInt32((long)clientMsg.DramAddress + 0, serverHeader.Word0);
System.Device.Memory.WriteUInt32((long)clientMsg.DramAddress + 4, serverHeader.Word1);
//Copy handles.
// Copy handles.
uint offset;
if (serverHeader.HasHandles)
@ -763,7 +763,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
offset = 2;
}
//Copy pointer/receive list buffers.
// Copy pointer/receive list buffers.
uint recvListDstOffset = 0;
for (int index = 0; index < serverHeader.PointerBuffersCount; index++)
@ -811,7 +811,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
offset += 2;
}
//Set send, receive and exchange buffer descriptors to zero.
// Set send, receive and exchange buffer descriptors to zero.
uint totalBuffersCount =
serverHeader.SendBuffersCount +
serverHeader.ReceiveBuffersCount +
@ -828,7 +828,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
offset += 3;
}
//Copy raw data.
// Copy raw data.
if (serverHeader.RawDataSizeInWords != 0)
{
ulong copyDst = clientMsg.Address + offset * 4;
@ -861,7 +861,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
}
}
//Unmap buffers from server.
// Unmap buffers from server.
clientResult = request.BufferDescriptorTable.UnmapServerBuffers(serverProcess.MemoryManager);
if (clientResult != KernelResult.Success)
@ -1125,9 +1125,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
continue;
}
//Client sessions can only be disconnected on async requests (because
//the client would be otherwise blocked waiting for the response), so
//we only need to handle the async case here.
// Client sessions can only be disconnected on async requests (because
// the client would be otherwise blocked waiting for the response), so
// we only need to handle the async case here.
if (request.AsyncEvent != null)
{
SendResultToAsyncRequestClient(request, KernelResult.PortRemoteClosed);
@ -1204,7 +1204,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
private void WakeClientThread(KSessionRequest request, KernelResult result)
{
//Wait client thread waiting for a response for the given request.
// Wait client thread waiting for a response for the given request.
if (request.AsyncEvent != null)
{
SendResultToAsyncRequestClient(request, result);
@ -1237,7 +1237,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
private void WakeServerThreads(KernelResult result)
{
//Wake all server threads waiting for requests.
// Wake all server threads waiting for requests.
System.CriticalSection.Enter();
foreach (KThread thread in WaitingThreads)

View file

@ -23,8 +23,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
private const int KMemoryBlockSize = 0x40;
//We need 2 blocks for the case where a big block
//needs to be split in 2, plus one block that will be the new one inserted.
// We need 2 blocks for the case where a big block
// needs to be split in 2, plus one block that will be the new one inserted.
private const int MaxBlocksNeededForInsertion = 2;
private LinkedList<KMemoryBlock> _blocks;
@ -215,13 +215,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (CodeRegionStart - baseAddress >= addrSpaceEnd - CodeRegionEnd)
{
//Has more space before the start of the code region.
// Has more space before the start of the code region.
mapBaseAddress = baseAddress;
mapAvailableSize = CodeRegionStart - baseAddress;
}
else
{
//Has more space after the end of the code region.
// Has more space after the end of the code region.
mapBaseAddress = CodeRegionEnd;
mapAvailableSize = addrSpaceEnd - CodeRegionEnd;
}
@ -250,8 +250,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
tlsIoRegion.AslrOffset = GetRandomValue(0, aslrMaxOffset >> 21) << 21;
}
//Regions are sorted based on ASLR offset.
//When ASLR is disabled, the order is Map, Heap, NewMap and TlsIo.
// Regions are sorted based on ASLR offset.
// When ASLR is disabled, the order is Map, Heap, NewMap and TlsIo.
aliasRegion.Start = mapBaseAddress + aliasRegion.AslrOffset;
aliasRegion.End = aliasRegion.Start + aliasRegion.Size;
heapRegion.Start = mapBaseAddress + heapRegion.AslrOffset;
@ -336,8 +336,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
private KernelResult InitializeBlocks(ulong addrSpaceStart, ulong addrSpaceEnd)
{
//First insertion will always need only a single block,
//because there's nothing else to split.
// First insertion will always need only a single block,
// because there's nothing else to split.
if (!_blockAllocator.CanAllocate(1))
{
return KernelResult.OutOfResource;
@ -466,13 +466,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
public KernelResult MapNormalMemory(long address, long size, MemoryPermission permission)
{
//TODO.
// TODO.
return KernelResult.Success;
}
public KernelResult MapIoMemory(long address, long size, MemoryPermission permission)
{
//TODO.
// TODO.
return KernelResult.Success;
}
@ -696,7 +696,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return result;
}
//TODO: Missing some checks here.
// TODO: Missing some checks here.
if (!_blockAllocator.CanAllocate(MaxBlocksNeededForInsertion * 2))
{
@ -730,7 +730,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (currentHeapSize <= size)
{
//Expand.
// Expand.
ulong diffSize = size - currentHeapSize;
lock (_blocks)
@ -800,7 +800,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
else
{
//Shrink.
// Shrink.
ulong freeAddr = HeapRegionStart + size;
ulong diffSize = currentHeapSize - size;
@ -1147,7 +1147,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
out _,
out MemoryAttribute attribute))
{
//TODO: Missing checks.
// TODO: Missing checks.
if (!_blockAllocator.CanAllocate(MaxBlocksNeededForInsertion))
{
@ -1225,8 +1225,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
MemoryState newState = oldState;
//If writing into the code region is allowed, then we need
//to change it to mutable.
// If writing into the code region is allowed, then we need
// to change it to mutable.
if ((permission & MemoryPermission.Write) != 0)
{
if (oldState == MemoryState.CodeStatic)
@ -1362,8 +1362,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
lock (_blocks)
{
//Scan, ensure that the region can be unmapped (all blocks are heap or
//already unmapped), fill pages list for freeing memory.
// Scan, ensure that the region can be unmapped (all blocks are heap or
// already unmapped), fill pages list for freeing memory.
ulong heapMappedSize = 0;
KPageList pageList = new KPageList();
@ -1400,7 +1400,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.OutOfResource;
}
//Try to unmap all the heap mapped memory inside range.
// Try to unmap all the heap mapped memory inside range.
KernelResult result = KernelResult.Success;
foreach (KMemoryInfo info in IterateOverRange(address, endAddr))
@ -1416,7 +1416,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (result != KernelResult.Success)
{
//If we failed to unmap, we need to remap everything back again.
// If we failed to unmap, we need to remap everything back again.
MapPhysicalMemory(pageList, address, blockAddress + blockSize);
break;
@ -1508,7 +1508,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryAttribute attributeMask,
MemoryAttribute attributeExpected)
{
//Client -> server.
// Client -> server.
return CopyDataFromOrToCurrentProcess(
size,
src,
@ -1531,7 +1531,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryAttribute attributeExpected,
ulong src)
{
//Server -> client.
// Server -> client.
return CopyDataFromOrToCurrentProcess(
size,
dst,
@ -1731,7 +1731,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
foreach (KMemoryInfo info in IterateOverRange(address, endAddrRounded))
{
//Check if the block state matches what we expect.
// Check if the block state matches what we expect.
if ((info.State & stateMask) != stateMask ||
(info.Permission & permission) != permission ||
(info.Attribute & attributeMask) != MemoryAttribute.None)
@ -1830,12 +1830,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong unusedSizeAfter;
//When the start address is unaligned, we can't safely map the
//first page as it would expose other undesirable information on the
//target process. So, instead we allocate new pages, copy the data
//inside the range, and then clear the remaining space.
//The same also holds for the last page, if the end address
//(address + size) is also not aligned.
// When the start address is unaligned, we can't safely map the
// first page as it would expose other undesirable information on the
// target process. So, instead we allocate new pages, copy the data
// inside the range, and then clear the remaining space.
// The same also holds for the last page, if the end address
// (address + size) is also not aligned.
if (copyData)
{
ulong unusedSizeBefore = address - addressTruncated;
@ -1883,7 +1883,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (endAddrTruncated != endAddrRounded)
{
//End is also not aligned...
// End is also not aligned...
dstLastPagePa = AllocateSinglePage(region, aslrDisabled);
if (dstLastPagePa == 0)
@ -1980,9 +1980,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
for (int unit = MappingUnitSizes.Length - 1; unit >= 0 && va == 0; unit--)
{
int alignemnt = MappingUnitSizes[unit];
int alignment = MappingUnitSizes[unit];
va = AllocateVa(AliasRegionStart, regionPagesCount, neededPagesCount, alignemnt);
va = AllocateVa(AliasRegionStart, regionPagesCount, neededPagesCount, alignment);
}
if (va == 0)
@ -2109,7 +2109,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
foreach (KMemoryInfo info in IterateOverRange(address, endAddrTruncated))
{
//Check if the block state matches what we expect.
// Check if the block state matches what we expect.
if ((info.State & stateMask) != stateMask ||
(info.Attribute & attributeMask) != MemoryAttribute.IpcMapped)
{
@ -2331,7 +2331,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
info = node.Value.GetInfo();
//Check if the block state matches what we expect.
// Check if the block state matches what we expect.
if ( firstState != info.State ||
firstPermission != info.Permission ||
(info.Attribute & attributeMask) != attributeExpected ||
@ -2367,7 +2367,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
foreach (KMemoryInfo info in IterateOverRange(address, address + size))
{
//Check if the block state matches what we expect.
// Check if the block state matches what we expect.
if ((info.State & stateMask) != stateExpected ||
(info.Permission & permissionMask) != permissionExpected ||
(info.Attribute & attributeMask) != attributeExpected)
@ -2404,9 +2404,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryPermission newPermission,
MemoryAttribute newAttribute)
{
//Insert new block on the list only on areas where the state
//of the block matches the state specified on the old* state
//arguments, otherwise leave it as is.
// Insert new block on the list only on areas where the state
// of the block matches the state specified on the old* state
// arguments, otherwise leave it as is.
int oldCount = _blocks.Count;
oldAttribute |= MemoryAttribute.IpcAndDeviceMapped;
@ -2451,7 +2451,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
newNode.Value.SetState(newPermission, newState, newAttribute);
MergeEqualStateNeighbours(newNode);
MergeEqualStateNeighbors(newNode);
}
if (currEndAddr - 1 >= endAddr - 1)
@ -2472,8 +2472,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryPermission permission = MemoryPermission.None,
MemoryAttribute attribute = MemoryAttribute.None)
{
//Inserts new block at the list, replacing and spliting
//existing blocks as needed.
// Inserts new block at the list, replacing and splitting
// existing blocks as needed.
int oldCount = _blocks.Count;
ulong endAddr = baseAddress + pagesCount * PageSize;
@ -2505,7 +2505,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
newNode.Value.SetState(permission, state, attribute);
MergeEqualStateNeighbours(newNode);
MergeEqualStateNeighbors(newNode);
}
if (currEndAddr - 1 >= endAddr - 1)
@ -2537,9 +2537,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
BlockMutator blockMutate,
MemoryPermission permission = MemoryPermission.None)
{
//Inserts new block at the list, replacing and spliting
//existing blocks as needed, then calling the callback
//function on the new block.
// Inserts new block at the list, replacing and splitting
// existing blocks as needed, then calling the callback
// function on the new block.
int oldCount = _blocks.Count;
ulong endAddr = baseAddress + pagesCount * PageSize;
@ -2573,7 +2573,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
blockMutate(newBlock, permission);
MergeEqualStateNeighbours(newNode);
MergeEqualStateNeighbors(newNode);
}
if (currEndAddr - 1 >= endAddr - 1)
@ -2587,7 +2587,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
_blockAllocator.Count += _blocks.Count - oldCount;
}
private void MergeEqualStateNeighbours(LinkedListNode<KMemoryBlock> node)
private void MergeEqualStateNeighbors(LinkedListNode<KMemoryBlock> node)
{
KMemoryBlock block = node.Value;

View file

@ -126,21 +126,21 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong blockPagesCount = bestFitBlockSize / KMemoryManager.PageSize;
//Check if this is the best fit for this page size.
//If so, try allocating as much requested pages as possible.
// Check if this is the best fit for this page size.
// If so, try allocating as much requested pages as possible.
while (blockPagesCount <= pagesCount)
{
ulong address = AllocatePagesForOrder(blockIndex, backwards, bestFitBlockSize);
//The address being zero means that no free space was found on that order,
//just give up and try with the next one.
// The address being zero means that no free space was found on that order,
// just give up and try with the next one.
if (address == 0)
{
break;
}
//Add new allocated page(s) to the pages list.
//If an error occurs, then free all allocated pages and fail.
// Add new allocated page(s) to the pages list.
// If an error occurs, then free all allocated pages and fail.
KernelResult result = pageList.AddRange(address, blockPagesCount);
if (result != KernelResult.Success)
@ -159,13 +159,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
//Success case, all requested pages were allocated successfully.
// Success case, all requested pages were allocated successfully.
if (pagesCount == 0)
{
return KernelResult.Success;
}
//Error case, free allocated pages and return out of memory.
// Error case, free allocated pages and return out of memory.
foreach (KPageNode pageNode in pageList)
{
FreePages(pageNode.Address, pageNode.PagesCount);
@ -321,8 +321,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (address != 0)
{
//If we are using a larger order than best fit, then we should
//split it into smaller blocks.
// If we are using a larger order than best fit, then we should
// split it into smaller blocks.
ulong firstFreeBlockSize = 1UL << block.Order;
if (firstFreeBlockSize > bestFitBlockSize)
@ -416,7 +416,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
//Free inside aligned region.
// Free inside aligned region.
ulong baseAddress = addressRounded;
while (baseAddress < endAddrTruncated)
@ -430,7 +430,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
int nextBlockIndex = blockIndex - 1;
//Free region between Address and aligned region start.
// Free region between Address and aligned region start.
baseAddress = addressRounded;
for (blockIndex = nextBlockIndex; blockIndex >= 0; blockIndex--)
@ -445,7 +445,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
}
}
//Free region between aligned region end and End Address.
// Free region between aligned region end and End Address.
baseAddress = endAddrTruncated;
for (blockIndex = nextBlockIndex; blockIndex >= 0; blockIndex--)

View file

@ -1,10 +1,8 @@
using ChocolArm64.Memory;
using ChocolArm64.State;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Diagnostics.Demangler;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.Loaders.Elf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -75,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
}
}
//TODO: ARM32.
// TODO: ARM32.
long framePointer = (long)threadState.X29;
trace.AppendLine($"Process: {_owner.Name}, PID: {_owner.Pid}");
@ -89,8 +87,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
break;
}
//Note: This is the return address, we need to subtract one instruction
//worth of bytes to get the branch instruction address.
// Note: This is the return address, we need to subtract one instruction
// worth of bytes to get the branch instruction address.
AppendTrace(_owner.CpuMemory.ReadInt64(framePointer + 8) - 4);
framePointer = _owner.CpuMemory.ReadInt64(framePointer);
@ -245,7 +243,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
long ehHdrEndOffset = memory.ReadInt32(mod0Offset + 0x14) + mod0Offset;
long modObjOffset = memory.ReadInt32(mod0Offset + 0x18) + mod0Offset;
//TODO: Elf32.
// TODO: Elf32.
while (true)
{
long tagVal = memory.ReadInt64(dynamicOffset + 0);

View file

@ -350,7 +350,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
private KernelResult ParseProcessInfo(ProcessCreationInfo creationInfo)
{
//Ensure that the current kernel version is equal or above to the minimum required.
// Ensure that the current kernel version is equal or above to the minimum required.
uint requiredKernelVersionMajor = (uint)Capabilities.KernelReleaseVersion >> 19;
uint requiredKernelVersionMinor = ((uint)Capabilities.KernelReleaseVersion >> 15) & 0xf;
@ -429,7 +429,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
if (_freeTlsPages.Count > 0)
{
//If we have free TLS pages available, just use the first one.
// If we have free TLS pages available, just use the first one.
KTlsPageInfo pageInfo = _freeTlsPages.Values.First();
if (!pageInfo.TryGetFreePage(out address))
@ -448,7 +448,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
}
else
{
//Otherwise, we need to create a new one.
// Otherwise, we need to create a new one.
result = AllocateTlsPage(out KTlsPageInfo pageInfo);
if (result == KernelResult.Success)
@ -522,7 +522,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
if (_fullTlsPages.TryGetValue(tlsPageAddr, out pageInfo))
{
//TLS page was full, free slot and move to free pages tree.
// TLS page was full, free slot and move to free pages tree.
_fullTlsPages.Remove(tlsPageAddr);
_freeTlsPages.Add(tlsPageAddr, pageInfo);
@ -538,8 +538,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
if (pageInfo.IsEmpty())
{
//TLS page is now empty, we should ensure it is removed
//from all trees, and free the memory it was using.
// TLS page is now empty, we should ensure it is removed
// from all trees, and free the memory it was using.
_freeTlsPages.Remove(tlsPageAddr);
System.CriticalSection.Leave();
@ -574,7 +574,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
private void GenerateRandomEntropy()
{
//TODO.
// TODO.
}
public KernelResult Start(int mainThreadPriority, ulong stackSize)
@ -603,9 +603,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
ulong neededSize = stackSizeRounded + _imageSize;
//Check if the needed size for the code and the stack will fit on the
//memory usage capacity of this Process. Also check for possible overflow
//on the above addition.
// Check if the needed size for the code and the stack will fit on the
// memory usage capacity of this Process. Also check for possible overflow
// on the above addition.
if (neededSize > _memoryUsageCapacity ||
neededSize < stackSizeRounded)
{
@ -742,10 +742,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
SetState(newState);
//TODO: We can't call KThread.Start from a non-guest thread.
//We will need to make some changes to allow the creation of
//dummy threads that will be used to initialize the current
//thread on KCoreContext so that GetCurrentThread doesn't fail.
// TODO: We can't call KThread.Start from a non-guest thread.
// We will need to make some changes to allow the creation of
// dummy threads that will be used to initialize the current
// thread on KCoreContext so that GetCurrentThread doesn't fail.
/* Result = MainThread.Start();
if (Result != KernelResult.Success)
@ -935,7 +935,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
if (shallTerminate)
{
//UnpauseAndTerminateAllThreadsExcept(System.Scheduler.GetCurrentThread());
// UnpauseAndTerminateAllThreadsExcept(System.Scheduler.GetCurrentThread());
HandleTable.Destroy();
@ -948,12 +948,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
private void UnpauseAndTerminateAllThreadsExcept(KThread thread)
{
//TODO.
// TODO.
}
private void SignalExitForDebugEvent()
{
//TODO: Debug events.
// TODO: Debug events.
}
private void SignalExit()

View file

@ -131,7 +131,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
int codeMask = 1 << (32 - BitUtils.CountLeadingZeros32(code + 1));
//Check if the property was already set.
// Check if the property was already set.
if (((mask0 & codeMask) & 0x1e008) != 0)
{
return KernelResult.InvalidCombination;
@ -223,7 +223,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
case 0x800:
{
//TODO: GIC distributor check.
// TODO: GIC distributor check.
int irq0 = (cap >> 12) & 0x3ff;
int irq1 = (cap >> 22) & 0x3ff;
@ -256,7 +256,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
case 0x4000:
{
//Note: This check is bugged on kernel too, we are just replicating the bug here.
// Note: This check is bugged on kernel too, we are just replicating the bug here.
if ((KernelReleaseVersion >> 17) != 0 || cap < 0x80000)
{
return KernelResult.ReservedValue;

View file

@ -161,7 +161,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
process = thread.Owner;
}
//TODO: KDebugEvent.
// TODO: KDebugEvent.
}
pid = process?.Pid ?? 0;
@ -549,10 +549,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
switch (id)
{
//Memory region capacity.
// Memory region capacity.
case 0: value = (long)region.Size; break;
//Memory region free space.
// Memory region free space.
case 1:
{
ulong freePagesCount = region.GetFreePages();

View file

@ -151,10 +151,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
}
//For functions returning output values, the first registers
//are used to hold pointers where the value will be stored,
//so they can't be used to pass argument and we must
//skip them.
// For functions returning output values, the first registers
// are used to hold pointers where the value will be stored,
// so they can't be used to pass argument and we must
// skip them.
int byRefArgsCount = 0;
for (int index = 0; index < methodArgs.Length; index++)
@ -165,7 +165,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
}
//Print all the arguments for debugging purposes.
// Print all the arguments for debugging purposes.
int inputArgsCount = methodArgs.Length - byRefArgsCount;
generator.Emit(OpCodes.Ldc_I4_S, inputArgsCount);
@ -200,7 +200,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
generator.Emit(OpCodes.Call, printArgsMethod);
//Call the SVC function handler.
// Call the SVC function handler.
generator.Emit(OpCodes.Ldarg_0);
List<LocalBuilder> locals = new List<LocalBuilder>();
@ -239,7 +239,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
Type retType = methodInfo.ReturnType;
//Print result code.
// Print result code.
if (retType == typeof(KernelResult))
{
MethodInfo printResultMethod = typeof(SvcTable).GetMethod(nameof(PrintResult), staticNonPublic);
@ -249,7 +249,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
generator.Emit(OpCodes.Call, printResultMethod);
}
//Save return value into register X0 (when the method has a return value).
// Save return value into register X0 (when the method has a return value).
if (retType != typeof(void))
{
CheckIfTypeIsSupported(retType, svcName);
@ -275,7 +275,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
generator.Emit(OpCodes.Stfld, GetStateFieldX(outRegIndex++));
}
//Zero out the remaining unused registers.
// Zero out the remaining unused registers.
while (outRegIndex < SvcFuncMaxArguments)
{
generator.Emit(OpCodes.Ldarg_1);

View file

@ -175,7 +175,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult SetThreadPriority(int handle, int priority)
{
//TODO: NPDM check.
// TODO: NPDM check.
KThread thread = _process.HandleTable.GetKThread(handle);

View file

@ -68,8 +68,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (hasThreadExecuting)
{
//If this is not the thread that is currently executing, we need
//to request an interrupt to allow safely starting another thread.
// If this is not the thread that is currently executing, we need
// to request an interrupt to allow safely starting another thread.
if (!currentThread.Context.IsCurrentThread())
{
currentThread.Context.RequestInterrupt();
@ -80,8 +80,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
CoreManager.Reset(currentThread.Context.Work);
}
//Advance current core and try picking a thread,
//keep advancing if it is null.
// Advance current core and try picking a thread,
// keep advancing if it is null.
for (int core = 0; core < 4; core++)
{
_currentCore = (_currentCore + 1) % CpuCoresCount;
@ -100,8 +100,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
}
//If nothing was running before, then we are on a "external"
//HLE thread, we don't need to wait.
// If nothing was running before, then we are on a "external"
// HLE thread, we don't need to wait.
if (!hasThreadExecuting)
{
return;
@ -114,9 +114,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
private void PreemptCurrentThread()
{
//Preempts current thread every 10 milliseconds on a round-robin fashion,
//when multi core scheduling is disabled, to try ensuring that all threads
//gets a chance to run.
// Preempts current thread every 10 milliseconds on a round-robin fashion,
// when multi core scheduling is disabled, to try ensuring that all threads
// gets a chance to run.
while (_keepPreempting)
{
lock (CoreContexts)

View file

@ -207,7 +207,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
signaledThreads.Enqueue(thread);
//If the count is <= 0, we should signal all threads waiting.
// If the count is <= 0, we should signal all threads waiting.
if (count >= 1 && --count == 0)
{
break;
@ -234,7 +234,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
{
if (!KernelTransfer.UserToKernelInt32(_system, address, out mutexValue))
{
//Invalid address.
// Invalid address.
requester.SignaledObj = null;
requester.ObjSyncResult = KernelResult.InvalidMemState;
@ -243,12 +243,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (mutexValue != 0)
{
//Update value to indicate there is a mutex waiter now.
// Update value to indicate there is a mutex waiter now.
newMutexValue = mutexValue | HasListenersMask;
}
else
{
//No thread owning the mutex, assign to requesting thread.
// No thread owning the mutex, assign to requesting thread.
newMutexValue = requester.ThreadHandleForUserMutex;
}
}
@ -256,7 +256,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (mutexValue == 0)
{
//We now own the mutex.
// We now own the mutex.
requester.SignaledObj = null;
requester.ObjSyncResult = KernelResult.Success;
@ -271,12 +271,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (mutexOwner != null)
{
//Mutex already belongs to another thread, wait for it.
// Mutex already belongs to another thread, wait for it.
mutexOwner.AddMutexWaiter(requester);
}
else
{
//Invalid mutex owner.
// Invalid mutex owner.
requester.SignaledObj = null;
requester.ObjSyncResult = KernelResult.InvalidHandle;
@ -513,9 +513,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
int offset;
//The value is decremented if the number of threads waiting is less
//or equal to the Count of threads to be signaled, or Count is zero
//or negative. It is incremented if there are no threads waiting.
// The value is decremented if the number of threads waiting is less
// or equal to the Count of threads to be signaled, or Count is zero
// or negative. It is incremented if there are no threads waiting.
int waitingCount = 0;
foreach (KThread thread in ArbiterThreads.Where(x => x.MutexAddress == address))
@ -572,7 +572,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
{
signaledThreads.Enqueue(thread);
//If the count is <= 0, we should signal all threads waiting.
// If the count is <= 0, we should signal all threads waiting.
if (count >= 1 && --count == 0)
{
break;

View file

@ -57,17 +57,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (currentHleThread == null)
{
//Nothing is running, we can perform the context switch immediately.
// Nothing is running, we can perform the context switch immediately.
coreContext.ContextSwitch();
}
else if (currentHleThread.IsCurrentThread())
{
//Thread running on the current core, context switch will block.
// Thread running on the current core, context switch will block.
doContextSwitch = true;
}
else
{
//Thread running on another core, request a interrupt.
// Thread running on another core, request a interrupt.
currentHleThread.RequestInterrupt();
}
}

View file

@ -55,7 +55,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KThread selectedThread = scheduledThreads.FirstOrDefault(x => x.DynamicPriority == prio);
//Yield priority queue.
// Yield priority queue.
if (selectedThread != null)
{
SchedulingData.Reschedule(prio, core, selectedThread);
@ -82,7 +82,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
}
//If the candidate was scheduled after the current thread, then it's not worth it.
// If the candidate was scheduled after the current thread, then it's not worth it.
if (selectedThread == null || selectedThread.LastScheduledTime >= thread.LastScheduledTime)
{
yield return thread;
@ -90,8 +90,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
}
//Select candidate threads that could run on this core.
//Only take into account threads that are not yet selected.
// Select candidate threads that could run on this core.
// Only take into account threads that are not yet selected.
KThread dst = SuitableCandidates().FirstOrDefault(x => x.DynamicPriority == prio);
if (dst != null)
@ -101,8 +101,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
selectedThread = dst;
}
//If the priority of the currently selected thread is lower than preemption priority,
//then allow threads with lower priorities to be selected aswell.
// If the priority of the currently selected thread is lower than preemption priority,
// then allow threads with lower priorities to be selected aswell.
if (selectedThread != null && selectedThread.DynamicPriority > prio)
{
Func<KThread, bool> predicate = x => x.DynamicPriority >= selectedThread.DynamicPriority;
@ -131,8 +131,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
for (int core = 0; core < CpuCoresCount; core++)
{
//If the core is not idle (there's already a thread running on it),
//then we don't need to attempt load balancing.
// If the core is not idle (there's already a thread running on it),
// then we don't need to attempt load balancing.
if (SchedulingData.ScheduledThreads(core).Any())
{
continue;
@ -144,8 +144,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KThread dst = null;
//Select candidate threads that could run on this core.
//Give preference to threads that are not yet selected.
// Select candidate threads that could run on this core.
// Give preference to threads that are not yet selected.
foreach (KThread thread in SchedulingData.SuggestedThreads(core))
{
if (thread.CurrentCore < 0 || thread != CoreContexts[thread.CurrentCore].SelectedThread)
@ -158,11 +158,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
srcCoresHighestPrioThreads[srcCoresHighestPrioThreadsCount++] = thread.CurrentCore;
}
//Not yet selected candidate found.
// Not yet selected candidate found.
if (dst != null)
{
//Priorities < 2 are used for the kernel message dispatching
//threads, we should skip load balancing entirely.
// Priorities < 2 are used for the kernel message dispatching
// threads, we should skip load balancing entirely.
if (dst.DynamicPriority >= 2)
{
SchedulingData.TransferToCore(dst.DynamicPriority, core, dst);
@ -173,8 +173,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
continue;
}
//All candiates are already selected, choose the best one
//(the first one that doesn't make the source core idle if moved).
// All candidates are already selected, choose the best one
// (the first one that doesn't make the source core idle if moved).
for (int index = 0; index < srcCoresHighestPrioThreadsCount; index++)
{
int srcCore = srcCoresHighestPrioThreads[index];
@ -183,8 +183,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (src != null)
{
//Run the second thread on the queue on the source core,
//move the first one to the current core.
// Run the second thread on the queue on the source core,
// move the first one to the current core.
KThread origSelectedCoreSrc = CoreContexts[srcCore].SelectedThread;
CoreContexts[srcCore].SelectThread(src);

View file

@ -20,7 +20,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
_system.CriticalSection.Enter();
//Check if objects are already signaled before waiting.
// Check if objects are already signaled before waiting.
for (int index = 0; index < syncObjs.Length; index++)
{
if (!syncObjs[index].IsSignaled())

View file

@ -276,7 +276,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
public void Exit()
{
//TODO: Debug event.
// TODO: Debug event.
if (Owner != null)
{
@ -352,7 +352,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (DynamicPriority < KScheduler.PrioritiesCount)
{
//Move current thread to the end of the queue.
// Move current thread to the end of the queue.
_schedulingData.Reschedule(DynamicPriority, CurrentCore, this);
}
@ -383,7 +383,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (DynamicPriority < KScheduler.PrioritiesCount)
{
//Move current thread to the end of the queue.
// Move current thread to the end of the queue.
_schedulingData.Reschedule(prio, core, this);
Func<KThread, bool> predicate = x => x.DynamicPriority == prio;
@ -407,8 +407,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
}
//If the candidate was scheduled after the current thread, then it's not worth it,
//unless the priority is higher than the current one.
// If the candidate was scheduled after the current thread, then it's not worth it,
// unless the priority is higher than the current one.
if (nextThreadOnCurrentQueue.LastScheduledTime >= thread.LastScheduledTime ||
nextThreadOnCurrentQueue.DynamicPriority < thread.DynamicPriority)
{
@ -524,7 +524,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
{
if (pause)
{
//Pause, the force pause flag should be clear (thread is NOT paused).
// Pause, the force pause flag should be clear (thread is NOT paused).
if ((_forcePauseFlags & ThreadSchedState.ThreadPauseFlag) == 0)
{
_forcePauseFlags |= ThreadSchedState.ThreadPauseFlag;
@ -538,7 +538,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
else
{
//Unpause, the force pause flag should be set (thread is paused).
// Unpause, the force pause flag should be set (thread is paused).
if ((_forcePauseFlags & ThreadSchedState.ThreadPauseFlag) != 0)
{
ThreadSchedState oldForcePauseFlags = _forcePauseFlags;
@ -604,7 +604,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
bool useOverride = _affinityOverrideCount != 0;
//The value -3 is "do not change the preferred core".
// The value -3 is "do not change the preferred core".
if (newCore == -3)
{
newCore = useOverride ? _preferredCoreOverride : PreferredCore;
@ -766,7 +766,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
do
{
//Skip all threads that are not waiting for this mutex.
// Skip all threads that are not waiting for this mutex.
while (currentNode != null && currentNode.Value.MutexAddress != mutexAddress)
{
currentNode = currentNode.Next;
@ -785,12 +785,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (newMutexOwner != null)
{
//New owner was already selected, re-insert on new owner list.
// New owner was already selected, re-insert on new owner list.
newMutexOwner.AddToMutexWaitersList(currentNode.Value);
}
else
{
//New owner not selected yet, use current thread.
// New owner not selected yet, use current thread.
newMutexOwner = currentNode.Value;
}
@ -812,9 +812,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
private void UpdatePriorityInheritance()
{
//If any of the threads waiting for the mutex has
//higher priority than the current thread, then
//the current thread inherits that priority.
// If any of the threads waiting for the mutex has
// higher priority than the current thread, then
// the current thread inherits that priority.
int highestPriority = BasePriority;
if (_mutexWaiters.First != null)
@ -837,7 +837,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (MutexOwner != null)
{
//Remove and re-insert to ensure proper sorting based on new priority.
// Remove and re-insert to ensure proper sorting based on new priority.
MutexOwner._mutexWaiters.Remove(_mutexWaiterNode);
MutexOwner.AddToMutexWaitersList(this);
@ -877,7 +877,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (oldFlags == ThreadSchedState.Running)
{
//Was running, now it's stopped.
// Was running, now it's stopped.
if (CurrentCore >= 0)
{
_schedulingData.Unschedule(DynamicPriority, CurrentCore, this);
@ -893,7 +893,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
else if (SchedFlags == ThreadSchedState.Running)
{
//Was stopped, now it's running.
// Was stopped, now it's running.
if (CurrentCore >= 0)
{
_schedulingData.Schedule(DynamicPriority, CurrentCore, this);
@ -918,7 +918,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
return;
}
//Remove thread from the old priority queues.
// Remove thread from the old priority queues.
if (CurrentCore >= 0)
{
_schedulingData.Unschedule(oldPriority, CurrentCore, this);
@ -932,7 +932,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
}
//Add thread to the new priority queues.
// Add thread to the new priority queues.
KThread currentThread = _scheduler.GetCurrentThread();
if (CurrentCore >= 0)
@ -965,7 +965,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
return;
}
//Remove thread from the old priority queues.
// Remove thread from the old priority queues.
for (int core = 0; core < KScheduler.CpuCoresCount; core++)
{
if (((oldAffinityMask >> core) & 1) != 0)
@ -981,7 +981,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
}
}
//Add thread to the new priority queues.
// Add thread to the new priority queues.
for (int core = 0; core < KScheduler.CpuCoresCount; core++)
{
if (((AffinityMask >> core) & 1) != 0)
@ -1069,7 +1069,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
System.CriticalSection.Enter();
//Wake up all threads that may be waiting for a mutex being held by this thread.
// Wake up all threads that may be waiting for a mutex being held by this thread.
foreach (KThread thread in _mutexWaiters)
{
thread.MutexOwner = null;