summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/Microsoft/Win32
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/Microsoft/Win32')
-rw-r--r--src/mscorlib/src/Microsoft/Win32/OAVariantLib.cs6
-rw-r--r--src/mscorlib/src/Microsoft/Win32/Registry.cs24
-rw-r--r--src/mscorlib/src/Microsoft/Win32/RegistryKey.cs296
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.cs43
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileMappingHandle.cs4
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs3
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs12
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLocalAllocHandle.cs6
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs4
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeViewOfFileHandle.cs4
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs2
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs25
-rw-r--r--src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs8
-rw-r--r--src/mscorlib/src/Microsoft/Win32/Win32Native.cs115
14 files changed, 20 insertions, 532 deletions
diff --git a/src/mscorlib/src/Microsoft/Win32/OAVariantLib.cs b/src/mscorlib/src/Microsoft/Win32/OAVariantLib.cs
index 118c69b8b7..6c2c6e9630 100644
--- a/src/mscorlib/src/Microsoft/Win32/OAVariantLib.cs
+++ b/src/mscorlib/src/Microsoft/Win32/OAVariantLib.cs
@@ -73,13 +73,12 @@ namespace Microsoft.Win32 {
* Variant and the types that CLR supports explicitly in the
* CLR Variant class.
*/
- [System.Security.SecurityCritical] // auto-generated
internal static Variant ChangeType(Variant source, Type targetClass, short options, CultureInfo culture)
{
if (targetClass == null)
- throw new ArgumentNullException("targetClass");
+ throw new ArgumentNullException(nameof(targetClass));
if (culture == null)
- throw new ArgumentNullException("culture");
+ throw new ArgumentNullException(nameof(culture));
Variant result = new Variant ();
ChangeTypeEx(ref result, ref source,
#if FEATURE_USE_LCID
@@ -125,7 +124,6 @@ namespace Microsoft.Win32 {
#region Private FCalls
- [System.Security.SecurityCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void ChangeTypeEx(ref Variant result, ref Variant source, int lcid, IntPtr typeHandle, int cvType, short flags);
diff --git a/src/mscorlib/src/Microsoft/Win32/Registry.cs b/src/mscorlib/src/Microsoft/Win32/Registry.cs
index 4faf29da7f..3ee5f4648b 100644
--- a/src/mscorlib/src/Microsoft/Win32/Registry.cs
+++ b/src/mscorlib/src/Microsoft/Win32/Registry.cs
@@ -17,7 +17,6 @@ namespace Microsoft.Win32 {
//This class contains only static members and does not need to be serializable.
[ComVisible(true)]
public static class Registry {
- [System.Security.SecuritySafeCritical] // auto-generated
static Registry()
{
}
@@ -63,17 +62,6 @@ namespace Microsoft.Win32 {
* This is where current configuration information is stored.
*/
public static readonly RegistryKey CurrentConfig = RegistryKey.GetBaseKey(RegistryKey.HKEY_CURRENT_CONFIG);
-
-#if !FEATURE_CORECLR
- /**
- * Dynamic Data Root Key.
- *
- * LEGACY: This is where dynamic performance data is stored on Win9X.
- * This does not exist on NT.
- */
- [Obsolete("The DynData registry key only works on Win9x, which is no longer supported by the CLR. On NT-based operating systems, use the PerformanceData registry key instead.")]
- public static readonly RegistryKey DynData = RegistryKey.GetBaseKey(RegistryKey.HKEY_DYN_DATA);
-#endif
//
// Following function will parse a keyName and returns the basekey for it.
@@ -81,10 +69,9 @@ namespace Microsoft.Win32 {
// If the keyName is not valid, we will throw ArgumentException.
// The return value shouldn't be null.
//
- [System.Security.SecurityCritical] // auto-generated
private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subKeyName) {
if( keyName == null) {
- throw new ArgumentNullException("keyName");
+ throw new ArgumentNullException(nameof(keyName));
}
string basekeyName;
@@ -116,13 +103,8 @@ namespace Microsoft.Win32 {
case "HKEY_CURRENT_CONFIG":
basekey = Registry.CurrentConfig;
break;
-#if !FEATURE_CORECLR
- case "HKEY_DYN_DATA":
- basekey = RegistryKey.GetBaseKey(RegistryKey.HKEY_DYN_DATA);
- break;
-#endif
default:
- throw new ArgumentException(Environment.GetResourceString("Arg_RegInvalidKeyName", "keyName"));
+ throw new ArgumentException(Environment.GetResourceString("Arg_RegInvalidKeyName", nameof(keyName)));
}
if( i == -1 || i == keyName.Length) {
subKeyName = string.Empty;
@@ -133,7 +115,6 @@ namespace Microsoft.Win32 {
return basekey;
}
- [System.Security.SecuritySafeCritical] // auto-generated
public static object GetValue(string keyName, string valueName, object defaultValue ) {
string subKeyName;
RegistryKey basekey = GetBaseKeyFromKeyName(keyName, out subKeyName);
@@ -154,7 +135,6 @@ namespace Microsoft.Win32 {
SetValue(keyName, valueName, value, RegistryValueKind.Unknown);
}
- [System.Security.SecuritySafeCritical] // auto-generated
public static void SetValue(string keyName, string valueName, object value, RegistryValueKind valueKind ) {
string subKeyName;
RegistryKey basekey = GetBaseKeyFromKeyName(keyName, out subKeyName);
diff --git a/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs b/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs
index dcf31dc60c..ff678f132c 100644
--- a/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs
+++ b/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs
@@ -49,15 +49,12 @@
*/
-namespace Microsoft.Win32 {
-
+namespace Microsoft.Win32
+{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Security;
-#if FEATURE_MACL
- using System.Security.AccessControl;
-#endif
using System.Security.Permissions;
using System.Text;
using System.Threading;
@@ -74,7 +71,7 @@ namespace Microsoft.Win32 {
* Registry hive values. Useful only for GetRemoteBaseKey
*/
[Serializable]
-[System.Runtime.InteropServices.ComVisible(true)]
+ [System.Runtime.InteropServices.ComVisible(true)]
public enum RegistryHive
{
ClassesRoot = unchecked((int)0x80000000),
@@ -83,9 +80,6 @@ namespace Microsoft.Win32 {
Users = unchecked((int)0x80000003),
PerformanceData = unchecked((int)0x80000004),
CurrentConfig = unchecked((int)0x80000005),
-#if !FEATURE_CORECLR
- DynData = unchecked((int)0x80000006),
-#endif
}
/**
@@ -96,13 +90,8 @@ namespace Microsoft.Win32 {
* @security(checkDllCalls=off)
* @security(checkClassLinking=on)
*/
-#if FEATURE_REMOTING
[ComVisible(true)]
public sealed class RegistryKey : MarshalByRefObject, IDisposable
-#else
- [ComVisible(true)]
- public sealed class RegistryKey : IDisposable
-#endif
{
// We could use const here, if C# supported ELEMENT_TYPE_I fully.
@@ -112,9 +101,6 @@ namespace Microsoft.Win32 {
internal static readonly IntPtr HKEY_USERS = new IntPtr(unchecked((int)0x80000003));
internal static readonly IntPtr HKEY_PERFORMANCE_DATA = new IntPtr(unchecked((int)0x80000004));
internal static readonly IntPtr HKEY_CURRENT_CONFIG = new IntPtr(unchecked((int)0x80000005));
-#if !FEATURE_CORECLR
- internal static readonly IntPtr HKEY_DYN_DATA = new IntPtr(unchecked((int)0x80000006));
-#endif
// Dirty indicates that we have munged data that should be potentially
// written to disk.
@@ -142,9 +128,6 @@ namespace Microsoft.Win32 {
"HKEY_USERS",
"HKEY_PERFORMANCE_DATA",
"HKEY_CURRENT_CONFIG",
-#if !FEATURE_CORECLR
- "HKEY_DYN_DATA"
-#endif
};
// MSDN defines the following limits for registry key names & values:
@@ -154,7 +137,6 @@ namespace Microsoft.Win32 {
private const int MaxKeyLength = 255;
private const int MaxValueLength = 16383;
- [System.Security.SecurityCritical] // auto-generated
private volatile SafeRegistryHandle hkey = null;
private volatile int state = 0;
private volatile String keyName;
@@ -188,7 +170,6 @@ namespace Microsoft.Win32 {
* This key is bound to hkey, if writable is <b>false</b> then no write operations
* will be allowed.
*/
- [System.Security.SecurityCritical] // auto-generated
private RegistryKey(SafeRegistryHandle hkey, bool writable, RegistryView view)
: this(hkey, writable, false, false, false, view) {
}
@@ -203,7 +184,6 @@ namespace Microsoft.Win32 {
* The remoteKey flag when set to true indicates that we are dealing with registry entries
* on a remote machine and requires the program making these calls to have full trust.
*/
- [System.Security.SecurityCritical] // auto-generated
private RegistryKey(SafeRegistryHandle hkey, bool writable, bool systemkey, bool remoteKey, bool isPerfData, RegistryView view) {
this.hkey = hkey;
this.keyName = "";
@@ -227,7 +207,6 @@ namespace Microsoft.Win32 {
Dispose(true);
}
- [System.Security.SecuritySafeCritical] // auto-generated
private void Dispose(bool disposing) {
if (hkey != null) {
@@ -260,7 +239,6 @@ namespace Microsoft.Win32 {
}
}
- [System.Security.SecuritySafeCritical] // auto-generated
public void Flush() {
if (hkey != null) {
if (IsDirty()) {
@@ -269,11 +247,7 @@ namespace Microsoft.Win32 {
}
}
-#if FEATURE_CORECLR
void IDisposable.Dispose()
-#else
- public void Dispose()
-#endif
{
Dispose(true);
}
@@ -314,22 +288,6 @@ namespace Microsoft.Win32 {
return CreateSubKeyInternal(subkey, writable ? RegistryKeyPermissionCheck.ReadWriteSubTree : RegistryKeyPermissionCheck.ReadSubTree, null, options);
}
-
-#if FEATURE_MACL
- [ComVisible(false)]
- public unsafe RegistryKey CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck, RegistrySecurity registrySecurity)
- {
- return CreateSubKeyInternal(subkey, permissionCheck, registrySecurity, RegistryOptions.None);
- }
-
- [ComVisible(false)]
- public unsafe RegistryKey CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck, RegistryOptions registryOptions, RegistrySecurity registrySecurity)
- {
- return CreateSubKeyInternal(subkey, permissionCheck, registrySecurity, registryOptions);
- }
-#endif
-
- [System.Security.SecuritySafeCritical] // auto-generated
[ComVisible(false)]
private unsafe RegistryKey CreateSubKeyInternal(String subkey, RegistryKeyPermissionCheck permissionCheck, object registrySecurityObj, RegistryOptions registryOptions)
{
@@ -351,23 +309,9 @@ namespace Microsoft.Win32 {
}
CheckPermission(RegistryInternalCheck.CheckSubKeyCreatePermission, subkey, false, RegistryKeyPermissionCheck.Default);
-
+
Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
-#if FEATURE_MACL
- RegistrySecurity registrySecurity = (RegistrySecurity)registrySecurityObj;
- // For ACL's, get the security descriptor from the RegistrySecurity.
- if (registrySecurity != null) {
- secAttrs = new Win32Native.SECURITY_ATTRIBUTES();
- secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);
-
- byte[] sd = registrySecurity.GetSecurityDescriptorBinaryForm();
- // We allocate memory on the stack to improve the speed.
- // So this part of code can't be refactored into a method.
- byte* pSecDescriptor = stackalloc byte[sd.Length];
- Buffer.Memcpy(pSecDescriptor, 0, sd, 0, sd.Length);
- secAttrs.pSecurityDescriptor = pSecDescriptor;
- }
-#endif
+
int disposition = 0;
// By default, the new key will be writable.
@@ -412,7 +356,6 @@ namespace Microsoft.Win32 {
DeleteSubKey(subkey, true);
}
- [System.Security.SecuritySafeCritical] // auto-generated
public void DeleteSubKey(String subkey, bool throwOnMissingSubKey) {
ValidateKeyName(subkey);
EnsureWriteable();
@@ -466,7 +409,6 @@ namespace Microsoft.Win32 {
DeleteSubKeyTree(subkey, true /*throwOnMissingSubKey*/);
}
- [System.Security.SecuritySafeCritical] // auto-generated
[ComVisible(false)]
public void DeleteSubKeyTree(String subkey, Boolean throwOnMissingSubKey) {
ValidateKeyName(subkey);
@@ -514,7 +456,6 @@ namespace Microsoft.Win32 {
// An internal version which does no security checks or argument checking. Skipping the
// security checks should give us a slight perf gain on large trees.
- [System.Security.SecurityCritical] // auto-generated
private void DeleteSubKeyTreeInternal(string subkey) {
RegistryKey key = InternalOpenSubKey(subkey, true);
if (key != null) {
@@ -541,7 +482,7 @@ namespace Microsoft.Win32 {
if (ret!=0) Win32Error(ret, null);
}
else {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RegSubKeyAbsent);
+ ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RegSubKeyAbsent);
}
}
@@ -554,7 +495,6 @@ namespace Microsoft.Win32 {
DeleteValue(name, true);
}
- [System.Security.SecuritySafeCritical] // auto-generated
public void DeleteValue(String name, bool throwOnMissingValue) {
EnsureWriteable();
CheckPermission(RegistryInternalCheck.CheckValueWritePermission, name, false, RegistryKeyPermissionCheck.Default);
@@ -592,12 +532,10 @@ namespace Microsoft.Win32 {
*
* @return the RegistryKey requested.
*/
- [System.Security.SecurityCritical] // auto-generated
internal static RegistryKey GetBaseKey(IntPtr hKey) {
return GetBaseKey(hKey, RegistryView.Default);
}
- [System.Security.SecurityCritical] // auto-generated
internal static RegistryKey GetBaseKey(IntPtr hKey, RegistryView view) {
int index = ((int)hKey) & 0x0FFFFFFF;
@@ -615,7 +553,6 @@ namespace Microsoft.Win32 {
}
- [System.Security.SecuritySafeCritical] // auto-generated
[ComVisible(false)]
public static RegistryKey OpenBaseKey(RegistryHive hKey, RegistryView view) {
ValidateKeyView(view);
@@ -645,11 +582,10 @@ namespace Microsoft.Win32 {
return OpenRemoteBaseKey(hKey, machineName, RegistryView.Default);
}
- [System.Security.SecuritySafeCritical] // auto-generated
[ComVisible(false)]
public static RegistryKey OpenRemoteBaseKey(RegistryHive hKey, String machineName, RegistryView view) {
if (machineName==null)
- throw new ArgumentNullException("machineName");
+ throw new ArgumentNullException(nameof(machineName));
int index = (int)hKey & 0x0FFFFFFF;
if (index < 0 || index >= hkeyNames.Length || ((int)hKey & 0xFFFFFFF0) != 0x80000000) {
throw new ArgumentException(Environment.GetResourceString("Arg_RegKeyOutOfRange"));
@@ -687,11 +623,6 @@ namespace Microsoft.Win32 {
*
* @return the Subkey requested, or <b>null</b> if the operation failed.
*/
- #if FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated
- #else
- [System.Security.SecuritySafeCritical]
- #endif
public RegistryKey OpenSubKey(string name, bool writable ) {
ValidateKeyName(name);
EnsureNotDisposed();
@@ -722,63 +653,8 @@ namespace Microsoft.Win32 {
return null;
}
-#if FEATURE_MACL
-
- [System.Security.SecuritySafeCritical] // auto-generated
- [ComVisible(false)]
- public RegistryKey OpenSubKey(String name, RegistryKeyPermissionCheck permissionCheck) {
- ValidateKeyMode(permissionCheck);
- return InternalOpenSubKey(name, permissionCheck, GetRegistryKeyAccess(permissionCheck));
- }
-
- [System.Security.SecuritySafeCritical]
- [ComVisible(false)]
- public RegistryKey OpenSubKey(String name, RegistryRights rights)
- {
- return InternalOpenSubKey(name, this.checkMode, (int)rights);
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
- [ComVisible(false)]
- public RegistryKey OpenSubKey(String name, RegistryKeyPermissionCheck permissionCheck, RegistryRights rights) {
- return InternalOpenSubKey(name, permissionCheck, (int)rights);
- }
-
- [System.Security.SecurityCritical] // auto-generated
- private RegistryKey InternalOpenSubKey(String name, RegistryKeyPermissionCheck permissionCheck, int rights) {
- ValidateKeyName(name);
- ValidateKeyMode(permissionCheck);
-
- ValidateKeyRights(rights);
-
- EnsureNotDisposed();
- name = FixupName(name); // Fixup multiple slashes to a single slash
-
- CheckPermission(RegistryInternalCheck.CheckOpenSubKeyPermission, name, false, permissionCheck);
- CheckPermission(RegistryInternalCheck.CheckSubTreePermission, name, false, permissionCheck);
- SafeRegistryHandle result = null;
- int ret = Win32Native.RegOpenKeyEx(hkey, name, 0, (rights | (int)regView), out result);
- if (ret == 0 && !result.IsInvalid) {
- RegistryKey key = new RegistryKey(result, (permissionCheck == RegistryKeyPermissionCheck.ReadWriteSubTree), false, remoteKey, false, regView);
- key.keyName = keyName + "\\" + name;
- key.checkMode = permissionCheck;
- return key;
- }
-
- // Return null if we didn't find the key.
- if (ret == Win32Native.ERROR_ACCESS_DENIED || ret == Win32Native.ERROR_BAD_IMPERSONATION_LEVEL) {
- // We need to throw SecurityException here for compatiblity reason,
- // although UnauthorizedAccessException will make more sense.
- ThrowHelper.ThrowSecurityException(ExceptionResource.Security_RegistryPermission);
- }
-
- return null;
- }
-#endif
-
// This required no security checks. This is to get around the Deleting SubKeys which only require
// write permission. They call OpenSubKey which required read. Now instead call this function w/o security checks
- [System.Security.SecurityCritical] // auto-generated
internal RegistryKey InternalOpenSubKey(String name, bool writable) {
ValidateKeyName(name);
EnsureNotDisposed();
@@ -805,9 +681,6 @@ namespace Microsoft.Win32 {
*
* @return the Subkey requested, or <b>null</b> if the operation failed.
*/
-#if FEATURE_CORECLR
- [System.Security.SecurityCritical]
-#endif
public RegistryKey OpenSubKey(String name) {
return OpenSubKey(name, false);
}
@@ -818,7 +691,6 @@ namespace Microsoft.Win32 {
* @return a count of subkeys.
*/
public int SubKeyCount {
- [System.Security.SecuritySafeCritical] // auto-generated
get {
CheckPermission(RegistryInternalCheck.CheckKeyReadPermission, null, false, RegistryKeyPermissionCheck.Default);
return InternalSubKeyCount();
@@ -827,90 +699,12 @@ namespace Microsoft.Win32 {
[ComVisible(false)]
public RegistryView View {
- [System.Security.SecuritySafeCritical]
get {
EnsureNotDisposed();
return regView;
}
}
-#if !FEATURE_CORECLR
- [ComVisible(false)]
- public SafeRegistryHandle Handle {
- [System.Security.SecurityCritical]
- [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
- get {
- EnsureNotDisposed();
- int ret = Win32Native.ERROR_INVALID_HANDLE;
- if (IsSystemKey()) {
- IntPtr baseKey = (IntPtr)0;
- switch (keyName) {
- case "HKEY_CLASSES_ROOT":
- baseKey = HKEY_CLASSES_ROOT;
- break;
- case "HKEY_CURRENT_USER":
- baseKey = HKEY_CURRENT_USER;
- break;
- case "HKEY_LOCAL_MACHINE":
- baseKey = HKEY_LOCAL_MACHINE;
- break;
- case "HKEY_USERS":
- baseKey = HKEY_USERS;
- break;
- case "HKEY_PERFORMANCE_DATA":
- baseKey = HKEY_PERFORMANCE_DATA;
- break;
- case "HKEY_CURRENT_CONFIG":
- baseKey = HKEY_CURRENT_CONFIG;
- break;
- case "HKEY_DYN_DATA":
- baseKey = HKEY_DYN_DATA;
- break;
- default:
- Win32Error(ret, null);
- break;
- }
- // open the base key so that RegistryKey.Handle will return a valid handle
- SafeRegistryHandle result;
- ret = Win32Native.RegOpenKeyEx(baseKey,
- null,
- 0,
- GetRegistryKeyAccess(IsWritable()) | (int)regView,
- out result);
-
- if (ret == 0 && !result.IsInvalid) {
- return result;
- }
- else {
- Win32Error(ret, null);
- }
- }
- else {
- return hkey;
- }
- throw new IOException(Win32Native.GetMessage(ret), ret);
- }
- }
-
- [System.Security.SecurityCritical]
- [ComVisible(false)]
- [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
- public static RegistryKey FromHandle(SafeRegistryHandle handle) {
- return FromHandle(handle, RegistryView.Default);
- }
-
- [System.Security.SecurityCritical]
- [ComVisible(false)]
- [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
- public static RegistryKey FromHandle(SafeRegistryHandle handle, RegistryView view) {
- if (handle == null) throw new ArgumentNullException("handle");
- ValidateKeyView(view);
-
- return new RegistryKey(handle, true /* isWritable */, view);
- }
-#endif
-
- [System.Security.SecurityCritical] // auto-generated
internal int InternalSubKeyCount() {
EnsureNotDisposed();
@@ -939,17 +733,11 @@ namespace Microsoft.Win32 {
*
* @return all subkey names.
*/
- #if FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated
- #else
- [System.Security.SecuritySafeCritical]
- #endif
public String[] GetSubKeyNames() {
CheckPermission(RegistryInternalCheck.CheckKeyReadPermission, null, false, RegistryKeyPermissionCheck.Default);
return InternalGetSubKeyNames();
}
- [System.Security.SecurityCritical] // auto-generated
internal unsafe String[] InternalGetSubKeyNames() {
EnsureNotDisposed();
int subkeys = InternalSubKeyCount();
@@ -988,14 +776,12 @@ namespace Microsoft.Win32 {
* @return a count of values.
*/
public int ValueCount {
- [System.Security.SecuritySafeCritical] // auto-generated
get {
CheckPermission(RegistryInternalCheck.CheckKeyReadPermission, null, false, RegistryKeyPermissionCheck.Default);
return InternalValueCount();
}
}
- [System.Security.SecurityCritical] // auto-generated
internal int InternalValueCount() {
EnsureNotDisposed();
int values = 0;
@@ -1022,7 +808,6 @@ namespace Microsoft.Win32 {
*
* @return all value names.
*/
- [System.Security.SecuritySafeCritical] // auto-generated
public unsafe String[] GetValueNames() {
CheckPermission(RegistryInternalCheck.CheckKeyReadPermission, null, false, RegistryKeyPermissionCheck.Default);
EnsureNotDisposed();
@@ -1073,7 +858,6 @@ namespace Microsoft.Win32 {
*
* @return the data associated with the value.
*/
- [System.Security.SecuritySafeCritical] // auto-generated
public Object GetValue(String name) {
CheckPermission(RegistryInternalCheck.CheckValueReadPermission, name, false, RegistryKeyPermissionCheck.Default);
return InternalGetValue(name, null, false, true);
@@ -1094,32 +878,21 @@ namespace Microsoft.Win32 {
*
* @return the data associated with the value.
*/
- #if FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated
- #else
- [System.Security.SecuritySafeCritical]
- #endif
public Object GetValue(String name, Object defaultValue) {
CheckPermission(RegistryInternalCheck.CheckValueReadPermission, name, false, RegistryKeyPermissionCheck.Default);
return InternalGetValue(name, defaultValue, false, true);
}
- #if FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated
- #else
- [System.Security.SecuritySafeCritical]
- #endif
[ComVisible(false)]
public Object GetValue(String name, Object defaultValue, RegistryValueOptions options) {
if( options < RegistryValueOptions.None || options > RegistryValueOptions.DoNotExpandEnvironmentNames) {
- throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)options), "options");
+ throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)options), nameof(options));
}
bool doNotExpand = (options == RegistryValueOptions.DoNotExpandEnvironmentNames);
CheckPermission(RegistryInternalCheck.CheckValueReadPermission, name, false, RegistryKeyPermissionCheck.Default);
return InternalGetValue(name, defaultValue, doNotExpand, true);
}
- [System.Security.SecurityCritical] // auto-generated
internal Object InternalGetValue(String name, Object defaultValue, bool doNotExpand, bool checkSecurity) {
if (checkSecurity) {
// Name can be null! It's the most common use of RegQueryValueEx
@@ -1338,7 +1111,6 @@ namespace Microsoft.Win32 {
}
- [System.Security.SecuritySafeCritical] // auto-generated
[ComVisible(false)]
public RegistryValueKind GetValueKind(string name) {
CheckPermission(RegistryInternalCheck.CheckValueReadPermission, name, false, RegistryKeyPermissionCheck.Default);
@@ -1382,7 +1154,6 @@ namespace Microsoft.Win32 {
}
public String Name {
- [System.Security.SecuritySafeCritical] // auto-generated
get {
EnsureNotDisposed();
return keyName;
@@ -1403,7 +1174,6 @@ namespace Microsoft.Win32 {
SetValue(name, value, RegistryValueKind.Unknown);
}
- [System.Security.SecuritySafeCritical] //auto-generated
[ComVisible(false)]
public unsafe void SetValue(String name, Object value, RegistryValueKind valueKind) {
if (value==null)
@@ -1414,7 +1184,7 @@ namespace Microsoft.Win32 {
}
if (!Enum.IsDefined(typeof(RegistryValueKind), valueKind))
- throw new ArgumentException(Environment.GetResourceString("Arg_RegBadKeyKind"), "valueKind");
+ throw new ArgumentException(Environment.GetResourceString("Arg_RegBadKeyKind"), nameof(valueKind));
EnsureWriteable();
@@ -1575,33 +1345,11 @@ namespace Microsoft.Win32 {
*
* @return a string representing the key.
*/
- [System.Security.SecuritySafeCritical] // auto-generated
public override String ToString() {
EnsureNotDisposed();
return keyName;
}
-#if FEATURE_MACL
- public RegistrySecurity GetAccessControl() {
- return GetAccessControl(AccessControlSections.Access | AccessControlSections.Owner | AccessControlSections.Group);
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
- public RegistrySecurity GetAccessControl(AccessControlSections includeSections) {
- EnsureNotDisposed();
- return new RegistrySecurity(hkey, keyName, includeSections);
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
- public void SetAccessControl(RegistrySecurity registrySecurity) {
- EnsureWriteable();
- if (registrySecurity == null)
- throw new ArgumentNullException("registrySecurity");
-
- registrySecurity.Persist(hkey, keyName);
- }
-#endif
-
/**
* After calling GetLastWin32Error(), it clears the last error field,
* so you must save the HResult and pass it to this method. This method
@@ -1609,7 +1357,6 @@ namespace Microsoft.Win32 {
* error, and depending on the error, insert a string into the message
* gotten from the ResourceManager.
*/
- [System.Security.SecuritySafeCritical] // auto-generated
internal void Win32Error(int errorCode, String str) {
switch (errorCode) {
case Win32Native.ERROR_ACCESS_DENIED:
@@ -1645,7 +1392,6 @@ namespace Microsoft.Win32 {
}
}
- [SecuritySafeCritical]
internal static void Win32ErrorStatic(int errorCode, String str) {
switch (errorCode) {
case Win32Native.ERROR_ACCESS_DENIED:
@@ -1778,18 +1524,12 @@ namespace Microsoft.Win32 {
path = keyName + "\\.";
}
- [System.Security.SecurityCritical] // auto-generated
- private void CheckPermission(RegistryInternalCheck check, string item, bool subKeyWritable, RegistryKeyPermissionCheck subKeyCheck) {
+ private void CheckPermission(RegistryInternalCheck check, string item, bool subKeyWritable, RegistryKeyPermissionCheck subKeyCheck)
+ {
bool demand = false;
RegistryPermissionAccess access = RegistryPermissionAccess.NoAccess;
string path = null;
-#if !FEATURE_CORECLR
- if (CodeAccessSecurityEngine.QuickCheckForAllDemands()) {
- return; // full trust fast path
- }
-#endif // !FEATURE_CORECLR
-
switch (check) {
//
// Read/Write/Create SubKey Permission
@@ -2020,14 +1760,12 @@ namespace Microsoft.Win32 {
}
}
- [System.Security.SecurityCritical] // auto-generated
static private void CheckUnmanagedCodePermission() {
#pragma warning disable 618
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
#pragma warning restore 618
}
- [System.Security.SecurityCritical] // auto-generated
private bool ContainsRegistryValue(string name) {
int type = 0;
int datasize = 0;
@@ -2035,14 +1773,12 @@ namespace Microsoft.Win32 {
return retval == 0;
}
- [System.Security.SecurityCritical] // auto-generated
private void EnsureNotDisposed(){
if (hkey == null) {
ThrowHelper.ThrowObjectDisposedException(keyName, ExceptionResource.ObjectDisposed_RegKeyClosed);
}
}
- [System.Security.SecurityCritical] // auto-generated
private void EnsureWriteable() {
EnsureNotDisposed();
if (!IsWritable()) {
@@ -2134,16 +1870,6 @@ namespace Microsoft.Win32 {
}
}
-
-#if FEATURE_MACL
- static private void ValidateKeyRights(int rights) {
- if(0 != (rights & ~((int)RegistryRights.FullControl))) {
- // We need to throw SecurityException here for compatiblity reason,
- // although UnauthorizedAccessException will make more sense.
- ThrowHelper.ThrowSecurityException(ExceptionResource.Security_RegistryPermission);
- }
- }
-#endif
// Win32 constants for error handling
private const int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
private const int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.cs
deleted file mode 100644
index ab06347ee4..0000000000
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-// 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.
-
-/*============================================================
-**
-**
-**
-** A wrapper for file handles
-**
-**
-===========================================================*/
-
-using System;
-using System.Security;
-using System.Security.Permissions;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
-using System.Runtime.Versioning;
-using Microsoft.Win32;
-
-namespace Microsoft.Win32.SafeHandles {
-
- [System.Security.SecurityCritical] // auto-generated_required
- public sealed class SafeFileHandle: SafeHandleZeroOrMinusOneIsInvalid {
-
- private SafeFileHandle() : base(true)
- {
- }
-
- public SafeFileHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) {
- SetHandle(preexistingHandle);
- }
-
- [System.Security.SecurityCritical]
- override protected bool ReleaseHandle()
- {
- return Win32Native.CloseHandle(handle);
- }
- }
-}
-
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileMappingHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileMappingHandle.cs
index 5e1b5100bc..cb915fe7c3 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileMappingHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileMappingHandle.cs
@@ -20,20 +20,16 @@ using System.Runtime.Versioning;
namespace Microsoft.Win32.SafeHandles
{
- [System.Security.SecurityCritical] // auto-generated
internal sealed class SafeFileMappingHandle : SafeHandleZeroOrMinusOneIsInvalid
{
- [System.Security.SecurityCritical] // auto-generated_required
internal SafeFileMappingHandle() : base(true) {}
// 0 is an Invalid Handle
- [System.Security.SecurityCritical] // auto-generated_required
internal SafeFileMappingHandle(IntPtr handle, bool ownsHandle) : base (ownsHandle)
{
SetHandle(handle);
}
- [System.Security.SecurityCritical]
override protected bool ReleaseHandle()
{
return Win32Native.CloseHandle(handle);
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs
index b24535f997..219fb77001 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs
@@ -20,13 +20,10 @@ using System.Runtime.ConstrainedExecution;
using Microsoft.Win32;
namespace Microsoft.Win32.SafeHandles {
- [System.Security.SecurityCritical] // auto-generated
internal sealed class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid
{
- [System.Security.SecurityCritical] // auto-generated_required
internal SafeFindHandle() : base(true) {}
- [System.Security.SecurityCritical]
override protected bool ReleaseHandle()
{
return Win32Native.FindClose(handle);
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs
index d2ea42b14e..23631987a5 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs
@@ -3,24 +3,12 @@
// See the LICENSE file in the project root for more information.
namespace Microsoft.Win32 {
- using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
- using System;
- using System.Runtime.CompilerServices;
- using System.Runtime.ConstrainedExecution;
- using System.Runtime.InteropServices;
- using System.Runtime.Serialization;
- using System.Runtime.Versioning;
- using System.Security;
using System.Security.Permissions;
- using System.Text;
- [System.Security.SecurityCritical] // auto-generated
- [HostProtectionAttribute(MayLeakOnAbort = true)]
sealed internal class SafeLibraryHandle : SafeHandleZeroOrMinusOneIsInvalid {
internal SafeLibraryHandle() : base(true) {}
- [System.Security.SecurityCritical]
override protected bool ReleaseHandle()
{
return UnsafeNativeMethods.FreeLibrary(handle);
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLocalAllocHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLocalAllocHandle.cs
index 3eea2b9937..d6c1577eeb 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLocalAllocHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLocalAllocHandle.cs
@@ -1,13 +1,14 @@
// 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.
-namespace Microsoft.Win32.SafeHandles {
+
+namespace Microsoft.Win32.SafeHandles
+{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
- [System.Security.SecurityCritical] // auto-generated
internal sealed class SafeLocalAllocHandle : SafeBuffer {
private SafeLocalAllocHandle () : base(true) {}
@@ -20,7 +21,6 @@ namespace Microsoft.Win32.SafeHandles {
get { return new SafeLocalAllocHandle(IntPtr.Zero); }
}
- [System.Security.SecurityCritical]
override protected bool ReleaseHandle()
{
return Win32Native.LocalFree(handle) == IntPtr.Zero;
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
index d0e3f048f2..4f96b81e72 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
@@ -17,17 +17,13 @@ namespace Microsoft.Win32.SafeHandles {
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
- [System.Security.SecurityCritical]
public sealed class SafeRegistryHandle : SafeHandleZeroOrMinusOneIsInvalid {
- [System.Security.SecurityCritical]
internal SafeRegistryHandle() : base(true) {}
- [System.Security.SecurityCritical]
public SafeRegistryHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) {
SetHandle(preexistingHandle);
}
- [System.Security.SecurityCritical]
override protected bool ReleaseHandle() {
return (RegCloseKey(handle) == Win32Native.ERROR_SUCCESS);
}
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeViewOfFileHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeViewOfFileHandle.cs
index 01ec4d2ad8..38a9323c0b 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeViewOfFileHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeViewOfFileHandle.cs
@@ -22,19 +22,15 @@ using Microsoft.Win32.SafeHandles;
namespace Microsoft.Win32.SafeHandles
{
- [System.Security.SecurityCritical] // auto-generated
internal sealed class SafeViewOfFileHandle : SafeHandleZeroOrMinusOneIsInvalid
{
- [System.Security.SecurityCritical] // auto-generated_required
internal SafeViewOfFileHandle() : base(true) {}
// 0 is an Invalid Handle
- [System.Security.SecurityCritical] // auto-generated_required
internal SafeViewOfFileHandle(IntPtr handle, bool ownsHandle) : base (ownsHandle) {
SetHandle(handle);
}
- [System.Security.SecurityCritical]
override protected bool ReleaseHandle()
{
if (Win32Native.UnmapViewOfFile(handle))
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs
index fa24c96718..0e57136952 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs
@@ -24,7 +24,6 @@ using System.Threading;
namespace Microsoft.Win32.SafeHandles {
- [System.Security.SecurityCritical] // auto-generated_required
public sealed class SafeWaitHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Called by P/Invoke marshaler
@@ -38,7 +37,6 @@ namespace Microsoft.Win32.SafeHandles {
SetHandle(existingHandle);
}
- [System.Security.SecurityCritical]
override protected bool ReleaseHandle()
{
return Win32Native.CloseHandle(handle);
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs
index 58e0d7ad1d..08ae0955a8 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs
@@ -22,10 +22,6 @@ namespace Microsoft.Win32.SafeHandles
using System.Runtime.ConstrainedExecution;
// Class of safe handle which uses 0 or -1 as an invalid handle.
- [System.Security.SecurityCritical] // auto-generated_required
-#if !FEATURE_CORECLR
- [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)]
-#endif
public abstract class SafeHandleZeroOrMinusOneIsInvalid : SafeHandle
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
@@ -33,25 +29,18 @@ namespace Microsoft.Win32.SafeHandles
{
}
-#if FEATURE_CORECLR
// A default constructor is needed to satisfy CoreCLR inheritence rules. It should not be called at runtime
protected SafeHandleZeroOrMinusOneIsInvalid()
{
throw new NotImplementedException();
}
-#endif // FEATURE_CORECLR
public override bool IsInvalid {
- [System.Security.SecurityCritical]
get { return handle.IsNull() || handle == new IntPtr(-1); }
}
}
// Class of safe handle which uses only -1 as an invalid handle.
- [System.Security.SecurityCritical] // auto-generated_required
-#if !FEATURE_CORECLR
- [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)]
-#endif
public abstract class SafeHandleMinusOneIsInvalid : SafeHandle
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
@@ -59,25 +48,18 @@ namespace Microsoft.Win32.SafeHandles
{
}
-#if FEATURE_CORECLR
// A default constructor is needed to satisfy CoreCLR inheritence rules. It should not be called at runtime
protected SafeHandleMinusOneIsInvalid()
{
throw new NotImplementedException();
}
-#endif // FEATURE_CORECLR
public override bool IsInvalid {
- [System.Security.SecurityCritical]
get { return handle == new IntPtr(-1); }
}
}
// Class of critical handle which uses 0 or -1 as an invalid handle.
- [System.Security.SecurityCritical] // auto-generated_required
-#if !FEATURE_CORECLR
- [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)]
-#endif
public abstract class CriticalHandleZeroOrMinusOneIsInvalid : CriticalHandle
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
@@ -86,16 +68,11 @@ namespace Microsoft.Win32.SafeHandles
}
public override bool IsInvalid {
- [System.Security.SecurityCritical]
get { return handle.IsNull() || handle == new IntPtr(-1); }
}
}
// Class of critical handle which uses only -1 as an invalid handle.
- [System.Security.SecurityCritical] // auto-generated_required
-#if !FEATURE_CORECLR
- [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)]
-#endif
public abstract class CriticalHandleMinusOneIsInvalid : CriticalHandle
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
@@ -104,9 +81,7 @@ namespace Microsoft.Win32.SafeHandles
}
public override bool IsInvalid {
- [System.Security.SecurityCritical]
get { return handle == new IntPtr(-1); }
}
}
-
}
diff --git a/src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs b/src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs
index 9da9811ee8..19d638d61a 100644
--- a/src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs
+++ b/src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs
@@ -16,7 +16,6 @@ namespace Microsoft.Win32 {
using System.Text;
using System.Diagnostics.Tracing;
- [System.Security.SecurityCritical] // auto-generated
[SuppressUnmanagedCodeSecurityAttribute()]
internal static class UnsafeNativeMethods {
@@ -64,7 +63,6 @@ namespace Microsoft.Win32 {
internal static extern bool FreeLibrary(IntPtr hModule);
- [SecurityCritical]
[SuppressUnmanagedCodeSecurityAttribute()]
internal static unsafe class ManifestEtw
{
@@ -96,7 +94,6 @@ namespace Microsoft.Win32 {
//
// Callback
//
- [SecurityCritical]
internal unsafe delegate void EtwEnableCallback(
[In] ref Guid sourceId,
[In] int isEnabled,
@@ -110,7 +107,6 @@ namespace Microsoft.Win32 {
//
// Registration APIs
//
- [SecurityCritical]
[DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventRegister", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern unsafe uint EventRegister(
[In] ref Guid providerId,
@@ -120,7 +116,6 @@ namespace Microsoft.Win32 {
);
//
- [SecurityCritical]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventUnregister", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern uint EventUnregister([In] long registrationHandle);
@@ -129,7 +124,6 @@ namespace Microsoft.Win32 {
// Writing (Publishing/Logging) APIs
//
//
- [SecurityCritical]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventWrite", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern unsafe int EventWrite(
@@ -139,7 +133,6 @@ namespace Microsoft.Win32 {
[In] EventProvider.EventData* userData
);
- [SecurityCritical]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventWriteString", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern unsafe int EventWriteString(
@@ -270,7 +263,6 @@ namespace Microsoft.Win32 {
}
#if FEATURE_COMINTEROP
- [SecurityCritical]
[DllImport("combase.dll", PreserveSig = true)]
internal static extern int RoGetActivationFactory(
[MarshalAs(UnmanagedType.HString)] string activatableClassId,
diff --git a/src/mscorlib/src/Microsoft/Win32/Win32Native.cs b/src/mscorlib/src/Microsoft/Win32/Win32Native.cs
index ebe53f45af..b5b808b424 100644
--- a/src/mscorlib/src/Microsoft/Win32/Win32Native.cs
+++ b/src/mscorlib/src/Microsoft/Win32/Win32Native.cs
@@ -90,9 +90,6 @@
namespace Microsoft.Win32 {
using System;
using System.Security;
-#if FEATURE_IMPERSONATION
- using System.Security.Principal;
-#endif
using System.Text;
using System.Configuration.Assemblies;
using System.Runtime.Remoting;
@@ -113,7 +110,6 @@ namespace Microsoft.Win32 {
// Remove the default demands for all P/Invoke methods with this
// global declaration on the class.
- [System.Security.SecurityCritical]
[SuppressUnmanagedCodeSecurityAttribute()]
internal static class Win32Native {
@@ -327,7 +323,7 @@ namespace Microsoft.Win32 {
// } REG_TZI_FORMAT;
//
if (bytes == null || bytes.Length != 44) {
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidREG_TZI_FORMAT"), "bytes");
+ throw new ArgumentException(Environment.GetResourceString("Argument_InvalidREG_TZI_FORMAT"), nameof(bytes));
}
Bias = BitConverter.ToInt32(bytes, 0);
StandardBias = BitConverter.ToInt32(bytes, 4);
@@ -454,7 +450,6 @@ namespace Microsoft.Win32 {
internal int fileSizeHigh;
internal int fileSizeLow;
- [System.Security.SecurityCritical]
internal void PopulateFrom(WIN32_FIND_DATA findData) {
// Copy the information to data
fileAttributes = findData.dwFileAttributes;
@@ -516,7 +511,6 @@ namespace Microsoft.Win32 {
/// strings created with this version of the constructor will be unsafe to use after the buffer
/// has been freed.
/// </remarks>
- [System.Security.SecurityCritical] // auto-generated
internal UNICODE_INTPTR_STRING (int stringBytes, SafeLocalAllocHandle buffer) {
BCLDebug.Assert(buffer == null || (stringBytes >= 0 && (ulong)stringBytes <= buffer.ByteLength),
"buffer == null || (stringBytes >= 0 && stringBytes <= buffer.ByteLength)");
@@ -802,7 +796,6 @@ namespace Microsoft.Win32 {
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
private static extern IntPtr GetModuleHandle(String moduleName);
- [System.Security.SecurityCritical] // auto-generated
internal static bool DoesWin32MethodExist(String moduleName, String methodName)
{
// GetModuleHandle does not increment the module's ref count, so we don't need to call FreeLibrary.
@@ -910,56 +903,6 @@ namespace Microsoft.Win32 {
[DllImport(KERNEL32, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static extern uint GetLongPathNameW(string lpszShortPath, SafeHandle lpszLongPath, uint cchBuffer);
- // Disallow access to all non-file devices from methods that take
- // a String. This disallows DOS devices like "con:", "com1:",
- // "lpt1:", etc. Use this to avoid security problems, like allowing
- // a web client asking a server for "http://server/com1.aspx" and
- // then causing a worker process to hang.
- [System.Security.SecurityCritical] // auto-generated
- internal static SafeFileHandle SafeCreateFile(String lpFileName,
- int dwDesiredAccess, System.IO.FileShare dwShareMode,
- SECURITY_ATTRIBUTES securityAttrs, System.IO.FileMode dwCreationDisposition,
- int dwFlagsAndAttributes, IntPtr hTemplateFile)
- {
- SafeFileHandle handle = CreateFile( lpFileName, dwDesiredAccess, dwShareMode,
- securityAttrs, dwCreationDisposition,
- dwFlagsAndAttributes, hTemplateFile );
-
- if (!handle.IsInvalid)
- {
- int fileType = Win32Native.GetFileType(handle);
- if (fileType != Win32Native.FILE_TYPE_DISK) {
- handle.Dispose();
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_FileStreamOnNonFiles"));
- }
- }
-
- return handle;
- }
-
- [System.Security.SecurityCritical] // auto-generated
- internal static SafeFileHandle UnsafeCreateFile(String lpFileName,
- int dwDesiredAccess, System.IO.FileShare dwShareMode,
- SECURITY_ATTRIBUTES securityAttrs, System.IO.FileMode dwCreationDisposition,
- int dwFlagsAndAttributes, IntPtr hTemplateFile)
- {
- SafeFileHandle handle = CreateFile( lpFileName, dwDesiredAccess, dwShareMode,
- securityAttrs, dwCreationDisposition,
- dwFlagsAndAttributes, hTemplateFile );
-
- return handle;
- }
-
- // Do not use these directly, use the safe or unsafe versions above.
- // The safe version does not support devices (aka if will only open
- // files on disk), while the unsafe version give you the full semantic
- // of the native version.
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- private static extern SafeFileHandle CreateFile(String lpFileName,
- int dwDesiredAccess, System.IO.FileShare dwShareMode,
- SECURITY_ATTRIBUTES securityAttrs, System.IO.FileMode dwCreationDisposition,
- int dwFlagsAndAttributes, IntPtr hTemplateFile);
-
[DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
internal static extern SafeFileMappingHandle CreateFileMapping(SafeFileHandle hFile, IntPtr lpAttributes, uint fProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, String lpName);
@@ -988,7 +931,6 @@ namespace Microsoft.Win32 {
[DllImport(KERNEL32, SetLastError=true, EntryPoint="SetFilePointer")]
private unsafe static extern int SetFilePointerWin32(SafeFileHandle handle, int lo, int * hi, int origin);
- [System.Security.SecurityCritical] // auto-generated
internal unsafe static long SetFilePointer(SafeFileHandle handle, long offset, System.IO.SeekOrigin origin, out int hr) {
hr = 0;
int lo = (int) offset;
@@ -1070,7 +1012,6 @@ namespace Microsoft.Win32 {
internal const int FIND_FROMSTART = 0x00400000; // look for value in source, starting at the beginning
internal const int FIND_FROMEND = 0x00800000; // look for value in source, starting at the end
-#if !FEATURE_CORECLR
[StructLayout(LayoutKind.Sequential)]
internal struct NlsVersionInfoEx
{
@@ -1080,7 +1021,6 @@ namespace Microsoft.Win32 {
internal int dwEffectiveId;
internal Guid guidCustomVersion;
}
-#endif
[DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=false)]
internal static extern int GetWindowsDirectory([Out]StringBuilder sb, int length);
@@ -1797,18 +1737,11 @@ namespace Microsoft.Win32 {
[In] uint dwFlags);
#endif // FEATURE_LEGACYSURFACE
-#if FEATURE_CORECLR
[DllImport(NTDLL, CharSet=CharSet.Unicode, SetLastError=true)]
internal static extern
int RtlNtStatusToDosError (
[In] int status);
-#else
- // identical to RtlNtStatusToDosError, but we are in ask mode for desktop CLR
- [DllImport(ADVAPI32, CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern
- int LsaNtStatusToWinError (
- [In] int status);
-#endif
+
// Get the current FIPS policy setting on Vista and above
[DllImport("bcrypt.dll")]
internal static extern uint BCryptGetFipsAlgorithmMode(
@@ -1930,28 +1863,6 @@ namespace Microsoft.Win32 {
[In] bool bInheritHandle,
[In] uint dwOptions);
-#if FEATURE_IMPERSONATION
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- bool DuplicateTokenEx (
- [In] SafeAccessTokenHandle ExistingTokenHandle,
- [In] TokenAccessLevels DesiredAccess,
- [In] IntPtr TokenAttributes,
- [In] SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
- [In] System.Security.Principal.TokenType TokenType,
- [In,Out] ref SafeAccessTokenHandle DuplicateTokenHandle );
-
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- bool DuplicateTokenEx (
- [In] SafeAccessTokenHandle hExistingToken,
- [In] uint dwDesiredAccess,
- [In] IntPtr lpTokenAttributes, // LPSECURITY_ATTRIBUTES
- [In] uint ImpersonationLevel,
- [In] uint TokenType,
- [In,Out] ref SafeAccessTokenHandle phNewToken);
-#endif
[DllImport(
ADVAPI32,
EntryPoint="EqualDomainSid",
@@ -2345,15 +2256,6 @@ namespace Microsoft.Win32 {
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern int LsaFreeReturnBuffer(IntPtr handle);
-#if FEATURE_IMPERSONATION
- [DllImport (ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- bool OpenProcessToken (
- [In] IntPtr ProcessToken,
- [In] TokenAccessLevels DesiredAccess,
- [Out] out SafeAccessTokenHandle TokenHandle);
-#endif
-
[DllImport(
ADVAPI32,
EntryPoint="SetNamedSecurityInfoW",
@@ -2386,16 +2288,6 @@ namespace Microsoft.Win32 {
byte[] dacl,
byte[] sacl );
- // Fusion APIs
-#if FEATURE_FUSION
- [DllImport(MSCORWKS, CharSet=CharSet.Unicode)]
- internal static extern int CreateAssemblyNameObject(out IAssemblyName ppEnum, String szAssemblyName, uint dwFlags, IntPtr pvReserved);
-
- [DllImport(MSCORWKS, CharSet=CharSet.Auto)]
- internal static extern int CreateAssemblyEnum(out IAssemblyEnum ppEnum, IApplicationContext pAppCtx, IAssemblyName pName, uint dwFlags, IntPtr pvReserved);
-#endif // FEATURE_FUSION
-
-#if FEATURE_CORECLR
[DllImport(KERNEL32, CharSet=CharSet.Unicode)]
[SuppressUnmanagedCodeSecurityAttribute()]
internal unsafe static extern int WideCharToMultiByte(
@@ -2417,13 +2309,11 @@ namespace Microsoft.Win32 {
int cchMultiByte,
char* lpWideCharStr,
int cchWideChar);
-#endif // FEATURE_CORECLR
[DllImport(KERNEL32, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal extern static bool QueryUnbiasedInterruptTime(out ulong UnbiasedTime);
-#if FEATURE_CORECLR
#if FEATURE_PAL
[DllImport(KERNEL32, EntryPoint = "PAL_Random")]
internal extern static bool Random(bool bStrong,
@@ -2450,6 +2340,5 @@ namespace Microsoft.Win32 {
}
}
#endif
-#endif
}
}