示例#1
0
        private unsafe static UnsafeNativeMethods.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability,
                                                                                  MemoryMappedFileSecurity memoryMappedFileSecurity, out Object pinningHandle)
        {
            pinningHandle = null;
            UnsafeNativeMethods.SECURITY_ATTRIBUTES secAttrs = null;
            if ((inheritability & HandleInheritability.Inheritable) != 0 ||
                memoryMappedFileSecurity != null)
            {
                secAttrs         = new UnsafeNativeMethods.SECURITY_ATTRIBUTES();
                secAttrs.nLength = (Int32)Marshal.SizeOf(secAttrs);

                if ((inheritability & HandleInheritability.Inheritable) != 0)
                {
                    secAttrs.bInheritHandle = 1;
                }

                // For ACLs, get the security descriptor from the MemoryMappedFileSecurity.
                if (memoryMappedFileSecurity != null)
                {
                    byte[] sd = memoryMappedFileSecurity.GetSecurityDescriptorBinaryForm();
                    pinningHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);

                    fixed(byte *pSecDescriptor = sd)
                    secAttrs.pSecurityDescriptor = pSecDescriptor;
                }
            }
            return(secAttrs);
        }
示例#2
0
        public static MemoryMappedFile CreateFromFile(FileStream fileStream, string mapName, long capacity, MemoryMappedFileAccess access,
                                                      MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability,
                                                      bool leaveOpen)
        {
            if (fileStream == null)
            {
                throw new ArgumentNullException("fileStream");
            }
            if (mapName != null && mapName.Length == 0)
            {
                throw new ArgumentException("mapName");
            }
            if ((capacity == 0 && fileStream.Length == 0) || (capacity > fileStream.Length))
            {
                throw new ArgumentException("capacity");
            }

            if (MonoUtil.IsUnix)
            {
                ConfigureUnixFD(fileStream.Handle, inheritability);
            }
            else
            {
                ConfigureWindowsFD(fileStream.Handle, inheritability);
            }

            return(new MemoryMappedFile()
            {
                stream = fileStream,
                fileAccess = access,
                name = mapName,
                fileCapacity = capacity,
                keepOpen = leaveOpen
            });
        }
示例#3
0
        public static MemoryMappedFile CreateNew(string mapName, long capacity, MemoryMappedFileAccess access,
                                                 MemoryMappedFileOptions options, MemoryMappedFileSecurity memoryMappedFileSecurity,
                                                 HandleInheritability inheritability)
#endif
        {
            return(CreateFromFile(mapName, FileMode.CreateNew, mapName, capacity, access));
        }
示例#4
0
        public static MemoryMappedFile CreateFromFile(FileStream fileStream, string mapName, long capacity, MemoryMappedFileAccess access,
                                                      MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability,
                                                      bool leaveOpen)
        {
            if (fileStream == null)
            {
                throw new ArgumentNullException("fileStream");
            }
            if (mapName != null && mapName.Length == 0)
            {
                throw new ArgumentException("mapName");
            }
            if ((!MonoUtil.IsUnix && capacity == 0 && fileStream.Length == 0) || (capacity > fileStream.Length))
            {
                throw new ArgumentException("capacity");
            }

            IntPtr handle = MemoryMapImpl.OpenHandle(fileStream.SafeFileHandle.DangerousGetHandle(), mapName, out capacity, access, MemoryMappedFileOptions.None);

            MemoryMapImpl.ConfigureHandleInheritability(handle, inheritability);

            return(new MemoryMappedFile()
            {
                handle = handle,
                // fileAccess = access,
                // name = mapName,
                // fileCapacity = capacity,

                stream = fileStream,
                keepOpen = leaveOpen
            });
        }
示例#5
0
        public static MemoryMappedFile CreateOrOpen(String mapName, Int64 capacity,
                                                    MemoryMappedFileAccess access, MemoryMappedFileOptions options,
                                                    MemoryMappedFileSecurity memoryMappedFileSecurity,
                                                    HandleInheritability inheritability)
        {
            if (mapName == null)
            {
                throw new ArgumentNullException("mapName", SR.GetString(SR.ArgumentNull_MapName));
            }

            if (mapName.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.Argument_MapNameEmptyString));
            }

            if (capacity <= 0)
            {
                throw new ArgumentOutOfRangeException("capacity", SR.GetString(SR.ArgumentOutOfRange_NeedPositiveNumber));
            }

            if (IntPtr.Size == 4 && capacity > UInt32.MaxValue)
            {
                throw new ArgumentOutOfRangeException("capacity", SR.GetString(SR.ArgumentOutOfRange_CapacityLargerThanLogicalAddressSpaceNotAllowed));
            }

            if (access < MemoryMappedFileAccess.ReadWrite ||
                access > MemoryMappedFileAccess.ReadWriteExecute)
            {
                throw new ArgumentOutOfRangeException("access");
            }

            if (((int)options & ~((int)(MemoryMappedFileOptions.DelayAllocatePages))) != 0)
            {
                throw new ArgumentOutOfRangeException("options");
            }

            if (inheritability < HandleInheritability.None || inheritability > HandleInheritability.Inheritable)
            {
                throw new ArgumentOutOfRangeException("inheritability");
            }

            SafeMemoryMappedFileHandle handle;

            // special case for write access; create will never succeed
            if (access == MemoryMappedFileAccess.Write)
            {
                handle = OpenCore(mapName, inheritability, GetFileMapAccess(access), true);
            }
            else
            {
                handle = CreateOrOpenCore(new SafeFileHandle(new IntPtr(-1), true), mapName, inheritability,
                                          memoryMappedFileSecurity, access, options, capacity);
            }

            return(new MemoryMappedFile(handle));
        }
示例#6
0
 public void SetAccessControl(MemoryMappedFileSecurity memoryMappedFileSecurity)
 {
     if (memoryMappedFileSecurity == null)
     {
         throw new ArgumentNullException("memoryMappedFileSecurity");
     }
     if (this._handle.IsClosed)
     {
         System.IO.__Error.FileNotOpen();
     }
     memoryMappedFileSecurity.PersistHandle(this._handle);
 }
示例#7
0
        public static MemoryMappedFile CreateNew(String mapName, Int64 capacity, MemoryMappedFileAccess access,
                                                 MemoryMappedFileOptions options, MemoryMappedFileSecurity memoryMappedFileSecurity,
                                                 HandleInheritability inheritability)
        {
            if (mapName != null && mapName.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.Argument_MapNameEmptyString));
            }

            if (capacity <= 0)
            {
                throw new ArgumentOutOfRangeException("capacity", SR.GetString(SR.ArgumentOutOfRange_NeedPositiveNumber));
            }

            if (IntPtr.Size == 4 && capacity > UInt32.MaxValue)
            {
                throw new ArgumentOutOfRangeException("capacity", SR.GetString(SR.ArgumentOutOfRange_CapacityLargerThanLogicalAddressSpaceNotAllowed));
            }

            if (access < MemoryMappedFileAccess.ReadWrite ||
                access > MemoryMappedFileAccess.ReadWriteExecute)
            {
                throw new ArgumentOutOfRangeException("access");
            }

            if (access == MemoryMappedFileAccess.Write)
            {
                throw new ArgumentException(SR.GetString(SR.Argument_NewMMFWriteAccessNotAllowed), "access");
            }

            if (((int)options & ~((int)(MemoryMappedFileOptions.DelayAllocatePages))) != 0)
            {
                throw new ArgumentOutOfRangeException("options");
            }

            if (inheritability < HandleInheritability.None || inheritability > HandleInheritability.Inheritable)
            {
                throw new ArgumentOutOfRangeException("inheritability");
            }

            SafeMemoryMappedFileHandle handle = CreateCore(new SafeFileHandle(new IntPtr(-1), true), mapName, inheritability,
                                                           memoryMappedFileSecurity, access, options, capacity);

            return(new MemoryMappedFile(handle));
        }
示例#8
0
        private static SafeMemoryMappedFileHandle CreateCore(SafeFileHandle fileHandle, String mapName,
                                                             HandleInheritability inheritability,
                                                             MemoryMappedFileSecurity memoryMappedFileSecurity,
                                                             MemoryMappedFileAccess access, MemoryMappedFileOptions options,
                                                             Int64 capacity)
        {
            SafeMemoryMappedFileHandle handle = null;
            Object pinningHandle;

            UnsafeNativeMethods.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(inheritability, memoryMappedFileSecurity, out pinningHandle);

            // split the long into two ints
            Int32 capacityLow  = (Int32)(capacity & 0x00000000FFFFFFFFL);
            Int32 capacityHigh = (Int32)(capacity >> 32);

            try {
                handle = UnsafeNativeMethods.CreateFileMapping(fileHandle, secAttrs, GetPageAccess(access) | (int)options,
                                                               capacityHigh, capacityLow, mapName);

                Int32 errorCode = Marshal.GetLastWin32Error();
                if (!handle.IsInvalid && errorCode == UnsafeNativeMethods.ERROR_ALREADY_EXISTS)
                {
                    handle.Dispose();
                    __Error.WinIOError(errorCode, String.Empty);
                }
                else if (handle.IsInvalid)
                {
                    __Error.WinIOError(errorCode, String.Empty);
                }
            }
            finally {
                if (pinningHandle != null)
                {
                    GCHandle pinHandle = (GCHandle)pinningHandle;
                    pinHandle.Free();
                }
            }
            return(handle);
        }
示例#9
0
        static MemoryMappedFile CoreShmCreate(string mapName, long capacity, MemoryMappedFileAccess access,
                                              MemoryMappedFileOptions options, MemoryMappedFileSecurity memoryMappedFileSecurity,
                                              HandleInheritability inheritability, FileMode mode)
        {
            if (mapName != null && mapName.Length == 0)
            {
                throw new ArgumentException("mapName");
            }
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException("capacity");
            }

            IntPtr handle = MemoryMapImpl.OpenFile(null, mode, mapName, out capacity, access, options);

            return(new MemoryMappedFile()
            {
                handle = handle,
                // fileAccess = access,
                // name = mapName,
                // fileCapacity = capacity
            });
        }
示例#10
0
 private static unsafe Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability, MemoryMappedFileSecurity memoryMappedFileSecurity, out object pinningHandle)
 {
     pinningHandle = null;
     Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES structure = null;
     if (((inheritability & HandleInheritability.Inheritable) != HandleInheritability.None) || (memoryMappedFileSecurity != null))
     {
         structure = new Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES {
             nLength = Marshal.SizeOf(structure)
         };
         if ((inheritability & HandleInheritability.Inheritable) != HandleInheritability.None)
         {
             structure.bInheritHandle = 1;
         }
         if (memoryMappedFileSecurity == null)
         {
             return(structure);
         }
         byte[] securityDescriptorBinaryForm = memoryMappedFileSecurity.GetSecurityDescriptorBinaryForm();
         pinningHandle = GCHandle.Alloc(securityDescriptorBinaryForm, GCHandleType.Pinned);
         fixed(byte *numRef = securityDescriptorBinaryForm)
         {
             structure.pSecurityDescriptor = numRef;
         }
     }
     return(structure);
 }
示例#11
0
        private static Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle CreateCore(SafeFileHandle fileHandle, string mapName, HandleInheritability inheritability, MemoryMappedFileSecurity memoryMappedFileSecurity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, long capacity)
        {
            Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle handle = null;
            object obj2;

            Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES lpAttributes = GetSecAttrs(inheritability, memoryMappedFileSecurity, out obj2);
            int dwMaximumSizeLow  = (int)(((ulong)capacity) & 0xffffffffL);
            int dwMaximumSizeHigh = (int)(capacity >> 0x20);

            try
            {
                handle = Microsoft.Win32.UnsafeNativeMethods.CreateFileMapping(fileHandle, lpAttributes, GetPageAccess(access) | options, dwMaximumSizeHigh, dwMaximumSizeLow, mapName);
                int errorCode = Marshal.GetLastWin32Error();
                if (!handle.IsInvalid && (errorCode == 0xb7))
                {
                    handle.Dispose();
                    System.IO.__Error.WinIOError(errorCode, string.Empty);
                    return(handle);
                }
                if (handle.IsInvalid)
                {
                    System.IO.__Error.WinIOError(errorCode, string.Empty);
                }
            }
            finally
            {
                if (obj2 != null)
                {
                    ((GCHandle)obj2).Free();
                }
            }
            return(handle);
        }
示例#12
0
        private static Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle CreateOrOpenCore(SafeFileHandle fileHandle, string mapName, HandleInheritability inheritability, MemoryMappedFileSecurity memoryMappedFileSecurity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, long capacity)
        {
            Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle handle = null;
            object obj2;

            Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES lpAttributes = GetSecAttrs(inheritability, memoryMappedFileSecurity, out obj2);
            int dwMaximumSizeLow  = (int)(((ulong)capacity) & 0xffffffffL);
            int dwMaximumSizeHigh = (int)(capacity >> 0x20);

            try
            {
                int num3 = 14;
                int millisecondsTimeout = 0;
                while (num3 > 0)
                {
                    handle = Microsoft.Win32.UnsafeNativeMethods.CreateFileMapping(fileHandle, lpAttributes, GetPageAccess(access) | options, dwMaximumSizeHigh, dwMaximumSizeLow, mapName);
                    int errorCode = Marshal.GetLastWin32Error();
                    if (!handle.IsInvalid)
                    {
                        break;
                    }
                    if (errorCode != 5)
                    {
                        System.IO.__Error.WinIOError(errorCode, string.Empty);
                    }
                    handle.SetHandleAsInvalid();
                    handle = Microsoft.Win32.UnsafeNativeMethods.OpenFileMapping(GetFileMapAccess(access), (inheritability & HandleInheritability.Inheritable) != HandleInheritability.None, mapName);
                    int num6 = Marshal.GetLastWin32Error();
                    if (!handle.IsInvalid)
                    {
                        break;
                    }
                    if (num6 != 2)
                    {
                        System.IO.__Error.WinIOError(num6, string.Empty);
                    }
                    num3--;
                    if (millisecondsTimeout == 0)
                    {
                        millisecondsTimeout = 10;
                    }
                    else
                    {
                        Thread.Sleep(millisecondsTimeout);
                        millisecondsTimeout *= 2;
                    }
                }
                if ((handle == null) || handle.IsInvalid)
                {
                    throw new InvalidOperationException(System.SR.GetString("InvalidOperation_CantCreateFileMapping"));
                }
                return(handle);
            }
            finally
            {
                if (obj2 != null)
                {
                    ((GCHandle)obj2).Free();
                }
            }
            return(handle);
        }
示例#13
0
 public static MemoryMappedFile CreateOrOpen(string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability)
 {
     Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle handle;
     if (mapName == null)
     {
         throw new ArgumentNullException("mapName", System.SR.GetString("ArgumentNull_MapName"));
     }
     if (mapName.Length == 0)
     {
         throw new ArgumentException(System.SR.GetString("Argument_MapNameEmptyString"));
     }
     if (capacity <= 0L)
     {
         throw new ArgumentOutOfRangeException("capacity", System.SR.GetString("ArgumentOutOfRange_NeedPositiveNumber"));
     }
     if ((IntPtr.Size == 4) && (capacity > 0xffffffffL))
     {
         throw new ArgumentOutOfRangeException("capacity", System.SR.GetString("ArgumentOutOfRange_CapacityLargerThanLogicalAddressSpaceNotAllowed"));
     }
     if ((access < MemoryMappedFileAccess.ReadWrite) || (access > MemoryMappedFileAccess.ReadWriteExecute))
     {
         throw new ArgumentOutOfRangeException("access");
     }
     if ((options & ~MemoryMappedFileOptions.DelayAllocatePages) != MemoryMappedFileOptions.None)
     {
         throw new ArgumentOutOfRangeException("options");
     }
     if ((inheritability < HandleInheritability.None) || (inheritability > HandleInheritability.Inheritable))
     {
         throw new ArgumentOutOfRangeException("inheritability");
     }
     if (access == MemoryMappedFileAccess.Write)
     {
         handle = OpenCore(mapName, inheritability, GetFileMapAccess(access), true);
     }
     else
     {
         handle = CreateOrOpenCore(new SafeFileHandle(new IntPtr(-1), true), mapName, inheritability, memoryMappedFileSecurity, access, options, capacity);
     }
     return(new MemoryMappedFile(handle));
 }
示例#14
0
        public static MemoryMappedFile CreateFromFile(FileStream fileStream, string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability, bool leaveOpen)
        {
            Contract.Ensures(Contract.Result <System.IO.MemoryMappedFiles.MemoryMappedFile>() != null);

            return(default(MemoryMappedFile));
        }
示例#15
0
 public static MemoryMappedFile CreateFromFile(FileStream fileStream, string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability, bool leaveOpen)
 {
     throw new NotImplementedException();
 }
示例#16
0
 public static MemoryMappedFile CreateOrOpen(string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability)
 {
     return(CoreShmCreate(mapName, capacity, access, options, memoryMappedFileSecurity, inheritability, FileMode.OpenOrCreate));
 }
示例#17
0
        private static SafeMemoryMappedFileHandle CreateOrOpenCore(SafeFileHandle fileHandle, String mapName,
                                                                   HandleInheritability inheritability,
                                                                   MemoryMappedFileSecurity memoryMappedFileSecurity,
                                                                   MemoryMappedFileAccess access, MemoryMappedFileOptions options,
                                                                   Int64 capacity)
        {
            Debug.Assert(access != MemoryMappedFileAccess.Write, "Callers requesting write access shouldn't try to create a mmf");

            SafeMemoryMappedFileHandle handle = null;
            Object pinningHandle;

            UnsafeNativeMethods.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(inheritability, memoryMappedFileSecurity, out pinningHandle);

            // split the long into two ints
            Int32 capacityLow  = (Int32)(capacity & 0x00000000FFFFFFFFL);
            Int32 capacityHigh = (Int32)(capacity >> 32);

            try {
                int waitRetries = 14;   //((2^13)-1)*10ms == approximately 1.4mins
                int waitSleep   = 0;

                // keep looping until we've exhausted retries or break as soon we we get valid handle
                while (waitRetries > 0)
                {
                    // try to create
                    handle = UnsafeNativeMethods.CreateFileMapping(fileHandle, secAttrs,
                                                                   GetPageAccess(access) | (int)options, capacityHigh, capacityLow, mapName);

                    Int32 createErrorCode = Marshal.GetLastWin32Error();
                    if (!handle.IsInvalid)
                    {
                        break;
                    }
                    else
                    {
                        if (createErrorCode != UnsafeNativeMethods.ERROR_ACCESS_DENIED)
                        {
                            __Error.WinIOError(createErrorCode, String.Empty);
                        }

                        // the mapname exists but our ACL is preventing us from opening it with CreateFileMapping.
                        // Let's try to open it with OpenFileMapping.
                        handle.SetHandleAsInvalid();
                    }

                    // try to open
                    handle = UnsafeNativeMethods.OpenFileMapping(GetFileMapAccess(access), (inheritability &
                                                                                            HandleInheritability.Inheritable) != 0, mapName);

                    Int32 openErrorCode = Marshal.GetLastWin32Error();

                    // valid handle
                    if (!handle.IsInvalid)
                    {
                        break;
                    }
                    // didn't get valid handle; have to retry
                    else
                    {
                        if (openErrorCode != UnsafeNativeMethods.ERROR_FILE_NOT_FOUND)
                        {
                            __Error.WinIOError(openErrorCode, String.Empty);
                        }

                        // increase wait time
                        --waitRetries;
                        if (waitSleep == 0)
                        {
                            waitSleep = 10;
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(waitSleep);
                            waitSleep *= 2;
                        }
                    }
                }

                // finished retrying but couldn't create or open
                if (handle == null || handle.IsInvalid)
                {
                    throw new InvalidOperationException(SR.GetString(SR.InvalidOperation_CantCreateFileMapping));
                }
            }

            finally {
                if (pinningHandle != null)
                {
                    GCHandle pinHandle = (GCHandle)pinningHandle;
                    pinHandle.Free();
                }
            }
            return(handle);
        }
示例#18
0
        public static MemoryMappedFile CreateFromFile(FileStream fileStream, String mapName, Int64 capacity,
                                                      MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity,
                                                      HandleInheritability inheritability, bool leaveOpen)
        {
            if (fileStream == null)
            {
                throw new ArgumentNullException("fileStream", SR.GetString(SR.ArgumentNull_FileStream));
            }

            if (mapName != null && mapName.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.Argument_MapNameEmptyString));
            }

            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException("capacity", SR.GetString(SR.ArgumentOutOfRange_PositiveOrDefaultCapacityRequired));
            }

            if (capacity == 0 && fileStream.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.Argument_EmptyFile));
            }

            if (access < MemoryMappedFileAccess.ReadWrite ||
                access > MemoryMappedFileAccess.ReadWriteExecute)
            {
                throw new ArgumentOutOfRangeException("access");
            }

            if (access == MemoryMappedFileAccess.Write)
            {
                throw new ArgumentException(SR.GetString(SR.Argument_NewMMFWriteAccessNotAllowed), "access");
            }

            if (access == MemoryMappedFileAccess.Read && capacity > fileStream.Length)
            {
                throw new ArgumentException(SR.GetString(SR.Argument_ReadAccessWithLargeCapacity));
            }

            if (inheritability < HandleInheritability.None || inheritability > HandleInheritability.Inheritable)
            {
                throw new ArgumentOutOfRangeException("inheritability");
            }

            // flush any bytes written to the FileStream buffer so that we can see them in our MemoryMappedFile
            fileStream.Flush();

            if (capacity == DefaultSize)
            {
                capacity = fileStream.Length;
            }

            // one can always create a small view if they do not want to map an entire file
            if (fileStream.Length > capacity)
            {
                throw new ArgumentOutOfRangeException("capacity", SR.GetString(SR.ArgumentOutOfRange_CapacityGEFileSizeRequired));
            }

            SafeMemoryMappedFileHandle handle = CreateCore(fileStream.SafeFileHandle, mapName, inheritability, memoryMappedFileSecurity,
                                                           access, MemoryMappedFileOptions.None, capacity);

            return(new MemoryMappedFile(handle, fileStream, leaveOpen));
        }
示例#19
0
 public static MemoryMappedFile CreateOrOpen(string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability handleInheritability)
 {
     throw new NotImplementedException();
 }
示例#20
0
        public static MemoryMappedFile CreateNew(string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability)
        {
            Contract.Ensures(Contract.Result <System.IO.MemoryMappedFiles.MemoryMappedFile>() != null);

            return(default(MemoryMappedFile));
        }
示例#21
0
 public static MemoryMappedFile CreateFromFile(FileStream fileStream, string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability, bool leaveOpen)
 {
     if (fileStream == null)
     {
         throw new ArgumentNullException("fileStream", System.SR.GetString("ArgumentNull_FileStream"));
     }
     if ((mapName != null) && (mapName.Length == 0))
     {
         throw new ArgumentException(System.SR.GetString("Argument_MapNameEmptyString"));
     }
     if (capacity < 0L)
     {
         throw new ArgumentOutOfRangeException("capacity", System.SR.GetString("ArgumentOutOfRange_PositiveOrDefaultCapacityRequired"));
     }
     if ((capacity == 0L) && (fileStream.Length == 0L))
     {
         throw new ArgumentException(System.SR.GetString("Argument_EmptyFile"));
     }
     if ((access < MemoryMappedFileAccess.ReadWrite) || (access > MemoryMappedFileAccess.ReadWriteExecute))
     {
         throw new ArgumentOutOfRangeException("access");
     }
     if (access == MemoryMappedFileAccess.Write)
     {
         throw new ArgumentException(System.SR.GetString("Argument_NewMMFWriteAccessNotAllowed"), "access");
     }
     if ((access == MemoryMappedFileAccess.Read) && (capacity > fileStream.Length))
     {
         throw new ArgumentException(System.SR.GetString("Argument_ReadAccessWithLargeCapacity"));
     }
     if ((inheritability < HandleInheritability.None) || (inheritability > HandleInheritability.Inheritable))
     {
         throw new ArgumentOutOfRangeException("inheritability");
     }
     fileStream.Flush();
     if (capacity == 0L)
     {
         capacity = fileStream.Length;
     }
     if (fileStream.Length > capacity)
     {
         throw new ArgumentOutOfRangeException("capacity", System.SR.GetString("ArgumentOutOfRange_CapacityGEFileSizeRequired"));
     }
     return(new MemoryMappedFile(CreateCore(fileStream.SafeFileHandle, mapName, inheritability, memoryMappedFileSecurity, access, MemoryMappedFileOptions.None, capacity), fileStream, leaveOpen));
 }
示例#22
0
 public static MemoryMappedFile CreateNew(string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability)
 {
     if ((mapName != null) && (mapName.Length == 0))
     {
         throw new ArgumentException(System.SR.GetString("Argument_MapNameEmptyString"));
     }
     if (capacity <= 0L)
     {
         throw new ArgumentOutOfRangeException("capacity", System.SR.GetString("ArgumentOutOfRange_NeedPositiveNumber"));
     }
     if ((IntPtr.Size == 4) && (capacity > 0xffffffffL))
     {
         throw new ArgumentOutOfRangeException("capacity", System.SR.GetString("ArgumentOutOfRange_CapacityLargerThanLogicalAddressSpaceNotAllowed"));
     }
     if ((access < MemoryMappedFileAccess.ReadWrite) || (access > MemoryMappedFileAccess.ReadWriteExecute))
     {
         throw new ArgumentOutOfRangeException("access");
     }
     if (access == MemoryMappedFileAccess.Write)
     {
         throw new ArgumentException(System.SR.GetString("Argument_NewMMFWriteAccessNotAllowed"), "access");
     }
     if ((options & ~MemoryMappedFileOptions.DelayAllocatePages) != MemoryMappedFileOptions.None)
     {
         throw new ArgumentOutOfRangeException("options");
     }
     if ((inheritability < HandleInheritability.None) || (inheritability > HandleInheritability.Inheritable))
     {
         throw new ArgumentOutOfRangeException("inheritability");
     }
     return(new MemoryMappedFile(CreateCore(new SafeFileHandle(new IntPtr(-1), true), mapName, inheritability, memoryMappedFileSecurity, access, options, capacity)));
 }
示例#23
0
 public void SetAccessControl(MemoryMappedFileSecurity memoryMappedFileSecurity)
 {
     throw new NotImplementedException();
 }
示例#24
0
 public void SetAccessControl(MemoryMappedFileSecurity memoryMappedFileSecurity)
 {
 }