예제 #1
0
        public override unsafe void ReleaseAllocationInfo(byte *baseAddress, long size)
        {
            base.ReleaseAllocationInfo(baseAddress, size);

            if (_supportsUnmapping == false)
            {
                return;
            }

            var ptr = new IntPtr(baseAddress);

            if (DeleteOnClose)
            {
                if (Syscall.madvise(ptr, new UIntPtr((ulong)size), MAdvFlags.MADV_DONTNEED) != 0)
                {
                    if (_log.IsInfoEnabled)
                    {
                        _log.Info($"Failed to madvise MDV_DONTNEED for {FileName?.FullPath}");
                    }
                }
            }

            var result = Syscall.munmap(ptr, (UIntPtr)size);

            if (result == -1)
            {
                var err = Marshal.GetLastWin32Error();
                Syscall.ThrowLastError(err, "munmap " + FileName);
            }
            NativeMemory.UnregisterFileMapping(FileName.FullPath, ptr, size);
        }
예제 #2
0
 public override void ReleaseAllocationInfo(byte *baseAddress, long size)
 {
     base.ReleaseAllocationInfo(baseAddress, size);
     if (Win32MemoryMapNativeMethods.UnmapViewOfFile(baseAddress) == false)
     {
         throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to UnMapView of file " + FileName);
     }
     NativeMemory.UnregisterFileMapping(_fileInfo.FullName, new IntPtr(baseAddress), size);
 }
예제 #3
0
        private void CleanupMemory(TransactionState txState)
        {
            _globalMemory.EnterWriteLock();
            try
            {
                foreach (var addr in txState.AddressesToUnload)
                {
                    if (addr.Usages != 0)
                    {
                        continue;
                    }

                    if (!_globalMapping.TryGetValue(addr.StartPage, out var set))
                    {
                        continue;
                    }

                    if (!set.TryRemove(addr))
                    {
                        continue;
                    }

                    if (LockMemory && addr.Size > 0)
                    {
                        UnlockMemory32Bits((byte *)addr.Address, addr.Size);
                    }

                    Interlocked.Add(ref _totalMapped, -addr.Size);
                    UnmapViewOfFile((byte *)addr.Address);
                    NativeMemory.UnregisterFileMapping(addr.File, addr.Address, addr.Size);

                    if (set.Count == 0)
                    {
                        _globalMapping.TryRemove(addr.StartPage, out set);
                    }
                }
            }
            finally
            {
                _globalMemory.ExitWriteLock();
            }
        }