/// <summary>Converts file rights to minimum expected file accesses.</summary>
        private static MemoryMappedFileAccess RightsToAccess(MemoryMappedFileRights rights)
        {
            if ((rights & MemoryMappedFileRights.ReadWriteExecute) == MemoryMappedFileRights.ReadWriteExecute)
            {
                return(MemoryMappedFileAccess.ReadWriteExecute);
            }

            if ((rights & MemoryMappedFileRights.ReadWrite) == MemoryMappedFileRights.ReadWrite)
            {
                return(MemoryMappedFileAccess.ReadWrite);
            }

            if ((rights & MemoryMappedFileRights.Write) == MemoryMappedFileRights.Write)
            {
                return(MemoryMappedFileAccess.Write);
            }

            if ((rights & MemoryMappedFileRights.ReadExecute) == MemoryMappedFileRights.ReadExecute)
            {
                return(MemoryMappedFileAccess.ReadExecute);
            }

            if ((rights & MemoryMappedFileRights.Read) == MemoryMappedFileRights.Read)
            {
                return(MemoryMappedFileAccess.Read);
            }

            return((MemoryMappedFileAccess)(-1)); // no None, so just use -1
        }
Пример #2
0
        public void OpenCreatedNew(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
        {
            const int Capacity = 4096;

            using (MemoryMappedFile original = MemoryMappedFile.CreateNew(mapName, Capacity))
            {
                using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(mapName))
                {
                    Assert.Throws <IOException>(() => MemoryMappedFile.OpenExisting(mapName, MemoryMappedFileRights.AccessSystemSecurity));
                    Assert.Throws <IOException>(() => MemoryMappedFile.OpenExisting(mapName, MemoryMappedFileRights.AccessSystemSecurity, HandleInheritability.None));
                    ValidateMemoryMappedFile(opened, Capacity);
                }
                using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(mapName, desiredAccessRights | MemoryMappedFileRights.ReadPermissions)) // can't do anything if we don't have read permissions
                {
                    ValidateMemoryMappedFile(opened, Capacity, RightsToAccess(desiredAccessRights));
                }
                using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(mapName, desiredAccessRights | MemoryMappedFileRights.ReadPermissions, inheritability))
                {
                    ValidateMemoryMappedFile(opened, Capacity, RightsToAccess(desiredAccessRights), inheritability);
                }
            }

            // The map no longer exists
            Assert.Throws <FileNotFoundException>(() => MemoryMappedFile.OpenExisting(mapName));
            Assert.Throws <FileNotFoundException>(() => MemoryMappedFile.OpenExisting(mapName, MemoryMappedFileRights.ReadWrite));
            Assert.Throws <FileNotFoundException>(() => MemoryMappedFile.OpenExisting(mapName, MemoryMappedFileRights.ReadWrite, HandleInheritability.None));
        }
Пример #3
0
        public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights,
                                                                    HandleInheritability inheritability)
        {
            if (mapName == null)
            {
                throw new ArgumentNullException("mapName", SR.ArgumentNull_MapName);
            }

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

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

            if (((int)desiredAccessRights & ~((int)(MemoryMappedFileRights.FullControl | MemoryMappedFileRights.AccessSystemSecurity))) != 0)
            {
                throw new ArgumentOutOfRangeException("desiredAccessRights");
            }

            SafeMemoryMappedFileHandle handle = OpenCore(mapName, inheritability, desiredAccessRights, false);
            return new MemoryMappedFile(handle);
        }
Пример #4
0
        public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights,
                                                    HandleInheritability inheritability)
        {
            if (mapName == null)
            {
                throw new ArgumentNullException(nameof(mapName), SR.ArgumentNull_MapName);
            }

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

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

            if (((int)desiredAccessRights & ~((int)(MemoryMappedFileRights.FullControl | MemoryMappedFileRights.AccessSystemSecurity))) != 0)
            {
                throw new ArgumentOutOfRangeException(nameof(desiredAccessRights));
            }

            SafeMemoryMappedFileHandle handle = OpenCore(mapName, inheritability, desiredAccessRights, false);

            return(new MemoryMappedFile(handle));
        }
Пример #5
0
        public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
        {
            Contract.Ensures(1 <= mapName.Length);
            Contract.Ensures(Contract.Result <System.IO.MemoryMappedFiles.MemoryMappedFile>() != null);

            return(default(MemoryMappedFile));
        }
        public void OpenCreatedNew(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
        {
            const int Capacity = 4096;
            using (MemoryMappedFile original = MemoryMappedFile.CreateNew(mapName, Capacity))
            {
                using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(mapName))
                {
                    Assert.Throws<IOException>(() => MemoryMappedFile.OpenExisting(mapName, MemoryMappedFileRights.AccessSystemSecurity));
                    Assert.Throws<IOException>(() => MemoryMappedFile.OpenExisting(mapName, MemoryMappedFileRights.AccessSystemSecurity, HandleInheritability.None));
                    ValidateMemoryMappedFile(opened, Capacity);
                }
                using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(mapName, desiredAccessRights | MemoryMappedFileRights.ReadPermissions)) // can't do anything if we don't have read permissions
                {
                    ValidateMemoryMappedFile(opened, Capacity, RightsToAccess(desiredAccessRights));
                }
                using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(mapName, desiredAccessRights | MemoryMappedFileRights.ReadPermissions, inheritability))
                {
                    ValidateMemoryMappedFile(opened, Capacity, RightsToAccess(desiredAccessRights), inheritability);
                }
            }

            // The map no longer exists
            Assert.Throws<FileNotFoundException>(() => MemoryMappedFile.OpenExisting(mapName));
            Assert.Throws<FileNotFoundException>(() => MemoryMappedFile.OpenExisting(mapName, MemoryMappedFileRights.ReadWrite));
            Assert.Throws<FileNotFoundException>(() => MemoryMappedFile.OpenExisting(mapName, MemoryMappedFileRights.ReadWrite, HandleInheritability.None));
        }
        public void OpenCreatedFromFile(string name, MemoryMappedFileRights rights, HandleInheritability inheritability)
        {
            const int Capacity = 4096;

            using (TempFile file = new TempFile(GetTestFilePath()))
                using (FileStream fs = File.Open(file.Path, FileMode.Open))
                    using (MemoryMappedFile original = MemoryMappedFile.CreateFromFile(fs, name, Capacity, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, false))
                    {
                        using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(name))
                        {
                            Assert.Throws <IOException>(() => MemoryMappedFile.OpenExisting(name, MemoryMappedFileRights.AccessSystemSecurity));
                            Assert.Throws <IOException>(() => MemoryMappedFile.OpenExisting(name, MemoryMappedFileRights.AccessSystemSecurity, HandleInheritability.None));
                            ValidateMemoryMappedFile(opened, Capacity);
                        }
                        using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(name, rights | MemoryMappedFileRights.ReadPermissions))
                        {
                            ValidateMemoryMappedFile(opened, Capacity, RightsToAccess(rights));
                        }
                        using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(name, rights | MemoryMappedFileRights.ReadPermissions, inheritability))
                        {
                            ValidateMemoryMappedFile(opened, Capacity, RightsToAccess(rights), inheritability);
                        }
                    }

            // The map no longer exists
            Assert.Throws <FileNotFoundException>(() => MemoryMappedFile.OpenExisting(name));
            Assert.Throws <FileNotFoundException>(() => MemoryMappedFile.OpenExisting(name, MemoryMappedFileRights.Read));
            Assert.Throws <FileNotFoundException>(() => MemoryMappedFile.OpenExisting(name, MemoryMappedFileRights.Read, HandleInheritability.None));
        }
Пример #8
0
 public IMemoryMappedFile OpenExisting(
     string mapName,
     MemoryMappedFileRights desiredAccessRights,
     HandleInheritability inheritability)
 {
     return new MemoryMappedFileWrapper(
         MemoryMappedFile.OpenExisting(mapName, desiredAccessRights, inheritability));
 }
 public void OpenExistingstring(string mapName, MemoryMappedFileRights desiredAccessRights)
 {
     instance                 = MemoryMappedFile.OpenExisting(mapName, desiredAccessRights);
     this.mapName             = mapName;
     this.desiredAccessRights = desiredAccessRights;
     ci = CreateInstance.OpenExistingstring;
     ni = 1;
 }
Пример #10
0
 public IMemoryMappedFile OpenExisting(
     string mapName,
     MemoryMappedFileRights desiredAccessRights,
     HandleInheritability inheritability)
 {
     return(new MemoryMappedFileWrapper(
                MemoryMappedFile.OpenExisting(mapName, desiredAccessRights, inheritability)));
 }
 public void OpenExistingstring(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
 {
     instance                 = MemoryMappedFile.OpenExisting(mapName, desiredAccessRights, inheritability);
     this.mapName             = mapName;
     this.desiredAccessRights = desiredAccessRights;
     this.inheritability      = inheritability;
     ci = CreateInstance.OpenExistingstring;
     ni = 2;
 }
Пример #12
0
        /// <summary>
        /// Opens an existing memory-mapped file. Throws FileNotFoundException if it doesn't exist.
        /// </summary>
        /// <param name="mapName"></param>
        /// <returns></returns>
        public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights access)
        {
            SafeMemoryMappedFileHandle safeMemoryMappedFileHandle = UnsafeNativeMethods.OpenFileMapping((uint)access, false, mapName);
            int lastWin32Error = Marshal.GetLastWin32Error();

            if (safeMemoryMappedFileHandle.IsInvalid)
            {
                if (lastWin32Error == UnsafeNativeMethods.ERROR_FILE_NOT_FOUND)
                {
                    throw new FileNotFoundException();
                }
                throw new System.IO.IOException(UnsafeNativeMethods.GetMessage(lastWin32Error));
            }
            return(new MemoryMappedFile(safeMemoryMappedFileHandle));
        }
Пример #13
0
        public static MemoryMappedFile OpenExisting(string mappedName, MemoryMappedFileRights desiredAccessRights = MemoryMappedFileRights.ReadWrite)
        {
            MemoryMappedFile mappedFile = new MemoryMappedFile();

            //mappedFile.map = Win32APIs.OpenFileMapping(desiredAccessRights, false, @"Global\" + mappedName);
            mappedFile.rights  = desiredAccessRights;
            mappedFile.basemap = Win32APIs.OpenFileMapping(mappedFile.rights, false, mappedName);

            if (mappedFile.basemap == IntPtr.Zero) //생성 실패
            {
                return(null);
            }

            return(mappedFile);
        }
Пример #14
0
 public void VerifyOpenExisting(String strLoc, String mapName, MemoryMappedFileRights rights, HandleInheritability inheritability, MemoryMappedFileAccess expectedAccess)
 {
     iCountTestcases++;
     try
     {
         using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(mapName, rights, inheritability))
         {
             VerifyHandleInheritability(strLoc, mmf.SafeMemoryMappedFileHandle, inheritability);
             VerifyAccess(strLoc, mmf, expectedAccess, 10);
         }
     }
     catch (Exception ex)
     {
         iCountErrors++;
         Console.WriteLine("ERROR, {0}: Unexpected exception, {1}", strLoc, ex);
     }
 }
Пример #15
0
        public static MemoryMappedFileSecurity MapSecurity(bool create)
        {
            SecurityIdentifier       user   = GetEveryoneSID();
            MemoryMappedFileSecurity result = new MemoryMappedFileSecurity();

            MemoryMappedFileRights rights = MemoryMappedFileRights.ReadWrite;

            if (create)
            {
                rights |= MemoryMappedFileRights.Delete;
            }

            AccessRule <MemoryMappedFileRights> rule = new AccessRule <MemoryMappedFileRights>(user, rights, AccessControlType.Allow);

            result.AddAccessRule(rule);

            return(result);
        }
Пример #16
0
 public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
 {
     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 ((inheritability < HandleInheritability.None) || (inheritability > HandleInheritability.Inheritable))
     {
         throw new ArgumentOutOfRangeException("inheritability");
     }
     if ((desiredAccessRights & ~(MemoryMappedFileRights.AccessSystemSecurity | MemoryMappedFileRights.FullControl)) != 0)
     {
         throw new ArgumentOutOfRangeException("desiredAccessRights");
     }
     return(new MemoryMappedFile(OpenCore(mapName, inheritability, (int)desiredAccessRights, false)));
 }
Пример #17
0
 public void VerifyOpenExistingException <EXCTYPE>(String strLoc, String mapName, MemoryMappedFileRights rights, HandleInheritability inheritability) where EXCTYPE : Exception
 {
     iCountTestcases++;
     try
     {
         using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(mapName, rights, inheritability))
         {
             iCountErrors++;
             Console.WriteLine("ERROR, {0}: No exception thrown, expected {1}", strLoc, typeof(EXCTYPE));
         }
     }
     catch (EXCTYPE)
     {
         //Console.WriteLine("{0}: Expected, {1}: {2}", strLoc, ex.GetType(), ex.Message);
     }
     catch (Exception ex)
     {
         iCountErrors++;
         Console.WriteLine("ERROR, {0}: Unexpected exception, {1}", strLoc, ex);
     }
 }
Пример #18
0
 MemoryMappedFileAccess RightsToMinAccess(MemoryMappedFileRights rights)
 {
     // MemoryMappedFileRights.FullControl, MemoryMappedFileRights.ReadWriteExecute
     if ((rights & MemoryMappedFileRights.ReadWriteExecute) == MemoryMappedFileRights.ReadWriteExecute)
     {
         return(MemoryMappedFileAccess.ReadWriteExecute);
     }
     // MemoryMappedFileRights.ReadWrite,
     else if ((rights & MemoryMappedFileRights.ReadWrite) == MemoryMappedFileRights.ReadWrite)
     {
         return(MemoryMappedFileAccess.ReadWrite);
     }
     // MemoryMappedFileRights.Write,
     else if ((rights & MemoryMappedFileRights.Write) == MemoryMappedFileRights.Write)
     {
         return(MemoryMappedFileAccess.Write);
     }
     // MemoryMappedFileRights.ReadExecute,
     else if ((rights & MemoryMappedFileRights.ReadExecute) == MemoryMappedFileRights.ReadExecute)
     {
         return(MemoryMappedFileAccess.ReadExecute);
     }
     // MemoryMappedFileRights.Read,
     else if ((rights & MemoryMappedFileRights.Read) == MemoryMappedFileRights.Read)
     {
         return(MemoryMappedFileAccess.Read);
     }
     // MemoryMappedFileRights.CopyOnWrite,
     // access=CopyOnWrite implies read access, but rights=CopyOnWrite doesn't, so map it equal to no access here
     //else if ((rights & MemoryMappedFileRights.CopyOnWrite) == MemoryMappedFileRights.CopyOnWrite)
     //    return MemoryMappedFileAccess.CopyOnWrite;
     // MemoryMappedFileRights.Execute, MemoryMappedFileRights.Delete, MemoryMappedFileRights.ReadPermissions, MemoryMappedFileRights.ChangePermissions, MemoryMappedFileRights.TakeOwnership, MemoryMappedFileRights.AccessSystemSecurity
     else
     {
         return((MemoryMappedFileAccess)(-1)); // since there's no "None" value
     }
 }
        public void OpenCreatedFromFile(string name, MemoryMappedFileRights rights, HandleInheritability inheritability)
        {
            const int Capacity = 4096;
            using (TempFile file = new TempFile(GetTestFilePath()))
            using (FileStream fs = File.Open(file.Path, FileMode.Open))
            using (MemoryMappedFile original = MemoryMappedFile.CreateFromFile(fs, name, Capacity, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, false))
            {
                using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(name))
                {
                    Assert.Throws<IOException>(() => MemoryMappedFile.OpenExisting(name, MemoryMappedFileRights.AccessSystemSecurity));
                    Assert.Throws<IOException>(() => MemoryMappedFile.OpenExisting(name, MemoryMappedFileRights.AccessSystemSecurity, HandleInheritability.None));
                    ValidateMemoryMappedFile(opened, Capacity);
                }
                using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(name, rights | MemoryMappedFileRights.ReadPermissions))
                {
                    ValidateMemoryMappedFile(opened, Capacity, RightsToAccess(rights));
                }
                using (MemoryMappedFile opened = MemoryMappedFile.OpenExisting(name, rights | MemoryMappedFileRights.ReadPermissions, inheritability))
                {
                    ValidateMemoryMappedFile(opened, Capacity, RightsToAccess(rights), inheritability);
                }
            }

            // The map no longer exists
            Assert.Throws<FileNotFoundException>(() => MemoryMappedFile.OpenExisting(name));
            Assert.Throws<FileNotFoundException>(() => MemoryMappedFile.OpenExisting(name, MemoryMappedFileRights.Read));
            Assert.Throws<FileNotFoundException>(() => MemoryMappedFile.OpenExisting(name, MemoryMappedFileRights.Read, HandleInheritability.None));
        }
 public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability);
        /// <summary>Converts file rights to minimum expected file accesses.</summary>
        private static MemoryMappedFileAccess RightsToAccess(MemoryMappedFileRights rights)
        {
            if ((rights & MemoryMappedFileRights.ReadWriteExecute) == MemoryMappedFileRights.ReadWriteExecute)
                return MemoryMappedFileAccess.ReadWriteExecute;

            if ((rights & MemoryMappedFileRights.ReadWrite) == MemoryMappedFileRights.ReadWrite)
                return MemoryMappedFileAccess.ReadWrite;

            if ((rights & MemoryMappedFileRights.Write) == MemoryMappedFileRights.Write)
                return MemoryMappedFileAccess.Write;

            if ((rights & MemoryMappedFileRights.ReadExecute) == MemoryMappedFileRights.ReadExecute)
                return MemoryMappedFileAccess.ReadExecute;

            if ((rights & MemoryMappedFileRights.Read) == MemoryMappedFileRights.Read)
                return MemoryMappedFileAccess.Read;

            return (MemoryMappedFileAccess)(-1); // no None, so just use -1
        }
Пример #22
0
 /// <summary>
 /// Used by the OpenExisting factory method group and by CreateOrOpen if access is write.
 /// We'll throw an ArgumentException if the file mapping object didn't exist and the
 /// caller used CreateOrOpen since Create isn't valid with Write access
 /// </summary>
 private static SafeMemoryMappedFileHandle OpenCore(
     string mapName, HandleInheritability inheritability, MemoryMappedFileRights rights, bool createOrOpen)
 {
     return OpenCore(mapName, inheritability, GetFileMapAccess(rights), createOrOpen);
 }
Пример #23
0
 public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
 {
     throw new NotImplementedException();
 }
Пример #24
0
 /// <summary>
 /// Used by the OpenExisting factory method group and by CreateOrOpen if access is write.
 /// We'll throw an ArgumentException if the file mapping object didn't exist and the
 /// caller used CreateOrOpen since Create isn't valid with Write access
 /// </summary>
 private static SafeMemoryMappedFileHandle OpenCore(
     string mapName, HandleInheritability inheritability, MemoryMappedFileRights rights, bool createOrOpen)
 {
     return(OpenCore(mapName, inheritability, GetFileMapAccess(rights), createOrOpen));
 }
Пример #25
0
		public static MemoryMappedFile OpenExisting (string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
		{
			throw new NotImplementedException ();
		}
Пример #26
0
 private static SafeMemoryMappedFileHandle OpenCore(
     String mapName, HandleInheritability inheritability, MemoryMappedFileRights rights, bool createOrOpen)
 {
     throw NotImplemented.ByDesign; // TODO: Implement this
 }
Пример #27
0
 private static SafeMemoryMappedFileHandle OpenCore(
     string mapName, HandleInheritability inheritability, MemoryMappedFileRights rights, bool createOrOpen)
 {
     throw CreateNamedMapsNotSupportedException();
 }
Пример #28
0
 public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability);
Пример #29
0
 public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights);
Пример #30
0
    public bool runTest()
    {
        try
        {
            ////////////////////////////////////////////////////////////////////////
            // OpenExisting(mapName)
            ////////////////////////////////////////////////////////////////////////

            // [] mapName

            // mapname > 260 chars
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("OpenExisting_" + new String('a', 1000) + s_uniquifier, 4096))
            {
                VerifyOpenExisting("Loc111", "OpenExisting_" + new String('a', 1000) + s_uniquifier, MemoryMappedFileAccess.ReadWrite);
            }

            // null
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew(null, 4096))
            {
                VerifyOpenExistingException <ArgumentNullException>("Loc112", null);
            }

            // empty string disallowed
            VerifyOpenExistingException <ArgumentException>("Loc113", String.Empty);

            // all whitespace
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("\t \n\u00A0 \t", 4096))
            {
                VerifyOpenExisting("Loc114", "\t \n\u00A0 \t", MemoryMappedFileAccess.ReadWrite);
            }

            // MMF with this mapname already exists (pagefile backed)
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("OpenExisting_map115a" + s_uniquifier, 1000))
            {
                VerifyOpenExisting("Loc115a", "OpenExisting_map115a" + s_uniquifier, MemoryMappedFileAccess.ReadWrite);
            }

            // MMF with this mapname already exists (filesystem backed)
            String fileText = "Non-empty file for MMF testing.";
            File.WriteAllText(s_fileNameTest, fileText);
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(s_fileNameTest, FileMode.Open, "map115b" + s_uniquifier))
            {
                VerifyOpenExisting("Loc115b", "map115b" + s_uniquifier, MemoryMappedFileAccess.ReadWrite);
            }

            // MMF with this mapname existed, but was closed - new MMF
            VerifyOpenExistingException <FileNotFoundException>("Loc116", "OpenExisting_map115a" + s_uniquifier);


            ////////////////////////////////////////////////////////////////////////
            // OpenExisting(mapName, MemoryMappedFileRights)
            ////////////////////////////////////////////////////////////////////////

            // [] rights
            MemoryMappedFileRights[] rightsList;

            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("mapname334" + s_uniquifier, 1000))
            {
                // default security - AccessSystemSecurity fails
                VerifyOpenExistingException <IOException>("Loc333", "mapname334" + s_uniquifier, MemoryMappedFileRights.AccessSystemSecurity);

                // default security - all others valid
                rightsList = new MemoryMappedFileRights[] {
                    MemoryMappedFileRights.CopyOnWrite,
                    MemoryMappedFileRights.Read,
                    MemoryMappedFileRights.Write,
                    MemoryMappedFileRights.Execute,
                    MemoryMappedFileRights.ReadWrite,
                    MemoryMappedFileRights.ReadExecute,
                    MemoryMappedFileRights.ReadWriteExecute,
                    MemoryMappedFileRights.Delete,
                    MemoryMappedFileRights.ReadPermissions,
                    MemoryMappedFileRights.ChangePermissions,
                    MemoryMappedFileRights.TakeOwnership,
                    MemoryMappedFileRights.FullControl,
                };
                foreach (MemoryMappedFileRights rights in rightsList)
                {
                    //Console.WriteLine("{0}  {1}", rights, RightsToMinAccess(rights));
                    // include ReadPermissions or we won't be able to verify the security object
                    VerifyOpenExisting("Loc334_" + rights, "mapname334" + s_uniquifier, rights | MemoryMappedFileRights.ReadPermissions, RightsToMinAccess(rights));
                }

                // invalid enum value
                rightsList = new MemoryMappedFileRights[] {
                    (MemoryMappedFileRights)(-1),
                    (MemoryMappedFileRights)(0x10000000),
                };
                foreach (MemoryMappedFileRights rights in rightsList)
                {
                    VerifyOpenExistingException <ArgumentOutOfRangeException>("Loc335_" + ((int)rights), "mapname334" + s_uniquifier, rights);
                }
            }

            ////////////////////////////////////////////////////////////////////////
            // OpenExisting(String, MemoryMappedFileRights, HandleInheritability)
            ////////////////////////////////////////////////////////////////////////

            // [] mapName

            // mapname > 260 chars
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew(new String('a', 1000) + s_uniquifier, 4096))
            {
                VerifyOpenExisting("Loc411", new String('a', 1000) + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.None, MemoryMappedFileAccess.ReadWriteExecute);
            }

            // null
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew(null, 4096))
            {
                VerifyOpenExistingException <ArgumentNullException>("Loc412", null, MemoryMappedFileRights.FullControl, HandleInheritability.None);
            }

            // empty string disallowed
            VerifyOpenExistingException <ArgumentException>("Loc413", String.Empty, MemoryMappedFileRights.FullControl, HandleInheritability.None);

            // all whitespace
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("\t \n\u00A0\t\t ", 4096))
            {
                VerifyOpenExisting("Loc414", "\t \n\u00A0\t\t ", MemoryMappedFileRights.FullControl, HandleInheritability.None, MemoryMappedFileAccess.ReadWriteExecute);
            }

            // MMF with this mapname already exists (pagefile backed)
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("map415a" + s_uniquifier, 1000))
            {
                VerifyOpenExisting("Loc415a", "map415a" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.None, MemoryMappedFileAccess.ReadWriteExecute);
            }

            // MMF with this mapname already exists (filesystem backed)
            File.WriteAllText(s_fileNameTest, fileText);
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(s_fileNameTest, FileMode.Open, "map415b" + s_uniquifier))
            {
                VerifyOpenExisting("Loc415b", "map415b" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.None, MemoryMappedFileAccess.ReadWriteExecute);
            }

            // MMF with this mapname existed, but was closed
            VerifyOpenExistingException <FileNotFoundException>("Loc416", "map415a" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.None);

            // [] rights

            // invalid enum value
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("mapname432" + s_uniquifier, 1000))
            {
                rightsList = new MemoryMappedFileRights[] {
                    (MemoryMappedFileRights)(-1),
                    (MemoryMappedFileRights)(0x10000000),
                };
                foreach (MemoryMappedFileRights rights in rightsList)
                {
                    VerifyOpenExistingException <ArgumentOutOfRangeException>("Loc432_" + ((int)rights), "mapname432" + s_uniquifier, rights, HandleInheritability.None);
                }
            }

            // default security - all valid
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("mapname433" + s_uniquifier, 1000))
            {
                rightsList = new MemoryMappedFileRights[] {
                    MemoryMappedFileRights.CopyOnWrite,
                    MemoryMappedFileRights.Read,
                    MemoryMappedFileRights.Write,
                    MemoryMappedFileRights.Execute,
                    MemoryMappedFileRights.ReadWrite,
                    MemoryMappedFileRights.ReadExecute,
                    MemoryMappedFileRights.ReadWriteExecute,
                    MemoryMappedFileRights.Delete,
                    MemoryMappedFileRights.ReadPermissions,
                    MemoryMappedFileRights.ChangePermissions,
                    MemoryMappedFileRights.TakeOwnership,
                    MemoryMappedFileRights.FullControl,
                };
                foreach (MemoryMappedFileRights rights in rightsList)
                {
                    // include ReadPermissions or we won't be able to verify the security object
                    VerifyOpenExisting("Loc433_" + rights, "mapname433" + s_uniquifier, rights | MemoryMappedFileRights.ReadPermissions, HandleInheritability.None, RightsToMinAccess(rights));
                }

                // default security - AccessSystemSecurity fails
                VerifyOpenExistingException <IOException>("Loc433b", "mapname433" + s_uniquifier, MemoryMappedFileRights.AccessSystemSecurity);
            }

            // default security, original (lesser) viewAccess is respected
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("mapname434" + s_uniquifier, 1000, MemoryMappedFileAccess.Read))
            {
                rightsList = new MemoryMappedFileRights[] {
                    MemoryMappedFileRights.CopyOnWrite,
                    MemoryMappedFileRights.Read,
                    MemoryMappedFileRights.Write,
                    MemoryMappedFileRights.Execute,
                    MemoryMappedFileRights.ReadWrite,
                    MemoryMappedFileRights.ReadExecute,
                    MemoryMappedFileRights.ReadWriteExecute,
                    MemoryMappedFileRights.Delete,
                    MemoryMappedFileRights.ReadPermissions,
                    MemoryMappedFileRights.ChangePermissions,
                    MemoryMappedFileRights.TakeOwnership,
                    MemoryMappedFileRights.FullControl,
                };
                foreach (MemoryMappedFileRights rights in rightsList)
                {
                    // include ReadPermissions or we won't be able to verify the security object
                    VerifyOpenExisting("Loc434_" + rights, "mapname434" + s_uniquifier, rights | MemoryMappedFileRights.ReadPermissions, HandleInheritability.None, RightsToMinAccess(rights & ~MemoryMappedFileRights.Write));
                }
            }

            // [] inheritability

            // None - existing file w/None
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("mapname463" + s_uniquifier, 1000, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.None))
            {
                VerifyOpenExisting("Loc463a", "mapname463" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.None, MemoryMappedFileAccess.ReadWriteExecute);
            }

            using (FileStream fs = new FileStream(s_fileNameTest, FileMode.Open))
            {
                using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fs, "mapname463" + s_uniquifier, 1000, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, false))
                {
                    VerifyOpenExisting("Loc463b", "mapname463" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.None, MemoryMappedFileAccess.ReadWriteExecute);
                }
            }

            // None - existing file w/Inheritable
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("mapname464" + s_uniquifier, 1000, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.Inheritable))
            {
                VerifyOpenExisting("Loc464a", "mapname464" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.None, MemoryMappedFileAccess.ReadWriteExecute);
            }

            using (FileStream fs = new FileStream(s_fileNameTest, FileMode.Open))
            {
                using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fs, "mapname464" + s_uniquifier, 1000, MemoryMappedFileAccess.ReadWrite, HandleInheritability.Inheritable, false))
                {
                    VerifyOpenExisting("Loc464b", "mapname464" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.None, MemoryMappedFileAccess.ReadWriteExecute);
                }
            }

            // Inheritable - existing file w/None
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("mapname465" + s_uniquifier, 1000, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.None))
            {
                VerifyOpenExisting("Loc465a", "mapname465" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.Inheritable, MemoryMappedFileAccess.ReadWriteExecute);
            }

            using (FileStream fs = new FileStream(s_fileNameTest, FileMode.Open))
            {
                using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fs, "mapname465" + s_uniquifier, 1000, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, false))
                {
                    VerifyOpenExisting("Loc465b", "mapname465" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.Inheritable, MemoryMappedFileAccess.ReadWriteExecute);
                }
            }

            // Inheritable - existing file w/Inheritable
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("mapname466" + s_uniquifier, 1000, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.Inheritable))
            {
                VerifyOpenExisting("Loc466a", "mapname466" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.Inheritable, MemoryMappedFileAccess.ReadWriteExecute);
            }

            using (FileStream fs = new FileStream(s_fileNameTest, FileMode.Open))
            {
                using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fs, "mapname466" + s_uniquifier, 1000, MemoryMappedFileAccess.ReadWrite, HandleInheritability.Inheritable, false))
                {
                    VerifyOpenExisting("Loc466b", "mapname466" + s_uniquifier, MemoryMappedFileRights.FullControl, HandleInheritability.Inheritable, MemoryMappedFileAccess.ReadWriteExecute);
                }
            }

            // invalid
            VerifyOpenExistingException <ArgumentOutOfRangeException>("Loc467", "mapname467" + s_uniquifier, MemoryMappedFileRights.FullControl, (HandleInheritability)(-1));
            VerifyOpenExistingException <ArgumentOutOfRangeException>("Loc468", "mapname468" + s_uniquifier, MemoryMappedFileRights.FullControl, (HandleInheritability)(2));

            /// END TEST CASES

            if (iCountErrors == 0)
            {
                return(true);
            }
            else
            {
                Console.WriteLine("Fail! iCountErrors==" + iCountErrors);
                return(false);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("ERR999: Unexpected exception in runTest, {0}", ex);
            return(false);
        }
    }
Пример #31
0
 public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights)
 {
     return(OpenExisting(mapName, desiredAccessRights, HandleInheritability.None));
 }
Пример #32
0
 public IMemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights)
 {
     return(new MemoryMappedFileWrapper(MemoryMappedFile.OpenExisting(mapName, desiredAccessRights)));
 }
Пример #33
0
		public static MemoryMappedFile OpenExisting (string mapName, MemoryMappedFileRights desiredAccessRights)
		{
			throw new NotImplementedException ();
		}
Пример #34
0
 public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject,
                                           MemoryMappedFileRights dwDesiredAccess,
                                           long dwFileOffsetHigh,
                                           long dwFileOffsetLow,
                                           int dwNumberOfBytesToMap);
Пример #35
0
        // -----------------------------
        // ---- PAL layer ends here ----
        // -----------------------------

        /// <summary>
        /// This converts a MemoryMappedFileRights to its corresponding native FILE_MAP_XXX value to be used when
        /// creating new views.
        /// </summary>
        private static int GetFileMapAccess(MemoryMappedFileRights rights)
        {
            return((int)rights);
        }
    public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
    {
      Contract.Ensures(1 <= mapName.Length);
      Contract.Ensures(Contract.Result<System.IO.MemoryMappedFiles.MemoryMappedFile>() != null);

      return default(MemoryMappedFile);
    }
Пример #37
0
 public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights)
 {
     throw new NotImplementedException();
 }
Пример #38
0
 public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights)
 {
     return OpenExisting(mapName, desiredAccessRights, HandleInheritability.None);
 }
Пример #39
0
        // -----------------------------
        // ---- PAL layer ends here ----
        // -----------------------------

        /// <summary>
        /// This converts a MemoryMappedFileRights to its corresponding native FILE_MAP_XXX value to be used when 
        /// creating new views.  
        /// </summary>
        private static int GetFileMapAccess(MemoryMappedFileRights rights)
        {
            return (int)rights;
        }
Пример #40
0
 public static extern IntPtr OpenFileMapping(MemoryMappedFileRights dwDesiredAccess,
                                             bool bInheritHandle,
                                             string lpName);
Пример #41
0
 public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
 {
     // FIXME: Actually use desiredAccessRights
     return(CoreShmCreate(mapName, 0, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, null, inheritability, FileMode.Open));
 }
 public static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights);
Пример #43
0
 private static SafeMemoryMappedFileHandle OpenCore(
     string mapName, HandleInheritability inheritability, MemoryMappedFileRights rights, bool createOrOpen)
 {
     throw CreateNamedMapsNotSupportedException();
 }
Пример #44
0
 public IMemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights)
 {
     return new MemoryMappedFileWrapper(MemoryMappedFile.OpenExisting(mapName, desiredAccessRights));
 }