Exemplo n.º 1
0
        internal CultureInfo(String name, bool useUserOverride)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name",
                                                SR.ArgumentNull_String);
            }

#if CORERT
            // CORERT-TODO CultureInfo
            if (s_InvariantCultureInfo == null)
            {
                m_cultureData = CultureData.GetCultureData("", useUserOverride);
            }
            else
            {
                m_cultureData = s_InvariantCultureInfo.m_cultureData;
            }
            m_name        = _sortName = _nonSortName = name;
            m_isInherited = false;
#else
            // Get our data providing record
            this.m_cultureData = CultureData.GetCultureData(name, useUserOverride);

            if (this.m_cultureData == null)
            {
                throw new CultureNotFoundException(
                          "name", name, SR.Argument_CultureNotSupported);
            }

            this.m_name        = this.m_cultureData.CultureName;
            this.m_isInherited = !this.EETypePtr.FastEquals(EETypePtr.EETypePtrOf <CultureInfo>());
#endif // CORERT
        }
Exemplo n.º 2
0
 internal static Action GetCompletionAction <TStateMachine>(ref Action cachedMoveNextAction, ref TStateMachine stateMachine, Task taskIfDebuggingEnabled)
     where TStateMachine : IAsyncStateMachine
 {
     return(GetCompletionActionHelper(
                ref cachedMoveNextAction,
                ref Unsafe.As <TStateMachine, byte>(ref stateMachine),
                EETypePtr.EETypePtrOf <TStateMachine>(),
                taskIfDebuggingEnabled));
 }
Exemplo n.º 3
0
        internal EEType *GetArrayEEType()
        {
#if INPLACE_RUNTIME
            return(EETypePtr.EETypePtrOf <Array>().ToPointer());
#else
            fixed(EEType *pThis = &this)
            return(InternalCalls.RhpGetArrayBaseType(pThis));
#endif
        }
Exemplo n.º 4
0
        //==============================================================================================
        // Access to the underlying execution engine's object allocation routines.
        //==============================================================================================

        //
        // Perform the equivalent of a "newobj", but without invoking any constructors. Other than the EEType, the result object is zero-initialized.
        //
        // Special cases:
        //
        //    Strings: The .ctor performs both the construction and initialization
        //      and compiler special cases these.
        //
        //    Nullable<T>: the boxed result is the underlying type rather than Nullable so the constructor
        //      cannot truly initialize it.
        //
        //    In these cases, this helper returns "null" and ConstructorInfo.Invoke() must deal with these specially.
        //
        public static object NewObject(RuntimeTypeHandle typeHandle)
        {
            EETypePtr eeType = typeHandle.ToEETypePtr();

            if (eeType.IsNullable ||
                eeType == EETypePtr.EETypePtrOf <string>()
                )
            {
                return(null);
            }
            return(RuntimeImports.RhNewObject(eeType));
        }
Exemplo n.º 5
0
#pragma warning disable CA1822
        internal MethodTable *GetArrayEEType()
        {
#if INPLACE_RUNTIME
            return(EETypePtr.EETypePtrOf <Array>().ToPointer());
#else
            fixed(MethodTable *pThis = &this)
            {
                void *pGetArrayEEType = InternalCalls.RhpGetClasslibFunctionFromEEType(new IntPtr(pThis), ClassLibFunctionId.GetSystemArrayEEType);

                return(((delegate * < MethodTable * >)pGetArrayEEType)());
            }
#endif
        }
Exemplo n.º 6
0
        internal EEType *GetArrayEEType()
        {
#if INPLACE_RUNTIME
            return(EETypePtr.EETypePtrOf <Array>().ToPointer());
#else
            fixed(EEType *pThis = &this)
            {
                IntPtr pGetArrayEEType = (IntPtr)InternalCalls.RhpGetClasslibFunctionFromEEType(new IntPtr(pThis), ClassLibFunctionId.GetSystemArrayEEType);

                return((EEType *)CalliIntrinsics.Call <IntPtr>(pGetArrayEEType));
            }
#endif
        }
Exemplo n.º 7
0
        //==============================================================================================
        // Access to the underlying execution engine's object allocation routines.
        //==============================================================================================

        //
        // Perform the equivalent of a "newobj", but without invoking any constructors. Other than the EEType, the result object is zero-initialized.
        //
        // Special cases:
        //
        //    Strings: The .ctor performs both the construction and initialization
        //      and compiler special cases these.
        //
        //    IntPtr/UIntPtr: These have intrinsic constructors and it happens, special-casing these in the class library
        //      is the lesser evil compared to special-casing them in the toolchain.
        //
        //    Nullable<T>: the boxed result is the underlying type rather than Nullable so the constructor
        //      cannot truly initialize it.
        //
        //    In these cases, this helper returns "null" and ConstructorInfo.Invoke() must deal with these specially.
        //
        public static Object NewObject(RuntimeTypeHandle typeHandle)
        {
            EETypePtr eeType = typeHandle.ToEETypePtr();

            if (RuntimeImports.RhIsNullable(eeType) ||
                eeType == EETypePtr.EETypePtrOf <String>() ||
                eeType == EETypePtr.EETypePtrOf <IntPtr>() ||
                eeType == EETypePtr.EETypePtrOf <UIntPtr>()
                )
            {
                return(null);
            }
            return(RuntimeImports.RhNewObject(eeType));
        }
Exemplo n.º 8
0
        private static Lock GetLock(Object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            // TODO: Fix framework code to not call Monitor methods on Lock objects and replace this check with an assertion.
            // The Lock class is sealed and never cloned, therefore it is safe to use raw pointer equality.
            if (obj.EETypePtr.RawValue == EETypePtr.EETypePtrOf <Lock>().RawValue)
            {
                return(RuntimeHelpers.UncheckedCast <Lock>(obj));
            }

            return(s_lockTable.GetValue(obj, s_createLock));
        }
Exemplo n.º 9
0
        //==============================================================================================
        // Access to the underlying execution engine's object allocation routines.
        //==============================================================================================

        //
        // Perform the equivalent of a "newobj", but without invoking any constructors. Other than the MethodTable, the result object is zero-initialized.
        //
        // Special cases:
        //
        //    Strings: The .ctor performs both the construction and initialization
        //      and compiler special cases these.
        //
        //    Nullable<T>: the boxed result is the underlying type rather than Nullable so the constructor
        //      cannot truly initialize it.
        //
        //    In these cases, this helper returns "null" and ConstructorInfo.Invoke() must deal with these specially.
        //
        public static object NewObject(RuntimeTypeHandle typeHandle)
        {
            EETypePtr eeType = typeHandle.ToEETypePtr();

            if (eeType.IsNullable ||
                eeType == EETypePtr.EETypePtrOf <string>()
                )
            {
                return(null);
            }
            if (eeType.IsByRefLike)
            {
                throw new System.Reflection.TargetException();
            }
            return(RuntimeImports.RhNewObject(eeType));
        }
Exemplo n.º 10
0
        internal CultureInfo(String name, bool useUserOverride)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name),
                                                SR.ArgumentNull_String);
            }

            // Get our data providing record
            this.m_cultureData = CultureData.GetCultureData(name, useUserOverride);

            if (this.m_cultureData == null)
            {
                throw new CultureNotFoundException(
                          nameof(name), name, SR.Argument_CultureNotSupported);
            }

            this.m_name        = this.m_cultureData.CultureName;
            this.m_isInherited = !this.EETypePtr.FastEquals(EETypePtr.EETypePtrOf <CultureInfo>());
        }
Exemplo n.º 11
0
        public static object ToObject(TypedReference value)
        {
            RuntimeTypeHandle typeHandle = value._typeHandle;

            if (typeHandle.IsNull)
            {
                throw new ArgumentNullException(); // For compatibility.
            }
            EETypePtr eeType = typeHandle.ToEETypePtr();

            if (eeType.IsValueType)
            {
                return(RuntimeImports.RhBox(eeType, ref value.Value));
            }
            else if (eeType.IsPointer)
            {
                return(RuntimeImports.RhBox(EETypePtr.EETypePtrOf <UIntPtr>(), ref value.Value));
            }
            else
            {
                return(Unsafe.As <byte, object>(ref value.Value));
            }
        }
Exemplo n.º 12
0
        private static unsafe void InitializeStringTable(IntPtr stringTableStart, int length)
        {
            IntPtr stringTableEnd = (IntPtr)((byte *)stringTableStart + length);

            for (IntPtr *tab = (IntPtr *)stringTableStart; tab < (IntPtr *)stringTableEnd; tab++)
            {
                byte *bytes = (byte *)*tab;
                int   len   = (int)NativePrimitiveDecoder.DecodeUnsigned(ref bytes);
                int   count = LowLevelUTF8Encoding.GetCharCount(bytes, len);
                Contract.Assert(count >= 0);

                string newStr = RuntimeImports.RhNewArrayAsString(EETypePtr.EETypePtrOf <string>(), count);
                fixed(char *dest = newStr)
                {
                    int newCount = LowLevelUTF8Encoding.GetChars(bytes, len, dest, count);

                    Contract.Assert(newCount == count);
                }

                GCHandle handle = GCHandle.Alloc(newStr);
                *        tab    = (IntPtr)handle;
            }
        }
Exemplo n.º 13
0
 public static RuntimeTypeHandle RuntimeTypeHandleOf <T>()
 {
     return(new RuntimeTypeHandle(EETypePtr.EETypePtrOf <T>()));
 }
Exemplo n.º 14
0
        public static bool IsReferenceOrContainsReferences <T>()
        {
            var pEEType = EETypePtr.EETypePtrOf <T>();

            return(!pEEType.IsValueType || pEEType.HasPointers);
        }
Exemplo n.º 15
0
 internal EEType *GetArrayEEType()
 {
     return(EETypePtr.EETypePtrOf <Array>().ToPointer());
 }
Exemplo n.º 16
0
        public unsafe object?Invoke(
            object?thisPtr,
            IntPtr methodToCall,
            object?[]?parameters,
            BinderBundle?binderBundle,
            bool wrapInTargetInvocationException)
        {
            int argCount = parameters?.Length ?? 0;

            if (argCount != _argumentCount)
            {
                if (_argumentCount < 0)
                {
                    if (_argumentCount == ArgumentCount_NotSupported_ByRefLike)
                    {
                        throw new NotSupportedException(SR.NotSupported_ByRefLike);
                    }
                    throw new NotSupportedException();
                }

                throw new TargetParameterCountException(SR.Arg_ParmCnt);
            }

            object?returnObject = null;

            scoped ref byte thisArg = ref Unsafe.NullRef <byte>();

            if (!_isStatic)
            {
                // The caller is expected to validate this
                Debug.Assert(thisPtr != null);

                // See TODO comment in DynamicInvokeMethodThunk.NormalizeSignature
                // if (_isValueTypeInstanceMethod)
                // {
                //     // thisArg is a raw data byref for valuetype instance methods
                //     thisArg = ref thisPtr.GetRawData();
                // }
                // else
                {
                    thisArg = ref Unsafe.As <object?, byte>(ref thisPtr);
                }
            }

            scoped ref byte ret = ref Unsafe.As <object?, byte>(ref returnObject);

            if ((_returnTransform & Transform.AllocateReturnBox) != 0)
            {
                returnObject = RuntimeImports.RhNewObject(
                    (_returnTransform & Transform.Pointer) != 0 ?
                    EETypePtr.EETypePtrOf <IntPtr>() : _returnType);
                ret = ref returnObject.GetRawData();
            }

            if (argCount == 0)
            {
                try
                {
                    ret = ref RawCalliHelper.Call(InvokeThunk, (void *)methodToCall, ref thisArg, ref ret, null);
                    DebugAnnotations.PreviousCallContainsDebuggerStepInCode();
                }
                catch (Exception e) when(wrapInTargetInvocationException)
                {
                    throw new TargetInvocationException(e);
                }
            }
            else if (argCount > MaxStackAllocArgCount)
            {
                ret = ref InvokeWithManyArguments(methodToCall, ref thisArg, ref ret,
                                                  parameters, binderBundle, wrapInTargetInvocationException);
            }
            else
            {
                StackAllocedArguments argStorage   = default;
                StackAllocatedByRefs  byrefStorage = default;

                CheckArguments(ref argStorage._arg0 !, (ByReference *)&byrefStorage, parameters, binderBundle);

                try
                {
                    ret = ref RawCalliHelper.Call(InvokeThunk, (void *)methodToCall, ref thisArg, ref ret, &byrefStorage);
                    DebugAnnotations.PreviousCallContainsDebuggerStepInCode();
                }
                catch (Exception e) when(wrapInTargetInvocationException)
                {
                    throw new TargetInvocationException(e);
                }
                finally
                {
                    if (_needsCopyBack)
                    {
                        CopyBack(ref argStorage._arg0 !, parameters);
                    }
                }
            }

            return(((_returnTransform & (Transform.Nullable | Transform.Pointer | Transform.ByRef)) != 0) ?
                   ReturnTransform(ref ret, wrapInTargetInvocationException) : returnObject);
        }
Exemplo n.º 17
0
        public static bool IsReference <T>()
        {
            var pEEType = EETypePtr.EETypePtrOf <T>();

            return(!pEEType.IsValueType);
        }
Exemplo n.º 18
0
        private static int s_maxSpinCount = -1; // -1 means the spin count has not yet beeen determined.

        //
        // IsLock is faster that "obj as Lock()", as it avoids the overhead of the full
        // casting logic in the runtime.  This is only safe because a) EETypePtr
        // overloads operator == to do the right thing, and b) Lock is sealed, so we
        // don't need to waste time traversing the inheritence heirarchy.
        //
        internal static bool IsLock(object obj)
        {
            return(obj.EETypePtr == EETypePtr.EETypePtrOf <Lock>());
        }
Exemplo n.º 19
0
 internal MethodTable *GetArrayEEType()
 {
     return(EETypePtr.EETypePtrOf <Array>().ToPointer());
 }