blob: 5ce5a299daafdc42076921ddc7aa638dd8e7ccf6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
using Ryujinx.HLE.HOS.Kernel.Memory;
namespace Ryujinx.HLE.HOS.Kernel.Process
{
class KTlsPageInfo
{
public const int TlsEntrySize = 0x200;
public ulong PageAddr { get; private set; }
private bool[] _isSlotFree;
public KTlsPageInfo(ulong pageAddress)
{
PageAddr = pageAddress;
_isSlotFree = new bool[KMemoryManager.PageSize / TlsEntrySize];
for (int index = 0; index < _isSlotFree.Length; index++)
{
_isSlotFree[index] = true;
}
}
public bool TryGetFreePage(out ulong address)
{
address = PageAddr;
for (int index = 0; index < _isSlotFree.Length; index++)
{
if (_isSlotFree[index])
{
_isSlotFree[index] = false;
return true;
}
address += TlsEntrySize;
}
address = 0;
return false;
}
public bool IsFull()
{
bool hasFree = false;
for (int index = 0; index < _isSlotFree.Length; index++)
{
hasFree |= _isSlotFree[index];
}
return !hasFree;
}
public bool IsEmpty()
{
bool allFree = true;
for (int index = 0; index < _isSlotFree.Length; index++)
{
allFree &= _isSlotFree[index];
}
return allFree;
}
public void FreeTlsSlot(ulong address)
{
_isSlotFree[(address - PageAddr) / TlsEntrySize] = true;
}
}
}
|