Imported Upstream version 6.4.0.137

Former-commit-id: 943baa9f16a098c33e129777827f3a9d20da00d6
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-07-26 19:53:28 +00:00
parent e9207cf623
commit ef583813eb
2712 changed files with 74169 additions and 40587 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -151,11 +151,7 @@ namespace System.Reflection {
if (codebase == null)
return null;
#if NETCORE
throw new NotImplementedException ();
#else
return Mono.Security.Uri.EscapeString (codebase, false, true, true);
#endif
}
}
@@ -286,12 +282,7 @@ namespace System.Reflection {
#if MOBILE || NETCORE
return true;
#else
try {
CryptoConvert.FromCapiPublicKeyBlob (
publicKey, 12);
return true;
} catch (CryptographicException) {
}
return CryptoConvert.TryImportCapiPublicKeyBlob (publicKey, 12);
#endif
}
break;
@@ -299,12 +290,7 @@ namespace System.Reflection {
#if MOBILE || NETCORE
return true;
#else
try {
CryptoConvert.FromCapiPublicKeyBlob (publicKey);
return true;
} catch (CryptographicException) {
}
break;
return CryptoConvert.TryImportCapiPublicKeyBlob (publicKey, 0);
#endif
case 0x07: // private key
break;
@@ -487,8 +473,13 @@ namespace System.Reflection {
this.major = native->major;
this.minor = native->minor;
#if NETCORE
this.build = native->build == 65535 ? -1 : native->build;
this.revision = native->revision == 65535 ? -1 : native->revision;
#else
this.build = native->build;
this.revision = native->revision;
#endif
this.flags = (AssemblyNameFlags)native->flags;
@@ -497,13 +488,29 @@ namespace System.Reflection {
this.versioncompat = AssemblyVersionCompatibility.SameMachine;
this.processor_architecture = (ProcessorArchitecture)native->arch;
#if NETCORE
if (addVersion) {
if (this.build == -1)
this.version = new Version (this.major, this.minor);
else if (this.revision == -1)
this.version = new Version (this.major, this.minor, this.build);
else
this.version = new Version (this.major, this.minor, this.build, this.revision);
}
#else
if (addVersion)
this.version = new Version (this.major, this.minor, this.build, this.revision);
#endif
this.codebase = codeBase;
#if NETCORE
if (native->culture != IntPtr.Zero)
this.cultureinfo = CultureInfo.GetCultureInfo (RuntimeMarshal.PtrToUtf8String (native->culture));
#else
if (native->culture != IntPtr.Zero)
this.cultureinfo = CultureInfo.CreateCulture ( RuntimeMarshal.PtrToUtf8String (native->culture), assemblyRef);
#endif
if (native->public_key != IntPtr.Zero) {
this.publicKey = RuntimeMarshal.DecodeBlobArray (native->public_key);
@@ -530,10 +537,16 @@ namespace System.Reflection {
{
AssemblyName aname = new AssemblyName ();
unsafe {
MonoAssemblyName *native = GetNativeName (assembly._mono_assembly);
MonoAssemblyName *native = GetNativeName (assembly.MonoAssembly);
aname.FillName (native, fillCodebase ? assembly.CodeBase : null, true, true, true, false);
}
return aname;
}
#if NETCORE
internal static string EscapeCodeBase (string codebase) {
throw new NotImplementedException ();
}
#endif
}
}

View File

@@ -144,6 +144,9 @@ namespace System.Reflection {
return MonoCustomAttrs.GetCustomAttributesData (target);
}
#if NETCORE
virtual
#endif
public Type AttributeType {
get { return ctorInfo.DeclaringType; }
}
@@ -185,6 +188,9 @@ namespace System.Reflection {
public override bool Equals (object obj)
{
#if NETCORE
return obj == (object)this;
#else
CustomAttributeData other = obj as CustomAttributeData;
if (other == null || other.ctorInfo != ctorInfo ||
other.ctorArgs.Count != ctorArgs.Count ||
@@ -204,10 +210,14 @@ namespace System.Reflection {
return false;
}
return true;
#endif
}
public override int GetHashCode ()
{
#if NETCORE
return base.GetHashCode ();
#else
int ret = ctorInfo == null ? 13 : (ctorInfo.GetHashCode () << 16);
// argument order-dependent
if (ctorArgs != null) {
@@ -221,6 +231,7 @@ namespace System.Reflection {
ret += (namedArgs [i].GetHashCode () << 5);
}
return ret;
#endif
}
}

View File

@@ -35,7 +35,11 @@ namespace System.Reflection {
[Serializable]
public abstract partial class EventInfo : MemberInfo {
// Field needed by runtime, just disable warning.
#pragma warning disable CS0169
AddEventAdapter cached_add_event;
#pragma warning restore CS0169
[DebuggerHidden]
[DebuggerStepThrough]

View File

@@ -37,62 +37,15 @@ using System.Collections.Generic;
namespace System.Reflection {
internal enum ResolveTokenError {
OutOfRange,
BadTable,
Other
};
[Serializable]
[StructLayout (LayoutKind.Sequential)]
partial class Module {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern int get_MetadataToken (Module module);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern int GetMDStreamVersion (IntPtr module_handle);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern Type[] InternalGetTypes ();
internal Guid MvId {
get {
return GetModuleVersionId ();
}
}
internal Exception resolve_token_exception (int metadataToken, ResolveTokenError error, string tokenType) {
if (error == ResolveTokenError.OutOfRange)
return new ArgumentOutOfRangeException ("metadataToken", String.Format ("Token 0x{0:x} is not valid in the scope of module {1}", metadataToken, Name));
else
return new ArgumentException (String.Format ("Token 0x{0:x} is not a valid {1} token in the scope of module {2}", metadataToken, tokenType, Name), "metadataToken");
}
internal IntPtr[] ptrs_from_types (Type[] types) {
if (types == null)
return null;
else {
IntPtr[] res = new IntPtr [types.Length];
for (int i = 0; i < types.Length; ++i) {
if (types [i] == null)
throw new ArgumentException ();
res [i] = types [i].TypeHandle.Value;
}
return res;
}
}
internal static Type MonoDebugger_ResolveType (Module module, int token)
{
ResolveTokenError error;
IntPtr handle = ResolveTypeToken (module.GetImpl (), token, null, null, out error);
if (handle == IntPtr.Zero)
return null;
else
return Type.GetTypeFromHandle (new RuntimeTypeHandle (handle));
}
// Used by mcs, the symbol writer, and mdb through reflection
internal static Guid Mono_GetGuid (Module module)
{
@@ -101,46 +54,12 @@ namespace System.Reflection {
internal virtual Guid GetModuleVersionId ()
{
return new Guid (GetGuidInternal ());
throw new NotImplementedException ();
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern IntPtr GetHINSTANCE ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern string GetGuidInternal ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern Type GetGlobalType ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern IntPtr ResolveTypeToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern IntPtr ResolveMethodToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern IntPtr ResolveFieldToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern string ResolveStringToken (IntPtr module, int token, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern MemberInfo ResolveMemberToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern byte[] ResolveSignature (IntPtr module, int metadataToken, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern void GetPEKind (IntPtr module, out PortableExecutableKinds peKind, out ImageFileMachine machine);
public virtual X509Certificate GetSignerCertificate ()
{
throw NotImplemented.ByDesign;
}
internal virtual IntPtr GetImpl () {
throw NotImplemented.ByDesign;
}
}
}

View File

@@ -27,6 +27,7 @@
//
using System;
using System.IO;
using System.Collections;
using System.Globalization;
using System.Runtime.InteropServices;
@@ -50,8 +51,65 @@ namespace System.Reflection {
[ComDefaultInterfaceAttribute (typeof (_Assembly))]
[Serializable]
[ClassInterface(ClassInterfaceType.None)]
[StructLayout (LayoutKind.Sequential)]
class RuntimeAssembly : Assembly
{
#region Sync with AssemblyBuilder.cs and ReflectionAssembly in object-internals.h
#pragma warning disable 649
internal IntPtr _mono_assembly;
#pragma warning restore 649
#if !MOBILE
internal Evidence _evidence;
#else
object _evidence;
#endif
#endregion
internal ResolveEventHolder resolve_event_holder;
#if !MOBILE
internal PermissionSet _minimum; // for SecurityAction.RequestMinimum
internal PermissionSet _optional; // for SecurityAction.RequestOptional
internal PermissionSet _refuse; // for SecurityAction.RequestRefuse
internal PermissionSet _granted; // for the resolved assembly granted permissions
internal PermissionSet _denied; // for the resolved assembly denied permissions
#else
object _minimum, _optional, _refuse, _granted, _denied;
#endif
internal bool fromByteArray;
internal string assemblyName;
internal class UnmanagedMemoryStreamForModule : UnmanagedMemoryStream
{
#pragma warning disable 414
Module module;
#pragma warning restore
public unsafe UnmanagedMemoryStreamForModule (byte* pointer, long length, Module module)
: base (pointer, length)
{
this.module = module;
}
protected override void Dispose (bool disposing)
{
if (_isOpen) {
/*
* The returned pointer points inside metadata, so
* we have to increase the refcount of the module, and decrease
* it when the stream is finalized.
*/
module = null;
}
base.Dispose (disposing);
}
}
protected RuntimeAssembly ()
{
resolve_event_holder = new ResolveEventHolder ();
}
public override void GetObjectData (SerializationInfo info, StreamingContext context)
{
if (info == null)
@@ -162,7 +220,6 @@ namespace System.Reflection {
// 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) {
@@ -269,7 +326,406 @@ namespace System.Reflection {
return get_global_assembly_cache ();
}
}
public override Type[] GetExportedTypes ()
{
return GetTypes (true);
}
internal static byte[] GetAotId () {
var guid = new byte [16];
var res = GetAotIdInternal (guid);
if (res)
return guid;
else
return null;
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
extern static string get_code_base (Assembly a, bool escaped);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern string get_location ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern static string get_fullname (Assembly a);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern static bool GetAotIdInternal (byte[] aotid);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern static string InternalImageRuntimeVersion (Assembly a);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern bool get_global_assembly_cache ();
public override extern MethodInfo EntryPoint {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
get;
}
[ComVisible (false)]
public override extern bool ReflectionOnly {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
get;
}
// SECURITY: this should be the only caller to icall get_code_base
internal static string GetCodeBase (Assembly a, bool escaped)
{
string cb = get_code_base (a, escaped);
#if !MOBILE
if (SecurityManager.SecurityEnabled) {
// we cannot divulge local file informations
if (String.Compare ("FILE://", 0, cb, 0, 7, true, CultureInfo.InvariantCulture) == 0) {
string file = cb.Substring (7);
new FileIOPermission (FileIOPermissionAccess.PathDiscovery, file).Demand ();
}
}
#endif
return cb;
}
public override string CodeBase {
get { return GetCodeBase (this, false); }
}
public override string EscapedCodeBase {
get { return GetCodeBase (this, true); }
}
public override string FullName {
get {
return get_fullname (this);
}
}
[ComVisible (false)]
public override string ImageRuntimeVersion {
get {
return InternalImageRuntimeVersion (this);
}
}
internal override IntPtr MonoAssembly {
get {
return _mono_assembly;
}
}
internal override bool FromByteArray {
set { fromByteArray = value; }
}
public override String Location {
get {
if (fromByteArray)
return String.Empty;
string loc = get_location ();
#if !MOBILE
if ((loc != String.Empty) && SecurityManager.SecurityEnabled) {
// we cannot divulge local file informations
new FileIOPermission (FileIOPermissionAccess.PathDiscovery, loc).Demand ();
}
#endif
return loc;
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern bool GetManifestResourceInfoInternal (String name, ManifestResourceInfo info);
public override ManifestResourceInfo GetManifestResourceInfo (String resourceName)
{
if (resourceName == null)
throw new ArgumentNullException ("resourceName");
if (resourceName.Length == 0)
throw new ArgumentException ("String cannot have zero length.");
ManifestResourceInfo result = new ManifestResourceInfo (null, null, 0);
bool found = GetManifestResourceInfoInternal (resourceName, result);
if (found)
return result;
else
return null;
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public override extern String[] GetManifestResourceNames ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern IntPtr GetManifestResourceInternal (String name, out int size, out Module module);
public override Stream GetManifestResourceStream (String name)
{
if (name == null)
throw new ArgumentNullException ("name");
if (name.Length == 0)
throw new ArgumentException ("String cannot have zero length.",
"name");
ManifestResourceInfo info = GetManifestResourceInfo (name);
if (info == null) {
Assembly a = AppDomain.CurrentDomain.DoResourceResolve (name, this);
if (a != null && a != this)
return a.GetManifestResourceStream (name);
else
return null;
}
if (info.ReferencedAssembly != null)
return info.ReferencedAssembly.GetManifestResourceStream (name);
if ((info.FileName != null) && (info.ResourceLocation == 0)) {
if (fromByteArray)
throw new FileNotFoundException (info.FileName);
string location = Path.GetDirectoryName (Location);
string filename = Path.Combine (location, info.FileName);
return new FileStream (filename, FileMode.Open, FileAccess.Read);
}
int size;
Module module;
IntPtr data = GetManifestResourceInternal (name, out size, out module);
if (data == (IntPtr) 0)
return null;
else {
UnmanagedMemoryStream stream;
unsafe {
stream = new UnmanagedMemoryStreamForModule ((byte*) data, size, module);
}
return stream;
}
}
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public override Stream GetManifestResourceStream (Type type, String name)
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return GetManifestResourceStream(type, name, false, ref stackMark);
}
public override bool IsDefined (Type attributeType, bool inherit)
{
return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
}
public override object [] GetCustomAttributes (bool inherit)
{
return MonoCustomAttrs.GetCustomAttributes (this, inherit);
}
public override object [] GetCustomAttributes (Type attributeType, bool inherit)
{
return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
}
public override IList<CustomAttributeData> GetCustomAttributesData ()
{
return CustomAttributeData.GetCustomAttributes (this);
}
//
// We can't store the event directly in this class, since the
// compiler would silently insert the fields before _mono_assembly
//
public override event ModuleResolveEventHandler ModuleResolve {
[SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
add {
resolve_event_holder.ModuleResolve += value;
}
[SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
remove {
resolve_event_holder.ModuleResolve -= value;
}
}
internal override Module GetManifestModule () {
return GetManifestModuleInternal ();
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern Module GetManifestModuleInternal ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal override extern Module[] GetModulesInternal ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern object GetFilesInternal (String name, bool getResourceModules);
public override FileStream [] GetFiles (bool getResourceModules)
{
string[] names = (string[]) GetFilesInternal (null, getResourceModules);
if (names == null)
return EmptyArray<FileStream>.Value;
string location = Location;
FileStream[] res;
if (location != String.Empty) {
res = new FileStream [names.Length + 1];
res [0] = new FileStream (location, FileMode.Open, FileAccess.Read);
for (int i = 0; i < names.Length; ++i)
res [i + 1] = new FileStream (names [i], FileMode.Open, FileAccess.Read);
} else {
res = new FileStream [names.Length];
for (int i = 0; i < names.Length; ++i)
res [i] = new FileStream (names [i], FileMode.Open, FileAccess.Read);
}
return res;
}
public override FileStream GetFile (String name)
{
if (name == null)
throw new ArgumentNullException (null, "Name cannot be null.");
if (name.Length == 0)
throw new ArgumentException ("Empty name is not valid");
string filename = (string)GetFilesInternal (name, true);
if (filename != null)
return new FileStream (filename, FileMode.Open, FileAccess.Read);
else
return null;
}
public override int GetHashCode ()
{
return base.GetHashCode ();
}
public override bool Equals (object o)
{
if (((object) this) == o)
return true;
if (o == null)
return false;
if (!(o is RuntimeAssembly))
return false;
var other = (RuntimeAssembly) o;
return other._mono_assembly == _mono_assembly;
}
public override string ToString ()
{
// note: ToString work without requiring CodeBase (so no checks are needed)
if (assemblyName != null)
return assemblyName;
assemblyName = FullName;
return assemblyName;
}
public override Evidence Evidence {
[SecurityPermission (SecurityAction.Demand, ControlEvidence = true)]
get { return UnprotectedGetEvidence (); }
}
// note: the security runtime requires evidences but may be unable to do so...
internal override Evidence UnprotectedGetEvidence ()
{
#if MOBILE || DISABLE_SECURITY
return null;
#else
// if the host (runtime) hasn't provided it's own evidence...
if (_evidence == null) {
// ... we will provide our own
lock (this) {
_evidence = Evidence.GetDefaultHostEvidence (this);
}
}
return _evidence;
#endif
}
#if !MOBILE
// Code Access Security
internal void Resolve ()
{
lock (this) {
// FIXME: As we (currently) delay the resolution until the first CAS
// Demand it's too late to evaluate the Minimum permission set as a
// condition to load the assembly into the AppDomain
LoadAssemblyPermissions ();
Evidence e = new Evidence (UnprotectedGetEvidence ()); // we need a copy to add PRE
e.AddHost (new PermissionRequestEvidence (_minimum, _optional, _refuse));
_granted = SecurityManager.ResolvePolicy (e,
_minimum, _optional, _refuse, out _denied);
}
}
internal override PermissionSet GrantedPermissionSet {
get {
if (_granted == null) {
if (SecurityManager.ResolvingPolicyLevel != null) {
if (SecurityManager.ResolvingPolicyLevel.IsFullTrustAssembly (this))
return DefaultPolicies.FullTrust;
else
return null; // we can't resolve during resolution
}
Resolve ();
}
return _granted;
}
}
internal override PermissionSet DeniedPermissionSet {
get {
// yes we look for granted, as denied may be null
if (_granted == null) {
if (SecurityManager.ResolvingPolicyLevel != null) {
if (SecurityManager.ResolvingPolicyLevel.IsFullTrustAssembly (this))
return null;
else
return DefaultPolicies.FullTrust; // deny unrestricted
}
Resolve ();
}
return _denied;
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
extern internal static bool LoadPermissions (Assembly a,
ref IntPtr minimum, ref int minLength,
ref IntPtr optional, ref int optLength,
ref IntPtr refused, ref int refLength);
// Support for SecurityAction.RequestMinimum, RequestOptional and RequestRefuse
private void LoadAssemblyPermissions ()
{
IntPtr minimum = IntPtr.Zero, optional = IntPtr.Zero, refused = IntPtr.Zero;
int minLength = 0, optLength = 0, refLength = 0;
if (LoadPermissions (this, ref minimum, ref minLength, ref optional,
ref optLength, ref refused, ref refLength)) {
// Note: no need to cache these permission sets as they will only be created once
// at assembly resolution time.
if (minLength > 0) {
byte[] data = new byte [minLength];
Marshal.Copy (minimum, data, 0, minLength);
_minimum = SecurityManager.Decode (data);
}
if (optLength > 0) {
byte[] data = new byte [optLength];
Marshal.Copy (optional, data, 0, optLength);
_optional = SecurityManager.Decode (data);
}
if (refLength > 0) {
byte[] data = new byte [refLength];
Marshal.Copy (refused, data, 0, refLength);
_refuse = SecurityManager.Decode (data);
}
}
}
public override PermissionSet PermissionSet {
get { return this.GrantedPermissionSet; }
}
#endif
}
}

View File

@@ -231,11 +231,24 @@ namespace System.Reflection {
}
}
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeEventInfo> (other);
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int get_metadata_token (RuntimeEventInfo monoEvent);
#if NETCORE
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern EventInfo internal_from_handle_type (IntPtr event_handle, IntPtr type_handle);
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;
}
#endif
}
}

View File

@@ -228,10 +228,8 @@ namespace System.Reflection {
return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
}
#if !NETCORE
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal override extern int GetFieldOffset ();
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern object GetValueInternal (object obj);
@@ -311,6 +309,24 @@ namespace System.Reflection {
{
return 1;
}
#elif NETCORE
public override bool IsSecurityTransparent {
get {
return false;
}
}
public override bool IsSecurityCritical {
get {
return true;
}
}
public override bool IsSecuritySafeCritical {
get {
return false;
}
}
#else
//seclevel { transparent = 0, safe-critical = 1, critical = 2}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -329,9 +345,7 @@ namespace System.Reflection {
}
#endif
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeFieldInfo> (other);
#endif
public override int MetadataToken {
get {
@@ -350,15 +364,5 @@ namespace System.Reflection {
public override Type[] GetRequiredCustomModifiers () => GetCustomModifiers (false);
private Type[] GetCustomModifiers (bool optional) => GetTypeModifiers (optional) ?? Type.EmptyTypes;
#if NETCORE
internal object[] GetPseudoCustomAttributes () {
throw new NotImplementedException ();
}
internal CustomAttributeData[] GetPseudoCustomAttributesData () {
throw new NotImplementedException ();
}
#endif
}
}

View File

@@ -259,7 +259,11 @@ namespace System.Reflection {
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
#if NETCORE
[PreserveDependency(".ctor(System.Reflection.ExceptionHandlingClause[],System.Reflection.LocalVariableInfo[],System.Byte[],System.Boolean,System.Int32,System.Int32)", "System.Reflection.RuntimeMethodBody")]
#else
[PreserveDependency(".ctor(System.Reflection.ExceptionHandlingClause[],System.Reflection.LocalVariableInfo[],System.Byte[],System.Boolean,System.Int32,System.Int32)", "System.Reflection.MethodBody")]
#endif
internal extern static MethodBody GetMethodBodyInternal (IntPtr handle);
internal static MethodBody GetMethodBody (IntPtr handle)
@@ -394,6 +398,10 @@ namespace System.Reflection {
#if MOBILE
} catch (MethodAccessException) {
throw;
#endif
#if NETCORE
} catch (Mono.NullByRefReturnException) {
throw new NullReferenceException ();
#endif
} catch (OverflowException) {
throw;
@@ -403,7 +411,15 @@ namespace System.Reflection {
}
else
{
#if NETCORE
try {
o = InternalInvoke (obj, parameters, out exc);
} catch (Mono.NullByRefReturnException) {
throw new NullReferenceException ();
}
#else
o = InternalInvoke (obj, parameters, out exc);
#endif
}
if (exc != null)
@@ -510,7 +526,7 @@ namespace System.Reflection {
attrs [count ++] = new PreserveSigAttribute ();
if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) {
#if NETCORE
throw new NotImplementedException ();
attrs [count ++] = GetDllImportAttribute ();
#else
attrs [count ++] = DllImportAttribute.GetCustomAttribute (this);
#endif
@@ -519,6 +535,52 @@ namespace System.Reflection {
return attrs;
}
#if NETCORE
Attribute GetDllImportAttribute ()
{
string entryPoint, dllName = null;
int token = MetadataToken;
PInvokeAttributes flags = 0;
GetPInvoke (out flags, out entryPoint, out dllName);
CharSet charSet = CharSet.None;
switch (flags & PInvokeAttributes.CharSetMask) {
case PInvokeAttributes.CharSetNotSpec: charSet = CharSet.None; break;
case PInvokeAttributes.CharSetAnsi: charSet = CharSet.Ansi; break;
case PInvokeAttributes.CharSetUnicode: charSet = CharSet.Unicode; break;
case PInvokeAttributes.CharSetAuto: charSet = CharSet.Auto; break;
// Invalid: default to CharSet.None
default: break;
}
CallingConvention callingConvention = InteropServicesCallingConvention.Cdecl;
switch (flags & PInvokeAttributes.CallConvMask) {
case PInvokeAttributes.CallConvWinapi: callingConvention = InteropServicesCallingConvention.Winapi; break;
case PInvokeAttributes.CallConvCdecl: callingConvention = InteropServicesCallingConvention.Cdecl; break;
case PInvokeAttributes.CallConvStdcall: callingConvention = InteropServicesCallingConvention.StdCall; break;
case PInvokeAttributes.CallConvThiscall: callingConvention = InteropServicesCallingConvention.ThisCall; break;
case PInvokeAttributes.CallConvFastcall: callingConvention = InteropServicesCallingConvention.FastCall; break;
// Invalid: default to CallingConvention.Cdecl
default: break;
}
bool exactSpelling = (flags & PInvokeAttributes.NoMangle) != 0;
bool setLastError = (flags & PInvokeAttributes.SupportsLastError) != 0;
bool bestFitMapping = (flags & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
bool throwOnUnmappableChar = (flags & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
bool preserveSig = (GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;
return new DllImportAttribute (dllName) { EntryPoint = entryPoint, CharSet = charSet, SetLastError = setLastError,
ExactSpelling = exactSpelling, PreserveSig = preserveSig, BestFitMapping = bestFitMapping,
ThrowOnUnmappableChar = throwOnUnmappableChar, CallingConvention = callingConvention };
}
#endif // NETCORE
internal CustomAttributeData[] GetPseudoCustomAttributesData ()
{
int count = 0;
@@ -649,13 +711,11 @@ namespace System.Reflection {
}
if (hasUserType) {
#if FULL_AOT_RUNTIME
throw new NotSupportedException ("User types are not supported under full aot");
#elif NETCORE
throw new NotImplementedException ();
#else
return new MethodOnTypeBuilderInst (this, methodInstantiation);
#if !FULL_AOT_RUNTIME
if (RuntimeFeature.IsDynamicCodeSupported)
return new MethodOnTypeBuilderInst (this, methodInstantiation);
#endif
throw new NotSupportedException ("User types are not supported under full aot");
}
MethodInfo ret = MakeGenericMethod_impl (methodInstantiation);
@@ -704,11 +764,7 @@ namespace System.Reflection {
}
public override MethodBody GetMethodBody () {
#if NETCORE
throw new NotImplementedException ();
#else
return GetMethodBody (mhandle);
#endif
}
public override IList<CustomAttributeData> GetCustomAttributesData () {
@@ -738,9 +794,7 @@ namespace System.Reflection {
get { return get_core_clr_security_level () == 1; }
}
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeMethodInfo> (other);
#endif
}
[Serializable()]
@@ -966,7 +1020,16 @@ namespace System.Reflection {
public override string ToString () {
#if NETCORE
throw new NotImplementedException ();
StringBuilder sbName = new StringBuilder(Name);
sbName.Append ("Void ");
TypeNameFormatFlags format = TypeNameFormatFlags.FormatBasic;
sbName.Append("(");
RuntimeParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention, false);
sbName.Append(")");
return sbName.ToString();
#else
return "Void " + FormatNameAndSig (false);
#endif
@@ -986,9 +1049,7 @@ namespace System.Reflection {
public extern int get_core_clr_security_level ();
#endif
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeConstructorInfo> (other);
#endif
public override bool IsSecurityTransparent {
get { return get_core_clr_security_level () == 0; }

View File

@@ -31,15 +31,20 @@ using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
#if !NETCORE
using System.Security.Cryptography.X509Certificates;
using System.Security;
using System.Security.Permissions;
#endif
using System.Runtime.Serialization;
namespace System.Reflection {
[ComVisible (true)]
#if !NETCORE
[ComDefaultInterfaceAttribute (typeof (_Module))]
#endif
[Serializable]
[ClassInterface(ClassInterfaceType.None)]
[StructLayout (LayoutKind.Sequential)]
@@ -100,7 +105,7 @@ namespace System.Reflection {
public override
string FullyQualifiedName {
get {
#if !MOBILE
#if !MOBILE && !NETCORE
if (SecurityManager.SecurityEnabled) {
new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fqname).Demand ();
}
@@ -148,7 +153,7 @@ namespace System.Reflection {
if (IsResource ())
return null;
Type globalType = GetGlobalType ();
Type globalType = GetGlobalType (_impl);
return (globalType != null) ? globalType.GetField (name, bindingAttr) : null;
}
@@ -158,14 +163,17 @@ namespace System.Reflection {
if (IsResource ())
return new FieldInfo [0];
Type globalType = GetGlobalType ();
Type globalType = GetGlobalType (_impl);
return (globalType != null) ? globalType.GetFields (bindingFlags) : new FieldInfo [0];
}
public override
int MetadataToken {
get { return get_MetadataToken (this); }
get {
return get_MetadataToken (this);
}
}
protected
override
MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
@@ -173,7 +181,7 @@ namespace System.Reflection {
if (IsResource ())
return null;
Type globalType = GetGlobalType ();
Type globalType = GetGlobalType (_impl);
if (globalType == null)
return null;
if (types == null)
@@ -187,15 +195,17 @@ namespace System.Reflection {
if (IsResource ())
return new MethodInfo [0];
Type globalType = GetGlobalType ();
Type globalType = GetGlobalType (_impl);
return (globalType != null) ? globalType.GetMethods (bindingFlags) : new MethodInfo [0];
}
#if !NETCORE
internal override ModuleHandle GetModuleHandleImpl() => new ModuleHandle (_impl);
#endif
public override
void GetPEKind (out PortableExecutableKinds peKind, out ImageFileMachine machine) {
ModuleHandle.GetPEKind (out peKind, out machine);
RuntimeModule.GetPEKind (_impl, out peKind, out machine);
}
public override
@@ -217,11 +227,15 @@ namespace System.Reflection {
public
override
FieldInfo ResolveField (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
return ResolveField (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
}
internal static FieldInfo ResolveField (Module module, IntPtr monoModule, int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
ResolveTokenError error;
IntPtr handle = ResolveFieldToken (_impl, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
IntPtr handle = ResolveFieldToken (monoModule, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
if (handle == IntPtr.Zero)
throw resolve_token_exception (metadataToken, error, "Field");
throw resolve_token_exception (module.Name, metadataToken, error, "Field");
else
return FieldInfo.GetFieldFromHandle (new RuntimeFieldHandle (handle));
}
@@ -229,12 +243,15 @@ namespace System.Reflection {
public
override
MemberInfo ResolveMember (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
return ResolveMember (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
}
internal static MemberInfo ResolveMember (Module module, IntPtr monoModule, int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
ResolveTokenError error;
MemberInfo m = ResolveMemberToken (_impl, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
MemberInfo m = ResolveMemberToken (monoModule, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
if (m == null)
throw resolve_token_exception (metadataToken, error, "MemberInfo");
throw resolve_token_exception (module.Name, metadataToken, error, "MemberInfo");
else
return m;
}
@@ -242,11 +259,15 @@ namespace System.Reflection {
public
override
MethodBase ResolveMethod (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
return ResolveMethod (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
}
internal static MethodBase ResolveMethod (Module module, IntPtr monoModule, int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
ResolveTokenError error;
IntPtr handle = ResolveMethodToken (_impl, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
IntPtr handle = ResolveMethodToken (monoModule, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
if (handle == IntPtr.Zero)
throw resolve_token_exception (metadataToken, error, "MethodBase");
throw resolve_token_exception (module.Name, metadataToken, error, "MethodBase");
else
return RuntimeMethodInfo.GetMethodFromHandleNoGenericCheck (new RuntimeMethodHandle (handle));
}
@@ -254,11 +275,15 @@ namespace System.Reflection {
public
override
string ResolveString (int metadataToken) {
return ResolveString (this, _impl, metadataToken);
}
internal static string ResolveString (Module module, IntPtr monoModule, int metadataToken) {
ResolveTokenError error;
string s = ResolveStringToken (_impl, metadataToken, out error);
string s = ResolveStringToken (monoModule, metadataToken, out error);
if (s == null)
throw resolve_token_exception (metadataToken, error, "string");
throw resolve_token_exception (module.Name, metadataToken, error, "string");
else
return s;
}
@@ -266,11 +291,15 @@ namespace System.Reflection {
public
override
Type ResolveType (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
return ResolveType (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
}
internal static Type ResolveType (Module module, IntPtr monoModule, int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
ResolveTokenError error;
IntPtr handle = ResolveTypeToken (_impl, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
IntPtr handle = ResolveTypeToken (monoModule, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
if (handle == IntPtr.Zero)
throw resolve_token_exception (metadataToken, error, "Type");
throw resolve_token_exception (module.Name, metadataToken, error, "Type");
else
return Type.GetTypeFromHandle (new RuntimeTypeHandle (handle));
}
@@ -278,15 +307,20 @@ namespace System.Reflection {
public
override
byte[] ResolveSignature (int metadataToken) {
return ResolveSignature (this, _impl, metadataToken);
}
internal static byte[] ResolveSignature (Module module, IntPtr monoModule, int metadataToken) {
ResolveTokenError error;
byte[] res = ResolveSignature (_impl, metadataToken, out error);
byte[] res = ResolveSignature (monoModule, metadataToken, out error);
if (res == null)
throw resolve_token_exception (metadataToken, error, "signature");
throw resolve_token_exception (module.Name, metadataToken, error, "signature");
else
return res;
}
#if !NETCORE
public override void GetObjectData (SerializationInfo info, StreamingContext context)
{
if (info == null)
@@ -294,9 +328,9 @@ namespace System.Reflection {
UnitySerializationHolder.GetUnitySerializationInfo (info, UnitySerializationHolder.ModuleUnity, this.ScopeName, this.GetRuntimeAssembly ());
}
#endif
#if !MOBILE
#if !MOBILE && !NETCORE
public
override
X509Certificate GetSignerCertificate ()
@@ -313,7 +347,7 @@ namespace System.Reflection {
public override
Type[] GetTypes()
{
return InternalGetTypes ();
return InternalGetTypes (_impl);
}
public override IList<CustomAttributeData> GetCustomAttributesData () {
@@ -325,8 +359,88 @@ namespace System.Reflection {
return (RuntimeAssembly)assembly;
}
internal override IntPtr GetImpl () {
return _impl;
internal IntPtr MonoModule {
get {
return _impl;
}
}
#if NETCORE
internal Guid GetModuleVersionId ()
#else
internal override Guid GetModuleVersionId ()
#endif
{
var guid = new byte [16];
GetGuidInternal (_impl, guid);
return new Guid (guid);
}
internal static Exception resolve_token_exception (string name, int metadataToken, ResolveTokenError error, string tokenType) {
if (error == ResolveTokenError.OutOfRange)
return new ArgumentOutOfRangeException ("metadataToken", String.Format ("Token 0x{0:x} is not valid in the scope of module {1}", metadataToken, name));
else
return new ArgumentException (String.Format ("Token 0x{0:x} is not a valid {1} token in the scope of module {2}", metadataToken, tokenType, name), "metadataToken");
}
internal static IntPtr[] ptrs_from_types (Type[] types) {
if (types == null)
return null;
else {
IntPtr[] res = new IntPtr [types.Length];
for (int i = 0; i < types.Length; ++i) {
if (types [i] == null)
throw new ArgumentException ();
res [i] = types [i].TypeHandle.Value;
}
return res;
}
}
// This calls ves_icall_reflection_get_token, so needs a Module argument
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern int get_MetadataToken (Module module);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern int GetMDStreamVersion (IntPtr module);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern Type[] InternalGetTypes (IntPtr module);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern IntPtr GetHINSTANCE (IntPtr module);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private static extern void GetGuidInternal (IntPtr module, byte[] guid);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern Type GetGlobalType (IntPtr module);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern IntPtr ResolveTypeToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern IntPtr ResolveMethodToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern IntPtr ResolveFieldToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern string ResolveStringToken (IntPtr module, int token, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern MemberInfo ResolveMemberToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern byte[] ResolveSignature (IntPtr module, int metadataToken, out ResolveTokenError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern void GetPEKind (IntPtr module, out PortableExecutableKinds peKind, out ImageFileMachine machine);
}
internal enum ResolveTokenError {
OutOfRange,
BadTable,
Other
}
}

View File

@@ -44,15 +44,22 @@ namespace System.Reflection
[Serializable]
[ClassInterfaceAttribute (ClassInterfaceType.None)]
#endif
[StructLayout (LayoutKind.Sequential)]
class RuntimeParameterInfo : ParameterInfo {
internal MarshalAsAttribute marshalAs;
// Called by the runtime
internal RuntimeParameterInfo (string name, Type type, int position, int attrs, object defaultValue, MemberInfo member, MarshalAsAttribute marshalAs) {
NameImpl = name;
ClassImpl = type;
PositionImpl = position;
AttrsImpl = (ParameterAttributes)attrs;
DefaultValueImpl = defaultValue;
MemberImpl = member;
this.marshalAs = marshalAs;
}
internal static void FormatParameters (StringBuilder sb, ParameterInfo[] p, CallingConventions callingConvention, bool serialization)
{
#if NETCORE
throw new NotImplementedException ();
#else
for (int i = 0; i < p.Length; ++i) {
if (i > 0)
sb.Append (", ");
@@ -77,7 +84,6 @@ namespace System.Reflection
sb.Append (", ");
sb.Append ("...");
}
#endif
}
#if MONO_FEATURE_SRE
@@ -244,7 +250,7 @@ namespace System.Reflection
if (marshalAs != null) {
#if NETCORE
throw new NotImplementedException ();
attrs [count ++] = (MarshalAsAttribute)marshalAs.CloneInternal ();
#else
attrs [count ++] = marshalAs.Copy ();
#endif
@@ -304,7 +310,7 @@ namespace System.Reflection
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern Type[] GetTypeModifiers (bool optional);
internal static extern Type[] GetTypeModifiers (Type type, MemberInfo member, int position, bool optional);
internal static ParameterInfo New (ParameterInfo pinfo, Type type, MemberInfo member, int position)
{
@@ -321,6 +327,6 @@ namespace System.Reflection
return new RuntimeParameterInfo (type, member, marshalAs);
}
private Type[] GetCustomModifiers (bool optional) => GetTypeModifiers (optional) ?? Type.EmptyTypes;
private Type[] GetCustomModifiers (bool optional) => GetTypeModifiers (ParameterType, Member, Position, optional) ?? Type.EmptyTypes;
}
}

View File

@@ -90,12 +90,42 @@ namespace System.Reflection {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern object get_default_value (RuntimePropertyInfo prop);
#if NETCORE
internal BindingFlags BindingFlags {
get {
return 0;
CachePropertyInfo (PInfo.GetMethod | PInfo.SetMethod);
bool isPublic = info.set_method?.IsPublic == true || info.get_method?.IsPublic == true;
bool isStatic = info.set_method?.IsStatic == true || info.get_method?.IsStatic == true;
bool isInherited = DeclaringType != ReflectedType;
return FilterPreCalculate (isPublic, isInherited, isStatic);
}
}
// Copied from https://github.com/dotnet/coreclr/blob/7a24a538cd265993e5864179f51781398c28ecdf/src/System.Private.CoreLib/src/System/RtType.cs#L2022
static BindingFlags FilterPreCalculate (bool isPublic, bool isInherited, bool isStatic)
{
BindingFlags bindingFlags = isPublic ? BindingFlags.Public : BindingFlags.NonPublic;
if (isInherited) {
// We arrange things so the DeclaredOnly flag means "include inherited members"
bindingFlags |= BindingFlags.DeclaredOnly;
if (isStatic)
bindingFlags |= BindingFlags.Static | BindingFlags.FlattenHierarchy;
else
bindingFlags |= BindingFlags.Instance;
}
else {
if (isStatic)
bindingFlags |= BindingFlags.Static;
else
bindingFlags |= BindingFlags.Instance;
}
return bindingFlags;
}
#else
internal BindingFlags BindingFlags => 0;
#endif
public override Module Module {
get {
return GetRuntimeModule ();
@@ -126,9 +156,6 @@ namespace System.Reflection {
private string FormatNameAndSig(bool serialization)
{
#if NETCORE
throw new NotImplementedException ();
#else
StringBuilder sbName = new StringBuilder(PropertyType.FormatTypeName(serialization));
sbName.Append(" ");
@@ -142,7 +169,6 @@ namespace System.Reflection {
}
return sbName.ToString();
#endif
}
#endregion
@@ -381,7 +407,7 @@ namespace System.Reflection {
MethodInfo method = GetGetMethod (true);
if (method == null)
throw new ArgumentException ($"Get Method not found for '{Name}'");
if (!DeclaringType.IsValueType && !method.ContainsGenericParameters) { //FIXME find a way to build an invoke delegate for value types.
if (!DeclaringType.IsValueType && !PropertyType.IsByRef && !method.ContainsGenericParameters) { //FIXME find a way to build an invoke delegate for value types.
cached_getter = CreateGetterDelegate (method);
// The try-catch preserves the .Invoke () behaviour
try {
@@ -453,9 +479,7 @@ namespace System.Reflection {
return CustomAttributeData.GetCustomAttributes (this);
}
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimePropertyInfo> (other);
#endif
public override int MetadataToken {
get {