예제 #1
0
        public MemoryBlock(UIntPtr start, long size)
        {
#if !MONO
            Start = Kernel32.VirtualAlloc(start, checked ((UIntPtr)size),
                                          Kernel32.AllocationType.RESERVE | Kernel32.AllocationType.COMMIT,
                                          Kernel32.MemoryProtection.NOACCESS);
            if (Start == UIntPtr.Zero)
            {
                throw new InvalidOperationException("VirtualAlloc() returned NULL");
            }
            if (start != UIntPtr.Zero)
            {
                End = (UIntPtr)((long)start + size);
            }
            else
            {
                End = (UIntPtr)((long)Start + size);
            }
            Size = (long)End - (long)Start;
#else
            Start = LibC.mmap(start, checked ((UIntPtr)size), 0, LibC.MapType.MAP_ANONYMOUS, -1, IntPtr.Zero);
            if (Start == UIntPtr.Zero)
            {
                throw new InvalidOperationException("mmap() returned NULL");
            }
            End  = (UIntPtr)((long)Start + size);
            Size = (long)End - (long)Start;
#endif
        }
예제 #2
0
        /// <summary>
        /// allocate size bytes starting at a particular address
        /// </summary>
        /// <param name="start"></param>
        /// <param name="size"></param>
        public MemoryBlock(ulong start, ulong size)
        {
#if !MONO
            Start = (ulong)Kernel32.VirtualAlloc(Z.UU(start), Z.UU(size),
                                                 Kernel32.AllocationType.RESERVE | Kernel32.AllocationType.COMMIT,
                                                 Kernel32.MemoryProtection.NOACCESS);
            if (Start == 0)
            {
                throw new InvalidOperationException("VirtualAlloc() returned NULL");
            }
            if (start != 0)
            {
                End = start + size;
            }
            else
            {
                End = Start + size;
            }
            Size = End - Start;
#else
            Start = (ulong)LibC.mmap(ZC.U(start), ZC.U(size), 0, LibC.MapType.MAP_ANONYMOUS, -1, IntPtr.Zero);
            if (Start == 0)
            {
                throw new InvalidOperationException("mmap() returned NULL");
            }
            End  = Start + size;
            Size = End - Start;
#endif
        }
예제 #3
0
 static void openEndpoint(string path, ref FileHandle file, ref IntPtr mapped, int size)
 {
     file   = FileHandle.openFile(path, eFileFlags.O_RDWR | eFileFlags.O_SYNC);
     mapped = LibC.mmap(IntPtr.Zero, (UIntPtr)size, eMemoryProtection.ReadWrite, (int)eMapFlags.Shared, file, (IntPtr)0);
     if (mapped == LibC.MAP_FAILED)
     {
         throw LibC.exception($"memory map failed for device \"{ path }\"", -1);
     }
 }