You've already forked linux-packaging-mono
Imported Upstream version 6.4.0.137
Former-commit-id: 943baa9f16a098c33e129777827f3a9d20da00d6
This commit is contained in:
parent
e9207cf623
commit
ef583813eb
25
mcs/class/System.Private.CoreLib/System/AppContext.cs
Normal file
25
mcs/class/System.Private.CoreLib/System/AppContext.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace System
|
||||
{
|
||||
partial class AppContext
|
||||
{
|
||||
// Called by the runtime
|
||||
internal static unsafe void Setup (char** pNames, char** pValues, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
s_dataStore.Add (new string ((sbyte*)pNames[i]), new string ((sbyte*)pValues[i]));
|
||||
}
|
||||
|
||||
static string? GetBaseDirectoryCore ()
|
||||
{
|
||||
// Fallback path for hosts that do not set APP_CONTEXT_BASE_DIRECTORY explicitly
|
||||
var directory = Path.GetDirectoryName (Assembly.GetEntryAssembly()?.Location);
|
||||
if (directory != null && !Path.EndsInDirectorySeparator (directory))
|
||||
directory += Path.DirectorySeparatorChar;
|
||||
|
||||
return directory;
|
||||
}
|
||||
}
|
||||
}
|
104
mcs/class/System.Private.CoreLib/System/ArgIterator.cs
Normal file
104
mcs/class/System.Private.CoreLib/System/ArgIterator.cs
Normal file
@ -0,0 +1,104 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
[StructLayout (LayoutKind.Auto)]
|
||||
public ref struct ArgIterator
|
||||
{
|
||||
#pragma warning disable 169, 414
|
||||
IntPtr sig;
|
||||
IntPtr args;
|
||||
int next_arg;
|
||||
int num_args;
|
||||
#pragma warning restore 169, 414
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
extern void Setup (IntPtr argsp, IntPtr start);
|
||||
|
||||
public ArgIterator (RuntimeArgumentHandle arglist)
|
||||
{
|
||||
sig = IntPtr.Zero;
|
||||
args = IntPtr.Zero;
|
||||
next_arg = num_args = 0;
|
||||
if (arglist.args == IntPtr.Zero)
|
||||
throw new PlatformNotSupportedException ();
|
||||
Setup (arglist.args, IntPtr.Zero);
|
||||
}
|
||||
|
||||
[CLSCompliant (false)]
|
||||
unsafe public ArgIterator (RuntimeArgumentHandle arglist, void *ptr)
|
||||
{
|
||||
sig = IntPtr.Zero;
|
||||
args = IntPtr.Zero;
|
||||
next_arg = num_args = 0;
|
||||
if (arglist.args == IntPtr.Zero)
|
||||
throw new PlatformNotSupportedException ();
|
||||
Setup (arglist.args, (IntPtr) ptr);
|
||||
}
|
||||
|
||||
public void End ()
|
||||
{
|
||||
next_arg = num_args;
|
||||
}
|
||||
|
||||
public override bool Equals (object? o)
|
||||
{
|
||||
throw new NotSupportedException ("ArgIterator does not support Equals.");
|
||||
}
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
return sig.GetHashCode ();
|
||||
}
|
||||
|
||||
[CLSCompliant (false)]
|
||||
public TypedReference GetNextArg ()
|
||||
{
|
||||
if (num_args == next_arg)
|
||||
throw new InvalidOperationException ("Invalid iterator position.");
|
||||
TypedReference result = new TypedReference ();
|
||||
unsafe {
|
||||
IntGetNextArg (&result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
extern unsafe void IntGetNextArg (void *res);
|
||||
|
||||
[CLSCompliant (false)]
|
||||
public TypedReference GetNextArg (RuntimeTypeHandle rth)
|
||||
{
|
||||
if (num_args == next_arg)
|
||||
throw new InvalidOperationException ("Invalid iterator position.");
|
||||
TypedReference result = new TypedReference ();
|
||||
unsafe {
|
||||
IntGetNextArgWithType (&result, rth.Value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
extern unsafe void IntGetNextArgWithType (void *res, IntPtr rth);
|
||||
|
||||
public RuntimeTypeHandle GetNextArgType ()
|
||||
{
|
||||
if (num_args == next_arg)
|
||||
throw new InvalidOperationException ("Invalid iterator position.");
|
||||
return new RuntimeTypeHandle (IntGetNextArgType ());
|
||||
}
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
extern IntPtr IntGetNextArgType ();
|
||||
|
||||
public int GetRemainingCount ()
|
||||
{
|
||||
return num_args - next_arg;
|
||||
}
|
||||
}
|
||||
}
|
598
mcs/class/System.Private.CoreLib/System/Array.cs
Normal file
598
mcs/class/System.Private.CoreLib/System/Array.cs
Normal file
File diff suppressed because it is too large
Load Diff
78
mcs/class/System.Private.CoreLib/System/Attribute.cs
Normal file
78
mcs/class/System.Private.CoreLib/System/Attribute.cs
Normal file
@ -0,0 +1,78 @@
|
||||
#nullable disable
|
||||
using System.Reflection;
|
||||
|
||||
namespace System
|
||||
{
|
||||
partial class Attribute
|
||||
{
|
||||
static Attribute? GetAttr (ICustomAttributeProvider element, Type attributeType, bool inherit)
|
||||
{
|
||||
if (attributeType == null)
|
||||
throw new ArgumentNullException (nameof (attributeType));
|
||||
if (!attributeType.IsSubclassOf (typeof (Attribute)) && attributeType != typeof (Attribute) && attributeType != typeof (MonoCustomAttrs))
|
||||
throw new ArgumentException (SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName);
|
||||
|
||||
var attrs = MonoCustomAttrs.GetCustomAttributes (element, attributeType, inherit);
|
||||
if (attrs == null || attrs.Length == 0)
|
||||
return null;
|
||||
if (attrs.Length != 1)
|
||||
throw new AmbiguousMatchException ();
|
||||
return (Attribute)(attrs [0]);
|
||||
}
|
||||
|
||||
public static Attribute GetCustomAttribute (Assembly element, Type attributeType) => GetAttr (element, attributeType, true);
|
||||
public static Attribute GetCustomAttribute(Assembly element, Type attributeType, bool inherit) => GetAttr (element, attributeType, inherit);
|
||||
public static Attribute GetCustomAttribute(MemberInfo element, Type attributeType) => GetAttr (element, attributeType, true);
|
||||
public static Attribute GetCustomAttribute(MemberInfo element, Type attributeType, bool inherit) => GetAttr (element, attributeType, inherit);
|
||||
public static Attribute GetCustomAttribute(Module element, Type attributeType) => GetAttr (element, attributeType, true);
|
||||
public static Attribute GetCustomAttribute(Module element, Type attributeType, bool inherit) => GetAttr (element, attributeType, inherit);
|
||||
public static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType) => GetAttr (element, attributeType, true);
|
||||
public static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType, bool inherit) => GetAttr (element, attributeType, inherit);
|
||||
|
||||
public static Attribute[] GetCustomAttributes (Assembly element) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, true);
|
||||
public static Attribute[] GetCustomAttributes (Assembly element, bool inherit) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, inherit);
|
||||
public static Attribute[] GetCustomAttributes (Assembly element, Type attributeType) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
|
||||
public static Attribute[] GetCustomAttributes (Assembly element, Type attributeType, bool inherit) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
|
||||
public static Attribute[] GetCustomAttributes (MemberInfo element) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, true);
|
||||
public static Attribute[] GetCustomAttributes (MemberInfo element, bool inherit) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, inherit);
|
||||
public static Attribute[] GetCustomAttributes (MemberInfo element, Type attributeType) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
|
||||
public static Attribute[] GetCustomAttributes (MemberInfo element, Type attributeType, bool inherit) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
|
||||
public static Attribute[] GetCustomAttributes (Module element) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, true);
|
||||
public static Attribute[] GetCustomAttributes (Module element, bool inherit) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, inherit);
|
||||
public static Attribute[] GetCustomAttributes (Module element, Type attributeType) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
|
||||
public static Attribute[] GetCustomAttributes (Module element, Type attributeType, bool inherit) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
|
||||
public static Attribute[] GetCustomAttributes (ParameterInfo element) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, true);
|
||||
public static Attribute[] GetCustomAttributes (ParameterInfo element, bool inherit) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, inherit);
|
||||
public static Attribute[] GetCustomAttributes (ParameterInfo element, Type attributeType) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
|
||||
public static Attribute[] GetCustomAttributes (ParameterInfo element, Type attributeType, bool inherit) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
|
||||
|
||||
internal static Attribute[] GetCustomAttributes (ICustomAttributeProvider element, Type attributeType, bool inherit)
|
||||
{
|
||||
if (attributeType == null)
|
||||
throw new ArgumentNullException (nameof (attributeType));
|
||||
if (!attributeType.IsSubclassOf (typeof (Attribute)) && attributeType != typeof (Attribute))
|
||||
throw new ArgumentException (SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName);
|
||||
|
||||
return (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, attributeType, inherit);
|
||||
}
|
||||
|
||||
public static bool IsDefined (Assembly element, Type attributeType) => IsDefined ((ICustomAttributeProvider)element, attributeType, true);
|
||||
public static bool IsDefined (Assembly element, Type attributeType, bool inherit) => IsDefined ((ICustomAttributeProvider)element, attributeType, inherit);
|
||||
public static bool IsDefined (MemberInfo element, Type attributeType) => IsDefined ((ICustomAttributeProvider)element, attributeType, true);
|
||||
public static bool IsDefined (MemberInfo element, Type attributeType, bool inherit) => IsDefined ((ICustomAttributeProvider)element, attributeType, inherit);
|
||||
public static bool IsDefined (Module element, Type attributeType) => IsDefined ((ICustomAttributeProvider)element, attributeType, true);
|
||||
public static bool IsDefined (Module element, Type attributeType, bool inherit) => IsDefined ((ICustomAttributeProvider)element, attributeType, inherit);
|
||||
public static bool IsDefined (ParameterInfo element, Type attributeType) => IsDefined ((ICustomAttributeProvider)element, attributeType, true);
|
||||
public static bool IsDefined (ParameterInfo element, Type attributeType, bool inherit) => IsDefined ((ICustomAttributeProvider)element, attributeType, inherit);
|
||||
|
||||
internal static bool IsDefined (ICustomAttributeProvider element, Type attributeType, bool inherit)
|
||||
{
|
||||
if (attributeType == null)
|
||||
throw new ArgumentNullException (nameof (attributeType));
|
||||
if (!attributeType.IsSubclassOf (typeof (Attribute)) && attributeType != typeof (Attribute))
|
||||
throw new ArgumentException (SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName);
|
||||
|
||||
return MonoCustomAttrs.IsDefined (element, attributeType, inherit);
|
||||
}
|
||||
}
|
||||
}
|
68
mcs/class/System.Private.CoreLib/System/Buffer.cs
Normal file
68
mcs/class/System.Private.CoreLib/System/Buffer.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System.Runtime;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Internal.Runtime.CompilerServices;
|
||||
|
||||
#if BIT64
|
||||
using nuint = System.UInt64;
|
||||
#else
|
||||
using nuint = System.UInt32;
|
||||
#endif
|
||||
|
||||
namespace System
|
||||
{
|
||||
partial class Buffer
|
||||
{
|
||||
public static void BlockCopy (Array src, int srcOffset, Array dst, int dstOffset, int count)
|
||||
{
|
||||
if (src == null)
|
||||
throw new ArgumentNullException (nameof (src));
|
||||
if (dst == null)
|
||||
throw new ArgumentNullException ("dst");
|
||||
|
||||
if (srcOffset < 0)
|
||||
throw new ArgumentOutOfRangeException (nameof (srcOffset), SR.ArgumentOutOfRange_MustBeNonNegInt32);
|
||||
if (dstOffset < 0)
|
||||
throw new ArgumentOutOfRangeException (nameof (dstOffset), SR.ArgumentOutOfRange_MustBeNonNegInt32);
|
||||
if (count < 0)
|
||||
throw new ArgumentOutOfRangeException (nameof (count), SR.ArgumentOutOfRange_MustBeNonNegInt32);
|
||||
if (!IsPrimitiveTypeArray (src))
|
||||
throw new ArgumentException (SR.Arg_MustBePrimArray, nameof (src));
|
||||
if (!IsPrimitiveTypeArray (dst))
|
||||
throw new ArgumentException (SR.Arg_MustBePrimArray, nameof (dst));
|
||||
|
||||
var uCount = (nuint) count;
|
||||
var uSrcOffset = (nuint) srcOffset;
|
||||
var uDstOffset = (nuint) dstOffset;
|
||||
|
||||
var uSrcLen = (nuint) ByteLength (src);
|
||||
var uDstLen = (nuint) ByteLength (dst);
|
||||
|
||||
if (uSrcLen < uSrcOffset + uCount)
|
||||
throw new ArgumentException (SR.Argument_InvalidOffLen, "");
|
||||
if (uDstLen < uDstOffset + uCount)
|
||||
throw new ArgumentException (SR.Argument_InvalidOffLen, "");
|
||||
|
||||
if (uCount != 0) {
|
||||
unsafe {
|
||||
fixed (byte* pSrc = &src.GetRawArrayData (), pDst = &dst.GetRawArrayData ()) {
|
||||
Memmove (pDst + uDstOffset, pSrc + uSrcOffset, uCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
static extern int _ByteLength (Array array);
|
||||
|
||||
static bool IsPrimitiveTypeArray (Array array)
|
||||
{
|
||||
// TODO: optimize
|
||||
return array.GetType ().GetElementType ()!.IsPrimitive;
|
||||
}
|
||||
|
||||
internal static unsafe void Memcpy (byte* dest, byte* src, int len) => Memmove (dest, src, (nuint) len);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
static extern unsafe void __Memmove (byte* dest, byte* src, nuint len);
|
||||
}
|
||||
}
|
483
mcs/class/System.Private.CoreLib/System/Delegate.cs
Normal file
483
mcs/class/System.Private.CoreLib/System/Delegate.cs
Normal file
@ -0,0 +1,483 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace System
|
||||
{
|
||||
/* Contains the rarely used fields of Delegate */
|
||||
sealed class DelegateData
|
||||
{
|
||||
public Type? target_type;
|
||||
public string? method_name;
|
||||
public bool curried_first_arg;
|
||||
}
|
||||
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
partial class Delegate
|
||||
{
|
||||
#region Sync with object-internals.h
|
||||
IntPtr method_ptr;
|
||||
IntPtr invoke_impl;
|
||||
object? _target;
|
||||
IntPtr method;
|
||||
IntPtr delegate_trampoline;
|
||||
IntPtr extra_arg;
|
||||
IntPtr method_code;
|
||||
IntPtr interp_method;
|
||||
IntPtr interp_invoke_impl;
|
||||
MethodInfo? method_info;
|
||||
|
||||
// Keep a ref of the MethodInfo passed to CreateDelegate.
|
||||
// Used to keep DynamicMethods alive.
|
||||
MethodInfo? original_method_info;
|
||||
|
||||
DelegateData data;
|
||||
|
||||
bool method_is_virtual;
|
||||
#endregion
|
||||
|
||||
protected Delegate (object target, string method)
|
||||
{
|
||||
if (target is null)
|
||||
throw new ArgumentNullException (nameof (target));
|
||||
|
||||
if (method is null)
|
||||
throw new ArgumentNullException (nameof (method));
|
||||
|
||||
this._target = target;
|
||||
this.data = new DelegateData () {
|
||||
method_name = method
|
||||
};
|
||||
}
|
||||
|
||||
protected Delegate (Type target, string method)
|
||||
{
|
||||
if (target is null)
|
||||
throw new ArgumentNullException (nameof (target));
|
||||
|
||||
if (target.ContainsGenericParameters)
|
||||
throw new ArgumentException (SR.Arg_UnboundGenParam, nameof (target));
|
||||
|
||||
if (method is null)
|
||||
throw new ArgumentNullException (nameof (method));
|
||||
|
||||
if (!target.IsRuntimeImplemented ())
|
||||
throw new ArgumentException (SR.Argument_MustBeRuntimeType, nameof (target));
|
||||
|
||||
this.data = new DelegateData () {
|
||||
method_name = method,
|
||||
target_type = target
|
||||
};
|
||||
}
|
||||
|
||||
public object? Target => GetTarget ();
|
||||
|
||||
internal virtual object? GetTarget () => _target;
|
||||
|
||||
public static Delegate CreateDelegate (Type type, object? firstArgument, MethodInfo method, bool throwOnBindFailure)
|
||||
{
|
||||
return CreateDelegate (type, firstArgument, method, throwOnBindFailure, true)!;
|
||||
}
|
||||
|
||||
public static Delegate? CreateDelegate (Type type, MethodInfo method, bool throwOnBindFailure)
|
||||
{
|
||||
return CreateDelegate (type, null, method, throwOnBindFailure, false);
|
||||
}
|
||||
|
||||
static Delegate? CreateDelegate (Type type, object? firstArgument, MethodInfo method, bool throwOnBindFailure, bool allowClosed)
|
||||
{
|
||||
if (type is null)
|
||||
throw new ArgumentNullException (nameof (type));
|
||||
if (method is null)
|
||||
throw new ArgumentNullException (nameof (method));
|
||||
|
||||
if (!(type is RuntimeType rtType))
|
||||
throw new ArgumentException (SR.Argument_MustBeRuntimeType, nameof (type));
|
||||
if (!(method is RuntimeMethodInfo || method is System.Reflection.Emit.DynamicMethod))
|
||||
throw new ArgumentException (SR.Argument_MustBeRuntimeMethodInfo, nameof (method));
|
||||
|
||||
if (!rtType.IsDelegate ())
|
||||
throw new ArgumentException (SR.Arg_MustBeDelegate, nameof (type));
|
||||
|
||||
if (!IsMatchingCandidate (type, firstArgument, method, allowClosed, out DelegateData? delegate_data)) {
|
||||
if (throwOnBindFailure)
|
||||
throw new ArgumentException (SR.Arg_DlgtTargMeth);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Delegate? d = CreateDelegate_internal (type, firstArgument, method, throwOnBindFailure);
|
||||
if (d != null) {
|
||||
d.original_method_info = method;
|
||||
d.data = delegate_data!;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
public static Delegate? CreateDelegate (Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure)
|
||||
{
|
||||
if (type is null)
|
||||
throw new ArgumentNullException (nameof (type));
|
||||
if (target is null)
|
||||
throw new ArgumentNullException (nameof (target));
|
||||
if (method is null)
|
||||
throw new ArgumentNullException (nameof (method));
|
||||
|
||||
if (!(type is RuntimeType rtType))
|
||||
throw new ArgumentException (SR.Argument_MustBeRuntimeType, nameof (type));
|
||||
if (!rtType.IsDelegate ())
|
||||
throw new ArgumentException (SR.Arg_MustBeDelegate, nameof (type));
|
||||
|
||||
MethodInfo? info = GetCandidateMethod (type, target.GetType (), method, BindingFlags.Instance, ignoreCase);
|
||||
if (info is null) {
|
||||
if (throwOnBindFailure)
|
||||
throw new ArgumentException (SR.Arg_DlgtTargMeth);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return CreateDelegate_internal (type, null, info, throwOnBindFailure);
|
||||
}
|
||||
|
||||
public static Delegate? CreateDelegate (Type type, Type target, string method, bool ignoreCase, bool throwOnBindFailure)
|
||||
{
|
||||
if (type is null)
|
||||
throw new ArgumentNullException (nameof (type));
|
||||
if (target is null)
|
||||
throw new ArgumentNullException (nameof (target));
|
||||
if (target.ContainsGenericParameters)
|
||||
throw new ArgumentException (SR.Arg_UnboundGenParam, nameof (target));
|
||||
if (method is null)
|
||||
throw new ArgumentNullException (nameof (method));
|
||||
|
||||
if (!(type is RuntimeType rtType))
|
||||
throw new ArgumentException (SR.Argument_MustBeRuntimeType, nameof (type));
|
||||
|
||||
if (!target.IsRuntimeImplemented ())
|
||||
throw new ArgumentException (SR.Argument_MustBeRuntimeType, nameof (target));
|
||||
if (!rtType.IsDelegate ())
|
||||
throw new ArgumentException (SR.Arg_MustBeDelegate, nameof (type));
|
||||
|
||||
MethodInfo? info = GetCandidateMethod (type, target, method, BindingFlags.Static, ignoreCase);
|
||||
if (info is null) {
|
||||
if (throwOnBindFailure)
|
||||
throw new ArgumentException (SR.Arg_DlgtTargMeth);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return CreateDelegate_internal (type, null, info, throwOnBindFailure);
|
||||
}
|
||||
|
||||
static MethodInfo? GetCandidateMethod (Type type, Type target, string method, BindingFlags bflags, bool ignoreCase)
|
||||
{
|
||||
MethodInfo? invoke = type.GetMethod ("Invoke");
|
||||
if (invoke is null)
|
||||
return null;
|
||||
|
||||
ParameterInfo [] delargs = invoke.GetParametersInternal ();
|
||||
Type[] delargtypes = new Type [delargs.Length];
|
||||
|
||||
for (int i = 0; i < delargs.Length; i++)
|
||||
delargtypes [i] = delargs [i].ParameterType;
|
||||
|
||||
/*
|
||||
* since we need to walk the inheritance chain anyway to
|
||||
* find private methods, adjust the bindingflags to ignore
|
||||
* inherited methods
|
||||
*/
|
||||
BindingFlags flags = BindingFlags.ExactBinding |
|
||||
BindingFlags.Public | BindingFlags.NonPublic |
|
||||
BindingFlags.DeclaredOnly | bflags;
|
||||
|
||||
if (ignoreCase)
|
||||
flags |= BindingFlags.IgnoreCase;
|
||||
|
||||
for (Type? targetType = target; targetType != null; targetType = targetType.BaseType) {
|
||||
MethodInfo? mi = targetType.GetMethod (method, flags, null, delargtypes, Array.Empty<ParameterModifier>());
|
||||
|
||||
if (mi != null && IsReturnTypeMatch (invoke.ReturnType!, mi.ReturnType!)) {
|
||||
return mi;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static bool IsMatchingCandidate (Type type, object? target, MethodInfo method, bool allowClosed, out DelegateData? delegateData)
|
||||
{
|
||||
MethodInfo? invoke = type.GetMethod ("Invoke");
|
||||
|
||||
if (invoke == null || !IsReturnTypeMatch (invoke.ReturnType!, method.ReturnType!)) {
|
||||
delegateData = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
ParameterInfo[] delargs = invoke.GetParametersInternal ();
|
||||
ParameterInfo[] args = method.GetParametersInternal ();
|
||||
|
||||
bool argLengthMatch;
|
||||
|
||||
if (target != null) {
|
||||
// delegate closed over target
|
||||
if (!method.IsStatic)
|
||||
// target is passed as this
|
||||
argLengthMatch = (args.Length == delargs.Length);
|
||||
else
|
||||
// target is passed as the first argument to the static method
|
||||
argLengthMatch = (args.Length == delargs.Length + 1);
|
||||
} else {
|
||||
if (!method.IsStatic) {
|
||||
//
|
||||
// Net 2.0 feature. The first argument of the delegate is passed
|
||||
// as the 'this' argument to the method.
|
||||
//
|
||||
argLengthMatch = (args.Length + 1 == delargs.Length);
|
||||
|
||||
if (!argLengthMatch)
|
||||
// closed over a null reference
|
||||
argLengthMatch = (args.Length == delargs.Length);
|
||||
} else {
|
||||
argLengthMatch = (args.Length == delargs.Length);
|
||||
|
||||
if (!argLengthMatch)
|
||||
// closed over a null reference
|
||||
argLengthMatch = args.Length == delargs.Length + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!argLengthMatch) {
|
||||
delegateData = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool argsMatch;
|
||||
delegateData = new DelegateData ();
|
||||
|
||||
if (target != null) {
|
||||
if (!method.IsStatic) {
|
||||
argsMatch = IsArgumentTypeMatchWithThis (target.GetType (), method.DeclaringType!, true);
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
argsMatch &= IsArgumentTypeMatch (delargs [i].ParameterType, args [i].ParameterType);
|
||||
} else {
|
||||
argsMatch = IsArgumentTypeMatch (target.GetType (), args [0].ParameterType);
|
||||
for (int i = 1; i < args.Length; i++)
|
||||
argsMatch &= IsArgumentTypeMatch (delargs [i - 1].ParameterType, args [i].ParameterType);
|
||||
|
||||
delegateData.curried_first_arg = true;
|
||||
}
|
||||
} else {
|
||||
if (!method.IsStatic) {
|
||||
if (args.Length + 1 == delargs.Length) {
|
||||
// The first argument should match this
|
||||
argsMatch = IsArgumentTypeMatchWithThis (delargs [0].ParameterType, method.DeclaringType!, false);
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
argsMatch &= IsArgumentTypeMatch (delargs [i + 1].ParameterType, args [i].ParameterType);
|
||||
} else {
|
||||
// closed over a null reference
|
||||
argsMatch = allowClosed;
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
argsMatch &= IsArgumentTypeMatch (delargs [i].ParameterType, args [i].ParameterType);
|
||||
}
|
||||
} else {
|
||||
if (delargs.Length + 1 == args.Length) {
|
||||
// closed over a null reference
|
||||
argsMatch = !(args [0].ParameterType.IsValueType || args [0].ParameterType.IsByRef) && allowClosed;
|
||||
for (int i = 0; i < delargs.Length; i++)
|
||||
argsMatch &= IsArgumentTypeMatch (delargs [i].ParameterType, args [i + 1].ParameterType);
|
||||
|
||||
delegateData.curried_first_arg = true;
|
||||
} else {
|
||||
argsMatch = true;
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
argsMatch &= IsArgumentTypeMatch (delargs [i].ParameterType, args [i].ParameterType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return argsMatch;
|
||||
}
|
||||
|
||||
static bool IsReturnTypeMatch (Type delReturnType, Type returnType)
|
||||
{
|
||||
bool returnMatch = returnType == delReturnType;
|
||||
|
||||
if (!returnMatch) {
|
||||
// Delegate covariance
|
||||
if (!returnType.IsValueType && delReturnType.IsAssignableFrom (returnType))
|
||||
returnMatch = true;
|
||||
}
|
||||
|
||||
return returnMatch;
|
||||
}
|
||||
|
||||
static bool IsArgumentTypeMatch (Type delArgType, Type argType)
|
||||
{
|
||||
bool match = delArgType == argType;
|
||||
|
||||
// Delegate contravariance
|
||||
if (!match) {
|
||||
if (!argType.IsValueType && argType.IsAssignableFrom (delArgType))
|
||||
match = true;
|
||||
}
|
||||
// enum basetypes
|
||||
if (!match) {
|
||||
if (delArgType.IsEnum && Enum.GetUnderlyingType (delArgType) == argType)
|
||||
match = true;
|
||||
else if (argType.IsEnum && Enum.GetUnderlyingType (argType) == delArgType)
|
||||
match = true;
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
static bool IsArgumentTypeMatchWithThis (Type delArgType, Type argType, bool boxedThis)
|
||||
{
|
||||
bool match;
|
||||
if (argType.IsValueType)
|
||||
match = delArgType.IsByRef && delArgType.GetElementType () == argType ||
|
||||
(boxedThis && delArgType == argType);
|
||||
else
|
||||
match = delArgType == argType || argType.IsAssignableFrom (delArgType);
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
protected virtual object? DynamicInvokeImpl (object?[]? args)
|
||||
{
|
||||
if (Method is null) {
|
||||
#nullable disable
|
||||
// FIXME: This code cannot handle null argument values
|
||||
Type[] mtypes = new Type [args.Length];
|
||||
for (int i = 0; i < args.Length; ++i) {
|
||||
mtypes [i] = args [i].GetType ();
|
||||
}
|
||||
method_info = _target.GetType ().GetMethod (data.method_name, mtypes);
|
||||
#nullable restore
|
||||
}
|
||||
|
||||
var target = _target;
|
||||
|
||||
if (data is null)
|
||||
data = CreateDelegateData ();
|
||||
|
||||
// replace all Type.Missing with default values defined on parameters of the delegate if any
|
||||
MethodInfo? invoke = GetType ().GetMethod ("Invoke");
|
||||
if (invoke != null && args != null) {
|
||||
ParameterInfo[] delegateParameters = invoke.GetParameters ();
|
||||
for (int i = 0; i < args.Length; i++) {
|
||||
if (args [i] == Type.Missing) {
|
||||
ParameterInfo dlgParam = delegateParameters [i];
|
||||
if (dlgParam.HasDefaultValue) {
|
||||
args [i] = dlgParam.DefaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Method.IsStatic) {
|
||||
//
|
||||
// The delegate is bound to _target
|
||||
//
|
||||
if (data.curried_first_arg) {
|
||||
if (args is null) {
|
||||
args = new object?[] { target };
|
||||
} else {
|
||||
Array.Resize (ref args, args.Length + 1);
|
||||
Array.Copy (args, 0, args, 1, args.Length - 1);
|
||||
args [0] = target;
|
||||
}
|
||||
|
||||
target = null;
|
||||
}
|
||||
} else {
|
||||
if (_target is null && args?.Length > 0) {
|
||||
target = args [0];
|
||||
Array.Copy (args, 1, args, 0, args.Length - 1);
|
||||
Array.Resize (ref args, args.Length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return Method.Invoke (target, args);
|
||||
}
|
||||
|
||||
public override bool Equals (object? obj)
|
||||
{
|
||||
if (!(obj is Delegate d) || !InternalEqualTypes (this, obj))
|
||||
return false;
|
||||
|
||||
// Do not compare method_ptr, since it can point to a trampoline
|
||||
if (d._target == _target && d.Method == Method) {
|
||||
if (d.data != null || data != null) {
|
||||
/* Uncommon case */
|
||||
if (d.data != null && data != null)
|
||||
return (d.data.target_type == data.target_type && d.data.method_name == data.method_name);
|
||||
else {
|
||||
if (d.data != null)
|
||||
return d.data.target_type is null;
|
||||
if (data != null)
|
||||
return data.target_type is null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
MethodInfo? m = Method;
|
||||
|
||||
return (m != null ? m.GetHashCode () : GetType ().GetHashCode ()) ^ RuntimeHelpers.GetHashCode (_target);
|
||||
}
|
||||
|
||||
protected virtual MethodInfo GetMethodImpl ()
|
||||
{
|
||||
if (method_info != null)
|
||||
return method_info;
|
||||
|
||||
if (method != IntPtr.Zero) {
|
||||
if (!method_is_virtual)
|
||||
method_info = (MethodInfo) RuntimeMethodInfo.GetMethodFromHandleNoGenericCheck (new RuntimeMethodHandle (method));
|
||||
else
|
||||
method_info = GetVirtualMethod_internal ();
|
||||
}
|
||||
|
||||
return method_info;
|
||||
}
|
||||
|
||||
DelegateData CreateDelegateData ()
|
||||
{
|
||||
DelegateData delegate_data = new DelegateData ();
|
||||
if (method_info.IsStatic) {
|
||||
if (_target != null) {
|
||||
delegate_data.curried_first_arg = true;
|
||||
} else {
|
||||
MethodInfo? invoke = GetType ().GetMethod ("Invoke");
|
||||
if (invoke != null && invoke.GetParametersCount () + 1 == method_info.GetParametersCount ())
|
||||
delegate_data.curried_first_arg = true;
|
||||
}
|
||||
}
|
||||
|
||||
return delegate_data;
|
||||
}
|
||||
|
||||
static bool InternalEqualTypes (object source, object value)
|
||||
{
|
||||
return source.GetType () == value.GetType ();
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
private protected extern static MulticastDelegate AllocDelegateLike_internal (Delegate d);
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
static extern Delegate? CreateDelegate_internal (Type type, object? target, MethodInfo info, bool throwOnBindFailure);
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
extern MethodInfo GetVirtualMethod_internal ();
|
||||
}
|
||||
}
|
147
mcs/class/System.Private.CoreLib/System/Enum.cs
Normal file
147
mcs/class/System.Private.CoreLib/System/Enum.cs
Normal file
@ -0,0 +1,147 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
partial class Enum
|
||||
{
|
||||
sealed class EnumInfo
|
||||
{
|
||||
public readonly bool HasFlagsAttribute;
|
||||
public readonly ulong[] Values;
|
||||
public readonly string[] Names;
|
||||
|
||||
// Each entry contains a list of sorted pair of enum field names and values, sorted by values
|
||||
public EnumInfo (bool hasFlagsAttribute, ulong[] values, string[] names)
|
||||
{
|
||||
HasFlagsAttribute = hasFlagsAttribute;
|
||||
Values = values;
|
||||
Names = names;
|
||||
}
|
||||
}
|
||||
|
||||
public int CompareTo (object? target)
|
||||
{
|
||||
const int retIncompatibleMethodTables = 2; // indicates that the method tables did not match
|
||||
|
||||
int ret = InternalCompareTo (this, target);
|
||||
|
||||
if (ret < retIncompatibleMethodTables)
|
||||
// -1, 0 and 1 are the normal return codes
|
||||
return ret;
|
||||
|
||||
if (ret == retIncompatibleMethodTables)
|
||||
throw new ArgumentException (SR.Format (SR.Arg_EnumAndObjectMustBeSameType, target!.GetType (), GetType ()));
|
||||
|
||||
throw new InvalidOperationException (SR.InvalidOperation_UnknownEnumType);
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
extern bool InternalHasFlag (Enum flags);
|
||||
|
||||
[Intrinsic]
|
||||
public bool HasFlag (Enum flag)
|
||||
{
|
||||
if (flag is null)
|
||||
throw new ArgumentNullException (nameof (flag));
|
||||
if (!this.GetType ().IsEquivalentTo (flag.GetType ()))
|
||||
throw new ArgumentException (SR.Format (SR.Argument_EnumTypeDoesNotMatch, flag.GetType (), this.GetType ()));
|
||||
|
||||
return InternalHasFlag (flag);
|
||||
}
|
||||
|
||||
public static string? GetName (Type enumType, object value)
|
||||
{
|
||||
if (enumType is null)
|
||||
throw new ArgumentNullException (nameof(enumType));
|
||||
|
||||
return enumType.GetEnumName (value);
|
||||
}
|
||||
|
||||
public static string[] GetNames (Type enumType)
|
||||
{
|
||||
if (enumType is null)
|
||||
throw new ArgumentNullException (nameof (enumType));
|
||||
|
||||
return enumType.GetEnumNames ();
|
||||
}
|
||||
|
||||
public static Type GetUnderlyingType (Type enumType)
|
||||
{
|
||||
if (enumType is null)
|
||||
throw new ArgumentNullException (nameof (enumType));
|
||||
|
||||
return enumType.GetEnumUnderlyingType ();
|
||||
}
|
||||
|
||||
public static Array GetValues (Type enumType)
|
||||
{
|
||||
if (enumType is null)
|
||||
throw new ArgumentNullException (nameof (enumType));
|
||||
|
||||
return enumType.GetEnumValues ();
|
||||
}
|
||||
|
||||
public static bool IsDefined (Type enumType, object value)
|
||||
{
|
||||
if (enumType is null)
|
||||
throw new ArgumentNullException (nameof (enumType));
|
||||
|
||||
return enumType.IsEnumDefined (value);
|
||||
}
|
||||
|
||||
internal static ulong[] InternalGetValues (RuntimeType enumType)
|
||||
{
|
||||
// Get all of the values
|
||||
return GetEnumInfo (enumType, false).Values;
|
||||
}
|
||||
|
||||
internal static string[] InternalGetNames (RuntimeType enumType)
|
||||
{
|
||||
// Get all of the names
|
||||
return GetEnumInfo (enumType, true).Names;
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
static extern bool GetEnumValuesAndNames (RuntimeType enumType, out ulong[] values, out string[] names);
|
||||
|
||||
static EnumInfo GetEnumInfo (RuntimeType enumType, bool getNames = true)
|
||||
{
|
||||
var entry = enumType.GenericCache as EnumInfo;
|
||||
|
||||
if (entry == null || (getNames && entry.Names == null)) {
|
||||
if (!GetEnumValuesAndNames (enumType, out var values, out var names))
|
||||
Array.Sort (values, names, System.Collections.Generic.Comparer<ulong>.Default);
|
||||
|
||||
bool hasFlagsAttribute = enumType.IsDefined (typeof(FlagsAttribute), inherit: false);
|
||||
entry = new EnumInfo (hasFlagsAttribute, values, names);
|
||||
enumType.GenericCache = entry;
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
static extern object InternalBoxEnum (RuntimeType enumType, long value);
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
static extern int InternalCompareTo (object o1, object? o2);
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
extern CorElementType InternalGetCorElementType ();
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
internal static extern RuntimeType InternalGetUnderlyingType (RuntimeType enumType);
|
||||
|
||||
static RuntimeType ValidateRuntimeType (Type enumType)
|
||||
{
|
||||
if (enumType is null)
|
||||
throw new ArgumentNullException (nameof (enumType));
|
||||
if (!enumType.IsEnum)
|
||||
throw new ArgumentException (SR.Arg_MustBeEnum, nameof (enumType));
|
||||
if (!(enumType is RuntimeType rtType))
|
||||
throw new ArgumentException (SR.Arg_MustBeType, nameof (enumType));
|
||||
return rtType;
|
||||
}
|
||||
}
|
||||
}
|
44
mcs/class/System.Private.CoreLib/System/Environment.Unix.cs
Normal file
44
mcs/class/System.Private.CoreLib/System/Environment.Unix.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using Mono;
|
||||
|
||||
namespace System
|
||||
{
|
||||
partial class Environment
|
||||
{
|
||||
static string GetEnvironmentVariableCore (string variable)
|
||||
{
|
||||
using (var h = RuntimeMarshal.MarshalString (variable)) {
|
||||
return internalGetEnvironmentVariable_native (h.Value);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
extern static string internalGetEnvironmentVariable_native (IntPtr variable);
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
private extern static string [] GetEnvironmentVariableNames ();
|
||||
|
||||
public static IDictionary GetEnvironmentVariables ()
|
||||
{
|
||||
Hashtable vars = new Hashtable ();
|
||||
foreach (string name in GetEnvironmentVariableNames ()) {
|
||||
vars [name] = GetEnvironmentVariableCore (name);
|
||||
}
|
||||
return vars;
|
||||
}
|
||||
|
||||
static unsafe void SetEnvironmentVariableCore (string variable, string value)
|
||||
{
|
||||
fixed (char *fixed_variable = variable)
|
||||
fixed (char *fixed_value = value)
|
||||
InternalSetEnvironmentVariable (fixed_variable, variable.Length, fixed_value, value?.Length ?? 0);
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
static extern unsafe void InternalSetEnvironmentVariable (char *variable, int variable_length, char *value, int value_length);
|
||||
}
|
||||
}
|
86
mcs/class/System.Private.CoreLib/System/Environment.cs
Normal file
86
mcs/class/System.Private.CoreLib/System/Environment.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using Mono;
|
||||
|
||||
namespace System
|
||||
{
|
||||
partial class Environment
|
||||
{
|
||||
// This is the version of the corlib-runtime interface (defined in configure.ac)
|
||||
private const string mono_corlib_version = Consts.MonoCorlibVersion;
|
||||
|
||||
public static int CurrentManagedThreadId => Thread.CurrentThread.ManagedThreadId;
|
||||
|
||||
public extern static int ExitCode {
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
get;
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
set;
|
||||
}
|
||||
|
||||
public static extern bool HasShutdownStarted {
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
get;
|
||||
}
|
||||
|
||||
public static extern int ProcessorCount {
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
get;
|
||||
}
|
||||
|
||||
public static string StackTrace {
|
||||
[MethodImpl (MethodImplOptions.NoInlining)] // Prevent inlining from affecting where the stacktrace starts
|
||||
get => new StackTrace (true).ToString (System.Diagnostics.StackTrace.TraceFormat.Normal);
|
||||
}
|
||||
|
||||
public extern static int TickCount {
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
get;
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
public extern static void Exit (int exitCode);
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
public extern static string[] GetCommandLineArgs ();
|
||||
|
||||
public static void FailFast (string message)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public static void FailFast(string message, Exception exception)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public static void FailFast (string message, Exception exception, string errorMessage)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
}
|
||||
|
||||
#region referencesource dependencies - to be removed
|
||||
|
||||
partial class Environment
|
||||
{
|
||||
internal static string GetResourceString (string key)
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
internal static string GetResourceString (string key, CultureInfo culture)
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
internal static string GetResourceString (string key, params object[] values)
|
||||
{
|
||||
return string.Format (CultureInfo.InvariantCulture, key, values);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
121
mcs/class/System.Private.CoreLib/System/Exception.cs
Normal file
121
mcs/class/System.Private.CoreLib/System/Exception.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
partial class Exception
|
||||
{
|
||||
internal readonly struct DispatchState
|
||||
{
|
||||
public readonly MonoStackFrame[] StackFrames;
|
||||
|
||||
public DispatchState (MonoStackFrame[] stackFrames)
|
||||
{
|
||||
StackFrames = stackFrames;
|
||||
}
|
||||
}
|
||||
|
||||
# region Keep in sync with MonoException in object-internals.h
|
||||
string? _unused1;
|
||||
internal string _message;
|
||||
IDictionary _data;
|
||||
Exception _innerException;
|
||||
string _helpURL;
|
||||
object _traceIPs;
|
||||
string? _stackTraceString;
|
||||
string? _unused3;
|
||||
int _unused4;
|
||||
object _dynamicMethods; // Dynamic methods referenced by the stack trace
|
||||
int _HResult;
|
||||
string _source;
|
||||
object? _unused6;
|
||||
internal MonoStackFrame[] foreignExceptionsFrames;
|
||||
IntPtr[] native_trace_ips;
|
||||
int caught_in_unmanaged;
|
||||
#endregion
|
||||
|
||||
public MethodBase? TargetSite {
|
||||
get {
|
||||
StackTrace st = new StackTrace (this, true);
|
||||
if (st.FrameCount > 0)
|
||||
return st.GetFrame (0)?.GetMethod ();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string? StackTrace => GetStackTrace (true);
|
||||
|
||||
string? GetStackTrace (bool needFileInfo)
|
||||
{
|
||||
if (_stackTraceString != null)
|
||||
return _stackTraceString;
|
||||
if (_traceIPs == null)
|
||||
return null;
|
||||
|
||||
return new StackTrace (this, needFileInfo).ToString (System.Diagnostics.StackTrace.TraceFormat.Normal);
|
||||
}
|
||||
|
||||
internal DispatchState CaptureDispatchState ()
|
||||
{
|
||||
MonoStackFrame[] stackFrames;
|
||||
|
||||
if (_traceIPs != null) {
|
||||
stackFrames = System.Diagnostics.StackTrace.get_trace (this, 0, true);
|
||||
stackFrames [stackFrames.Length - 1].isLastFrameFromForeignException = true;
|
||||
|
||||
if (foreignExceptionsFrames != null) {
|
||||
var combinedStackFrames = new MonoStackFrame [stackFrames.Length + foreignExceptionsFrames.Length];
|
||||
Array.Copy (foreignExceptionsFrames, 0, combinedStackFrames, 0, foreignExceptionsFrames.Length);
|
||||
Array.Copy (stackFrames, 0, combinedStackFrames, foreignExceptionsFrames.Length, stackFrames.Length);
|
||||
|
||||
stackFrames = combinedStackFrames;
|
||||
}
|
||||
} else {
|
||||
stackFrames = foreignExceptionsFrames;
|
||||
}
|
||||
|
||||
return new DispatchState (stackFrames);
|
||||
}
|
||||
|
||||
internal void RestoreDispatchState (in DispatchState state)
|
||||
{
|
||||
foreignExceptionsFrames = state.StackFrames;
|
||||
|
||||
_stackTraceString = null;
|
||||
}
|
||||
|
||||
string? CreateSourceName ()
|
||||
{
|
||||
var st = new StackTrace (this, fNeedFileInfo: false);
|
||||
if (st.FrameCount > 0) {
|
||||
StackFrame sf = st.GetFrame (0)!;
|
||||
MethodBase method = sf.GetMethod ();
|
||||
|
||||
Module module = method.Module;
|
||||
RuntimeModule rtModule = module as RuntimeModule;
|
||||
|
||||
if (rtModule == null) {
|
||||
var moduleBuilder = module as System.Reflection.Emit.ModuleBuilder;
|
||||
if (moduleBuilder != null)
|
||||
throw new NotImplementedException (); // TODO: rtModule = moduleBuilder.InternalModule;
|
||||
else
|
||||
throw new ArgumentException (SR.Argument_MustBeRuntimeReflectionObject);
|
||||
}
|
||||
|
||||
return rtModule.GetRuntimeAssembly ().GetName ().Name; // TODO: GetSimpleName ();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static IDictionary CreateDataContainer () => new ListDictionaryInternal ();
|
||||
|
||||
static string? SerializationWatsonBuckets => null;
|
||||
static string? SerializationRemoteStackTraceString => null;
|
||||
string? SerializationStackTraceString => GetStackTrace (true);
|
||||
}
|
||||
}
|
244
mcs/class/System.Private.CoreLib/System/GC.cs
Normal file
244
mcs/class/System.Private.CoreLib/System/GC.cs
Normal file
@ -0,0 +1,244 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
public enum GCCollectionMode
|
||||
{
|
||||
Default = 0,
|
||||
Forced = 1,
|
||||
Optimized = 2
|
||||
}
|
||||
|
||||
public enum GCNotificationStatus
|
||||
{
|
||||
Succeeded = 0,
|
||||
Failed = 1,
|
||||
Canceled = 2,
|
||||
Timeout = 3,
|
||||
NotApplicable = 4
|
||||
}
|
||||
|
||||
public static partial class GC
|
||||
{
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
extern static int GetCollectionCount (int generation);
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
extern static int GetMaxGeneration ();
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
extern static void InternalCollect (int generation);
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
extern static void RecordPressure (long bytesAllocated);
|
||||
|
||||
// TODO: Move following to ConditionalWeakTable
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
internal extern static void register_ephemeron_array (Ephemeron[] array);
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
extern static object get_ephemeron_tombstone ();
|
||||
|
||||
internal static readonly object EPHEMERON_TOMBSTONE = get_ephemeron_tombstone ();
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
public static extern long GetAllocatedBytesForCurrentThread ();
|
||||
|
||||
public static long GetTotalAllocatedBytes (bool precise = false) => 0;
|
||||
|
||||
public static void AddMemoryPressure (long bytesAllocated)
|
||||
{
|
||||
if (bytesAllocated <= 0)
|
||||
throw new ArgumentOutOfRangeException (nameof (bytesAllocated), SR.ArgumentOutOfRange_NeedPosNum);
|
||||
if (IntPtr.Size == 4 && bytesAllocated > Int32.MaxValue)
|
||||
throw new ArgumentOutOfRangeException (nameof (bytesAllocated), SR.ArgumentOutOfRange_MustBeNonNegInt32);
|
||||
RecordPressure (bytesAllocated);
|
||||
}
|
||||
|
||||
public static void RemoveMemoryPressure (long bytesAllocated)
|
||||
{
|
||||
if (bytesAllocated <= 0)
|
||||
throw new ArgumentOutOfRangeException (nameof (bytesAllocated), SR.ArgumentOutOfRange_NeedPosNum);
|
||||
if (IntPtr.Size == 4 && bytesAllocated > Int32.MaxValue)
|
||||
throw new ArgumentOutOfRangeException (nameof (bytesAllocated), SR.ArgumentOutOfRange_MustBeNonNegInt32);
|
||||
RecordPressure (-bytesAllocated);
|
||||
}
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
public static extern int GetGeneration (object obj);
|
||||
|
||||
public static void Collect (int generation)
|
||||
{
|
||||
Collect (generation, GCCollectionMode.Default);
|
||||
}
|
||||
|
||||
public static void Collect ()
|
||||
{
|
||||
InternalCollect (MaxGeneration);
|
||||
}
|
||||
|
||||
public static void Collect (int generation, GCCollectionMode mode) => Collect (generation, mode, true);
|
||||
|
||||
public static void Collect (int generation, GCCollectionMode mode, bool blocking) => Collect (generation, mode, blocking, false);
|
||||
|
||||
public static void Collect (int generation, GCCollectionMode mode, bool blocking, bool compacting)
|
||||
{
|
||||
if (generation < 0)
|
||||
throw new ArgumentOutOfRangeException (nameof (generation), "generation", SR.ArgumentOutOfRange_GenericPositive);
|
||||
if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
|
||||
throw new ArgumentOutOfRangeException (nameof (mode), SR.ArgumentOutOfRange_Enum);
|
||||
|
||||
InternalCollect (generation);
|
||||
}
|
||||
|
||||
public static int CollectionCount (int generation)
|
||||
{
|
||||
if (generation < 0)
|
||||
throw new ArgumentOutOfRangeException (nameof (generation), SR.ArgumentOutOfRange_GenericPositive);
|
||||
return GetCollectionCount (generation);
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.NoInlining)] // disable optimizations
|
||||
public static void KeepAlive (object obj)
|
||||
{
|
||||
}
|
||||
|
||||
public static int GetGeneration (WeakReference wo)
|
||||
{
|
||||
object obj = wo.Target;
|
||||
if (obj == null)
|
||||
throw new ArgumentException ();
|
||||
return GetGeneration (obj);
|
||||
}
|
||||
|
||||
public static int MaxGeneration {
|
||||
get {
|
||||
return GetMaxGeneration ();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
public static extern void WaitForPendingFinalizers ();
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
static extern void _SuppressFinalize (object o);
|
||||
|
||||
public static void SuppressFinalize (object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException (nameof (obj));
|
||||
_SuppressFinalize (obj);
|
||||
}
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
static extern void _ReRegisterForFinalize (object o);
|
||||
|
||||
public static void ReRegisterForFinalize (object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException (nameof (obj));
|
||||
_ReRegisterForFinalize (obj);
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
public extern static long GetTotalMemory (bool forceFullCollection);
|
||||
|
||||
static bool _RegisterForFullGCNotification(int maxGenerationPercentage, int largeObjectHeapPercentage)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
static bool _CancelFullGCNotification ()
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
static GCNotificationStatus _WaitForFullGCApproach (int millisecondsTimeout)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
static GCNotificationStatus _WaitForFullGCComplete (int millisecondsTimeout)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public static void RegisterForFullGCNotification (int maxGenerationThreshold, int largeObjectHeapThreshold)
|
||||
{
|
||||
if ((maxGenerationThreshold <= 0) || (maxGenerationThreshold >= 100))
|
||||
throw new ArgumentOutOfRangeException (nameof (maxGenerationThreshold),
|
||||
String.Format (SR.ArgumentOutOfRange_Bounds_Lower_Upper, 1, 99));
|
||||
if ((largeObjectHeapThreshold <= 0) || (largeObjectHeapThreshold >= 100))
|
||||
throw new ArgumentOutOfRangeException (nameof (largeObjectHeapThreshold),
|
||||
String.Format (SR.ArgumentOutOfRange_Bounds_Lower_Upper, 1, 99));
|
||||
|
||||
if (!_RegisterForFullGCNotification(maxGenerationThreshold, largeObjectHeapThreshold))
|
||||
throw new InvalidOperationException (SR.InvalidOperation_NotWithConcurrentGC);
|
||||
}
|
||||
|
||||
public static void CancelFullGCNotification ()
|
||||
{
|
||||
if (!_CancelFullGCNotification ())
|
||||
throw new InvalidOperationException (SR.InvalidOperation_NotWithConcurrentGC);
|
||||
}
|
||||
|
||||
public static GCNotificationStatus WaitForFullGCApproach ()
|
||||
{
|
||||
return (GCNotificationStatus)_WaitForFullGCApproach (-1);
|
||||
}
|
||||
|
||||
public static GCNotificationStatus WaitForFullGCApproach (int millisecondsTimeout)
|
||||
{
|
||||
if (millisecondsTimeout < -1)
|
||||
throw new ArgumentOutOfRangeException (nameof (millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
|
||||
|
||||
return _WaitForFullGCApproach (millisecondsTimeout);
|
||||
}
|
||||
|
||||
public static GCNotificationStatus WaitForFullGCComplete ()
|
||||
{
|
||||
return _WaitForFullGCComplete(-1);
|
||||
}
|
||||
|
||||
public static GCNotificationStatus WaitForFullGCComplete (int millisecondsTimeout)
|
||||
{
|
||||
if (millisecondsTimeout < -1)
|
||||
throw new ArgumentOutOfRangeException (nameof (millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
|
||||
return _WaitForFullGCComplete (millisecondsTimeout);
|
||||
}
|
||||
|
||||
static bool StartNoGCRegion (long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public static bool TryStartNoGCRegion (long totalSize) => StartNoGCRegion (totalSize, false, 0, false);
|
||||
|
||||
public static bool TryStartNoGCRegion (long totalSize, long lohSize) => StartNoGCRegion (totalSize, true, lohSize, false);
|
||||
|
||||
public static bool TryStartNoGCRegion (long totalSize, bool disallowFullBlockingGC) => StartNoGCRegion (totalSize, false, 0, disallowFullBlockingGC);
|
||||
|
||||
public static bool TryStartNoGCRegion (long totalSize, long lohSize, bool disallowFullBlockingGC) => StartNoGCRegion (totalSize, true, lohSize, disallowFullBlockingGC);
|
||||
|
||||
public static void EndNoGCRegion ()
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
internal static ulong GetSegmentSize ()
|
||||
{
|
||||
// coreclr default
|
||||
return 1024 * 1024 * 16;
|
||||
}
|
||||
|
||||
public static GCMemoryInfo GetGCMemoryInfo ()
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
internal static T[] AllocateUninitializedArray<T> (int length)
|
||||
{
|
||||
return new T [length];
|
||||
}
|
||||
}
|
||||
}
|
95
mcs/class/System.Private.CoreLib/System/Math.cs
Normal file
95
mcs/class/System.Private.CoreLib/System/Math.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
partial class Math
|
||||
{
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Abs (double value);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Abs (float value);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Acos (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Acosh (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Asin (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Asinh (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Atan (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Atan2 (double y, double x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Atanh (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Cbrt (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Ceiling (double a);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Cos (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Cosh (double value);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Exp (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Floor (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Log (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Log10 (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Pow (double x, double y);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Sin (double a);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Sinh (double value);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Sqrt (double d);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Tan (double a);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Tanh (double value);
|
||||
|
||||
// [Intrinsic] TODO: implement FMA intrinsic
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double FusedMultiplyAdd (double x, double y, double z);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern int ILogB (double x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double Log2 (double x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern double ScaleB (double x, int n);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
static extern double FMod(double x, double y);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
static extern unsafe double ModF(double x, double* intptr);
|
||||
}
|
||||
}
|
89
mcs/class/System.Private.CoreLib/System/MathF.cs
Normal file
89
mcs/class/System.Private.CoreLib/System/MathF.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
partial class MathF
|
||||
{
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Acos (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Acosh (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Asin (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Asinh (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Atan (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Atan2 (float y, float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Atanh (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Cbrt (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Ceiling (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Cos (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Cosh (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Exp (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Floor (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Log (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Log10 (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Pow (float x, float y);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Sin (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Sinh (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Sqrt (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Tan (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Tanh (float x);
|
||||
|
||||
// [Intrinsic] TODO: implement intrinsic (FMA)
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float FusedMultiplyAdd (float x, float y, float z);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern int ILogB (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float Log2 (float x);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
public static extern float ScaleB (float x, int n);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
static extern float FMod (float x, float y);
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
static extern unsafe float ModF (float x, float* intptr);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
namespace System
|
||||
{
|
||||
partial class MissingMemberException
|
||||
{
|
||||
internal static string FormatSignature (byte[] signature)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
142
mcs/class/System.Private.CoreLib/System/ModuleHandle.cs
Normal file
142
mcs/class/System.Private.CoreLib/System/ModuleHandle.cs
Normal file
@ -0,0 +1,142 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
public readonly struct ModuleHandle
|
||||
{
|
||||
readonly IntPtr value;
|
||||
|
||||
public static readonly ModuleHandle EmptyHandle = new ModuleHandle (IntPtr.Zero);
|
||||
|
||||
internal ModuleHandle (IntPtr v)
|
||||
{
|
||||
value = v;
|
||||
}
|
||||
|
||||
internal IntPtr Value {
|
||||
get {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public int MDStreamVersion {
|
||||
get {
|
||||
if (value == IntPtr.Zero)
|
||||
throw new ArgumentNullException (String.Empty, "Invalid handle");
|
||||
return RuntimeModule.GetMDStreamVersion (value);
|
||||
}
|
||||
}
|
||||
|
||||
public RuntimeFieldHandle ResolveFieldHandle (int fieldToken)
|
||||
{
|
||||
return ResolveFieldHandle (fieldToken, null, null);
|
||||
}
|
||||
|
||||
public RuntimeMethodHandle ResolveMethodHandle (int methodToken)
|
||||
{
|
||||
return ResolveMethodHandle (methodToken, null, null);
|
||||
}
|
||||
|
||||
public RuntimeTypeHandle ResolveTypeHandle (int typeToken)
|
||||
{
|
||||
return ResolveTypeHandle (typeToken, null, null);
|
||||
}
|
||||
|
||||
static IntPtr[]? ptrs_from_handles (RuntimeTypeHandle[]? handles)
|
||||
{
|
||||
if (handles == null)
|
||||
return null;
|
||||
|
||||
var res = new IntPtr [handles.Length];
|
||||
for (int i = 0; i < handles.Length; ++i)
|
||||
res [i] = handles [i].Value;
|
||||
return res;
|
||||
}
|
||||
|
||||
public RuntimeTypeHandle ResolveTypeHandle (int typeToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
|
||||
{
|
||||
ResolveTokenError error;
|
||||
if (value == IntPtr.Zero)
|
||||
throw new ArgumentNullException (String.Empty, "Invalid handle");
|
||||
IntPtr res = RuntimeModule.ResolveTypeToken (value, typeToken, ptrs_from_handles (typeInstantiationContext), ptrs_from_handles (methodInstantiationContext), out error);
|
||||
if (res == IntPtr.Zero)
|
||||
throw new TypeLoadException (String.Format ("Could not load type '0x{0:x}' from assembly '0x{1:x}'", typeToken, value.ToInt64 ()));
|
||||
else
|
||||
return new RuntimeTypeHandle (res);
|
||||
}
|
||||
|
||||
public RuntimeMethodHandle ResolveMethodHandle (int methodToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
|
||||
{
|
||||
ResolveTokenError error;
|
||||
if (value == IntPtr.Zero)
|
||||
throw new ArgumentNullException (String.Empty, "Invalid handle");
|
||||
IntPtr res = RuntimeModule.ResolveMethodToken (value, methodToken, ptrs_from_handles (typeInstantiationContext), ptrs_from_handles (methodInstantiationContext), out error);
|
||||
if (res == IntPtr.Zero)
|
||||
throw new Exception (String.Format ("Could not load method '0x{0:x}' from assembly '0x{1:x}'", methodToken, value.ToInt64 ()));
|
||||
else
|
||||
return new RuntimeMethodHandle (res);
|
||||
}
|
||||
|
||||
public RuntimeFieldHandle ResolveFieldHandle (int fieldToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
|
||||
{
|
||||
ResolveTokenError error;
|
||||
if (value == IntPtr.Zero)
|
||||
throw new ArgumentNullException (String.Empty, "Invalid handle");
|
||||
|
||||
IntPtr res = RuntimeModule.ResolveFieldToken (value, fieldToken, ptrs_from_handles (typeInstantiationContext), ptrs_from_handles (methodInstantiationContext), out error);
|
||||
if (res == IntPtr.Zero)
|
||||
throw new Exception (String.Format ("Could not load field '0x{0:x}' from assembly '0x{1:x}'", fieldToken, value.ToInt64 ()));
|
||||
else
|
||||
return new RuntimeFieldHandle (res);
|
||||
}
|
||||
|
||||
public RuntimeFieldHandle GetRuntimeFieldHandleFromMetadataToken (int fieldToken)
|
||||
{
|
||||
return ResolveFieldHandle (fieldToken);
|
||||
}
|
||||
|
||||
public RuntimeMethodHandle GetRuntimeMethodHandleFromMetadataToken (int methodToken)
|
||||
{
|
||||
return ResolveMethodHandle (methodToken);
|
||||
}
|
||||
|
||||
public RuntimeTypeHandle GetRuntimeTypeHandleFromMetadataToken (int typeToken)
|
||||
{
|
||||
return ResolveTypeHandle (typeToken);
|
||||
}
|
||||
|
||||
public override bool Equals (object? obj)
|
||||
{
|
||||
if (obj == null || GetType () != obj.GetType ())
|
||||
return false;
|
||||
|
||||
return value == ((ModuleHandle)obj).Value;
|
||||
}
|
||||
|
||||
public bool Equals (ModuleHandle handle)
|
||||
{
|
||||
return value == handle.Value;
|
||||
}
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
return value.GetHashCode ();
|
||||
}
|
||||
|
||||
public static bool operator == (ModuleHandle left, ModuleHandle right)
|
||||
{
|
||||
return Equals (left, right);
|
||||
}
|
||||
|
||||
public static bool operator != (ModuleHandle left, ModuleHandle right)
|
||||
{
|
||||
return !Equals (left, right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
262
mcs/class/System.Private.CoreLib/System/MulticastDelegate.cs
Normal file
262
mcs/class/System.Private.CoreLib/System/MulticastDelegate.cs
Normal file
@ -0,0 +1,262 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
public abstract class MulticastDelegate : Delegate
|
||||
{
|
||||
Delegate[]? delegates;
|
||||
|
||||
protected MulticastDelegate (object target, string method)
|
||||
: base (target, method)
|
||||
{
|
||||
}
|
||||
|
||||
protected MulticastDelegate (Type target, string method)
|
||||
: base (target, method)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetObjectData (SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
throw new SerializationException (SR.Serialization_DelegatesNotSupported);
|
||||
}
|
||||
|
||||
protected sealed override object? DynamicInvokeImpl (object?[]? args)
|
||||
{
|
||||
if (delegates == null) {
|
||||
return base.DynamicInvokeImpl (args);
|
||||
} else {
|
||||
object r;
|
||||
int i = 0, len = delegates.Length;
|
||||
do {
|
||||
r = delegates [i].DynamicInvoke (args);
|
||||
} while (++i < len);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
// Some high-performance applications use this internal property
|
||||
// to avoid using a slow path to determine if there is more than one handler
|
||||
// This brings an API that we removed in f410e545e2db0e0dc338673a6b10a5cfd2d3340f
|
||||
// which some users depeneded on
|
||||
//
|
||||
// This is an example of code that used this:
|
||||
// https://gist.github.com/migueldeicaza/cd99938c2a4372e7e5d5
|
||||
//
|
||||
// Do not remove this API
|
||||
internal bool HasSingleTarget {
|
||||
get { return delegates == null; }
|
||||
}
|
||||
|
||||
// <remarks>
|
||||
// Equals: two multicast delegates are equal if their base is equal
|
||||
// and their invocations list is equal.
|
||||
// </remarks>
|
||||
public sealed override bool Equals (object? obj)
|
||||
{
|
||||
if (!base.Equals (obj))
|
||||
return false;
|
||||
|
||||
if (!(obj is MulticastDelegate d))
|
||||
return false;
|
||||
|
||||
if (delegates == null && d.delegates == null) {
|
||||
return true;
|
||||
} else if (delegates == null ^ d.delegates == null) {
|
||||
return false;
|
||||
} else {
|
||||
if (delegates.Length != d.delegates.Length)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < delegates.Length; ++i) {
|
||||
if (!delegates [i].Equals (d.delegates [i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// FIXME: This could use some improvements.
|
||||
//
|
||||
public sealed override int GetHashCode ()
|
||||
{
|
||||
return base.GetHashCode ();
|
||||
}
|
||||
|
||||
protected override MethodInfo GetMethodImpl ()
|
||||
{
|
||||
if (delegates != null)
|
||||
return delegates [delegates.Length - 1].Method;
|
||||
|
||||
return base.GetMethodImpl ();
|
||||
}
|
||||
|
||||
// <summary>
|
||||
// Return, in order of invocation, the invocation list
|
||||
// of a MulticastDelegate
|
||||
// </summary>
|
||||
public sealed override Delegate[] GetInvocationList ()
|
||||
{
|
||||
if (delegates != null)
|
||||
return (Delegate[]) delegates.Clone ();
|
||||
else
|
||||
return new Delegate[1] { this };
|
||||
}
|
||||
|
||||
// <summary>
|
||||
// Combines this MulticastDelegate with the (Multicast)Delegate `follow'.
|
||||
// This does _not_ combine with Delegates. ECMA states the whole delegate
|
||||
// thing should have better been a simple System.Delegate class.
|
||||
// Compiler generated delegates are always MulticastDelegates.
|
||||
// </summary>
|
||||
protected sealed override Delegate CombineImpl (Delegate? follow)
|
||||
{
|
||||
if (follow == null)
|
||||
return this;
|
||||
|
||||
MulticastDelegate other = (MulticastDelegate) follow;
|
||||
|
||||
MulticastDelegate ret = AllocDelegateLike_internal (this);
|
||||
|
||||
if (delegates == null && other.delegates == null) {
|
||||
ret.delegates = new Delegate [2] { this, other };
|
||||
} else if (delegates == null) {
|
||||
ret.delegates = new Delegate [1 + other.delegates.Length];
|
||||
|
||||
ret.delegates [0] = this;
|
||||
Array.Copy (other.delegates, 0, ret.delegates, 1, other.delegates.Length);
|
||||
} else if (other.delegates == null) {
|
||||
ret.delegates = new Delegate [delegates.Length + 1];
|
||||
|
||||
Array.Copy (delegates, 0, ret.delegates, 0, delegates.Length);
|
||||
ret.delegates [ret.delegates.Length - 1] = other;
|
||||
} else {
|
||||
ret.delegates = new Delegate [delegates.Length + other.delegates.Length];
|
||||
|
||||
Array.Copy (delegates, 0, ret.delegates, 0, delegates.Length);
|
||||
Array.Copy (other.delegates, 0, ret.delegates, delegates.Length, other.delegates.Length);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Based on the Boyer–Moore string search algorithm */
|
||||
int LastIndexOf (Delegate[] haystack, Delegate[] needle)
|
||||
{
|
||||
if (haystack.Length < needle.Length)
|
||||
return -1;
|
||||
|
||||
if (haystack.Length == needle.Length) {
|
||||
for (int i = 0; i < haystack.Length; ++i)
|
||||
if (!haystack [i].Equals (needle [i]))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = haystack.Length - needle.Length, j; i >= 0;) {
|
||||
for (j = 0; needle [j].Equals (haystack [i]); ++i, ++j) {
|
||||
if (j == needle.Length - 1)
|
||||
return i - j;
|
||||
}
|
||||
|
||||
i -= j + 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected sealed override Delegate RemoveImpl (Delegate value)
|
||||
{
|
||||
if (value == null)
|
||||
return this;
|
||||
|
||||
MulticastDelegate other = (MulticastDelegate) value;
|
||||
|
||||
if (delegates == null && other.delegates == null) {
|
||||
/* if they are not equal and the current one is not
|
||||
* a multicastdelegate then we cannot delete it */
|
||||
return this.Equals (other) ? null : this;
|
||||
} else if (delegates == null) {
|
||||
foreach (var d in other.delegates) {
|
||||
if (this.Equals (d))
|
||||
return null;
|
||||
}
|
||||
return this;
|
||||
} else if (other.delegates == null) {
|
||||
int idx = Array.LastIndexOf (delegates, other);
|
||||
if (idx == -1)
|
||||
return this;
|
||||
|
||||
if (delegates.Length <= 1) {
|
||||
/* delegates.Length should never be equal or
|
||||
* lower than 1, it should be 2 or greater */
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
|
||||
if (delegates.Length == 2)
|
||||
return delegates [idx == 0 ? 1 : 0];
|
||||
|
||||
MulticastDelegate ret = AllocDelegateLike_internal (this);
|
||||
ret.delegates = new Delegate [delegates.Length - 1];
|
||||
|
||||
Array.Copy (delegates, ret.delegates, idx);
|
||||
Array.Copy (delegates, idx + 1, ret.delegates, idx, delegates.Length - idx - 1);
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
/* wild case : remove MulticastDelegate from MulticastDelegate
|
||||
* complexity is O(m + n), with n the number of elements in
|
||||
* this.delegates and m the number of elements in other.delegates */
|
||||
|
||||
if (delegates.Equals (other.delegates))
|
||||
return null;
|
||||
|
||||
/* we need to remove elements from the end to the beginning, as
|
||||
* the addition and removal of delegates behaves like a stack */
|
||||
int idx = LastIndexOf (delegates, other.delegates);
|
||||
if (idx == -1)
|
||||
return this;
|
||||
|
||||
MulticastDelegate ret = AllocDelegateLike_internal (this);
|
||||
ret.delegates = new Delegate [delegates.Length - other.delegates.Length];
|
||||
|
||||
Array.Copy (delegates, ret.delegates, idx);
|
||||
Array.Copy (delegates, idx + other.delegates.Length, ret.delegates, idx, delegates.Length - idx - other.delegates.Length);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator == (MulticastDelegate d1, MulticastDelegate d2)
|
||||
{
|
||||
if (d1 == null)
|
||||
return d2 == null;
|
||||
|
||||
return d1.Equals (d2);
|
||||
}
|
||||
|
||||
public static bool operator != (MulticastDelegate d1, MulticastDelegate d2)
|
||||
{
|
||||
if (d1 == null)
|
||||
return d2 != null;
|
||||
|
||||
return !d1.Equals (d2);
|
||||
}
|
||||
|
||||
internal override object GetTarget()
|
||||
{
|
||||
return delegates?.Length > 0 ? delegates [delegates.Length - 1].GetTarget () : base.GetTarget ();
|
||||
}
|
||||
}
|
||||
}
|
34
mcs/class/System.Private.CoreLib/System/NotImplemented.cs
Normal file
34
mcs/class/System.Private.CoreLib/System/NotImplemented.cs
Normal file
@ -0,0 +1,34 @@
|
||||
// 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 System
|
||||
{
|
||||
//
|
||||
// This simple class enables one to throw a NotImplementedException using the following
|
||||
// idiom:
|
||||
//
|
||||
// throw NotImplemented.ByDesign;
|
||||
//
|
||||
// Used by methods whose intended implementation is to throw a NotImplementedException (typically
|
||||
// virtual methods in public abstract classes that intended to be subclassed by third parties.)
|
||||
//
|
||||
// This makes it distinguishable both from human eyes and CCI from NYI's that truly represent undone work.
|
||||
//
|
||||
internal static class NotImplemented
|
||||
{
|
||||
internal static Exception ByDesign
|
||||
{
|
||||
get
|
||||
{
|
||||
return new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
internal static Exception ByDesignWithMessage(string message)
|
||||
{
|
||||
return new NotImplementedException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
mcs/class/System.Private.CoreLib/System/Nullable.cs
Normal file
37
mcs/class/System.Private.CoreLib/System/Nullable.cs
Normal file
@ -0,0 +1,37 @@
|
||||
namespace System
|
||||
{
|
||||
partial struct Nullable<T>
|
||||
{
|
||||
//
|
||||
// These are called by the JIT
|
||||
//
|
||||
|
||||
//
|
||||
// JIT implementation of box valuetype System.Nullable`1<T>
|
||||
//
|
||||
static object? Box (T? o)
|
||||
{
|
||||
if (!o.hasValue)
|
||||
return null;
|
||||
|
||||
return o.value;
|
||||
}
|
||||
|
||||
static T? Unbox (object o)
|
||||
{
|
||||
if (o == null)
|
||||
return null;
|
||||
return (T) o;
|
||||
}
|
||||
|
||||
static T? UnboxExact (object o)
|
||||
{
|
||||
if (o == null)
|
||||
return null;
|
||||
if (o.GetType() != typeof (T))
|
||||
throw new InvalidCastException();
|
||||
|
||||
return (T) o;
|
||||
}
|
||||
}
|
||||
}
|
22
mcs/class/System.Private.CoreLib/System/Object.cs
Normal file
22
mcs/class/System.Private.CoreLib/System/Object.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
partial class Object
|
||||
{
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
public extern Type GetType ();
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
protected extern object MemberwiseClone ();
|
||||
|
||||
// TODO: Move to RuntimeHelpers
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
internal static extern int InternalGetHashCode (object o);
|
||||
|
||||
[Intrinsic]
|
||||
internal ref byte GetRawData () => throw new NotImplementedException ();
|
||||
|
||||
internal object CloneInternal () => MemberwiseClone ();
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
// 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 System
|
||||
{
|
||||
public ref struct RuntimeArgumentHandle
|
||||
{
|
||||
internal IntPtr args;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user