aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Kernel/KTlsPageManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.HLE/HOS/Kernel/KTlsPageManager.cs')
-rw-r--r--Ryujinx.HLE/HOS/Kernel/KTlsPageManager.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/Ryujinx.HLE/HOS/Kernel/KTlsPageManager.cs b/Ryujinx.HLE/HOS/Kernel/KTlsPageManager.cs
new file mode 100644
index 00000000..1fb2ce6a
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Kernel/KTlsPageManager.cs
@@ -0,0 +1,60 @@
+using System;
+
+namespace Ryujinx.HLE.HOS.Kernel
+{
+ class KTlsPageManager
+ {
+ private const int TlsEntrySize = 0x200;
+
+ private long PagePosition;
+
+ private int UsedSlots;
+
+ private bool[] Slots;
+
+ public bool IsEmpty => UsedSlots == 0;
+ public bool IsFull => UsedSlots == Slots.Length;
+
+ public KTlsPageManager(long PagePosition)
+ {
+ this.PagePosition = PagePosition;
+
+ Slots = new bool[KMemoryManager.PageSize / TlsEntrySize];
+ }
+
+ public bool TryGetFreeTlsAddr(out long Position)
+ {
+ Position = PagePosition;
+
+ for (int Index = 0; Index < Slots.Length; Index++)
+ {
+ if (!Slots[Index])
+ {
+ Slots[Index] = true;
+
+ UsedSlots++;
+
+ return true;
+ }
+
+ Position += TlsEntrySize;
+ }
+
+ Position = 0;
+
+ return false;
+ }
+
+ public void FreeTlsSlot(int Slot)
+ {
+ if ((uint)Slot > Slots.Length)
+ {
+ throw new ArgumentOutOfRangeException(nameof(Slot));
+ }
+
+ Slots[Slot] = false;
+
+ UsedSlots--;
+ }
+ }
+} \ No newline at end of file