Skip to content

Commit

Permalink
Fix tests on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Sep 10, 2022
1 parent 0cf85ff commit 3eedb72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Varena.Tests/TestVirtualArena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void TestProtect()
using var manager = new VirtualArenaManager();
var buffer = manager.CreateBuffer("Hello", 1 << 20);
var span = buffer.AllocateRange(1024);
buffer.Protect(VirtualMemoryFlags.All);
Assert.AreEqual(VirtualMemoryFlags.All, buffer.Flags);
buffer.Protect(VirtualMemoryFlags.ReadWrite);
Assert.AreEqual(VirtualMemoryFlags.ReadWrite, buffer.Flags);
span[0] = 1;
buffer.Protect(VirtualMemoryFlags.Read);

Expand Down
2 changes: 1 addition & 1 deletion src/Varena.Tests/TestVirtualMemoryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void TestProtections()
VirtualMemoryFlags.Write,
})
{
Assert.IsTrue(handler.TryProtect(range, flags));
Assert.IsTrue(handler.TryProtect(range, flags), $"Unable to protect {flags}");
}
}
finally
Expand Down
10 changes: 9 additions & 1 deletion src/Varena/VirtualMemoryHandler.Posix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ private static MemoryProtection GetMemoryProtection(VirtualMemoryFlags flags)
{
var protect = MemoryProtection.PROT_NONE;

if ((flags & VirtualMemoryFlags.Execute) != 0) protect |= MemoryProtection.PROT_EXEC;
if ((flags & VirtualMemoryFlags.Execute) != 0)
{
protect |= MemoryProtection.PROT_EXEC;
// On MacOS, using exec cannot be used with read/write
if (OperatingSystem.IsMacOS())
{
return protect;
}
}
if ((flags & VirtualMemoryFlags.Read) != 0) protect |= MemoryProtection.PROT_READ;
if ((flags & VirtualMemoryFlags.Write) != 0) protect |= MemoryProtection.PROT_WRITE;
return protect;
Expand Down

0 comments on commit 3eedb72

Please sign in to comment.