AbstractRegion.cs 2.3 KB

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