private static IntPtr AllocateInternal(ulong size, MmapProts prot, bool shared = false) { MmapFlags flags = MmapFlags.MAP_ANONYMOUS; if (shared) { flags |= MmapFlags.MAP_SHARED | MmapFlags.MAP_UNLOCKED; } else { flags |= MmapFlags.MAP_PRIVATE; } if (prot == MmapProts.PROT_NONE) { flags |= MmapFlags.MAP_NORESERVE; } IntPtr ptr = mmap(IntPtr.Zero, size, prot, flags, -1, 0); if (ptr == new IntPtr(-1L)) { throw new OutOfMemoryException(); } if (!_allocations.TryAdd(ptr, size)) { // This should be impossible, kernel shouldn't return an already mapped address. throw new InvalidOperationException(); } return(ptr); }
public static IntPtr mmap64(IntPtr start, UIntPtr length, MmapProts prot, MmapFlags flags, int fd, long offset) { if (PlatformDetails.RunningOnMacOsx) { return(mmap64_mac(start, length, prot, flags, fd, offset)); } return(mmap64_posix(start, length, prot, flags, fd, offset)); }
public static Int32 FromMmapFlags(MmapFlags value) { Int32 rval; if (FromMmapFlags(value, out rval) == -1) { ThrowArgumentException(value); } return(rval); }
public static IntPtr Reserve(ulong size) { ulong pageSize = (ulong)Syscall.sysconf(SysconfName._SC_PAGESIZE); const MmapProts prot = MmapProts.PROT_NONE; const MmapFlags flags = MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS; IntPtr ptr = Syscall.mmap(IntPtr.Zero, size + pageSize, prot, flags, -1, 0); if (ptr == IntPtr.Zero) { throw new OutOfMemoryException(); } return(ptr); }
private static IntPtr AllocateInternal(ulong size, MmapProts prot) { const MmapFlags flags = MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS; IntPtr ptr = Syscall.mmap(IntPtr.Zero, size, prot, flags, -1, 0); if (ptr == new IntPtr(-1L)) { throw new OutOfMemoryException(); } if (!_allocations.TryAdd(ptr, size)) { // This should be impossible, kernel shouldn't return an already mapped address. throw new InvalidOperationException(); } return(ptr); }
public static IntPtr Allocate(ulong size) { ulong pageSize = (ulong)Syscall.sysconf(SysconfName._SC_PAGESIZE); const MmapProts prot = MmapProts.PROT_READ | MmapProts.PROT_WRITE; const MmapFlags flags = MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS; IntPtr ptr = Syscall.mmap(IntPtr.Zero, size + pageSize, prot, flags, -1, 0); if (ptr == IntPtr.Zero) { throw new OutOfMemoryException(); } unsafe { ptr = new IntPtr(ptr.ToInt64() + (long)pageSize); *((ulong *)ptr - 1) = size; } return(ptr); }
public static bool TryToMmapFlags(Int32 value, out MmapFlags rval) { return(ToMmapFlags(value, out rval) == 0); }
public static IntPtr mmap(IntPtr start, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset) { throw new System.NotImplementedException(); }
public static extern IntPtr mmap (IntPtr start, ulong length, MmapProt prot, MmapFlags flags, int fd, long offset);
private static extern IntPtr mmap64_mac(IntPtr start, UIntPtr length, MmapProts prot, MmapFlags flags, int fd, long offset);
public static IntPtr mmap(IntPtr address, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset) { return(Internal_mmap(address, length, prot, MmapFlagsToSystemFlags(flags), fd, offset)); }
public static bool TryToMmapFlags (Int32 value, out MmapFlags rval) { return ToMmapFlags (value, out rval) == 0; }
public static Int32 FromMmapFlags (MmapFlags value) { Int32 rval; if (FromMmapFlags (value, out rval) == -1) ThrowArgumentException (value); return rval; }
/// <summary> /// Allocate memory block. /// </summary> /// <param name="length">Length to allocate.</param> /// <returns>Address of block allocated.</returns> public static IntPtr mmap(int length, MmapProts prots, MmapFlags flags) { return(Syscall.mmap(IntPtr.Zero, (ulong)length, prots, flags, 0, 0)); }
public static int remap_file_pages (IntPtr start, ulong size, MmapProts prot, long pgoff, MmapFlags flags) { throw new System.NotImplementedException(); }
public static IntPtr mmap (IntPtr start, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset) { throw new System.NotImplementedException(); }
public static extern int remap_file_pages (IntPtr start, ulong size, MmapProt prot, long pgoff, MmapFlags flags);
private static extern int FromMmapFlags (MmapFlags value, out Int32 rval);
public static bool TryFromMmapFlags (MmapFlags value, out Int32 rval) { return FromMmapFlags (value, out rval) == 0; }
private static int FromMmapFlags (MmapFlags value, out Int32 rval) { throw new System.NotImplementedException(); }
private static extern int ToMmapFlags (Int32 value, out MmapFlags rval);
private static int ToMmapFlags (Int32 value, out MmapFlags rval) { throw new System.NotImplementedException(); }
public static int remap_file_pages(IntPtr start, ulong size, MmapProts prot, long pgoff, MmapFlags flags) { throw new System.NotImplementedException(); }
private static extern int FromMmapFlags(MmapFlags value, out Int32 rval);
private static int MmapFlagsToSystemFlags(MmapFlags flags) { int result = 0; if (flags.HasFlag(MmapFlags.MAP_SHARED)) { result |= (int)MmapFlags.MAP_SHARED; } if (flags.HasFlag(MmapFlags.MAP_PRIVATE)) { result |= (int)MmapFlags.MAP_PRIVATE; } if (flags.HasFlag(MmapFlags.MAP_FIXED)) { result |= (int)MmapFlags.MAP_FIXED; } if (flags.HasFlag(MmapFlags.MAP_ANONYMOUS)) { if (OperatingSystem.IsLinux()) { result |= MAP_ANONYMOUS_LINUX_GENERIC; } else if (OperatingSystem.IsMacOS()) { result |= MAP_ANONYMOUS_DARWIN; } else { throw new NotImplementedException(); } } if (flags.HasFlag(MmapFlags.MAP_NORESERVE)) { if (OperatingSystem.IsLinux()) { result |= MAP_NORESERVE_LINUX_GENERIC; } else if (OperatingSystem.IsMacOS()) { result |= MAP_NORESERVE_DARWIN; } else { throw new NotImplementedException(); } } if (flags.HasFlag(MmapFlags.MAP_UNLOCKED)) { if (OperatingSystem.IsLinux()) { result |= MAP_UNLOCKED_LINUX_GENERIC; } else if (OperatingSystem.IsMacOS()) { // FIXME: Doesn't exist on Darwin } else { throw new NotImplementedException(); } } if (OperatingSystem.IsMacOSVersionAtLeast(10, 14)) { result |= MAP_JIT_DARWIN; } return(result); }
private static int ToMmapFlags(Int32 value, out MmapFlags rval) { throw new System.NotImplementedException(); }
public static bool TryFromMmapFlags(MmapFlags value, out Int32 rval) { return(FromMmapFlags(value, out rval) == 0); }
public static extern IntPtr mmap(IntPtr start, UIntPtr length, MmapProts prot, MmapFlags flags, int fd, IntPtr offset);
private static int FromMmapFlags(MmapFlags value, out Int32 rval) { throw new System.NotImplementedException(); }
private static extern int ToMmapFlags(Int32 value, out MmapFlags rval);
public static extern IntPtr mmap(IntPtr start, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset);
public static extern int remap_file_pages (IntPtr start, ulong size, MmapProts prot, long pgoff, MmapFlags flags);