private void TestZeroMemory() { if (linuxProtectedMemoryAllocator == null) { return; } byte[] origValue = { 1, 2, 3, 4 }; ulong length = (ulong)origValue.Length; IntPtr pointer = linuxProtectedMemoryAllocator.Alloc(length); try { Marshal.Copy(origValue, 0, pointer, (int)length); byte[] retValue = new byte[length]; Marshal.Copy(pointer, retValue, 0, (int)length); Assert.Equal(origValue, retValue); linuxProtectedMemoryAllocator.ZeroMemory(pointer, length); Marshal.Copy(pointer, retValue, 0, (int)length); Assert.Equal(new byte[] { 0, 0, 0, 0 }, retValue); } finally { linuxProtectedMemoryAllocator.Free(pointer, length); } }
private void TestAllocFree() { Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); byte[] origValue = { 1, 2, 3, 4 }; ulong length = (ulong)origValue.Length; IntPtr pointer = linuxProtectedMemoryAllocator.Alloc(length); try { Marshal.Copy(origValue, 0, pointer, (int)length); byte[] retValue = new byte[length]; Marshal.Copy(pointer, retValue, 0, (int)length); Assert.Equal(origValue, retValue); } finally { linuxProtectedMemoryAllocator.Free(pointer, length); } }