/ src / Ryujinx.Memory / Tracking / AbstractRegion.cs
AbstractRegion.cs
 1  using Ryujinx.Memory.Range;
 2  
 3  namespace Ryujinx.Memory.Tracking
 4  {
 5      /// <summary>
 6      /// A region of memory.
 7      /// </summary>
 8      abstract class AbstractRegion : INonOverlappingRange
 9      {
10          /// <summary>
11          /// Base address.
12          /// </summary>
13          public ulong Address { get; }
14  
15          /// <summary>
16          /// Size of the range in bytes.
17          /// </summary>
18          public ulong Size { get; protected set; }
19  
20          /// <summary>
21          /// End address.
22          /// </summary>
23          public ulong EndAddress => Address + Size;
24  
25          /// <summary>
26          /// Create a new region.
27          /// </summary>
28          /// <param name="address">Base address</param>
29          /// <param name="size">Size of the range</param>
30          protected AbstractRegion(ulong address, ulong size)
31          {
32              Address = address;
33              Size = size;
34          }
35  
36          /// <summary>
37          /// Check if this range overlaps with another.
38          /// </summary>
39          /// <param name="address">Base address</param>
40          /// <param name="size">Size of the range</param>
41          /// <returns>True if overlapping, false otherwise</returns>
42          public bool OverlapsWith(ulong address, ulong size)
43          {
44              return Address < address + size && address < EndAddress;
45          }
46  
47          /// <summary>
48          /// Signals to the handles that a memory event has occurred, and unprotects the region. Assumes that the tracking lock has been obtained.
49          /// </summary>
50          /// <param name="address">Address accessed</param>
51          /// <param name="size">Size of the region affected in bytes</param>
52          /// <param name="write">Whether the region was written to or read</param>
53          /// <param name="exemptId">Optional ID of the handles that should not be signalled</param>
54          public abstract void Signal(ulong address, ulong size, bool write, int? exemptId);
55  
56          /// <summary>
57          /// Signals to the handles that a precise memory event has occurred. Assumes that the tracking lock has been obtained.
58          /// </summary>
59          /// <param name="address">Address accessed</param>
60          /// <param name="size">Size of the region affected in bytes</param>
61          /// <param name="write">Whether the region was written to or read</param>
62          /// <param name="exemptId">Optional ID of the handles that should not be signalled</param>
63          public abstract void SignalPrecise(ulong address, ulong size, bool write, int? exemptId);
64  
65          /// <summary>
66          /// Split this region into two, around the specified address.
67          /// This region is updated to end at the split address, and a new region is created to represent past that point.
68          /// </summary>
69          /// <param name="splitAddress">Address to split the region around</param>
70          /// <returns>The second part of the split region, with start address at the given split.</returns>
71          public abstract INonOverlappingRange Split(ulong splitAddress);
72      }
73  }