Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2018-09-11 09:33:05 +0300
committerJan Kotas <jkotas@microsoft.com>2018-09-11 16:38:31 +0300
commit140f71b6164e698eed4e4f5776607bf1be97f438 (patch)
treea15559ccdf74d090b60f7912182a86322635dd6f
parent3d69c4ae547213dabdb7e9c2123dee3a56f71d7f (diff)
Move more registry files to shared partition
-rw-r--r--src/Common/src/Interop/Windows/Interop.Libraries.cs4
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegFlushKey.cs15
-rw-r--r--src/System.Private.CoreLib/shared/Microsoft/Win32/RegistryOptions.cs (renamed from src/System.Private.CoreLib/src/Microsoft/Win32/RegistryOptions.cs)0
-rw-r--r--src/System.Private.CoreLib/shared/Microsoft/Win32/RegistryValueOptions.cs20
-rw-r--r--src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems22
-rw-r--r--src/System.Private.CoreLib/shared/System/Security/AccessControl/RegistryRights.cs (renamed from src/System.Private.CoreLib/src/System/Security/AccessControl/RegistryRights.cs)0
-rw-r--r--src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.Windows.cs138
-rw-r--r--src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs12
-rw-r--r--src/System.Private.CoreLib/src/System.Private.CoreLib.csproj2
9 files changed, 143 insertions, 70 deletions
diff --git a/src/Common/src/Interop/Windows/Interop.Libraries.cs b/src/Common/src/Interop/Windows/Interop.Libraries.cs
index 8536bc367..68a50eadd 100644
--- a/src/Common/src/Interop/Windows/Interop.Libraries.cs
+++ b/src/Common/src/Interop/Windows/Interop.Libraries.cs
@@ -6,9 +6,6 @@ internal static partial class Interop
{
internal static partial class Libraries
{
- internal const string CoreFile_L1 = "api-ms-win-core-file-l1-1-0.dll";
- internal const string CoreFile_L1_2 = "api-ms-win-core-file-l1-2-0.dll";
- internal const string CoreFile_L2 = "api-ms-win-core-file-l2-1-0.dll";
internal const string ErrorHandling = "api-ms-win-core-errorhandling-l1-1-0.dll";
internal const string Handle = "api-ms-win-core-handle-l1-1-0.dll";
internal const string IO = "api-ms-win-core-io-l1-1-0.dll";
@@ -17,7 +14,6 @@ internal static partial class Interop
internal const string ProcessThreads = "api-ms-win-core-processthreads-l1-1-0.dll";
internal const string RealTime = "api-ms-win-core-realtime-l1-1-0.dll";
internal const string SysInfo = "api-ms-win-core-sysinfo-l1-2-0.dll";
- internal const string Registry_L1 = "api-ms-win-core-registry-l1-1-0.dll";
internal const string ThreadPool = "api-ms-win-core-threadpool-l1-2-0.dll";
internal const string Localization = "api-ms-win-core-localization-l1-2-1.dll";
}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegFlushKey.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegFlushKey.cs
new file mode 100644
index 000000000..8f72798f8
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegFlushKey.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class Advapi32
+ {
+ [DllImport(Libraries.Advapi32)]
+ internal static extern int RegFlushKey(SafeRegistryHandle hKey);
+ }
+}
diff --git a/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryOptions.cs b/src/System.Private.CoreLib/shared/Microsoft/Win32/RegistryOptions.cs
index 201a6df0e..201a6df0e 100644
--- a/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryOptions.cs
+++ b/src/System.Private.CoreLib/shared/Microsoft/Win32/RegistryOptions.cs
diff --git a/src/System.Private.CoreLib/shared/Microsoft/Win32/RegistryValueOptions.cs b/src/System.Private.CoreLib/shared/Microsoft/Win32/RegistryValueOptions.cs
new file mode 100644
index 000000000..7d9b6c403
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Microsoft/Win32/RegistryValueOptions.cs
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+namespace Microsoft.Win32
+{
+ [Flags]
+#if REGISTRY_ASSEMBLY
+ public
+#else
+ internal
+#endif
+ enum RegistryValueOptions
+ {
+ None = 0,
+ DoNotExpandEnvironmentNames = 1
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
index eae701602..769b21609 100644
--- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
+++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
@@ -801,35 +801,39 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Windows.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetsWindows) and '$(EnableWinRT)' != 'true'">
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\NtDll\NtQueryInformationFile.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegCreateKeyEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegCloseKey.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegCreateKeyEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegDeleteKeyEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegDeleteValue.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegEnumKeyEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegEnumValue.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegFlushKey.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegistryConstants.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegOpenKeyEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegQueryInfoKey.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegQueryValueEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegSetValueEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegistryConstants.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Win32.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Win32.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\Registry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\RegistryHive.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\RegistryOptions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\RegistryValueKind.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\RegistryValueOptions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\RegistryView.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeLibraryHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeRegistryHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeRegistryHandle.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.LoadLibraryEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FreeLibrary.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Security\AccessControl\RegistryRights.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CreateFile.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FreeLibrary.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.LoadLibraryEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MUI.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.TimeZone.Registry.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\NtDll\NtQueryInformationFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.Constants.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.SendMessageTimeout.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.LoadString.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.SendMessageTimeout.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeLibraryHandle.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Win32.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Win32.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetsWindows) and '$(EnableWinRT)' == 'true'">
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.WinRT.cs" />
diff --git a/src/System.Private.CoreLib/src/System/Security/AccessControl/RegistryRights.cs b/src/System.Private.CoreLib/shared/System/Security/AccessControl/RegistryRights.cs
index 729e2f6b5..729e2f6b5 100644
--- a/src/System.Private.CoreLib/src/System/Security/AccessControl/RegistryRights.cs
+++ b/src/System.Private.CoreLib/shared/System/Security/AccessControl/RegistryRights.cs
diff --git a/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.Windows.cs b/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.Windows.cs
index a8fb1c187..b9221327e 100644
--- a/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.Windows.cs
+++ b/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.Windows.cs
@@ -4,6 +4,7 @@
using Microsoft.Win32.SafeHandles;
using System;
+using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@@ -285,36 +286,45 @@ namespace Microsoft.Win32
return subkeys;
}
- private unsafe string[] InternalGetSubKeyNamesCore(int subkeys)
+ private string[] InternalGetSubKeyNamesCore(int subkeys)
{
- string[] names = new string[subkeys];
- char[] name = new char[MaxKeyLength + 1];
+ var names = new List<string>(subkeys);
+ char[] name = ArrayPool<char>.Shared.Rent(MaxKeyLength + 1);
- int namelen;
-
- fixed (char* namePtr = &name[0])
+ try
{
- for (int i = 0; i < subkeys; i++)
+ int result;
+ int nameLength = name.Length;
+
+ while ((result = Interop.Advapi32.RegEnumKeyEx(
+ _hkey,
+ names.Count,
+ name,
+ ref nameLength,
+ null,
+ null,
+ null,
+ null)) != Interop.Errors.ERROR_NO_MORE_ITEMS)
{
- namelen = name.Length; // Don't remove this. The API's doesn't work if this is not properly initialized.
- int ret = Interop.Advapi32.RegEnumKeyEx(_hkey,
- i,
- namePtr,
- ref namelen,
- null,
- null,
- null,
- null);
- if (ret != 0)
+ switch (result)
{
- Win32Error(ret, null);
+ case Interop.Errors.ERROR_SUCCESS:
+ names.Add(new string(name, 0, nameLength));
+ nameLength = name.Length;
+ break;
+ default:
+ // Throw the error
+ Win32Error(result, null);
+ break;
}
-
- names[i] = new string(namePtr);
}
}
+ finally
+ {
+ ArrayPool<char>.Shared.Return(name);
+ }
- return names;
+ return names.ToArray();
}
private int InternalValueCountCore()
@@ -345,37 +355,79 @@ namespace Microsoft.Win32
/// <returns>All value names.</returns>
private unsafe string[] GetValueNamesCore(int values)
{
- string[] names = new string[values];
- char[] name = new char[MaxValueLength + 1];
- int namelen;
+ var names = new List<string>(values);
+
+ // Names in the registry aren't usually very long, although they can go to as large
+ // as 16383 characters (MaxValueLength).
+ //
+ // Every call to RegEnumValue will allocate another buffer to get the data from
+ // NtEnumerateValueKey before copying it back out to our passed in buffer. This can
+ // add up quickly- we'll try to keep the memory pressure low and grow the buffer
+ // only if needed.
+
+ char[] name = ArrayPool<char>.Shared.Rent(100);
- fixed (char* namePtr = &name[0])
+ try
{
- for (int i = 0; i < values; i++)
+ int result;
+ int nameLength = name.Length;
+
+ while ((result = Interop.Advapi32.RegEnumValue(
+ _hkey,
+ names.Count,
+ name,
+ ref nameLength,
+ IntPtr.Zero,
+ null,
+ null,
+ null)) != Interop.Errors.ERROR_NO_MORE_ITEMS)
{
- namelen = name.Length;
-
- int ret = Interop.Advapi32.RegEnumValue(_hkey,
- i,
- namePtr,
- ref namelen,
- IntPtr.Zero,
- null,
- null,
- null);
-
- if (ret != 0)
+ switch (result)
{
- // ignore ERROR_MORE_DATA if we're querying HKEY_PERFORMANCE_DATA
- if (!(IsPerfDataKey() && ret == Interop.Errors.ERROR_MORE_DATA))
- Win32Error(ret, null);
+ // The size is only ever reported back correctly in the case
+ // of ERROR_SUCCESS. It will almost always be changed, however.
+ case Interop.Errors.ERROR_SUCCESS:
+ names.Add(new string(name, 0, nameLength));
+ break;
+ case Interop.Errors.ERROR_MORE_DATA:
+ if (IsPerfDataKey())
+ {
+ // Enumerating the values for Perf keys always returns
+ // ERROR_MORE_DATA, but has a valid name. Buffer does need
+ // to be big enough however. 8 characters is the largest
+ // known name. The size isn't returned, but the string is
+ // null terminated.
+ fixed (char* c = &name[0])
+ {
+ names.Add(new string(c));
+ }
+ }
+ else
+ {
+ char[] oldName = name;
+ int oldLength = oldName.Length;
+ name = null;
+ ArrayPool<char>.Shared.Return(oldName);
+ name = ArrayPool<char>.Shared.Rent(checked(oldLength * 2));
+ }
+ break;
+ default:
+ // Throw the error
+ Win32Error(result, null);
+ break;
}
- names[i] = new string(namePtr);
+ // Always set the name length back to the buffer size
+ nameLength = name.Length;
}
}
+ finally
+ {
+ if (name != null)
+ ArrayPool<char>.Shared.Return(name);
+ }
- return names;
+ return names.ToArray();
}
private object InternalGetValueCore(string name, object defaultValue, bool doNotExpand)
diff --git a/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs b/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs
index 74d0ed362..ecf8376ed 100644
--- a/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs
+++ b/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs
@@ -562,16 +562,4 @@ namespace Microsoft.Win32
// Its not being used anywhere.
public void SetValue(string name, object value, RegistryValueKind valueKind) { }
}
-
- [Flags]
-#if REGISTRY_ASSEMBLY
- public
-#else
- internal
-#endif
- enum RegistryValueOptions
- {
- None = 0,
- DoNotExpandEnvironmentNames = 1
- }
}
diff --git a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj
index 88c6d2f02..923a7bfd4 100644
--- a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj
+++ b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj
@@ -349,9 +349,7 @@
<ItemGroup Condition="'$(TargetsWindows)'=='true' and '$(EnableWinRT)'!='true'">
<Compile Include="Microsoft\Win32\RegistryKey.cs" />
<Compile Include="Microsoft\Win32\RegistryKey.Windows.cs" />
- <Compile Include="Microsoft\Win32\RegistryOptions.cs" />
<Compile Include="Microsoft\Win32\ThrowHelper.cs" />
- <Compile Include="System\Security\AccessControl\RegistryRights.cs" />
<Compile Include="..\..\Common\src\Interop\Windows\Kernel32\Interop.ExitProcess.cs">
<Link>Interop\Windows\mincore\Interop.ExitProcess.cs</Link>
</Compile>