Fixed bitness assumptions in MessageHeap

This commit is contained in:
Yoshi Askharoun
2022-06-05 14:27:09 -05:00
parent 18fd5f6445
commit 3503068de0
@@ -49,8 +49,8 @@ namespace Microsoft.Iris.Render.Protocol
public unsafe void* Alloc(uint size) public unsafe void* Alloc(uint size)
{ {
size += this.allocExtraSize; size += this.allocExtraSize;
uint num = (uint)(sizeof(void*) - 1); int num = sizeof(void*) - 1;
size = (uint)((int)size + (int)num & ~(int)num); size = (uint)((int)size + num & ~num);
MessageHeap.BlockInfo block = this.tailBlock; MessageHeap.BlockInfo block = this.tailBlock;
if (size > block.size - block.used) if (size > block.size - block.used)
{ {
@@ -63,8 +63,8 @@ namespace Microsoft.Iris.Render.Protocol
} }
block = this.CreateBlock(type, actualSize); block = this.CreateBlock(type, actualSize);
} }
this.ZeroMemoryBlock(block, block.used, this.allocExtraSize); this.ZeroMemoryBlock(block, block.used, allocExtraSize);
void* voidPtr = (void*)((int)block.data + ((int)block.used + (int)this.allocExtraSize)); void* voidPtr = (void*)((nint)block.data + (block.used + allocExtraSize));
block.used += size; block.used += size;
++this.key; ++this.key;
return voidPtr; return voidPtr;
@@ -170,7 +170,7 @@ namespace Microsoft.Iris.Render.Protocol
{ {
if (p >= blockInfo.data) if (p >= blockInfo.data)
{ {
void* voidPtr = (void*)((int)blockInfo.data + (int)blockInfo.used); void* voidPtr = (void*)((nint)blockInfo.data + blockInfo.used);
if (p < voidPtr) if (p < voidPtr)
return blockInfo; return blockInfo;
} }
@@ -181,9 +181,9 @@ namespace Microsoft.Iris.Render.Protocol
private unsafe void ZeroMemoryBlock(MessageHeap.BlockInfo block, uint offset, uint size) private unsafe void ZeroMemoryBlock(MessageHeap.BlockInfo block, uint offset, uint size)
{ {
Debug2.Validate(offset + size <= block.size, typeof(ArgumentOutOfRangeException), "Invalid memory range for block"); Debug2.Validate(offset + size <= block.size, typeof(ArgumentOutOfRangeException), "Invalid memory range for block");
byte* numPtr1 = (byte*)((int)block.data + (int)offset); byte* start = (byte*)((nint)block.data + offset);
for (byte* numPtr2 = numPtr1 + (int)size; numPtr1 < numPtr2; ++numPtr1) for (byte* current = start + size; start < current; ++start)
*numPtr1 = 0; *start = 0;
} }
protected override void Invariant() => Debug2.Validate(!this.IsDisposed, typeof(InvalidOperationException), "MessageHeap has already been disposed"); protected override void Invariant() => Debug2.Validate(!this.IsDisposed, typeof(InvalidOperationException), "MessageHeap has already been disposed");