public unsafe StupidMemMapAllocator(string path, long fileSize, long offset, long size) { _mmap = MemoryMappedFileFactory.Create(path, fileSize); _fileSize = fileSize; _size = size; _offset = offset; _ptr = (byte*) _mmap.MapView(MapProtection.PageReadWrite, _offset, _size, IntPtr.Zero); }
public void Setup() { mockMemoryMappedFileFactory = Substitute.For <MemoryMappedFileFactory>(); mockMemoryMappedFile = Substitute.For <IMemoryMappedFile>(); // The first session should get a memory mapped file on the first try. mockMemoryMappedFileFactory.CreateNew(FILE_PREFIX + 0, Arg.Any <long>()).Returns( mockMemoryMappedFile); transportSessionFactory = new LldbTransportSession.Factory(mockMemoryMappedFileFactory); transportSession = transportSessionFactory.Create(); }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { memoryMappedFile.Dispose(); memoryMappedFile = null; } disposed = true; }
/// <summary> /// Creates a new memory mapped file based on the settings in this factory. /// </summary> /// <param name="sizeInBytes">The size in bytes.</param> /// <returns></returns> public IMemoryMappedFile New(long sizeInBytes) { IMemoryMappedFile newFile = null; if (!string.IsNullOrEmpty(_path)) { newFile = NativeMemoryMappedFileFactory.CreateFromFile(_path + System.Guid.NewGuid().ToString(), sizeInBytes); } else { newFile = NativeMemoryMappedFileFactory.CreateNew(System.Guid.NewGuid().ToString(), sizeInBytes); } _files.Add(newFile); return(newFile); }
int FindAvailableSessionId() { for (int i = 0; i < MAX_SESSIONS; i++) { try { // Create a memory mapped file in system memory, which will exist as long as // the debug engine is running. They will either be cleaned up when we call // dispose on this object, or when the process stops. These files let transport // sessions 'reserve' a system unique session ID. If the file exists it will // throw a System.IO.IOException, and we can try the next one. memoryMappedFile = memoryMappedFileFactory.CreateNew(FILE_PREFIX + i, sizeof(byte)); return(i); } catch (System.IO.IOException) { } } return(INVALID_SESSION_ID); }
public MemoryMappedStream(IMemoryMappedFile backingFile, long mapStartIdx, long mapSize, bool isWriteable) : this(backingFile, mapStartIdx, mapSize, isWriteable, DEF_VIEW_SIZE) { }
/// <summary> /// Constructor used internally by MemoryMappedFile. /// </summary> /// <param name="backingFile">Preconstructed MemoryMappedFile</param> /// <param name="mapStartIdx">Index in the backingFile at which the view starts</param> /// <param name="mapSize">Size of the view, in bytes.</param> /// <param name="isWriteable">True if Read/Write access is desired, False otherwise</param> /// <param name="viewSize">The desired view size</param> public MemoryMappedStream(IMemoryMappedFile backingFile, long mapStartIdx, long mapSize, bool isWriteable, long viewSize) { if (backingFile == null) { throw new ArgumentException("backingFile is null"); } if ((mapStartIdx < 0) || (mapStartIdx > (long)backingFile.MaxSize)) throw new ArgumentException( String.Format("mapStartIdx is invalid. mapStartIdx=={0}, backingFile.MaxSize=={1}", mapStartIdx, backingFile.MaxSize)); if ((mapSize < 1) || (((mapStartIdx) + mapSize) > (long)backingFile.MaxSize)) throw new ArgumentException( String.Format("mapSize is invalid. mapStartIdx=={0}, mapSize=={1}, backingFile.MaxSize=={2}", mapStartIdx, mapSize, backingFile.MaxSize)); if ((viewSize < MIN_VIEW_SIZE) || (viewSize > MAX_VIEW_SIZE)) throw new ArgumentException( String.Format("viewSize is invalid. viewSize=={0}", viewSize)); _backingFile = backingFile; _isWriteable = isWriteable; _access = isWriteable ? MapProtection.PageReadWrite : MapProtection.PageRead; _desiredViewSize = viewSize; _mapStartIdx = mapStartIdx; _mapSize = (long)mapSize; _isOpen = true; // Map the first view Seek(0, SeekOrigin.Begin); }