Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 156f554

Browse files
committed
Fix for linux mmap requiring MAP_PRIVATE
mac mmap allows it, so just set it on both platforms.
1 parent 9ffb705 commit 156f554

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/runtime/typemanager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ class UnixMemoryMapper : IMemoryMapper
592592
const int PROT_WRITE = 0x2;
593593
const int PROT_EXEC = 0x4;
594594

595+
const int MAP_PRIVATE = 0x2;
595596
int MAP_ANONYMOUS
596597
{
597598
get
@@ -616,7 +617,9 @@ int MAP_ANONYMOUS
616617

617618
public IntPtr MapWriteable(int numBytes)
618619
{
619-
return mmap(IntPtr.Zero, new IntPtr(numBytes), PROT_READ | PROT_WRITE, MAP_ANONYMOUS, -1, IntPtr.Zero);
620+
// MAP_PRIVATE must be set on linux, even though MAP_ANON implies it.
621+
// It doesn't hurt on darwin, so just do it.
622+
return mmap(IntPtr.Zero, new IntPtr(numBytes), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, IntPtr.Zero);
620623
}
621624

622625
public void SetReadExec(IntPtr mappedMemory, int numBytes)

0 commit comments

Comments
 (0)