Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@@ -53,11 +53,12 @@ namespace System.Reflection {
[ClassInterface(ClassInterfaceType.None)]
[StructLayout (LayoutKind.Sequential)]
#if MOBILE
public partial class Assembly : ICustomAttributeProvider {
public partial class Assembly : ICustomAttributeProvider, ISerializable
#else
public abstract class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable {
public abstract class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable
#endif
internal class ResolveEventHolder {
{
internal class ResolveEventHolder {
public event ModuleResolveEventHandler ModuleResolve;
}
@@ -88,7 +89,7 @@ namespace System.Reflection {
// Note: changes to fields must be reflected in _MonoReflectionAssembly struct (object-internals.h)
#pragma warning disable 649
private IntPtr _mono_assembly;
internal IntPtr _mono_assembly;
#pragma warning restore 649
private ResolveEventHolder resolve_event_holder;
@@ -115,7 +116,7 @@ namespace System.Reflection {
// We can't store the event directly in this class, since the
// compiler would silently insert the fields before _mono_assembly
//
public event ModuleResolveEventHandler ModuleResolve {
public virtual event ModuleResolveEventHandler ModuleResolve {
[SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
add {
resolve_event_holder.ModuleResolve += value;
@@ -145,7 +146,7 @@ namespace System.Reflection {
private string GetCodeBase (bool escaped)
{
string cb = get_code_base (escaped);
#if !NET_2_1
#if !MOBILE
if (SecurityManager.SecurityEnabled) {
// we cannot divulge local file informations
if (String.Compare ("FILE://", 0, cb, 0, 7, true, CultureInfo.InvariantCulture) == 0) {
@@ -215,7 +216,7 @@ namespace System.Reflection {
return String.Empty;
string loc = get_location ();
#if !NET_2_1
#if !MOBILE
if ((loc != String.Empty) && SecurityManager.SecurityEnabled) {
// we cannot divulge local file informations
new FileIOPermission (FileIOPermissionAccess.PathDiscovery, loc).Demand ();
@@ -425,19 +426,9 @@ namespace System.Reflection {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern static void InternalGetAssemblyName (string assemblyFile, AssemblyName aname);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern void FillName (Assembly ass, AssemblyName aname);
[MonoTODO ("copiedName == true is not supported")]
public virtual AssemblyName GetName (Boolean copiedName)
{
#if !MOBILE
// CodeBase, which is restricted, will be copied into the AssemblyName object so...
if (SecurityManager.SecurityEnabled) {
GetCodeBase (true); // this will ensure the Demand is made
}
#endif
return UnprotectedGetName ();
throw new NotImplementedException ();
}
public virtual AssemblyName GetName ()
@@ -445,14 +436,6 @@ namespace System.Reflection {
return GetName (false);
}
// the security runtime requires access to the assemblyname (e.g. to get the strongname)
internal virtual AssemblyName UnprotectedGetName ()
{
AssemblyName aname = new AssemblyName ();
FillName (this, aname);
return aname;
}
public override string ToString ()
{
// note: ToString work without requiring CodeBase (so no checks are needed)
@@ -523,10 +506,14 @@ namespace System.Reflection {
// Try the assembly directory
string location = Path.GetDirectoryName (Location);
string fullName = Path.Combine (location, Path.Combine (culture.Name, an.Name + ".dll"));
if (!throwOnFileNotFound && !File.Exists (fullName))
return null;
return (RuntimeAssembly)LoadFrom (fullName);
try {
return (RuntimeAssembly)LoadFrom (fullName);
} catch {
if (!throwOnFileNotFound && !File.Exists (fullName))
return null;
throw;
}
}
#if !MOBILE
@@ -549,7 +536,7 @@ namespace System.Reflection {
public static Assembly LoadFrom (String assemblyFile, Evidence securityEvidence)
{
Assembly a = LoadFrom (assemblyFile, false);
#if !NET_2_1
#if !MOBILE
if ((a != null) && (securityEvidence != null)) {
// merge evidence (i.e. replace defaults with provided evidences)
a.Evidence.Merge (securityEvidence);
@@ -821,7 +808,7 @@ namespace System.Reflection {
return other._mono_assembly == _mono_assembly;
}
#if !NET_2_1
#if !MOBILE
// Code Access Security
internal void Resolve ()
@@ -906,13 +893,12 @@ namespace System.Reflection {
public virtual PermissionSet PermissionSet {
get { return this.GrantedPermissionSet; }
}
#endif
public virtual SecurityRuleSet SecurityRuleSet {
get { throw CreateNIE (); }
}
#endif
static Exception CreateNIE ()
{
return new NotImplementedException ("Derived classes must implement it");

View File

@@ -40,6 +40,7 @@ using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.IO;
using Mono;
using Mono.Security;
using Mono.Security.Cryptography;
@@ -84,17 +85,29 @@ namespace System.Reflection {
}
[MethodImpl (MethodImplOptions.InternalCall)]
static extern bool ParseName (AssemblyName aname, string assemblyName);
static extern bool ParseAssemblyName (IntPtr name, out MonoAssemblyName aname, out bool is_version_definited, out bool is_token_defined);
public AssemblyName (string assemblyName)
{
if (assemblyName == null)
throw new ArgumentNullException ("assemblyName");
if (assemblyName.Length < 1)
throw new ArgumentException ("assemblyName cannot have zero length.");
if (!ParseName (this, assemblyName))
throw new FileLoadException ("The assembly name is invalid.");
using (var name = RuntimeMarshal.MarshalString (assemblyName)) {
MonoAssemblyName nativeName;
bool isVersionDefined, isTokenDefined;
//ParseName free the name if it fails.
if (!ParseAssemblyName (name.Value, out nativeName, out isVersionDefined, out isTokenDefined))
throw new FileLoadException ("The assembly name is invalid.");
try {
unsafe {
this.FillName (&nativeName, null, isVersionDefined, false, isTokenDefined);
}
} finally {
RuntimeMarshal.FreeAssemblyName (ref nativeName);
}
}
}
[MonoLimitation ("Not used, as the values are too limited; Mono supports more")]
@@ -447,5 +460,63 @@ namespace System.Reflection {
contentType = value;
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern unsafe MonoAssemblyName* GetNativeName (IntPtr assembly_ptr);
internal unsafe void FillName (MonoAssemblyName *native, string codeBase, bool addVersion, bool addPublickey, bool defaultToken)
{
this.name = RuntimeMarshal.PtrToUtf8String (native->name);
this.major = native->major;
this.minor = native->minor;
this.build = native->build;
this.revision = native->revision;
this.flags = (AssemblyNameFlags)native->flags;
this.hashalg = (AssemblyHashAlgorithm)native->hash_alg;
this.versioncompat = AssemblyVersionCompatibility.SameMachine;
this.processor_architecture = (ProcessorArchitecture)native->arch;
if (addVersion)
this.version = new Version (this.major, this.minor, this.build, this.revision);
this.codebase = codeBase;
if (native->culture != IntPtr.Zero)
this.cultureinfo = CultureInfo.CreateCulture ( RuntimeMarshal.PtrToUtf8String (native->culture), false);
if (native->public_key != IntPtr.Zero) {
this.publicKey = RuntimeMarshal.DecodeBlobArray (native->public_key);
this.flags |= AssemblyNameFlags.PublicKey;
} else if (addPublickey) {
this.publicKey = EmptyArray<byte>.Value;
this.flags |= AssemblyNameFlags.PublicKey;
}
// MonoAssemblyName keeps the public key token as an hexadecimal string
if (native->public_key_token [0] != 0) {
byte[] keyToken = new byte [8];
for (int i = 0, j = 0; i < 8; ++i) {
keyToken [i] = (byte)(RuntimeMarshal.AsciHexDigitValue (native->public_key_token [j++]) << 4);
keyToken [i] |= (byte)RuntimeMarshal.AsciHexDigitValue (native->public_key_token [j++]);
}
this.keyToken = keyToken;
} else if (defaultToken) {
this.keyToken = EmptyArray<byte>.Value;
}
}
internal static AssemblyName Create (Assembly assembly, bool fillCodebase)
{
AssemblyName aname = new AssemblyName ();
unsafe {
MonoAssemblyName *native = GetNativeName (assembly._mono_assembly);
aname.FillName (native, fillCodebase ? assembly.CodeBase : null, true, true, true);
}
return aname;
}
}
}

View File

@@ -28,6 +28,7 @@
//
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace System.Reflection {
@@ -252,7 +253,7 @@ namespace System.Reflection {
}
addHandlerType = addHandlerDelegateType.MakeGenericType (typeVector);
#if NET_2_1
#if MOBILE
// with Silverlight a coreclr failure (e.g. Transparent caller creating a delegate on a Critical method)
// would normally throw an ArgumentException, so we set throwOnBindFailure to false and check for a null
// delegate that we can transform into a MethodAccessException
@@ -277,5 +278,25 @@ namespace System.Reflection {
public virtual MethodInfo RemoveMethod {
get { return GetRemoveMethod (true); }
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern EventInfo internal_from_handle_type (IntPtr event_handle, IntPtr type_handle);
internal static EventInfo GetEventFromHandle (Mono.RuntimeEventHandle handle)
{
if (handle.Value == IntPtr.Zero)
throw new ArgumentException ("The handle is invalid.");
return internal_from_handle_type (handle.Value, IntPtr.Zero);
}
internal static EventInfo GetEventFromHandle (Mono.RuntimeEventHandle handle, RuntimeTypeHandle reflectedType)
{
if (handle.Value == IntPtr.Zero)
throw new ArgumentException ("The handle is invalid.");
EventInfo ei = internal_from_handle_type (handle.Value, reflectedType.Value);
if (ei == null)
throw new ArgumentException ("The event handle and the type handle are incompatible.");
return ei;
}
}
}

View File

@@ -37,9 +37,12 @@ using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Threading;
using System.Diagnostics.Contracts;
using System.Security;
using System.Security.Policy;
using System.Security.Permissions;
using Mono;
namespace System.Reflection {
abstract class RuntimeAssembly : Assembly
@@ -151,6 +154,18 @@ namespace System.Reflection {
return LoadWithPartialNameInternal (an.ToString (), securityEvidence, ref stackMark);
}
// the security runtime requires access to the assemblyname (e.g. to get the strongname)
public override AssemblyName GetName (bool copiedName)
{
#if !MOBILE
// CodeBase, which is restricted, will be copied into the AssemblyName object so...
if (SecurityManager.SecurityEnabled) {
var _ = CodeBase; // this will ensure the Demand is made
}
#endif
return AssemblyName.Create (this, true);
}
}
[ComVisible (true)]

View File

@@ -305,7 +305,7 @@ namespace System.Reflection {
o = InternalInvoke (obj, parameters, out exc);
} catch (ThreadAbortException) {
throw;
#if NET_2_1
#if MOBILE
} catch (MethodAccessException) {
throw;
#endif
@@ -659,7 +659,7 @@ namespace System.Reflection {
try {
o = InternalInvoke (obj, parameters, out exc);
#if NET_2_1
#if MOBILE
} catch (MethodAccessException) {
throw;
#endif

View File

@@ -90,7 +90,7 @@ namespace System.Reflection {
public override
string FullyQualifiedName {
get {
#if !NET_2_1
#if !MOBILE
if (SecurityManager.SecurityEnabled) {
new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fqname).Demand ();
}
@@ -283,7 +283,7 @@ namespace System.Reflection {
UnitySerializationHolder.GetUnitySerializationInfo (info, UnitySerializationHolder.ModuleUnity, this.ScopeName, this.GetRuntimeAssembly ());
}
#if !NET_2_1
#if !MOBILE
public
override

View File

@@ -359,7 +359,7 @@ namespace System.Reflection {
}
getterType = getterDelegateType.MakeGenericType (typeVector);
#if NET_2_1
#if MOBILE
// with Silverlight a coreclr failure (e.g. Transparent caller creating a delegate on a Critical method)
// would normally throw an ArgumentException, so we set throwOnBindFailure to false and check for a null
// delegate that we can transform into a MethodAccessException

View File

@@ -196,5 +196,18 @@ namespace System.Reflection {
throw new NotImplementedException ();
}
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern PropertyInfo internal_from_handle_type (IntPtr event_handle, IntPtr type_handle);
internal static PropertyInfo GetPropertyFromHandle (Mono.RuntimePropertyHandle handle, RuntimeTypeHandle reflectedType)
{
if (handle.Value == IntPtr.Zero)
throw new ArgumentException ("The handle is invalid.");
PropertyInfo pi = internal_from_handle_type (handle.Value, reflectedType.Value);
if (pi == null)
throw new ArgumentException ("The property handle and the type handle are incompatible.");
return pi;
}
}
}

View File

@@ -121,7 +121,7 @@ public class StrongNameKeyPair : ISerializable, IDeserializationCallback
_keyPairArray = null;
}
}
#if !NET_2_1
#if !MOBILE
else if (_keyPairContainer != null) {
CspParameters csp = new CspParameters ();
csp.KeyContainerName = _keyPairContainer;

View File

@@ -1,65 +0,0 @@
//
// System.Reflection.TargetException.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Globalization;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
namespace System.Reflection
{
[ComVisible (true)]
[Serializable]
#if NET_2_1
public class TargetException : Exception {
#else
public class TargetException : ApplicationException {
#endif
public TargetException ()
: base (Locale.GetText ("Unable to invoke an invalid target."))
{
}
public TargetException (string message)
: base (message)
{
}
public TargetException (string message, Exception inner)
: base (message, inner)
{
}
protected TargetException (SerializationInfo info, StreamingContext context)
: base (info, context)
{
}
}
}

View File

@@ -1,59 +0,0 @@
//
// System.Reflection.TargetInvocationException
//
// Sean MacIsaac (macisaac@ximian.com)
// Duncan Mak (duncan@ximian.com)
//
// (C) 2001 Ximian, Inc.
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
namespace System.Reflection
{
[ComVisible (true)]
[Serializable]
#if NET_2_1
public sealed class TargetInvocationException : Exception {
#else
public sealed class TargetInvocationException : ApplicationException {
#endif
public TargetInvocationException (Exception inner)
: base ("Exception has been thrown by the target of an invocation.", inner)
{
}
public TargetInvocationException (string message, Exception inner)
: base (message, inner)
{
}
internal TargetInvocationException (SerializationInfo info, StreamingContext sc)
: base (info, sc)
{
}
}
}

View File

@@ -1,66 +0,0 @@
//
// System.Reflection.TargetParameterCountException.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.Serialization;
using System.Globalization;
using System.Runtime.InteropServices;
namespace System.Reflection
{
[ComVisible (true)]
[Serializable]
#if NET_2_1
public sealed class TargetParameterCountException : Exception {
#else
public sealed class TargetParameterCountException : ApplicationException {
#endif
public TargetParameterCountException ()
: base (Locale.GetText ("Number of parameter does not match expected count."))
{
}
public TargetParameterCountException (string message)
: base (message)
{
}
public TargetParameterCountException (string message, Exception inner)
: base (message, inner)
{
}
internal TargetParameterCountException (SerializationInfo info,
StreamingContext context)
: base (info, context)
{
}
}
}