Exemple #1
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
        }
Exemple #2
0
        private void Dispose(bool disposing)
        {
            if (Start != 0)
            {
#if !MONO
                Kernel32.VirtualFree(Z.UU(Start), UIntPtr.Zero, Kernel32.FreeType.RELEASE);
#else
                LibC.munmap(ZC.U(Start), (UIntPtr)Size);
#endif
                Start = 0;
            }
        }