Exemplo n.º 1
0
        public PosixPageFileBackedMemoryMapPager(string file, long?initialFileSize = null)
        {
            var instanceId = Interlocked.Increment(ref _counter);

            _file = "/" + Syscall.getpid() + "-" + instanceId + "-" + file;
            _fd   = Rt.shm_open(_file, OpenFlags.O_RDWR | OpenFlags.O_CREAT, (int)FilePermissions.ALLPERMS);
            if (_fd == -1)
            {
                PosixHelper.ThrowLastError(Marshal.GetLastWin32Error());
            }

            SysPageSize = Syscall.sysconf(SysconfName._SC_PAGESIZE);

            if (initialFileSize.HasValue)
            {
                _totalAllocationSize = NearestSizeToPageSize(initialFileSize.Value);
            }

            _totalAllocationSize = NearestSizeToPageSize(_totalAllocationSize);
            var result = Syscall.ftruncate(_fd, _totalAllocationSize);

            if (result != 0)
            {
                PosixHelper.ThrowLastError(result);
            }

            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
            PagerState.Release();
            PagerState = CreatePagerState();
        }
Exemplo n.º 2
0
        private PagerState CreatePagerState()
        {
            var startingBaseAddressPtr = Syscall.mmap(IntPtr.Zero, (ulong)_totalAllocationSize,
                                                      MmapProts.PROT_READ | MmapProts.PROT_WRITE,
                                                      MmapFlags.MAP_SHARED, _fd, 0);

            if (startingBaseAddressPtr.ToInt64() == -1)             //system didn't succeed in mapping the address where we wanted
            {
                PosixHelper.ThrowLastError(Marshal.GetLastWin32Error());
            }

            var allocationInfo = new PagerState.AllocationInfo
            {
                BaseAddress = (byte *)startingBaseAddressPtr.ToPointer(),
                Size        = _totalAllocationSize,
                MappedFile  = null
            };

            var newPager = new PagerState(this)
            {
                Files           = null,       // unused
                MapBase         = allocationInfo.BaseAddress,
                AllocationInfos = new[] { allocationInfo }
            };

            newPager.AddRef();             // one for the pager
            return(newPager);
        }
Exemplo n.º 3
0
        public override void ReleaseAllocationInfo(byte *baseAddress, long size)
        {
            var result = Syscall.munmap(new IntPtr(baseAddress), (ulong)size);

            if (result == -1)
            {
                PosixHelper.ThrowLastError(Marshal.GetLastWin32Error());
            }
        }