diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2018-11-28 20:18:09 -0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-28 20:18:09 -0200 |
| commit | 00579927e43bf55ee06ae02933c1e755fb4120eb (patch) | |
| tree | 0fd06db7b28e0accf87b465ec6f4dc74691febab /Ryujinx.HLE/Memory/ArenaAllocator.cs | |
| parent | e7fe7d724778535f8eff390abef54274a343c0b7 (diff) | |
Better process implementation (#491)
* Initial implementation of KProcess
* Some improvements to the memory manager, implement back guest stack trace printing
* Better GetInfo implementation, improve checking in some places with information from process capabilities
* Allow the cpu to read/write from the correct memory locations for accesses crossing a page boundary
* Change long -> ulong for address/size on memory related methods to avoid unnecessary casts
* Attempt at implementing ldr:ro with new KProcess
* Allow BSS with size 0 on ldr:ro
* Add checking for memory block slab heap usage, return errors if full, exit gracefully
* Use KMemoryBlockSize const from KMemoryManager
* Allow all methods to read from non-contiguous locations
* Fix for TransactParcelAuto
* Address PR feedback, additionally fix some small issues related to the KIP loader and implement SVCs GetProcessId, GetProcessList, GetSystemInfo, CreatePort and ManageNamedPort
* Fix wrong check for source pages count from page list on MapPhysicalMemory
* Fix some issues with UnloadNro on ldr:ro
Diffstat (limited to 'Ryujinx.HLE/Memory/ArenaAllocator.cs')
| -rw-r--r-- | Ryujinx.HLE/Memory/ArenaAllocator.cs | 150 |
1 files changed, 0 insertions, 150 deletions
diff --git a/Ryujinx.HLE/Memory/ArenaAllocator.cs b/Ryujinx.HLE/Memory/ArenaAllocator.cs deleted file mode 100644 index 9bcb7873..00000000 --- a/Ryujinx.HLE/Memory/ArenaAllocator.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System.Collections.Generic; - -namespace Ryujinx.HLE.Memory -{ - class ArenaAllocator - { - private class Region - { - public long Position { get; set; } - public long Size { get; set; } - - public Region(long Position, long Size) - { - this.Position = Position; - this.Size = Size; - } - } - - private LinkedList<Region> FreeRegions; - - public long TotalAvailableSize { get; private set; } - public long TotalUsedSize { get; private set; } - - public ArenaAllocator(long ArenaSize) - { - TotalAvailableSize = ArenaSize; - - FreeRegions = new LinkedList<Region>(); - - FreeRegions.AddFirst(new Region(0, ArenaSize)); - } - - public bool TryAllocate(long Size, out long Position) - { - LinkedListNode<Region> Node = FreeRegions.First; - - while (Node != null) - { - Region Rg = Node.Value; - - if ((ulong)Rg.Size >= (ulong)Size) - { - Position = Rg.Position; - - Rg.Position += Size; - Rg.Size -= Size; - - if (Rg.Size == 0) - { - //Region is empty, just remove it. - FreeRegions.Remove(Node); - } - else if (Node.Previous != null) - { - //Re-sort based on size (smaller first). - Node = Node.Previous; - - FreeRegions.Remove(Node.Next); - - while (Node != null && (ulong)Node.Value.Size > (ulong)Rg.Size) - { - Node = Node.Previous; - } - - if (Node != null) - { - FreeRegions.AddAfter(Node, Rg); - } - else - { - FreeRegions.AddFirst(Rg); - } - } - - TotalUsedSize += Size; - - return true; - } - - Node = Node.Next; - } - - Position = 0; - - return false; - } - - public void Free(long Position, long Size) - { - long End = Position + Size; - - Region NewRg = new Region(Position, Size); - - LinkedListNode<Region> Node = FreeRegions.First; - LinkedListNode<Region> PrevSz = null; - - while (Node != null) - { - LinkedListNode<Region> NextNode = Node.Next; - - Region Rg = Node.Value; - - long RgEnd = Rg.Position + Rg.Size; - - if (Rg.Position == End) - { - //Current region position matches the end of the freed region, - //just merge the two and remove the current region from the list. - NewRg.Size += Rg.Size; - - FreeRegions.Remove(Node); - } - else if (RgEnd == Position) - { - //End of the current region matches the position of the freed region, - //just merge the two and remove the current region from the list. - NewRg.Position = Rg.Position; - NewRg.Size += Rg.Size; - - FreeRegions.Remove(Node); - } - else - { - if (PrevSz == null) - { - PrevSz = Node; - } - else if ((ulong)Rg.Size < (ulong)NewRg.Size && - (ulong)Rg.Size > (ulong)PrevSz.Value.Size) - { - PrevSz = Node; - } - } - - Node = NextNode; - } - - if (PrevSz != null && (ulong)PrevSz.Value.Size < (ulong)Size) - { - FreeRegions.AddAfter(PrevSz, NewRg); - } - else - { - FreeRegions.AddFirst(NewRg); - } - - TotalUsedSize -= Size; - } - } -}
\ No newline at end of file |
