public const string Cryptography_UnknownEllipticCurve = "Cryptography_UnknownEllipticCurve";
public const string Cryptography_UnknownEllipticCurveAlgorithm = "Cryptography_UnknownEllipticCurveAlgorithm";
public const string Cryptography_UnknownPaddingMode = "Cryptography_UnknownPaddingMode";
+
+ public const string InvalidOperation_ViewIsNull = "InvalidOperation_ViewIsNull";
+ public const string ObjectDisposed_ViewAccessorClosed = "ObjectDisposed_ViewAccessorClosed";
+ public const string NotSupported_MMViewStreamsFixedLength = "NotSupported_MMViewStreamsFixedLength";
}
public MemoryMappedViewStream CreateViewStream (long offset, long size, MemoryMappedFileAccess access)
{
- return new MemoryMappedViewStream (handle, offset, size, access);
+ var view = MemoryMappedView.Create (handle, offset, size, access);
+ return new MemoryMappedViewStream (view);
}
public MemoryMappedViewAccessor CreateViewAccessor ()
public MemoryMappedViewAccessor CreateViewAccessor (long offset, long size, MemoryMappedFileAccess access)
{
- return new MemoryMappedViewAccessor (handle, offset, size, access);
+ var view = MemoryMappedView.Create (handle, offset, size, access);
+ return new MemoryMappedViewAccessor (view);
}
MemoryMappedFile ()
throw new NotImplementedException ();
}
}
+
+ // This converts a MemoryMappedFileAccess to a FileAccess. MemoryMappedViewStream and
+ // MemoryMappedViewAccessor subclass UnmanagedMemoryStream and UnmanagedMemoryAccessor, which both use
+ // FileAccess to determine whether they are writable and/or readable.
+ internal static FileAccess GetFileAccess (MemoryMappedFileAccess access) {
+
+ if (access == MemoryMappedFileAccess.Read) {
+ return FileAccess.Read;
+ }
+ if (access == MemoryMappedFileAccess.Write) {
+ return FileAccess.Write;
+ }
+ else if (access == MemoryMappedFileAccess.ReadWrite) {
+ return FileAccess.ReadWrite;
+ }
+ else if (access == MemoryMappedFileAccess.CopyOnWrite) {
+ return FileAccess.ReadWrite;
+ }
+ else if (access == MemoryMappedFileAccess.ReadExecute) {
+ return FileAccess.Read;
+ }
+ else if (access == MemoryMappedFileAccess.ReadWriteExecute) {
+ return FileAccess.ReadWrite;
+ }
+
+ // If we reached here, access was invalid.
+ throw new ArgumentOutOfRangeException ("access");
+ }
}
}
--- /dev/null
+//
+// MemoryMappedView.cs
+//
+// Authors:
+// Marcos Henrich (marcos.henrich@gmail.com)
+//
+// Copyright (C) 2015, Xamarin, Inc
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+
+using System;
+using System.IO;
+using System.Diagnostics;
+using System.Collections.Generic;
+using Microsoft.Win32.SafeHandles;
+
+namespace System.IO.MemoryMappedFiles
+{
+ internal class MemoryMappedView : IDisposable {
+ private SafeMemoryMappedViewHandle m_viewHandle;
+ private Int64 m_pointerOffset;
+ private Int64 m_size;
+ private MemoryMappedFileAccess m_access;
+
+ [System.Security.SecurityCritical]
+ private unsafe MemoryMappedView(SafeMemoryMappedViewHandle viewHandle, Int64 pointerOffset,
+ Int64 size, MemoryMappedFileAccess access) {
+
+ m_viewHandle = viewHandle;
+ m_pointerOffset = pointerOffset;
+ m_size = size;
+ m_access = access;
+ }
+
+ internal SafeMemoryMappedViewHandle ViewHandle {
+ [System.Security.SecurityCritical]
+ get {
+ return m_viewHandle;
+ }
+ }
+
+ internal Int64 PointerOffset {
+ get {
+ return m_pointerOffset;
+ }
+ }
+
+ internal Int64 Size {
+ get {
+ return m_size;
+ }
+ }
+
+ internal MemoryMappedFileAccess Access {
+ get {
+ return m_access;
+ }
+ }
+
+ internal unsafe static MemoryMappedView Create (IntPtr handle, long offset, long size, MemoryMappedFileAccess access)
+ {
+ IntPtr base_address;
+ IntPtr mmap_handle;
+
+ MemoryMapImpl.Map (handle, offset, ref size, access, out mmap_handle, out base_address);
+
+ var safe_handle = new SafeMemoryMappedViewHandle (mmap_handle, base_address, size);
+
+ // MemoryMapImpl.Map returns a base_address to the offset so MemoryMappedView is initiated
+ // no offset.
+ return new MemoryMappedView (safe_handle, 0, size, access);
+ }
+
+ public void Flush (IntPtr capacity)
+ {
+ MemoryMapImpl.Flush (m_viewHandle.DangerousGetHandle ());
+ }
+
+ protected virtual void Dispose (bool disposing)
+ {
+ if (m_viewHandle != null && !m_viewHandle.IsClosed) {
+ m_viewHandle.Dispose ();
+ }
+ }
+
+ public void Dispose ()
+ {
+ Dispose (true);
+ GC.SuppressFinalize (this);
+ }
+
+ internal bool IsClosed {
+ get {
+ return (m_viewHandle == null || m_viewHandle.IsClosed);
+ }
+ }
+ }
+}
+
+++ /dev/null
-//
-// MemoryMappedViewAccessor.cs
-//
-// Authors:
-// Zoltan Varga (vargaz@gmail.com)
-//
-// Copyright (C) 2009, Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-
-using System;
-using System.IO;
-using System.Collections.Generic;
-using Microsoft.Win32.SafeHandles;
-
-namespace System.IO.MemoryMappedFiles
-{
- public sealed class MemoryMappedViewAccessor : UnmanagedMemoryAccessor, IDisposable {
- IntPtr mmap_handle;
- SafeMemoryMappedViewHandle safe_handle;
- long pointerOffset;
-
- internal MemoryMappedViewAccessor (IntPtr handle, long offset, long size, MemoryMappedFileAccess access)
- {
- pointerOffset = offset;
- Create (handle, offset, size, access);
- }
-
- public long PointerOffset
- {
- get { return pointerOffset; }
- }
-
- static FileAccess ToFileAccess (MemoryMappedFileAccess access)
- {
- switch (access){
- case MemoryMappedFileAccess.CopyOnWrite:
- case MemoryMappedFileAccess.ReadWrite:
- case MemoryMappedFileAccess.ReadWriteExecute:
- return FileAccess.ReadWrite;
-
- case MemoryMappedFileAccess.Write:
- return FileAccess.Write;
-
- case MemoryMappedFileAccess.ReadExecute:
- case MemoryMappedFileAccess.Read:
- default:
- return FileAccess.Read;
- }
- }
-
- unsafe void Create (IntPtr handle, long offset, long size, MemoryMappedFileAccess access)
- {
- IntPtr base_address;
-
- MemoryMapImpl.Map (handle, offset, ref size, access, out mmap_handle, out base_address);
- safe_handle = new SafeMemoryMappedViewHandle (mmap_handle, base_address, size);
-
- Initialize (safe_handle, 0, size, ToFileAccess (access));
- }
-
- public SafeMemoryMappedViewHandle SafeMemoryMappedViewHandle {
- get {
- return safe_handle;
- }
- }
-
- protected override void Dispose (bool disposing)
- {
- base.Dispose (disposing);
- }
-
- void IDisposable.Dispose () {
- Dispose (true);
- }
-
- public void Flush ()
- {
- MemoryMapImpl.Flush (mmap_handle);
- }
- }
-}
-
+++ /dev/null
-//
-// MemoryMappedViewStream.cs
-//
-// Authors:
-// Zoltan Varga (vargaz@gmail.com)
-//
-// Copyright (C) 2009, Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-
-using System;
-using System.IO;
-using Microsoft.Win32.SafeHandles;
-
-namespace System.IO.MemoryMappedFiles
-{
- public sealed class MemoryMappedViewStream : UnmanagedMemoryStream {
- IntPtr mmap_handle;
- object monitor;
- long pointerOffset;
-
- internal MemoryMappedViewStream (IntPtr handle, long offset, long size, MemoryMappedFileAccess access) {
- pointerOffset = offset;
- monitor = new Object ();
- CreateStream (handle, offset, size, access);
- }
-
- public long PointerOffset
- {
- get { return pointerOffset; }
- }
-
- public SafeMemoryMappedViewHandle SafeMemoryMappedViewHandle {
- get {
- throw new NotImplementedException ();
- }
- }
-
- unsafe void CreateStream (IntPtr handle, long offset, long size, MemoryMappedFileAccess access)
- {
- IntPtr base_address;
-
- MemoryMapImpl.Map (handle, offset, ref size, access, out mmap_handle, out base_address);
-
- FileAccess faccess;
- switch (access) {
- case MemoryMappedFileAccess.ReadWrite:
- faccess = FileAccess.ReadWrite;
- break;
- case MemoryMappedFileAccess.Read:
- faccess = FileAccess.Read;
- break;
- case MemoryMappedFileAccess.Write:
- faccess = FileAccess.Write;
- break;
- default:
- throw new NotImplementedException ("access mode " + access + " not supported.");
- }
- Initialize ((byte*)base_address, size, size, faccess);
- }
-
- protected override void Dispose (bool disposing)
- {
- base.Dispose (disposing);
- lock (monitor) {
- if (mmap_handle != (IntPtr)(-1)) {
- MemoryMapImpl.Unmap (mmap_handle);
- mmap_handle = (IntPtr)(-1);
- }
- }
- }
-
- public override void Flush ()
- {
- MemoryMapImpl.Flush (mmap_handle);
- }
- }
-}
-
Assembly/AssemblyInfo.cs
System/Util.cs
System.IO.MemoryMappedFiles/MemoryMappedFile.cs
-System.IO.MemoryMappedFiles/MemoryMappedViewStream.cs
-System.IO.MemoryMappedFiles/MemoryMappedViewAccessor.cs
+System.IO.MemoryMappedFiles/MemoryMappedView.cs
Microsoft.Win32.SafeHandles/SafeMemoryMappedFileHandle.cs
Microsoft.Win32.SafeHandles/SafeMemoryMappedViewHandle.cs
../../../external/referencesource/System.Core/System/IO/MemoryMappedFiles/Enums.cs
../../../external/referencesource/System.Core/System/IO/MemoryMappedFiles/MemoryMappedFileSecurity.cs
+../../../external/referencesource/System.Core/System/IO/MemoryMappedFiles/MemoryMappedViewAccessor.cs
+../../../external/referencesource/System.Core/System/IO/MemoryMappedFiles/MemoryMappedViewStream.cs
../../../external/referencesource/System.Core/System/Linq/Enumerable.cs
../../../external/referencesource/System.Core/System/Linq/IQueryable.cs