diff --git a/src/BizHawk.BizInvoke/MemoryBlockBase.cs b/src/BizHawk.BizInvoke/MemoryBlockBase.cs
index 359db4c6d4..1219c9b4d2 100644
--- a/src/BizHawk.BizInvoke/MemoryBlockBase.cs
+++ b/src/BizHawk.BizInvoke/MemoryBlockBase.cs
@@ -17,15 +17,15 @@ namespace BizHawk.BizInvoke
throw new ArgumentOutOfRangeException(nameof(size), size, "cannot create 0-length block");
Start = start;
Size = WaterboxUtils.AlignUp(size);
- End = Start + Size;
- _pageData = new Protection[GetPage(End - 1) + 1];
+ EndExclusive = Start + Size;
+ _pageData = new Protection[GetPage(EndExclusive - 1) + 1];
}
/// stores last set memory protection value for each page
protected readonly Protection[] _pageData;
- /// ending address of the memory block; equal to +
- public readonly ulong End;
+ /// end address of the memory block (not part of the block; class invariant: equal to + )
+ public readonly ulong EndExclusive;
/// total size of the memory block
public readonly ulong Size;
@@ -44,7 +44,7 @@ namespace BizHawk.BizInvoke
/// get a page index within the block
protected int GetPage(ulong addr)
{
- if (addr < Start || End <= addr) throw new ArgumentOutOfRangeException();
+ if (addr < Start || EndExclusive <= addr) throw new ArgumentOutOfRangeException(nameof(addr), addr, "invalid address");
return (int) ((addr - Start) >> WaterboxUtils.PageShift);
}
@@ -52,23 +52,23 @@ namespace BizHawk.BizInvoke
protected ulong GetStartAddr(int page) => ((ulong) page << WaterboxUtils.PageShift) + Start;
/// Get a stream that can be used to read or write from part of the block. Does not check for or change !
- /// or end (= + ) are outside
+ /// or end (= + - 1) are outside [, ), the range of the block
public Stream GetStream(ulong start, ulong length, bool writer)
{
if (start < Start)
- throw new ArgumentOutOfRangeException(nameof(start));
- if (End < start + length)
- throw new ArgumentOutOfRangeException(nameof(length));
+ throw new ArgumentOutOfRangeException(nameof(start), start, "invalid address");
+ if (EndExclusive < start + length)
+ throw new ArgumentOutOfRangeException(nameof(length), length, "requested length implies invalid end address");
return new MemoryViewStream(!writer, writer, (long) start, (long) length, this);
}
/// get a stream that can be used to read or write from part of the block. both reads and writes will be XORed against an earlier recorded snapshot
- /// or end (= + ) are outside bounds of memory block ( and )
+ /// or end (= + - 1) are outside [, ), the range of the block
/// no snapshot taken (haven't called )
public Stream GetXorStream(ulong start, ulong length, bool writer)
{
- if (start < Start) throw new ArgumentOutOfRangeException(nameof(start));
- if (End < start + length) throw new ArgumentOutOfRangeException(nameof(length));
+ if (start < Start) throw new ArgumentOutOfRangeException(nameof(start), start, "invalid address");
+ if (EndExclusive < start + length) throw new ArgumentOutOfRangeException(nameof(length), length, "requested length implies invalid end address");
if (_snapshot == null) throw new InvalidOperationException("No snapshot taken!");
return new MemoryViewXorStream(!writer, writer, (long) start, (long) length, this, _snapshot, (long) (start - Start));
}
diff --git a/src/BizHawk.Emulation.Cores/Waterbox/MapHeap.cs b/src/BizHawk.Emulation.Cores/Waterbox/MapHeap.cs
index 7785161181..8b34a4aff3 100644
--- a/src/BizHawk.Emulation.Cores/Waterbox/MapHeap.cs
+++ b/src/BizHawk.Emulation.Cores/Waterbox/MapHeap.cs
@@ -178,7 +178,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
{
// TODO: what is the expected behavior when everything requested for remap is allocated,
// but with different protections?
- if (start < Memory.Start || start + oldSize > Memory.End || oldSize == 0 || newSize == 0)
+ if (start < Memory.Start || start + oldSize > Memory.EndExclusive || oldSize == 0 || newSize == 0)
return 0;
var oldStartPage = GetPage(start);
@@ -243,7 +243,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
public bool Protect(ulong start, ulong size, MemoryBlockBase.Protection prot)
{
- if (start < Memory.Start || start + size > Memory.End || size == 0)
+ if (start < Memory.Start || start + size > Memory.EndExclusive || size == 0)
return false;
var startPage = GetPage(start);
diff --git a/src/BizHawk.Emulation.Cores/Waterbox/PeRunner.cs b/src/BizHawk.Emulation.Cores/Waterbox/PeRunner.cs
index d377963c8f..822cb1ff32 100644
--- a/src/BizHawk.Emulation.Cores/Waterbox/PeRunner.cs
+++ b/src/BizHawk.Emulation.Cores/Waterbox/PeRunner.cs
@@ -432,7 +432,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
var start = heap.Memory.Start;
var end = start + heap.Used;
- var max = heap.Memory.End;
+ var max = heap.Memory.EndExclusive;
var p = (ulong)_p;