Merge pull request #1857 from slluis/fix-assembly-resolver
[mono.git] / mcs / class / System.Core / System.IO.MemoryMappedFiles / MemoryMappedViewStream.cs
index aefda1bb70ff67ed4fd4d567b3c6704708f5af75..6fbaca605f900dd66241e5ed1a6cdbbad3d3f933 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_4_0
 
 using System;
 using System.IO;
+using Microsoft.Win32.SafeHandles;
 
 namespace System.IO.MemoryMappedFiles
 {
        public sealed class MemoryMappedViewStream : UnmanagedMemoryStream {
-               IntPtr mmap_addr;
-               ulong mmap_size;
+               IntPtr mmap_handle;
                object monitor;
-               int fd;
-               
-               internal MemoryMappedViewStream (int fd, long offset, long size, MemoryMappedFileAccess access) {
-                       this.fd = fd;
+               long pointerOffset;
+
+               internal MemoryMappedViewStream (IntPtr handle, long offset, long size, MemoryMappedFileAccess access) {
+                       pointerOffset = offset;
                        monitor = new Object ();
-                       CreateStream (fd, offset, size, access);
+                       CreateStream (handle, offset, size, access);
                }
 
-               unsafe void CreateStream (int fd, long offset, long size, MemoryMappedFileAccess access)
+               public long PointerOffset
                {
-                       int offset_diff;
-                       mmap_size = (ulong) size;
-                       MemoryMapImpl.Map (fd, offset, ref size, access, out mmap_addr, out offset_diff);
-                       FileAccess faccess;
+                       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;
@@ -65,25 +75,24 @@ namespace System.IO.MemoryMappedFiles
                        default:
                                throw new NotImplementedException ("access mode " + access + " not supported.");
                        }
-                       Initialize ((byte*)mmap_addr + offset_diff, size, size, faccess);
+                       Initialize ((byte*)base_address, size, size, faccess);
                }
                 
                protected override void Dispose (bool disposing)
                {
                        base.Dispose (disposing);
                        lock (monitor) {
-                               if (mmap_addr != (IntPtr)(-1)) {
-                                       MemoryMapImpl.Unmap (mmap_addr, mmap_size);
-                                       mmap_addr = (IntPtr)(-1);
+                               if (mmap_handle != (IntPtr)(-1)) {
+                                       MemoryMapImpl.Unmap (mmap_handle);
+                                       mmap_handle = (IntPtr)(-1);
                                }
                        }
                }
 
                public override void Flush ()
                {
-                       MemoryMapImpl.Flush (fd);
+                       MemoryMapImpl.Flush (mmap_handle);
                }
        }
 }
 
-#endif