From 70a06a5438b04599676ed891037d82ee2aa730ef Mon Sep 17 00:00:00 2001 From: dotnet-bot Date: Wed, 30 Sep 2015 00:36:18 -0700 Subject: [PATCH] Add JitInterface sources --- .../src/CommandLine/CommandLineException.cs | 15 + .../src/CommandLine/CommandLineParser.cs | 121 + src/JitInterface/src/CorInfoBase.cs | 840 ++++ src/JitInterface/src/CorInfoHelpFunc.cs | 362 ++ src/JitInterface/src/CorInfoImpl.cs | 1295 ++++++ src/JitInterface/src/CorInfoTypes.cs | 1354 ++++++ .../src/ThunkGenerator/Program.cs | 311 ++ .../src/ThunkGenerator/ThunkInput.txt | 317 ++ src/JitInterface/src/ThunkGenerator/corinfo.h | 3645 +++++++++++++++++ src/JitInterface/src/ThunkGenerator/corjit.h | 617 +++ 10 files changed, 8877 insertions(+) create mode 100644 src/Common/src/CommandLine/CommandLineException.cs create mode 100644 src/Common/src/CommandLine/CommandLineParser.cs create mode 100644 src/JitInterface/src/CorInfoBase.cs create mode 100644 src/JitInterface/src/CorInfoHelpFunc.cs create mode 100644 src/JitInterface/src/CorInfoImpl.cs create mode 100644 src/JitInterface/src/CorInfoTypes.cs create mode 100644 src/JitInterface/src/ThunkGenerator/Program.cs create mode 100644 src/JitInterface/src/ThunkGenerator/ThunkInput.txt create mode 100644 src/JitInterface/src/ThunkGenerator/corinfo.h create mode 100644 src/JitInterface/src/ThunkGenerator/corjit.h diff --git a/src/Common/src/CommandLine/CommandLineException.cs b/src/Common/src/CommandLine/CommandLineException.cs new file mode 100644 index 00000000000..8562032b6c0 --- /dev/null +++ b/src/Common/src/CommandLine/CommandLineException.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +namespace Internal.CommandLine +{ + class CommandLineException : Exception + { + public CommandLineException(string message) + : base(message) + { + } + } +} diff --git a/src/Common/src/CommandLine/CommandLineParser.cs b/src/Common/src/CommandLine/CommandLineParser.cs new file mode 100644 index 00000000000..fde451af126 --- /dev/null +++ b/src/Common/src/CommandLine/CommandLineParser.cs @@ -0,0 +1,121 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.IO; + +namespace Internal.CommandLine +{ + // + // Simple command line parser + // + class CommandLineParser + { + string[] _args; + int _current; + + string _currentOption; + + public CommandLineParser(string[] args) + { + _args = args; + _current = 0; + } + + public string GetOption() + { + if (_current >= _args.Length) + return null; + + string opt = _args[_current]; + _currentOption = opt; + + if (opt.StartsWith("-")) + { + opt = opt.Substring(1); + } +#if !FXCORE + else + if (Path.DirectorySeparatorChar != '/' && opt.StartsWith("/")) + { + // For convenience, allow command line options starting with slash on Windows + opt = opt.Substring(1); + } +#endif + else + { + return ""; + } + + _current++; + return opt; + } + + public string GetCurrentOption() + { + return _currentOption; + } + + public string GetStringValue() + { + if (_current >= _args.Length) + throw new CommandLineException("Value expected for " + GetCurrentOption()); + + return _args[_current++]; + } + public void AppendExpandedPaths(Dictionary dictionary, bool strict) + { + string pattern = GetStringValue(); + + bool empty = true; + + string directoryName = Path.GetDirectoryName(pattern); + string searchPattern = Path.GetFileName(pattern); + + if (directoryName == "") + directoryName = "."; + + if (Directory.Exists(directoryName)) + { + foreach (string fileName in Directory.EnumerateFiles(directoryName, searchPattern)) + { +#if !FXCORE + string fullFileName = Path.GetFullPath(fileName); +#else + string fullFileName = fileName; +#endif + string simpleName = Path.GetFileNameWithoutExtension(fileName); + + if (dictionary.ContainsKey(simpleName)) + { + if (strict) + { + throw new CommandLineException("Multiple input files matching same simple name " + + fullFileName + " " + dictionary[simpleName]); + } + } + else + { + dictionary.Add(simpleName, fullFileName); + } + + empty = false; + } + } + + if (empty) + { + if (strict) + { + throw new CommandLineException("No files matching " + pattern); + } + else + { + Console.WriteLine("Warning: No files matching " + pattern); + } + } + } + + } +} diff --git a/src/JitInterface/src/CorInfoBase.cs b/src/JitInterface/src/CorInfoBase.cs new file mode 100644 index 00000000000..c22983910e8 --- /dev/null +++ b/src/JitInterface/src/CorInfoBase.cs @@ -0,0 +1,840 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +// DO NOT EDIT THIS FILE! It IS AUTOGENERATED +using System; +using System.Runtime.InteropServices; + +namespace Internal.JitInterface +{ + unsafe partial class CorInfoImpl + { + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getMethodAttribs(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _setMethodAttribs(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, CorInfoMethodRuntimeFlags attribs); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getMethodSig(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, CORINFO_SIG_INFO* sig, CORINFO_CLASS_STRUCT_* memberParent); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.I1)]delegate bool _getMethodInfo(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref CORINFO_METHOD_INFO info); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoInline _canInline(IntPtr _this, CORINFO_METHOD_STRUCT_* callerHnd, CORINFO_METHOD_STRUCT_* calleeHnd, ref uint pRestrictions); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _reportInliningDecision(IntPtr _this, CORINFO_METHOD_STRUCT_* inlinerHnd, CORINFO_METHOD_STRUCT_* inlineeHnd, CorInfoInline inlineResult, byte* reason); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.I1)]delegate bool _canTailCall(IntPtr _this, CORINFO_METHOD_STRUCT_* callerHnd, CORINFO_METHOD_STRUCT_* declaredCalleeHnd, CORINFO_METHOD_STRUCT_* exactCalleeHnd, [MarshalAs(UnmanagedType.I1)]bool fIsTailPrefix); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _reportTailCallDecision(IntPtr _this, CORINFO_METHOD_STRUCT_* callerHnd, CORINFO_METHOD_STRUCT_* calleeHnd, [MarshalAs(UnmanagedType.I1)]bool fIsTailPrefix, CorInfoTailCall tailCallResult, byte* reason); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getEHinfo(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, uint EHnumber, ref CORINFO_EH_CLAUSE clause); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_CLASS_STRUCT_* _getMethodClass(IntPtr _this, CORINFO_METHOD_STRUCT_* method); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_MODULE_STRUCT_* _getMethodModule(IntPtr _this, CORINFO_METHOD_STRUCT_* method); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getMethodVTableOffset(IntPtr _this, CORINFO_METHOD_STRUCT_* method, ref uint offsetOfIndirection, ref uint offsetAfterIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoIntrinsics _getIntrinsicID(IntPtr _this, CORINFO_METHOD_STRUCT_* method); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.I1)]delegate bool _isInSIMDModule(IntPtr _this, CORINFO_CLASS_STRUCT_* classHnd); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoUnmanagedCallConv _getUnmanagedCallConv(IntPtr _this, CORINFO_METHOD_STRUCT_* method); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _pInvokeMarshalingRequired(IntPtr _this, CORINFO_METHOD_STRUCT_* method, CORINFO_SIG_INFO* callSiteSig); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _satisfiesMethodConstraints(IntPtr _this, CORINFO_CLASS_STRUCT_* parent, CORINFO_METHOD_STRUCT_* method); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _isCompatibleDelegate(IntPtr _this, CORINFO_CLASS_STRUCT_* objCls, CORINFO_CLASS_STRUCT_* methodParentCls, CORINFO_METHOD_STRUCT_* method, CORINFO_CLASS_STRUCT_* delegateCls, [MarshalAs(UnmanagedType.Bool)] ref bool pfIsOpenDelegate); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _isDelegateCreationAllowed(IntPtr _this, CORINFO_CLASS_STRUCT_* delegateHnd, CORINFO_METHOD_STRUCT_* calleeHnd); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoInstantiationVerification _isInstantiationOfVerifiedGeneric(IntPtr _this, CORINFO_METHOD_STRUCT_* method); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _initConstraintsForVerification(IntPtr _this, CORINFO_METHOD_STRUCT_* method, [MarshalAs(UnmanagedType.Bool)] ref bool pfHasCircularClassConstraints, [MarshalAs(UnmanagedType.Bool)] ref bool pfHasCircularMethodConstraint); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoCanSkipVerificationResult _canSkipMethodVerification(IntPtr _this, CORINFO_METHOD_STRUCT_* ftnHandle); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _methodMustBeLoadedBeforeCodeIsRun(IntPtr _this, CORINFO_METHOD_STRUCT_* method); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_METHOD_STRUCT_* _mapMethodDeclToMethodImpl(IntPtr _this, CORINFO_METHOD_STRUCT_* method); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getGSCookie(IntPtr _this, GSCookie* pCookieVal, GSCookie** ppCookieVal); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _resolveToken(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _findSig(IntPtr _this, CORINFO_MODULE_STRUCT_* module, uint sigTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _findCallSiteSig(IntPtr _this, CORINFO_MODULE_STRUCT_* module, uint methTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_CLASS_STRUCT_* _getTokenTypeAsHandle(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoCanSkipVerificationResult _canSkipVerification(IntPtr _this, CORINFO_MODULE_STRUCT_* module); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _isValidToken(IntPtr _this, CORINFO_MODULE_STRUCT_* module, uint metaTOK); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _isValidStringRef(IntPtr _this, CORINFO_MODULE_STRUCT_* module, uint metaTOK); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _shouldEnforceCallvirtRestriction(IntPtr _this, CORINFO_MODULE_STRUCT_* scope); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoType _asCorInfoType(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate byte* _getClassName(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate int _appendClassName(IntPtr _this, short** ppBuf, ref int pnBufLen, CORINFO_CLASS_STRUCT_* cls, [MarshalAs(UnmanagedType.Bool)]bool fNamespace, [MarshalAs(UnmanagedType.Bool)]bool fFullInst, [MarshalAs(UnmanagedType.Bool)]bool fAssembly); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _isValueClass(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _canInlineTypeCheckWithObjectVTable(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getClassAttribs(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _isStructRequiringStackAllocRetBuf(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_MODULE_STRUCT_* _getClassModule(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_ASSEMBLY_STRUCT_* _getModuleAssembly(IntPtr _this, CORINFO_MODULE_STRUCT_* mod); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate byte* _getAssemblyName(IntPtr _this, CORINFO_ASSEMBLY_STRUCT_* assem); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _LongLifetimeMalloc(IntPtr _this, UIntPtr sz); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _LongLifetimeFree(IntPtr _this, void* obj); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate byte* _getClassModuleIdForStatics(IntPtr _this, CORINFO_CLASS_STRUCT_* cls, CORINFO_MODULE_STRUCT_** pModule, void** ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getClassSize(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getClassAlignmentRequirement(IntPtr _this, CORINFO_CLASS_STRUCT_* cls, [MarshalAs(UnmanagedType.Bool)]bool fDoubleAlignHint); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getClassGClayout(IntPtr _this, CORINFO_CLASS_STRUCT_* cls, byte* gcPtrs); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getClassNumInstanceFields(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_FIELD_STRUCT_* _getFieldInClass(IntPtr _this, CORINFO_CLASS_STRUCT_* clsHnd, int num); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _checkMethodModifier(IntPtr _this, CORINFO_METHOD_STRUCT_* hMethod, byte* modifier, [MarshalAs(UnmanagedType.Bool)]bool fOptional); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoHelpFunc _getNewHelper(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoHelpFunc _getNewArrHelper(IntPtr _this, CORINFO_CLASS_STRUCT_* arrayCls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoHelpFunc _getCastingHelper(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, [MarshalAs(UnmanagedType.I1)]bool fThrowing); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoHelpFunc _getSharedCCtorHelper(IntPtr _this, CORINFO_CLASS_STRUCT_* clsHnd); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoHelpFunc _getSecurityPrologHelper(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_CLASS_STRUCT_* _getTypeForBox(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoHelpFunc _getBoxHelper(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoHelpFunc _getUnBoxHelper(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getReadyToRunHelper(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CorInfoHelpFunc id, ref CORINFO_CONST_LOOKUP pLookup); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate byte* _getHelperName(IntPtr _this, CorInfoHelpFunc helpFunc); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoInitClassResult _initClass(IntPtr _this, CORINFO_FIELD_STRUCT_* field, CORINFO_METHOD_STRUCT_* method, CORINFO_CONTEXT_STRUCT* context, [MarshalAs(UnmanagedType.Bool)]bool speculative); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _classMustBeLoadedBeforeCodeIsRun(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_CLASS_STRUCT_* _getBuiltinClass(IntPtr _this, CorInfoClassId classId); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoType _getTypeForPrimitiveValueClass(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _canCast(IntPtr _this, CORINFO_CLASS_STRUCT_* child, CORINFO_CLASS_STRUCT_* parent); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _areTypesEquivalent(IntPtr _this, CORINFO_CLASS_STRUCT_* cls1, CORINFO_CLASS_STRUCT_* cls2); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_CLASS_STRUCT_* _mergeClasses(IntPtr _this, CORINFO_CLASS_STRUCT_* cls1, CORINFO_CLASS_STRUCT_* cls2); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_CLASS_STRUCT_* _getParentType(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoType _getChildType(IntPtr _this, CORINFO_CLASS_STRUCT_* clsHnd, ref CORINFO_CLASS_STRUCT_* clsRet); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _satisfiesClassConstraints(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _isSDArray(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getArrayRank(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _getArrayInitializationData(IntPtr _this, CORINFO_FIELD_STRUCT_* field, uint size); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoIsAccessAllowedResult _canAccessClass(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, ref CORINFO_HELPER_DESC pAccessHelper); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate byte* _getFieldName(IntPtr _this, CORINFO_FIELD_STRUCT_* ftn, byte** moduleName); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_CLASS_STRUCT_* _getFieldClass(IntPtr _this, CORINFO_FIELD_STRUCT_* field); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoType _getFieldType(IntPtr _this, CORINFO_FIELD_STRUCT_* field, ref CORINFO_CLASS_STRUCT_* structType, CORINFO_CLASS_STRUCT_* memberParent); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getFieldOffset(IntPtr _this, CORINFO_FIELD_STRUCT_* field); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.I1)]delegate bool _isWriteBarrierHelperRequired(IntPtr _this, CORINFO_FIELD_STRUCT_* field); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getFieldInfo(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, CORINFO_ACCESS_FLAGS flags, ref CORINFO_FIELD_INFO pResult); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.I1)]delegate bool _isFieldStatic(IntPtr _this, CORINFO_FIELD_STRUCT_* fldHnd); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getBoundaries(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref uint cILOffsets, ref uint* pILOffsets, BoundaryTypes* implictBoundaries); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _setBoundaries(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, uint cMap, OffsetMapping* pMap); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getVars(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref uint cVars, ILVarInfo** vars, [MarshalAs(UnmanagedType.U1)] ref bool extendOthers); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _setVars(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, uint cVars, NativeVarInfo* vars); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _allocateArray(IntPtr _this, uint cBytes); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _freeArray(IntPtr _this, void* array); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_ARG_LIST_STRUCT_* _getArgNext(IntPtr _this, CORINFO_ARG_LIST_STRUCT_* args); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoTypeWithMod _getArgType(IntPtr _this, CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_STRUCT_* args, ref CORINFO_CLASS_STRUCT_* vcTypeRet); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_CLASS_STRUCT_* _getArgClass(IntPtr _this, CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_STRUCT_* args); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoType _getHFAType(IntPtr _this, CORINFO_CLASS_STRUCT_* hClass); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate HRESULT _GetErrorHRESULT(IntPtr _this, _EXCEPTION_POINTERS* pExceptionPointers); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _GetErrorMessage(IntPtr _this, short* buffer, uint bufferLength); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate int _FilterException(IntPtr _this, _EXCEPTION_POINTERS* pExceptionPointers); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _HandleException(IntPtr _this, _EXCEPTION_POINTERS* pExceptionPointers); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _ThrowExceptionForJitResult(IntPtr _this, HRESULT result); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _ThrowExceptionForHelper(IntPtr _this, ref CORINFO_HELPER_DESC throwHelper); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getEEInfo(IntPtr _this, ref CORINFO_EE_INFO pEEInfoOut); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.LPWStr)]delegate string _getJitTimeLogFilename(IntPtr _this); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate mdToken _getMethodDefFromMethod(IntPtr _this, CORINFO_METHOD_STRUCT_* hMethod); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate byte* _getMethodName(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, byte** moduleName); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getMethodHash(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate byte* _findNameOfToken(IntPtr _this, CORINFO_MODULE_STRUCT_* moduleHandle, mdToken token, byte* szFQName, UIntPtr FQNameCapacity); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate int _getIntConfigValue(IntPtr _this, String name, int defaultValue); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate short* _getStringConfigValue(IntPtr _this, String name); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _freeStringConfigValue(IntPtr _this, short* value); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getThreadTLSIndex(IntPtr _this, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _getInlinedCallFrameVptr(IntPtr _this, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate int* _getAddrOfCaptureThreadGlobal(IntPtr _this, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate SIZE_T* _getAddrModuleDomainID(IntPtr _this, CORINFO_MODULE_STRUCT_* module); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _getHelperFtn(IntPtr _this, CorInfoHelpFunc ftnNum, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getFunctionEntryPoint(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref CORINFO_CONST_LOOKUP pResult, CORINFO_ACCESS_FLAGS accessFlags); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getFunctionFixedEntryPoint(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref CORINFO_CONST_LOOKUP pResult); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _getMethodSync(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CorInfoHelpFunc _getLazyStringLiteralHelper(IntPtr _this, CORINFO_MODULE_STRUCT_* handle); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_MODULE_STRUCT_* _embedModuleHandle(IntPtr _this, CORINFO_MODULE_STRUCT_* handle, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_CLASS_STRUCT_* _embedClassHandle(IntPtr _this, CORINFO_CLASS_STRUCT_* handle, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_METHOD_STRUCT_* _embedMethodHandle(IntPtr _this, CORINFO_METHOD_STRUCT_* handle, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_FIELD_STRUCT_* _embedFieldHandle(IntPtr _this, CORINFO_FIELD_STRUCT_* handle, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _embedGenericHandle(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, [MarshalAs(UnmanagedType.Bool)]bool fEmbedParent, ref CORINFO_GENERICHANDLE_RESULT pResult); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_LOOKUP_KIND _getLocationOfThisType(IntPtr _this, CORINFO_METHOD_STRUCT_* context); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _getPInvokeUnmanagedTarget(IntPtr _this, CORINFO_METHOD_STRUCT_* method, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _getAddressOfPInvokeFixup(IntPtr _this, CORINFO_METHOD_STRUCT_* method, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _GetCookieForPInvokeCalliSig(IntPtr _this, CORINFO_SIG_INFO* szMetaSig, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.I1)]delegate bool _canGetCookieForPInvokeCalliSig(IntPtr _this, CORINFO_SIG_INFO* szMetaSig); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_JUST_MY_CODE_HANDLE_* _getJustMyCodeHandle(IntPtr _this, CORINFO_METHOD_STRUCT_* method, ref CORINFO_JUST_MY_CODE_HANDLE_** ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _GetProfilingHandle(IntPtr _this, [MarshalAs(UnmanagedType.Bool)] ref bool pbHookFunction, ref void* pProfilerHandle, [MarshalAs(UnmanagedType.Bool)] ref bool pbIndirectedHandles); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getCallInfo(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESOLVED_TOKEN* pConstrainedResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, CORINFO_CALLINFO_FLAGS flags, ref CORINFO_CALL_INFO pResult); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _canAccessFamily(IntPtr _this, CORINFO_METHOD_STRUCT_* hCaller, CORINFO_CLASS_STRUCT_* hInstanceType); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _isRIDClassDomainID(IntPtr _this, CORINFO_CLASS_STRUCT_* cls); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getClassDomainID(IntPtr _this, CORINFO_CLASS_STRUCT_* cls, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _getFieldAddress(IntPtr _this, CORINFO_FIELD_STRUCT_* field, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate IntPtr _getVarArgsHandle(IntPtr _this, CORINFO_SIG_INFO* pSig, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.I1)]delegate bool _canGetVarArgsHandle(IntPtr _this, CORINFO_SIG_INFO* pSig); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate InfoAccessType _constructStringLiteral(IntPtr _this, CORINFO_MODULE_STRUCT_* module, mdToken metaTok, ref void* ppValue); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate InfoAccessType _emptyStringLiteral(IntPtr _this, ref void* ppValue); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getFieldThreadLocalStoreID(IntPtr _this, CORINFO_FIELD_STRUCT_* field, ref void* ppIndirection); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _setOverride(IntPtr _this, IntPtr pOverride, CORINFO_METHOD_STRUCT_* currentMethod); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _addActiveDependency(IntPtr _this, CORINFO_MODULE_STRUCT_* moduleFrom, CORINFO_MODULE_STRUCT_* moduleTo); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate CORINFO_METHOD_STRUCT_* _GetDelegateCtor(IntPtr _this, CORINFO_METHOD_STRUCT_* methHnd, CORINFO_CLASS_STRUCT_* clsHnd, CORINFO_METHOD_STRUCT_* targetMethodHnd, ref DelegateCtorArgs pCtorData); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _MethodCompileComplete(IntPtr _this, CORINFO_METHOD_STRUCT_* methHnd); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _getTailCallCopyArgsThunk(IntPtr _this, CORINFO_SIG_INFO* pSig, CorInfoHelperTailCallSpecialHandling flags); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _getMemoryManager(IntPtr _this); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _allocMem(IntPtr _this, uint hotCodeSize, uint coldCodeSize, uint roDataSize, uint xcptnsCount, CorJitAllocMemFlag flag, ref void* hotCodeBlock, ref void* coldCodeBlock, ref void* roDataBlock); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _reserveUnwindInfo(IntPtr _this, [MarshalAs(UnmanagedType.Bool)]bool isFunclet, [MarshalAs(UnmanagedType.Bool)]bool isColdCode, uint unwindSize); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _allocUnwindInfo(IntPtr _this, byte* pHotCode, byte* pColdCode, uint startOffset, uint endOffset, uint unwindSize, byte* pUnwindBlock, CorJitFuncKind funcKind); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void* _allocGCInfo(IntPtr _this, UIntPtr size); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _yieldExecution(IntPtr _this); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _setEHcount(IntPtr _this, uint cEH); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _setEHinfo(IntPtr _this, uint EHnumber, ref CORINFO_EH_CLAUSE clause); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + [return: MarshalAs(UnmanagedType.Bool)]delegate bool _logMsg(IntPtr _this, uint level, byte* fmt, IntPtr args); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate int _doAssert(IntPtr _this, byte* szFile, int iLine, byte* szExpr); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _reportFatalError(IntPtr _this, CorJitResult result); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate HRESULT _allocBBProfileBuffer(IntPtr _this, uint count, ref ProfileBuffer* profileBuffer); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate HRESULT _getBBProfileData(IntPtr _this, CORINFO_METHOD_STRUCT_* ftnHnd, ref uint count, ref ProfileBuffer* profileBuffer, ref uint numRuns); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _recordCallSite(IntPtr _this, uint instrOffset, CORINFO_SIG_INFO* callSig, CORINFO_METHOD_STRUCT_* methodHandle); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _recordRelocation(IntPtr _this, void* location, void* target, ushort fRelocType, ushort slotNum, int addlDelta); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate ushort _getRelocTypeHint(IntPtr _this, void* target); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate void _getModuleNativeEntryPointRange(IntPtr _this, ref void* pStart, ref void* pEnd); + [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)] + delegate uint _getExpectedTargetArchitecture(IntPtr _this); + + Object[] _keepalive; + + protected IntPtr CreateUnmanagedInstance() + { + IntPtr * vtable = (IntPtr *)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 162); + Object[] keepalive = new Object[162]; + Delegate d; + + _keepalive = keepalive; + + d = new _getMethodAttribs(getMethodAttribs); + vtable[0] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[0] = d; + d = new _setMethodAttribs(setMethodAttribs); + vtable[1] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[1] = d; + d = new _getMethodSig(getMethodSig); + vtable[2] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[2] = d; + d = new _getMethodInfo(getMethodInfo); + vtable[3] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[3] = d; + d = new _canInline(canInline); + vtable[4] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[4] = d; + d = new _reportInliningDecision(reportInliningDecision); + vtable[5] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[5] = d; + d = new _canTailCall(canTailCall); + vtable[6] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[6] = d; + d = new _reportTailCallDecision(reportTailCallDecision); + vtable[7] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[7] = d; + d = new _getEHinfo(getEHinfo); + vtable[8] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[8] = d; + d = new _getMethodClass(getMethodClass); + vtable[9] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[9] = d; + d = new _getMethodModule(getMethodModule); + vtable[10] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[10] = d; + d = new _getMethodVTableOffset(getMethodVTableOffset); + vtable[11] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[11] = d; + d = new _getIntrinsicID(getIntrinsicID); + vtable[12] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[12] = d; + d = new _isInSIMDModule(isInSIMDModule); + vtable[13] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[13] = d; + d = new _getUnmanagedCallConv(getUnmanagedCallConv); + vtable[14] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[14] = d; + d = new _pInvokeMarshalingRequired(pInvokeMarshalingRequired); + vtable[15] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[15] = d; + d = new _satisfiesMethodConstraints(satisfiesMethodConstraints); + vtable[16] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[16] = d; + d = new _isCompatibleDelegate(isCompatibleDelegate); + vtable[17] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[17] = d; + d = new _isDelegateCreationAllowed(isDelegateCreationAllowed); + vtable[18] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[18] = d; + d = new _isInstantiationOfVerifiedGeneric(isInstantiationOfVerifiedGeneric); + vtable[19] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[19] = d; + d = new _initConstraintsForVerification(initConstraintsForVerification); + vtable[20] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[20] = d; + d = new _canSkipMethodVerification(canSkipMethodVerification); + vtable[21] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[21] = d; + d = new _methodMustBeLoadedBeforeCodeIsRun(methodMustBeLoadedBeforeCodeIsRun); + vtable[22] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[22] = d; + d = new _mapMethodDeclToMethodImpl(mapMethodDeclToMethodImpl); + vtable[23] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[23] = d; + d = new _getGSCookie(getGSCookie); + vtable[24] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[24] = d; + d = new _resolveToken(resolveToken); + vtable[25] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[25] = d; + d = new _findSig(findSig); + vtable[26] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[26] = d; + d = new _findCallSiteSig(findCallSiteSig); + vtable[27] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[27] = d; + d = new _getTokenTypeAsHandle(getTokenTypeAsHandle); + vtable[28] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[28] = d; + d = new _canSkipVerification(canSkipVerification); + vtable[29] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[29] = d; + d = new _isValidToken(isValidToken); + vtable[30] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[30] = d; + d = new _isValidStringRef(isValidStringRef); + vtable[31] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[31] = d; + d = new _shouldEnforceCallvirtRestriction(shouldEnforceCallvirtRestriction); + vtable[32] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[32] = d; + d = new _asCorInfoType(asCorInfoType); + vtable[33] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[33] = d; + d = new _getClassName(getClassName); + vtable[34] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[34] = d; + d = new _appendClassName(appendClassName); + vtable[35] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[35] = d; + d = new _isValueClass(isValueClass); + vtable[36] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[36] = d; + d = new _canInlineTypeCheckWithObjectVTable(canInlineTypeCheckWithObjectVTable); + vtable[37] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[37] = d; + d = new _getClassAttribs(getClassAttribs); + vtable[38] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[38] = d; + d = new _isStructRequiringStackAllocRetBuf(isStructRequiringStackAllocRetBuf); + vtable[39] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[39] = d; + d = new _getClassModule(getClassModule); + vtable[40] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[40] = d; + d = new _getModuleAssembly(getModuleAssembly); + vtable[41] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[41] = d; + d = new _getAssemblyName(getAssemblyName); + vtable[42] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[42] = d; + d = new _LongLifetimeMalloc(LongLifetimeMalloc); + vtable[43] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[43] = d; + d = new _LongLifetimeFree(LongLifetimeFree); + vtable[44] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[44] = d; + d = new _getClassModuleIdForStatics(getClassModuleIdForStatics); + vtable[45] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[45] = d; + d = new _getClassSize(getClassSize); + vtable[46] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[46] = d; + d = new _getClassAlignmentRequirement(getClassAlignmentRequirement); + vtable[47] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[47] = d; + d = new _getClassGClayout(getClassGClayout); + vtable[48] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[48] = d; + d = new _getClassNumInstanceFields(getClassNumInstanceFields); + vtable[49] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[49] = d; + d = new _getFieldInClass(getFieldInClass); + vtable[50] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[50] = d; + d = new _checkMethodModifier(checkMethodModifier); + vtable[51] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[51] = d; + d = new _getNewHelper(getNewHelper); + vtable[52] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[52] = d; + d = new _getNewArrHelper(getNewArrHelper); + vtable[53] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[53] = d; + d = new _getCastingHelper(getCastingHelper); + vtable[54] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[54] = d; + d = new _getSharedCCtorHelper(getSharedCCtorHelper); + vtable[55] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[55] = d; + d = new _getSecurityPrologHelper(getSecurityPrologHelper); + vtable[56] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[56] = d; + d = new _getTypeForBox(getTypeForBox); + vtable[57] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[57] = d; + d = new _getBoxHelper(getBoxHelper); + vtable[58] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[58] = d; + d = new _getUnBoxHelper(getUnBoxHelper); + vtable[59] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[59] = d; + d = new _getReadyToRunHelper(getReadyToRunHelper); + vtable[60] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[60] = d; + d = new _getHelperName(getHelperName); + vtable[61] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[61] = d; + d = new _initClass(initClass); + vtable[62] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[62] = d; + d = new _classMustBeLoadedBeforeCodeIsRun(classMustBeLoadedBeforeCodeIsRun); + vtable[63] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[63] = d; + d = new _getBuiltinClass(getBuiltinClass); + vtable[64] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[64] = d; + d = new _getTypeForPrimitiveValueClass(getTypeForPrimitiveValueClass); + vtable[65] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[65] = d; + d = new _canCast(canCast); + vtable[66] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[66] = d; + d = new _areTypesEquivalent(areTypesEquivalent); + vtable[67] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[67] = d; + d = new _mergeClasses(mergeClasses); + vtable[68] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[68] = d; + d = new _getParentType(getParentType); + vtable[69] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[69] = d; + d = new _getChildType(getChildType); + vtable[70] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[70] = d; + d = new _satisfiesClassConstraints(satisfiesClassConstraints); + vtable[71] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[71] = d; + d = new _isSDArray(isSDArray); + vtable[72] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[72] = d; + d = new _getArrayRank(getArrayRank); + vtable[73] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[73] = d; + d = new _getArrayInitializationData(getArrayInitializationData); + vtable[74] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[74] = d; + d = new _canAccessClass(canAccessClass); + vtable[75] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[75] = d; + d = new _getFieldName(getFieldName); + vtable[76] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[76] = d; + d = new _getFieldClass(getFieldClass); + vtable[77] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[77] = d; + d = new _getFieldType(getFieldType); + vtable[78] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[78] = d; + d = new _getFieldOffset(getFieldOffset); + vtable[79] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[79] = d; + d = new _isWriteBarrierHelperRequired(isWriteBarrierHelperRequired); + vtable[80] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[80] = d; + d = new _getFieldInfo(getFieldInfo); + vtable[81] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[81] = d; + d = new _isFieldStatic(isFieldStatic); + vtable[82] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[82] = d; + d = new _getBoundaries(getBoundaries); + vtable[83] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[83] = d; + d = new _setBoundaries(setBoundaries); + vtable[84] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[84] = d; + d = new _getVars(getVars); + vtable[85] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[85] = d; + d = new _setVars(setVars); + vtable[86] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[86] = d; + d = new _allocateArray(allocateArray); + vtable[87] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[87] = d; + d = new _freeArray(freeArray); + vtable[88] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[88] = d; + d = new _getArgNext(getArgNext); + vtable[89] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[89] = d; + d = new _getArgType(getArgType); + vtable[90] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[90] = d; + d = new _getArgClass(getArgClass); + vtable[91] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[91] = d; + d = new _getHFAType(getHFAType); + vtable[92] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[92] = d; + d = new _GetErrorHRESULT(GetErrorHRESULT); + vtable[93] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[93] = d; + d = new _GetErrorMessage(GetErrorMessage); + vtable[94] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[94] = d; + d = new _FilterException(FilterException); + vtable[95] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[95] = d; + d = new _HandleException(HandleException); + vtable[96] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[96] = d; + d = new _ThrowExceptionForJitResult(ThrowExceptionForJitResult); + vtable[97] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[97] = d; + d = new _ThrowExceptionForHelper(ThrowExceptionForHelper); + vtable[98] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[98] = d; + d = new _getEEInfo(getEEInfo); + vtable[99] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[99] = d; + d = new _getJitTimeLogFilename(getJitTimeLogFilename); + vtable[100] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[100] = d; + d = new _getMethodDefFromMethod(getMethodDefFromMethod); + vtable[101] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[101] = d; + d = new _getMethodName(getMethodName); + vtable[102] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[102] = d; + d = new _getMethodHash(getMethodHash); + vtable[103] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[103] = d; + d = new _findNameOfToken(findNameOfToken); + vtable[104] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[104] = d; + d = new _getIntConfigValue(getIntConfigValue); + vtable[105] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[105] = d; + d = new _getStringConfigValue(getStringConfigValue); + vtable[106] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[106] = d; + d = new _freeStringConfigValue(freeStringConfigValue); + vtable[107] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[107] = d; + d = new _getThreadTLSIndex(getThreadTLSIndex); + vtable[108] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[108] = d; + d = new _getInlinedCallFrameVptr(getInlinedCallFrameVptr); + vtable[109] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[109] = d; + d = new _getAddrOfCaptureThreadGlobal(getAddrOfCaptureThreadGlobal); + vtable[110] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[110] = d; + d = new _getAddrModuleDomainID(getAddrModuleDomainID); + vtable[111] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[111] = d; + d = new _getHelperFtn(getHelperFtn); + vtable[112] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[112] = d; + d = new _getFunctionEntryPoint(getFunctionEntryPoint); + vtable[113] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[113] = d; + d = new _getFunctionFixedEntryPoint(getFunctionFixedEntryPoint); + vtable[114] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[114] = d; + d = new _getMethodSync(getMethodSync); + vtable[115] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[115] = d; + d = new _getLazyStringLiteralHelper(getLazyStringLiteralHelper); + vtable[116] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[116] = d; + d = new _embedModuleHandle(embedModuleHandle); + vtable[117] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[117] = d; + d = new _embedClassHandle(embedClassHandle); + vtable[118] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[118] = d; + d = new _embedMethodHandle(embedMethodHandle); + vtable[119] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[119] = d; + d = new _embedFieldHandle(embedFieldHandle); + vtable[120] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[120] = d; + d = new _embedGenericHandle(embedGenericHandle); + vtable[121] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[121] = d; + d = new _getLocationOfThisType(getLocationOfThisType); + vtable[122] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[122] = d; + d = new _getPInvokeUnmanagedTarget(getPInvokeUnmanagedTarget); + vtable[123] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[123] = d; + d = new _getAddressOfPInvokeFixup(getAddressOfPInvokeFixup); + vtable[124] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[124] = d; + d = new _GetCookieForPInvokeCalliSig(GetCookieForPInvokeCalliSig); + vtable[125] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[125] = d; + d = new _canGetCookieForPInvokeCalliSig(canGetCookieForPInvokeCalliSig); + vtable[126] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[126] = d; + d = new _getJustMyCodeHandle(getJustMyCodeHandle); + vtable[127] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[127] = d; + d = new _GetProfilingHandle(GetProfilingHandle); + vtable[128] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[128] = d; + d = new _getCallInfo(getCallInfo); + vtable[129] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[129] = d; + d = new _canAccessFamily(canAccessFamily); + vtable[130] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[130] = d; + d = new _isRIDClassDomainID(isRIDClassDomainID); + vtable[131] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[131] = d; + d = new _getClassDomainID(getClassDomainID); + vtable[132] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[132] = d; + d = new _getFieldAddress(getFieldAddress); + vtable[133] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[133] = d; + d = new _getVarArgsHandle(getVarArgsHandle); + vtable[134] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[134] = d; + d = new _canGetVarArgsHandle(canGetVarArgsHandle); + vtable[135] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[135] = d; + d = new _constructStringLiteral(constructStringLiteral); + vtable[136] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[136] = d; + d = new _emptyStringLiteral(emptyStringLiteral); + vtable[137] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[137] = d; + d = new _getFieldThreadLocalStoreID(getFieldThreadLocalStoreID); + vtable[138] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[138] = d; + d = new _setOverride(setOverride); + vtable[139] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[139] = d; + d = new _addActiveDependency(addActiveDependency); + vtable[140] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[140] = d; + d = new _GetDelegateCtor(GetDelegateCtor); + vtable[141] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[141] = d; + d = new _MethodCompileComplete(MethodCompileComplete); + vtable[142] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[142] = d; + d = new _getTailCallCopyArgsThunk(getTailCallCopyArgsThunk); + vtable[143] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[143] = d; + d = new _getMemoryManager(getMemoryManager); + vtable[144] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[144] = d; + d = new _allocMem(allocMem); + vtable[145] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[145] = d; + d = new _reserveUnwindInfo(reserveUnwindInfo); + vtable[146] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[146] = d; + d = new _allocUnwindInfo(allocUnwindInfo); + vtable[147] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[147] = d; + d = new _allocGCInfo(allocGCInfo); + vtable[148] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[148] = d; + d = new _yieldExecution(yieldExecution); + vtable[149] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[149] = d; + d = new _setEHcount(setEHcount); + vtable[150] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[150] = d; + d = new _setEHinfo(setEHinfo); + vtable[151] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[151] = d; + d = new _logMsg(logMsg); + vtable[152] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[152] = d; + d = new _doAssert(doAssert); + vtable[153] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[153] = d; + d = new _reportFatalError(reportFatalError); + vtable[154] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[154] = d; + d = new _allocBBProfileBuffer(allocBBProfileBuffer); + vtable[155] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[155] = d; + d = new _getBBProfileData(getBBProfileData); + vtable[156] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[156] = d; + d = new _recordCallSite(recordCallSite); + vtable[157] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[157] = d; + d = new _recordRelocation(recordRelocation); + vtable[158] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[158] = d; + d = new _getRelocTypeHint(getRelocTypeHint); + vtable[159] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[159] = d; + d = new _getModuleNativeEntryPointRange(getModuleNativeEntryPointRange); + vtable[160] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[160] = d; + d = new _getExpectedTargetArchitecture(getExpectedTargetArchitecture); + vtable[161] = Marshal.GetFunctionPointerForDelegate(d); + keepalive[161] = d; + + IntPtr instance = Marshal.AllocCoTaskMem(sizeof(IntPtr)); + *(IntPtr**)instance = vtable; + return instance; + } + } +} + diff --git a/src/JitInterface/src/CorInfoHelpFunc.cs b/src/JitInterface/src/CorInfoHelpFunc.cs new file mode 100644 index 00000000000..2de90dcfc25 --- /dev/null +++ b/src/JitInterface/src/CorInfoHelpFunc.cs @@ -0,0 +1,362 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Internal.JitInterface +{ +// CorInfoHelpFunc defines the set of helpers (accessed via the ICorDynamicInfo::getHelperFtn()) +// These helpers can be called by native code which executes in the runtime. +// Compilers can emit calls to these helpers. +// +// The signatures of the helpers are below (see RuntimeHelperArgumentCheck) +// +// NOTE: CorInfoHelpFunc is closely related to MdilHelpFunc!!! +// +// - changing the order of jit helper ordinals works fine +// However: +// - adding a jit helpers requires usually the addition of a corresponding MdilHelper +// - removing a jit helper (or changing its arguments) should be done only sparingly +// and needs discussion with an "MDIL person". +// Please have a look also at the comment prepending the definition of MdilHelpFunc +// + + public enum CorInfoHelpFunc + { + CORINFO_HELP_UNDEF, // invalid value. This should never be used + + /* Arithmetic helpers */ + + CORINFO_HELP_DIV, // For the ARM 32-bit integer divide uses a helper call :-( + CORINFO_HELP_MOD, + CORINFO_HELP_UDIV, + CORINFO_HELP_UMOD, + + CORINFO_HELP_LLSH, + CORINFO_HELP_LRSH, + CORINFO_HELP_LRSZ, + CORINFO_HELP_LMUL, + CORINFO_HELP_LMUL_OVF, + CORINFO_HELP_ULMUL_OVF, + CORINFO_HELP_LDIV, + CORINFO_HELP_LMOD, + CORINFO_HELP_ULDIV, + CORINFO_HELP_ULMOD, + CORINFO_HELP_LNG2DBL, // Convert a signed int64 to a double + CORINFO_HELP_ULNG2DBL, // Convert a unsigned int64 to a double + CORINFO_HELP_DBL2INT, + CORINFO_HELP_DBL2INT_OVF, + CORINFO_HELP_DBL2LNG, + CORINFO_HELP_DBL2LNG_OVF, + CORINFO_HELP_DBL2UINT, + CORINFO_HELP_DBL2UINT_OVF, + CORINFO_HELP_DBL2ULNG, + CORINFO_HELP_DBL2ULNG_OVF, + CORINFO_HELP_FLTREM, + CORINFO_HELP_DBLREM, + CORINFO_HELP_FLTROUND, + CORINFO_HELP_DBLROUND, + + /* Allocating a new object. Always use ICorClassInfo::getNewHelper() to decide + which is the right helper to use to allocate an object of a given type. */ + + CORINFO_HELP_NEW_CROSSCONTEXT, // cross context new object + CORINFO_HELP_NEWFAST, + CORINFO_HELP_NEWSFAST, // allocator for small, non-finalizer, non-array object + CORINFO_HELP_NEWSFAST_ALIGN8, // allocator for small, non-finalizer, non-array object, 8 byte aligned + CORINFO_HELP_NEW_MDARR, // multi-dim array helper (with or without lower bounds) + CORINFO_HELP_NEWARR_1_DIRECT, // helper for any one dimensional array creation + CORINFO_HELP_NEWARR_1_OBJ, // optimized 1-D object arrays + CORINFO_HELP_NEWARR_1_VC, // optimized 1-D value class arrays + CORINFO_HELP_NEWARR_1_ALIGN8, // like VC, but aligns the array start + + CORINFO_HELP_STRCNS, // create a new string literal + #if !RYUJIT_CTPBUILD + CORINFO_HELP_STRCNS_CURRENT_MODULE, // create a new string literal from the current module (used by NGen code) + #endif + /* Object model */ + + CORINFO_HELP_INITCLASS, // Initialize class if not already initialized + CORINFO_HELP_INITINSTCLASS, // Initialize class for instantiated type + + // Use ICorClassInfo::getCastingHelper to determine + // the right helper to use + + CORINFO_HELP_ISINSTANCEOFINTERFACE, // Optimized helper for interfaces + CORINFO_HELP_ISINSTANCEOFARRAY, // Optimized helper for arrays + CORINFO_HELP_ISINSTANCEOFCLASS, // Optimized helper for classes + CORINFO_HELP_ISINSTANCEOFANY, // Slow helper for any type + + CORINFO_HELP_CHKCASTINTERFACE, + CORINFO_HELP_CHKCASTARRAY, + CORINFO_HELP_CHKCASTCLASS, + CORINFO_HELP_CHKCASTANY, + CORINFO_HELP_CHKCASTCLASS_SPECIAL, // Optimized helper for classes. Assumes that the trivial cases + // has been taken care of by the inlined check + + CORINFO_HELP_BOX, + CORINFO_HELP_BOX_NULLABLE, // special form of boxing for Nullable + CORINFO_HELP_UNBOX, + CORINFO_HELP_UNBOX_NULLABLE, // special form of unboxing for Nullable + CORINFO_HELP_GETREFANY, // Extract the byref from a TypedReference, checking that it is the expected type + + CORINFO_HELP_ARRADDR_ST, // assign to element of object array with type-checking + CORINFO_HELP_LDELEMA_REF, // does a precise type comparision and returns address + + /* Exceptions */ + + CORINFO_HELP_THROW, // Throw an exception object + CORINFO_HELP_RETHROW, // Rethrow the currently active exception + CORINFO_HELP_USER_BREAKPOINT, // For a user program to break to the debugger + CORINFO_HELP_RNGCHKFAIL, // array bounds check failed + CORINFO_HELP_OVERFLOW, // throw an overflow exception + CORINFO_HELP_THROWDIVZERO, // throw a divide by zero exception + #if !RYUJIT_CTPBUILD + CORINFO_HELP_THROWNULLREF, // throw a null reference exception + #endif + + CORINFO_HELP_INTERNALTHROW, // Support for really fast jit + CORINFO_HELP_VERIFICATION, // Throw a VerificationException + CORINFO_HELP_SEC_UNMGDCODE_EXCPT, // throw a security unmanaged code exception + CORINFO_HELP_FAIL_FAST, // Kill the process avoiding any exceptions or stack and data dependencies (use for GuardStack unsafe buffer checks) + + CORINFO_HELP_METHOD_ACCESS_EXCEPTION,//Throw an access exception due to a failed member/class access check. + CORINFO_HELP_FIELD_ACCESS_EXCEPTION, + CORINFO_HELP_CLASS_ACCESS_EXCEPTION, + + CORINFO_HELP_ENDCATCH, // call back into the EE at the end of a catch block + + /* Synchronization */ + + CORINFO_HELP_MON_ENTER, + CORINFO_HELP_MON_EXIT, + CORINFO_HELP_MON_ENTER_STATIC, + CORINFO_HELP_MON_EXIT_STATIC, + + CORINFO_HELP_GETCLASSFROMMETHODPARAM, // Given a generics method handle, returns a class handle + CORINFO_HELP_GETSYNCFROMCLASSHANDLE, // Given a generics class handle, returns the sync monitor + // in its ManagedClassObject + + /* Security callout support */ + + CORINFO_HELP_SECURITY_PROLOG, // Required if CORINFO_FLG_SECURITYCHECK is set, or CORINFO_FLG_NOSECURITYWRAP is not set + CORINFO_HELP_SECURITY_PROLOG_FRAMED, // Slow version of CORINFO_HELP_SECURITY_PROLOG. Used for instrumentation. + + CORINFO_HELP_METHOD_ACCESS_CHECK, // Callouts to runtime security access checks + CORINFO_HELP_FIELD_ACCESS_CHECK, + CORINFO_HELP_CLASS_ACCESS_CHECK, + + CORINFO_HELP_DELEGATE_SECURITY_CHECK, // Callout to delegate security transparency check + + /* Verification runtime callout support */ + + CORINFO_HELP_VERIFICATION_RUNTIME_CHECK, // Do a Demand for UnmanagedCode permission at runtime + + /* GC support */ + + CORINFO_HELP_STOP_FOR_GC, // Call GC (force a GC) + CORINFO_HELP_POLL_GC, // Ask GC if it wants to collect + + CORINFO_HELP_STRESS_GC, // Force a GC, but then update the JITTED code to be a noop call + CORINFO_HELP_CHECK_OBJ, // confirm that ECX is a valid object pointer (debugging only) + + /* GC Write barrier support */ + + CORINFO_HELP_ASSIGN_REF, // universal helpers with F_CALL_CONV calling convention + CORINFO_HELP_CHECKED_ASSIGN_REF, + CORINFO_HELP_ASSIGN_REF_ENSURE_NONHEAP, // Do the store, and ensure that the target was not in the heap. + + CORINFO_HELP_ASSIGN_BYREF, + CORINFO_HELP_ASSIGN_STRUCT, + + + /* Accessing fields */ + + // For COM object support (using COM get/set routines to update object) + // and EnC and cross-context support + CORINFO_HELP_GETFIELD8, + CORINFO_HELP_SETFIELD8, + CORINFO_HELP_GETFIELD16, + CORINFO_HELP_SETFIELD16, + CORINFO_HELP_GETFIELD32, + CORINFO_HELP_SETFIELD32, + CORINFO_HELP_GETFIELD64, + CORINFO_HELP_SETFIELD64, + CORINFO_HELP_GETFIELDOBJ, + CORINFO_HELP_SETFIELDOBJ, + CORINFO_HELP_GETFIELDSTRUCT, + CORINFO_HELP_SETFIELDSTRUCT, + CORINFO_HELP_GETFIELDFLOAT, + CORINFO_HELP_SETFIELDFLOAT, + CORINFO_HELP_GETFIELDDOUBLE, + CORINFO_HELP_SETFIELDDOUBLE, + + CORINFO_HELP_GETFIELDADDR, + + CORINFO_HELP_GETSTATICFIELDADDR_CONTEXT, // Helper for context-static fields + CORINFO_HELP_GETSTATICFIELDADDR_TLS, // Helper for PE TLS fields + + // There are a variety of specialized helpers for accessing static fields. The JIT should use + // ICorClassInfo::getSharedStaticsOrCCtorHelper to determine which helper to use + + // Helpers for regular statics + CORINFO_HELP_GETGENERICS_GCSTATIC_BASE, + CORINFO_HELP_GETGENERICS_NONGCSTATIC_BASE, + CORINFO_HELP_GETSHARED_GCSTATIC_BASE, + CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE, + CORINFO_HELP_GETSHARED_GCSTATIC_BASE_NOCTOR, + CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE_NOCTOR, + CORINFO_HELP_GETSHARED_GCSTATIC_BASE_DYNAMICCLASS, + CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE_DYNAMICCLASS, + // Helper to class initialize shared generic with dynamicclass, but not get static field address + CORINFO_HELP_CLASSINIT_SHARED_DYNAMICCLASS, + + // Helpers for thread statics + CORINFO_HELP_GETGENERICS_GCTHREADSTATIC_BASE, + CORINFO_HELP_GETGENERICS_NONGCTHREADSTATIC_BASE, + CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE, + CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE, + CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR, + CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR, + CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_DYNAMICCLASS, + CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_DYNAMICCLASS, + + /* Debugger */ + + CORINFO_HELP_DBG_IS_JUST_MY_CODE, // Check if this is "JustMyCode" and needs to be stepped through. + + /* Profiling enter/leave probe addresses */ + CORINFO_HELP_PROF_FCN_ENTER, // record the entry to a method (caller) + CORINFO_HELP_PROF_FCN_LEAVE, // record the completion of current method (caller) + CORINFO_HELP_PROF_FCN_TAILCALL, // record the completionof current method through tailcall (caller) + + /* Miscellaneous */ + + CORINFO_HELP_BBT_FCN_ENTER, // record the entry to a method for collecting Tuning data + + CORINFO_HELP_PINVOKE_CALLI, // Indirect pinvoke call + CORINFO_HELP_TAILCALL, // Perform a tail call + + CORINFO_HELP_GETCURRENTMANAGEDTHREADID, + + CORINFO_HELP_INIT_PINVOKE_FRAME, // initialize an inlined PInvoke Frame for the JIT-compiler + + CORINFO_HELP_MEMSET, // Init block of memory + CORINFO_HELP_MEMCPY, // Copy block of memory + + CORINFO_HELP_RUNTIMEHANDLE_METHOD, // determine a type/field/method handle at run-time + CORINFO_HELP_RUNTIMEHANDLE_METHOD_LOG,// determine a type/field/method handle at run-time, with IBC logging + CORINFO_HELP_RUNTIMEHANDLE_CLASS, // determine a type/field/method handle at run-time + CORINFO_HELP_RUNTIMEHANDLE_CLASS_LOG,// determine a type/field/method handle at run-time, with IBC logging + + // These helpers are required for MDIL backward compatibility only. They are not used by current JITed code. + CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE_OBSOLETE, // Convert from a TypeHandle (native structure pointer) to RuntimeTypeHandle at run-time + #if RYUJIT_CTPBUILD + CORINFO_HELP_METHODDESC_TO_RUNTIMEMETHODHANDLE_MAYBENULL_OBSOLETE, // Convert from a MethodDesc (native structure pointer) to RuntimeMethodHandle at run-time + #endif + CORINFO_HELP_METHODDESC_TO_RUNTIMEMETHODHANDLE_OBSOLETE, // Convert from a MethodDesc (native structure pointer) to RuntimeMethodHandle at run-time + CORINFO_HELP_FIELDDESC_TO_RUNTIMEFIELDHANDLE_OBSOLETE, // Convert from a FieldDesc (native structure pointer) to RuntimeFieldHandle at run-time + + CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, // Convert from a TypeHandle (native structure pointer) to RuntimeType at run-time + CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL, // Convert from a TypeHandle (native structure pointer) to RuntimeType at run-time, the type may be null + CORINFO_HELP_METHODDESC_TO_STUBRUNTIMEMETHOD, // Convert from a MethodDesc (native structure pointer) to RuntimeMethodHandle at run-time + CORINFO_HELP_FIELDDESC_TO_STUBRUNTIMEFIELD, // Convert from a FieldDesc (native structure pointer) to RuntimeFieldHandle at run-time + + CORINFO_HELP_VIRTUAL_FUNC_PTR, // look up a virtual method at run-time + //CORINFO_HELP_VIRTUAL_FUNC_PTR_LOG, // look up a virtual method at run-time, with IBC logging + + #if !RYUJIT_CTPBUILD + // Not a real helpers. Instead of taking handle arguments, these helpers point to a small stub that loads the handle argument and calls the static helper. + CORINFO_HELP_READYTORUN_NEW, + CORINFO_HELP_READYTORUN_NEWARR_1, + CORINFO_HELP_READYTORUN_ISINSTANCEOF, + CORINFO_HELP_READYTORUN_CHKCAST, + CORINFO_HELP_READYTORUN_STATIC_BASE, + CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, + CORINFO_HELP_READYTORUN_DELEGATE_CTOR, + #endif + + #if REDHAWK + // these helpers are arbitrary since we don't have any relation to the actual CLR corinfo.h. + CORINFO_HELP_PINVOKE, // transition to preemptive mode for a pinvoke, frame in EAX + CORINFO_HELP_PINVOKE_2, // transition to preemptive mode for a pinvoke, frame in ESI / R10 + CORINFO_HELP_PINVOKE_RETURN, // return to cooperative mode from a pinvoke + CORINFO_HELP_REVERSE_PINVOKE, // transition to cooperative mode for a callback from native + CORINFO_HELP_REVERSE_PINVOKE_RETURN,// return to preemptive mode to return to native from managed + CORINFO_HELP_REGISTER_MODULE, // module load notification + CORINFO_HELP_CREATECOMMANDLINE, // get the command line from the system and return it for Main + CORINFO_HELP_VSD_INITIAL_TARGET, // all VSD indirection cells initially point to this function + CORINFO_HELP_NEW_FINALIZABLE, // allocate finalizable object + CORINFO_HELP_SHUTDOWN, // called when Main returns from a managed executable + CORINFO_HELP_CHECKARRAYSTORE, // checks that an array element assignment is of the right type + CORINFO_HELP_CHECK_VECTOR_ELEM_ADDR,// does a precise type check on the array element type + CORINFO_HELP_FLT2INT_OVF, // checked float->int conversion + CORINFO_HELP_FLT2LNG, // float->long conversion + CORINFO_HELP_FLT2LNG_OVF, // checked float->long conversion + CORINFO_HELP_FLTREM_REV, // Bartok helper for float remainder - uses reversed param order from CLR helper + CORINFO_HELP_DBLREM_REV, // Bartok helper for double remainder - uses reversed param order from CLR helper + CORINFO_HELP_HIJACKFORGCSTRESS, // this helper hijacks the caller for GC stress + CORINFO_HELP_INIT_GCSTRESS, // this helper initializes the runtime for GC stress + CORINFO_HELP_SUPPRESS_GCSTRESS, // disables gc stress + CORINFO_HELP_UNSUPPRESS_GCSTRESS, // re-enables gc stress + CORINFO_HELP_THROW_INTRA, // Throw an exception object to a hander within the method + CORINFO_HELP_THROW_INTER, // Throw an exception object to a hander within the caller + CORINFO_HELP_THROW_ARITHMETIC, // Throw the classlib-defined arithmetic exception + CORINFO_HELP_THROW_DIVIDE_BY_ZERO, // Throw the classlib-defined divide by zero exception + CORINFO_HELP_THROW_INDEX, // Throw the classlib-defined index out of range exception + CORINFO_HELP_THROW_OVERFLOW, // Throw the classlib-defined overflow exception + CORINFO_HELP_EHJUMP_SCALAR, // Helper to jump to a handler in a different method for EH dispatch. + CORINFO_HELP_EHJUMP_OBJECT, // Helper to jump to a handler in a different method for EH dispatch. + CORINFO_HELP_EHJUMP_BYREF, // Helper to jump to a handler in a different method for EH dispatch. + CORINFO_HELP_EHJUMP_SCALAR_GCSTRESS,// Helper to jump to a handler in a different method for EH dispatch. + CORINFO_HELP_EHJUMP_OBJECT_GCSTRESS,// Helper to jump to a handler in a different method for EH dispatch. + CORINFO_HELP_EHJUMP_BYREF_GCSTRESS, // Helper to jump to a handler in a different method for EH dispatch. + + // Bartok emits code with destination in ECX rather than EDX and only ever uses EDX as the reference + // register. It also only ever specifies the checked version. + CORINFO_HELP_CHECKED_ASSIGN_REF_EDX, // EDX hold GC ptr, want do a 'mov [ECX], EDX' and inform GC + #endif // REDHAWK + + CORINFO_HELP_EE_PRESTUB, // Not real JIT helper. Used in native images. + + CORINFO_HELP_EE_PRECODE_FIXUP, // Not real JIT helper. Used for Precode fixup in native images. + CORINFO_HELP_EE_PINVOKE_FIXUP, // Not real JIT helper. Used for PInvoke target fixup in native images. + CORINFO_HELP_EE_VSD_FIXUP, // Not real JIT helper. Used for VSD cell fixup in native images. + CORINFO_HELP_EE_EXTERNAL_FIXUP, // Not real JIT helper. Used for to fixup external method thunks in native images. + CORINFO_HELP_EE_VTABLE_FIXUP, // Not real JIT helper. Used for inherited vtable slot fixup in native images. + + CORINFO_HELP_EE_REMOTING_THUNK, // Not real JIT helper. Used for remoting precode in native images. + + CORINFO_HELP_EE_PERSONALITY_ROUTINE,// Not real JIT helper. Used in native images. + CORINFO_HELP_EE_PERSONALITY_ROUTINE_FILTER_FUNCLET,// Not real JIT helper. Used in native images to detect filter funclets. + + // + // Keep platform-specific helpers at the end so that the ids for the platform neutral helpers stay same accross platforms + // + + #if TARGET_X86 || _HOST_X86_ || REDHAWK // _HOST_X86_ is for altjit + // NOGC_WRITE_BARRIERS JIT helper calls + // Unchecked versions EDX is required to point into GC heap + CORINFO_HELP_ASSIGN_REF_EAX, // EAX holds GC ptr, do a 'mov [EDX], EAX' and inform GC + CORINFO_HELP_ASSIGN_REF_EBX, // EBX holds GC ptr, do a 'mov [EDX], EBX' and inform GC + CORINFO_HELP_ASSIGN_REF_ECX, // ECX holds GC ptr, do a 'mov [EDX], ECX' and inform GC + CORINFO_HELP_ASSIGN_REF_ESI, // ESI holds GC ptr, do a 'mov [EDX], ESI' and inform GC + CORINFO_HELP_ASSIGN_REF_EDI, // EDI holds GC ptr, do a 'mov [EDX], EDI' and inform GC + CORINFO_HELP_ASSIGN_REF_EBP, // EBP holds GC ptr, do a 'mov [EDX], EBP' and inform GC + + CORINFO_HELP_CHECKED_ASSIGN_REF_EAX, // These are the same as ASSIGN_REF above ... + CORINFO_HELP_CHECKED_ASSIGN_REF_EBX, // ... but also check if EDX points into heap. + CORINFO_HELP_CHECKED_ASSIGN_REF_ECX, + CORINFO_HELP_CHECKED_ASSIGN_REF_ESI, + CORINFO_HELP_CHECKED_ASSIGN_REF_EDI, + CORINFO_HELP_CHECKED_ASSIGN_REF_EBP, + #endif + + CORINFO_HELP_LOOP_CLONE_CHOICE_ADDR, // Return the reference to a counter to decide to take cloned path in debug stress. + CORINFO_HELP_DEBUG_LOG_LOOP_CLONING, // Print a message that a loop cloning optimization has occurred in debug mode. + + CORINFO_HELP_COUNT, + } +} diff --git a/src/JitInterface/src/CorInfoImpl.cs b/src/JitInterface/src/CorInfoImpl.cs new file mode 100644 index 00000000000..358c4a0f310 --- /dev/null +++ b/src/JitInterface/src/CorInfoImpl.cs @@ -0,0 +1,1295 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Text; +using System.Runtime.InteropServices; +using System.Reflection; + +using Internal.TypeSystem; +using Internal.TypeSystem.Ecma; + +using Internal.IL; + +using ILToNative; + +namespace Internal.JitInterface +{ + unsafe partial class CorInfoImpl + { + IntPtr _comp; + + [DllImport("kernel32.dll", SetLastError = true)] + extern static IntPtr LoadLibraryEx(string s, IntPtr handle, int flags); + + [DllImport("kernel32.dll")] + extern static IntPtr GetProcAddress(IntPtr handle, string s); + + [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)] + delegate IntPtr _getJIT(); + + IntPtr _jit; + + [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)] + delegate CorJitResult _compileMethod(IntPtr _this, IntPtr comp, ref CORINFO_METHOD_INFO info, uint flags, + out IntPtr nativeEntry, out uint codeSize); + + _compileMethod _compile; + + Compilation _compilation; + + public CorInfoImpl(Compilation compilation) + { + _compilation = compilation; + + _comp = CreateUnmanagedInstance(); + + string clrjitPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\clrjit.dll"; + IntPtr jit = LoadLibraryEx(clrjitPath, new IntPtr(0), 0x1300); + + IntPtr proc = GetProcAddress(jit, "getJit"); + if (proc == new IntPtr(0)) + throw new Exception("JIT initialization failed"); + + var getJIT = Marshal.GetDelegateForFunctionPointer<_getJIT>(proc); + _jit = getJIT(); + + _compile = Marshal.GetDelegateForFunctionPointer<_compileMethod>(**((IntPtr**)_jit)); + } + + public TextWriter Log + { + get + { + return _compilation.Log; + } + } + + public MethodCode CompileMethod(MethodDesc method) + { + try + { + CORINFO_METHOD_INFO methodInfo; + Get_CORINFO_METHOD_INFO(method, out methodInfo); + + uint flags = (uint)( + CorJitFlag.CORJIT_FLG_SKIP_VERIFICATION | + CorJitFlag.CORJIT_FLG_READYTORUN | + CorJitFlag.CORJIT_FLG_RELOC | + CorJitFlag.CORJIT_FLG_PREJIT); + + IntPtr nativeEntry; + uint codeSize; + _compile(_jit, _comp, ref methodInfo, flags, out nativeEntry, out codeSize); + + if (_relocs != null) + _relocs.Sort((x, y) => (x.Block != y.Block) ? (x.Block - y.Block) : (x.Offset - y.Offset)); + + return new MethodCode() + { + Code = _code, + ColdCode = _coldCode, + ROData = _roData, + + Relocs = (_relocs != null) ? _relocs.ToArray() : null + }; + } + finally + { + FlushPins(); + } + } + + // TODO: Free pins at the end of the compilation + Dictionary _pins = new Dictionary(); + + IntPtr GetPin(Object obj) + { + GCHandle handle; + if (!_pins.TryGetValue(obj, out handle)) + { + handle = GCHandle.Alloc(obj, GCHandleType.Pinned); + _pins.Add(obj, handle); + } + return handle.AddrOfPinnedObject(); + } + void FlushPins() + { + foreach (var pin in _pins) + pin.Value.Free(); + _pins.Clear(); + + _code = null; + _coldCode = null; + _roData = null; + _relocs = null; + } + + Dictionary _objectToHandle = new Dictionary(); + List _handleToObject = new List(); + + const int handleMultipler = 8; + const int handleBase = 0x420000; + + IntPtr ObjectToHandle(Object obj) + { + IntPtr handle; + if (!_objectToHandle.TryGetValue(obj, out handle)) + { + handle = (IntPtr)(8 * _handleToObject.Count + handleBase); + _handleToObject.Add(obj); + _objectToHandle.Add(obj, handle); + } + return handle; + } + + Object HandleToObject(IntPtr handle) + { + int index = ((int)handle - handleBase) / handleMultipler; + return _handleToObject[index]; + } + + MethodDesc HandleToObject(CORINFO_METHOD_STRUCT_* method) { return (MethodDesc)HandleToObject((IntPtr)method); } + CORINFO_METHOD_STRUCT_* ObjectToHandle(MethodDesc method) { return (CORINFO_METHOD_STRUCT_*)ObjectToHandle((Object)method); } + + TypeDesc HandleToObject(CORINFO_CLASS_STRUCT_* type) { return (TypeDesc)HandleToObject((IntPtr)type); } + CORINFO_CLASS_STRUCT_* ObjectToHandle(TypeDesc type) { return (CORINFO_CLASS_STRUCT_*)ObjectToHandle((Object)type); } + + FieldDesc HandleToObject(CORINFO_FIELD_STRUCT_* field) { return (FieldDesc)HandleToObject((IntPtr)field); } + CORINFO_FIELD_STRUCT_* ObjectToHandle(FieldDesc field) { return (CORINFO_FIELD_STRUCT_*)ObjectToHandle((Object)field); } + + bool Get_CORINFO_METHOD_INFO(MethodDesc method, out CORINFO_METHOD_INFO methodInfo) + { + var methodIL = _compilation.GetMethodIL(method); + if (methodIL == null) + { + methodInfo = default(CORINFO_METHOD_INFO); + return false; + } + + methodInfo.ftn = ObjectToHandle(method); + methodInfo.scope = (CORINFO_MODULE_STRUCT_*)ObjectToHandle(methodIL); + var ilCode = methodIL.GetILBytes(); + methodInfo.ILCode = (byte*)GetPin(ilCode); + methodInfo.ILCodeSize = (uint)ilCode.Length; + methodInfo.maxStack = (uint)methodIL.GetMaxStack(); + methodInfo.EHcount = (uint)methodIL.GetExceptionRegions().Length; + methodInfo.options = methodIL.GetInitLocals() ? CorInfoOptions.CORINFO_OPT_INIT_LOCALS : (CorInfoOptions)0; + methodInfo.regionKind = CorInfoRegionKind.CORINFO_REGION_NONE; + + Get_CORINFO_SIG_INFO(method, out methodInfo.args); + Get_CORINFO_SIG_INFO(methodIL.GetLocals(), out methodInfo.locals); + + return true; + } + + void Get_CORINFO_SIG_INFO(MethodDesc method, out CORINFO_SIG_INFO sig) + { + var signature = method.Signature; + + sig.callConv = (CorInfoCallConv)0; + if (!signature.IsStatic) sig.callConv |= CorInfoCallConv.CORINFO_CALLCONV_HASTHIS; + + TypeDesc returnType = signature.ReturnType; + + CorInfoType corInfoRetType = asCorInfoType(signature.ReturnType, out sig.retTypeClass); + sig._retType = (byte)corInfoRetType; + sig.retTypeSigClass = sig.retTypeClass; // The difference between the two is not relevant for ILToNative + + sig.flags = 0; // used by IL stubs code + + sig.numArgs = (ushort)signature.Length; + + sig.args = (CORINFO_ARG_LIST_STRUCT_ * )0; // CORINFO_ARG_LIST_STRUCT_ is argument index + + // TODO: Shared generic + sig.sigInst.classInst = null; + sig.sigInst.classInstCount = 0; + sig.sigInst.methInst = null; + sig.sigInst.methInstCount = 0; + + sig.pSig = (byte * )ObjectToHandle(signature); + sig.cbSig = 0; // Not used by the JIT + sig.scope = null; // Not used by the JIT + sig.token = 0; // Not used by the JIT + + // TODO: Shared generic + // if (ftn->RequiresInstArg()) + // { + // sig.callConv = (CorInfoCallConv)(sig.callConv | CORINFO_CALLCONV_PARAMTYPE); + // } + } + + void Get_CORINFO_SIG_INFO(TypeDesc[] locals, out CORINFO_SIG_INFO sig) + { + sig.callConv = CorInfoCallConv.CORINFO_CALLCONV_DEFAULT; + sig._retType = (byte)CorInfoType.CORINFO_TYPE_VOID; + sig.retTypeClass = null; + sig.retTypeSigClass = null; + sig.flags = (byte)CorInfoSigInfoFlags.CORINFO_SIGFLAG_IS_LOCAL_SIG; + + sig.numArgs = (ushort)locals.Length; + + sig.sigInst.classInst = null; + sig.sigInst.classInstCount = 0; + sig.sigInst.methInst = null; + sig.sigInst.methInstCount = 0; + + sig.args = (CORINFO_ARG_LIST_STRUCT_*)0; // CORINFO_ARG_LIST_STRUCT_ is argument index + + sig.pSig = (byte*)ObjectToHandle(locals); + sig.cbSig = 0; // Not used by the JIT + sig.scope = null; // Not used by the JIT + sig.token = 0; // Not used by the JIT + } + + CorInfoType asCorInfoType(TypeDesc type, out CORINFO_CLASS_STRUCT_* structType) + { + if (type.IsEnum) + { + type = type.UnderlyingType; + } + + if (type.IsPrimitive) + { + Debug.Assert((CorInfoType)TypeFlags.Void == CorInfoType.CORINFO_TYPE_VOID); + Debug.Assert((CorInfoType)TypeFlags.Double == CorInfoType.CORINFO_TYPE_DOUBLE); + + structType = null; + return (CorInfoType)type.Category; + } + + if (type.IsValueType) + { + structType = ObjectToHandle(type); + return CorInfoType.CORINFO_TYPE_VALUECLASS; + } + + structType = null; + return CorInfoType.CORINFO_TYPE_CLASS; + } + + uint getMethodAttribsInternal(MethodDesc method) + { + CorInfoFlag result = 0; + + EcmaMethod ecmaMethod = method.GetTypicalMethodDefinition() as EcmaMethod; + if (ecmaMethod != null) + { + var attribs = ecmaMethod.Attributes; + + // CORINFO_FLG_PROTECTED - verification only + + if ((attribs & MethodAttributes.Static) != 0) + result |= CorInfoFlag.CORINFO_FLG_STATIC; + + // TODO: if (pMD->IsSynchronized()) + // result |= CORINFO_FLG_SYNCH; + + // TODO: if (pMD->IsFCallOrIntrinsic()) + // result |= CORINFO_FLG_NOGCCHECK | CORINFO_FLG_INTRINSIC; + + if ((attribs & MethodAttributes.Virtual) != 0) + result |= CorInfoFlag.CORINFO_FLG_VIRTUAL; + if ((attribs & MethodAttributes.Abstract) != 0) + result |= CorInfoFlag.CORINFO_FLG_ABSTRACT; + if ((attribs & MethodAttributes.SpecialName) != 0) + { + string name = method.Name; + if (name == ".ctor" || name == ".cctor") + result |= CorInfoFlag.CORINFO_FLG_CONSTRUCTOR; + } + + // + // See if we need to embed a .cctor call at the head of the + // method body. + // + + EcmaType owningType = (EcmaType)method.OwningType; + + var typeAttribs = owningType.Attributes; + + // method or class might have the final bit + if ((attribs & MethodAttributes.Final) != 0 || (typeAttribs & TypeAttributes.Sealed) != 0) + result |= CorInfoFlag.CORINFO_FLG_FINAL; + + // TODO: Generics + // if (pMD->IsSharedByGenericInstantiations()) + // result |= CORINFO_FLG_SHAREDINST; + + if ((attribs & MethodAttributes.PinvokeImpl) != 0) + result |= CorInfoFlag.CORINFO_FLG_PINVOKE; + + // TODO: Cache inlining hits + // Check for an inlining directive. + + var implAttribs = ecmaMethod.ImplAttributes; + if ((implAttribs & MethodImplAttributes.NoInlining) != 0) + { + /* Function marked as not inlineable */ + result |= CorInfoFlag.CORINFO_FLG_DONT_INLINE; + } + else if ((implAttribs & MethodImplAttributes.AggressiveInlining) != 0) + { + result |= CorInfoFlag.CORINFO_FLG_FORCEINLINE; + } + + if (owningType.IsDelegate) + { + if (method.Name == "Invoke") + // This is now used to emit efficient invoke code for any delegate invoke, + // including multicast. + result |= CorInfoFlag.CORINFO_FLG_DELEGATE_INVOKE; + } + } + else + { + if (method.Signature.IsStatic) + result |= CorInfoFlag.CORINFO_FLG_STATIC; + } + + result |= CorInfoFlag.CORINFO_FLG_NOSECURITYWRAP; + + return (uint)result; + } + + uint getMethodAttribs(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn) + { + return getMethodAttribsInternal(HandleToObject(ftn)); + } + + void setMethodAttribs(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, CorInfoMethodRuntimeFlags attribs) + { + // TODO: Inlining + } + + void getMethodSig(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, CORINFO_SIG_INFO* sig, CORINFO_CLASS_STRUCT_* memberParent) + { + MethodDesc method = HandleToObject(ftn); + + Get_CORINFO_SIG_INFO(method, out *sig); + } + + [return: MarshalAs(UnmanagedType.I1)] + bool getMethodInfo(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref CORINFO_METHOD_INFO info) + { + return Get_CORINFO_METHOD_INFO(HandleToObject(ftn), out info); + } + + CorInfoInline canInline(IntPtr _this, CORINFO_METHOD_STRUCT_* callerHnd, CORINFO_METHOD_STRUCT_* calleeHnd, ref uint pRestrictions) + { + // TODO: Inlining + return CorInfoInline.INLINE_NEVER; + } + + void reportInliningDecision(IntPtr _this, CORINFO_METHOD_STRUCT_* inlinerHnd, CORINFO_METHOD_STRUCT_* inlineeHnd, CorInfoInline inlineResult, byte* reason) + { + } + + [return: MarshalAs(UnmanagedType.I1)] + bool canTailCall(IntPtr _this, CORINFO_METHOD_STRUCT_* callerHnd, CORINFO_METHOD_STRUCT_* declaredCalleeHnd, CORINFO_METHOD_STRUCT_* exactCalleeHnd, [MarshalAs(UnmanagedType.I1)]bool fIsTailPrefix) + { throw new NotImplementedException(); } + + void reportTailCallDecision(IntPtr _this, CORINFO_METHOD_STRUCT_* callerHnd, CORINFO_METHOD_STRUCT_* calleeHnd, [MarshalAs(UnmanagedType.I1)]bool fIsTailPrefix, CorInfoTailCall tailCallResult, byte* reason) + { + } + + void getEHinfo(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, uint EHnumber, ref CORINFO_EH_CLAUSE clause) + { throw new NotImplementedException(); } + + CORINFO_CLASS_STRUCT_* getMethodClass(IntPtr _this, CORINFO_METHOD_STRUCT_* method) + { + var m = HandleToObject(method); + return ObjectToHandle(m.OwningType); + } + + CORINFO_MODULE_STRUCT_* getMethodModule(IntPtr _this, CORINFO_METHOD_STRUCT_* method) + { throw new NotImplementedException(); } + void getMethodVTableOffset(IntPtr _this, CORINFO_METHOD_STRUCT_* method, ref uint offsetOfIndirection, ref uint offsetAfterIndirection) + { throw new NotImplementedException(); } + CorInfoIntrinsics getIntrinsicID(IntPtr _this, CORINFO_METHOD_STRUCT_* method) + { throw new NotImplementedException(); } + + [return: MarshalAs(UnmanagedType.I1)] + bool isInSIMDModule(IntPtr _this, CORINFO_CLASS_STRUCT_* classHnd) + { + // TODO: SIMD + return false; + } + + CorInfoUnmanagedCallConv getUnmanagedCallConv(IntPtr _this, CORINFO_METHOD_STRUCT_* method) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool pInvokeMarshalingRequired(IntPtr _this, CORINFO_METHOD_STRUCT_* method, CORINFO_SIG_INFO* callSiteSig) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool satisfiesMethodConstraints(IntPtr _this, CORINFO_CLASS_STRUCT_* parent, CORINFO_METHOD_STRUCT_* method) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool isCompatibleDelegate(IntPtr _this, CORINFO_CLASS_STRUCT_* objCls, CORINFO_CLASS_STRUCT_* methodParentCls, CORINFO_METHOD_STRUCT_* method, CORINFO_CLASS_STRUCT_* delegateCls, [MarshalAs(UnmanagedType.Bool)] ref bool pfIsOpenDelegate) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool isDelegateCreationAllowed(IntPtr _this, CORINFO_CLASS_STRUCT_* delegateHnd, CORINFO_METHOD_STRUCT_* calleeHnd) + { throw new NotImplementedException(); } + CorInfoInstantiationVerification isInstantiationOfVerifiedGeneric(IntPtr _this, CORINFO_METHOD_STRUCT_* method) + { throw new NotImplementedException(); } + void initConstraintsForVerification(IntPtr _this, CORINFO_METHOD_STRUCT_* method, [MarshalAs(UnmanagedType.Bool)] ref bool pfHasCircularClassConstraints, [MarshalAs(UnmanagedType.Bool)] ref bool pfHasCircularMethodConstraint) + { throw new NotImplementedException(); } + CorInfoCanSkipVerificationResult canSkipMethodVerification(IntPtr _this, CORINFO_METHOD_STRUCT_* ftnHandle) + { throw new NotImplementedException(); } + + void methodMustBeLoadedBeforeCodeIsRun(IntPtr _this, CORINFO_METHOD_STRUCT_* method) + { + } + + CORINFO_METHOD_STRUCT_* mapMethodDeclToMethodImpl(IntPtr _this, CORINFO_METHOD_STRUCT_* method) + { throw new NotImplementedException(); } + void getGSCookie(IntPtr _this, GSCookie* pCookieVal, GSCookie** ppCookieVal) + { throw new NotImplementedException(); } + + void resolveToken(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken) + { + var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); + + var result = methodIL.GetObject((int)pResolvedToken.token); + + pResolvedToken.hClass = null; + pResolvedToken.hMethod = null; + pResolvedToken.hField = null; + + if (result is MethodDesc) + { + MethodDesc method = result as MethodDesc; + pResolvedToken.hMethod = ObjectToHandle(method); + pResolvedToken.hClass = ObjectToHandle(method.OwningType); + } + else + if (result is FieldDesc) + { + FieldDesc field = result as FieldDesc; + pResolvedToken.hField = ObjectToHandle(field); + pResolvedToken.hClass = ObjectToHandle(field.OwningType); + } + else + { + pResolvedToken.hClass = ObjectToHandle((TypeDesc)result); + } + + pResolvedToken.pTypeSpec = null; + pResolvedToken.cbTypeSpec = 0; + pResolvedToken.pMethodSpec = null; + pResolvedToken.cbMethodSpec = 0; + } + + void findSig(IntPtr _this, CORINFO_MODULE_STRUCT_* module, uint sigTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig) + { throw new NotImplementedException(); } + void findCallSiteSig(IntPtr _this, CORINFO_MODULE_STRUCT_* module, uint methTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig) + { throw new NotImplementedException(); } + CORINFO_CLASS_STRUCT_* getTokenTypeAsHandle(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken) + { throw new NotImplementedException(); } + CorInfoCanSkipVerificationResult canSkipVerification(IntPtr _this, CORINFO_MODULE_STRUCT_* module) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool isValidToken(IntPtr _this, CORINFO_MODULE_STRUCT_* module, uint metaTOK) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool isValidStringRef(IntPtr _this, CORINFO_MODULE_STRUCT_* module, uint metaTOK) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool shouldEnforceCallvirtRestriction(IntPtr _this, CORINFO_MODULE_STRUCT_* scope) + { throw new NotImplementedException(); } + CorInfoType asCorInfoType(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + + byte* getClassName(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { + var type = HandleToObject(cls); + return (byte*)GetPin(StringToUTF8(type.Name)); + } + + int appendClassName(IntPtr _this, short** ppBuf, ref int pnBufLen, CORINFO_CLASS_STRUCT_* cls, [MarshalAs(UnmanagedType.Bool)]bool fNamespace, [MarshalAs(UnmanagedType.Bool)]bool fFullInst, [MarshalAs(UnmanagedType.Bool)]bool fAssembly) + { throw new NotImplementedException(); } + + [return: MarshalAs(UnmanagedType.Bool)] + bool isValueClass(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { + return HandleToObject(cls).IsValueType; + } + + [return: MarshalAs(UnmanagedType.Bool)] + bool canInlineTypeCheckWithObjectVTable(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + + uint getClassAttribs(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { + TypeDesc type = HandleToObject(cls); + return getClassAttribsInternal(type); + } + + uint getClassAttribsInternal(TypeDesc type) + { + // TODO: This method needs to implement: + // 1. GenericParameterType: CORINFO_FLG_GENERIC_TYPE_VARIABLE + // 2. Shared instantiation: IsCanonicalSubtype, IsRuntimeDeterminedSubtype: CORINFO_FLG_SHAREDINST + // 3. HasVariance: CORINFO_FLG_VARIANCE + // 4. Finalizer support: CORINFO_FLG_HAS_FINALIZER + + CorInfoFlag result = (CorInfoFlag)0; + + if (type.IsInterface) + result |= CorInfoFlag.CORINFO_FLG_INTERFACE; + + if (type.IsArray || type.IsString) + result |= CorInfoFlag.CORINFO_FLG_VAROBJSIZE; + + if (type.IsValueType) + { + result |= CorInfoFlag.CORINFO_FLG_VALUECLASS; + + // TODO + // if (type.IsUnsafeValueType) + // result |= CorInfoFlag.CORINFO_FLG_UNSAFE_VALUECLASS; + } + + // TODO + // if (type.ContainsPointers) + // result |= CorInfoFlag.CORINFO_FLG_CONTAINS_GC_PTR; + + var ecmaType = type.GetTypeDefinition() as EcmaType; + if (ecmaType != null) + { + var attr = ecmaType.Attributes; + if ((attr & TypeAttributes.BeforeFieldInit) != 0) + result |= CorInfoFlag.CORINFO_FLG_BEFOREFIELDINIT; + + if ((attr & TypeAttributes.Sealed) != 0) + result |= CorInfoFlag.CORINFO_FLG_FINAL; + } + + return (uint)result; + } + + [return: MarshalAs(UnmanagedType.Bool)] + bool isStructRequiringStackAllocRetBuf(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + CORINFO_MODULE_STRUCT_* getClassModule(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + CORINFO_ASSEMBLY_STRUCT_* getModuleAssembly(IntPtr _this, CORINFO_MODULE_STRUCT_* mod) + { throw new NotImplementedException(); } + byte* getAssemblyName(IntPtr _this, CORINFO_ASSEMBLY_STRUCT_* assem) + { throw new NotImplementedException(); } + + void* LongLifetimeMalloc(IntPtr _this, UIntPtr sz) + { + return (void*)Marshal.AllocCoTaskMem((int)sz); + } + + void LongLifetimeFree(IntPtr _this, void* obj) + { + Marshal.FreeCoTaskMem((IntPtr)obj); + } + + byte* getClassModuleIdForStatics(IntPtr _this, CORINFO_CLASS_STRUCT_* cls, CORINFO_MODULE_STRUCT_** pModule, void** ppIndirection) + { throw new NotImplementedException(); } + + uint getClassSize(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { + TypeDesc type = HandleToObject(cls); + if (type.IsValueType) + { + return (uint)((MetadataType)type).InstanceFieldSize; + } + else + { + return (uint)type.Context.Target.PointerSize; + } + } + + uint getClassAlignmentRequirement(IntPtr _this, CORINFO_CLASS_STRUCT_* cls, [MarshalAs(UnmanagedType.Bool)]bool fDoubleAlignHint) + { throw new NotImplementedException(); } + + uint getClassGClayout(IntPtr _this, CORINFO_CLASS_STRUCT_* cls, byte* gcPtrs) + { + uint result = 0; + + MetadataType type = (MetadataType)HandleToObject(cls); + + Debug.Assert(type.IsValueType); + + int pointerSize = type.Context.Target.PointerSize; + + int ptrsCount = AlignmentHelper.AlignUp(type.InstanceByteCount, pointerSize) / pointerSize; + + // Assume no GC pointers at first + for (int i = 0; i < ptrsCount; i++) + gcPtrs[i] = (byte)CorInfoGCType.TYPE_GC_NONE; + + if (type.ContainsPointers) + { + throw new NotImplementedException(); + } + return result; + } + + uint getClassNumInstanceFields(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { + TypeDesc type = HandleToObject(cls); + + uint result = 0; + foreach (var field in type.GetFields()) + { + if (!field.IsStatic) + result++; + } + + return result; + } + + CORINFO_FIELD_STRUCT_* getFieldInClass(IntPtr _this, CORINFO_CLASS_STRUCT_* clsHnd, int num) + { + TypeDesc classWithFields = HandleToObject(clsHnd); + + int iCurrentFoundField = -1; + foreach (var field in classWithFields.GetFields()) + { + if (field.IsStatic) + continue; + + ++iCurrentFoundField; + if (iCurrentFoundField == num) + { + return ObjectToHandle(field); + } + } + + // We could not find the field that was searched for. + throw new InvalidOperationException(); + } + + [return: MarshalAs(UnmanagedType.Bool)] + bool checkMethodModifier(IntPtr _this, CORINFO_METHOD_STRUCT_* hMethod, byte* modifier, [MarshalAs(UnmanagedType.Bool)]bool fOptional) + { throw new NotImplementedException(); } + CorInfoHelpFunc getNewHelper(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle) + { throw new NotImplementedException(); } + CorInfoHelpFunc getNewArrHelper(IntPtr _this, CORINFO_CLASS_STRUCT_* arrayCls) + { throw new NotImplementedException(); } + CorInfoHelpFunc getCastingHelper(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, [MarshalAs(UnmanagedType.I1)]bool fThrowing) + { throw new NotImplementedException(); } + CorInfoHelpFunc getSharedCCtorHelper(IntPtr _this, CORINFO_CLASS_STRUCT_* clsHnd) + { throw new NotImplementedException(); } + CorInfoHelpFunc getSecurityPrologHelper(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn) + { throw new NotImplementedException(); } + CORINFO_CLASS_STRUCT_* getTypeForBox(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + CorInfoHelpFunc getBoxHelper(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + CorInfoHelpFunc getUnBoxHelper(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + + void getReadyToRunHelper(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CorInfoHelpFunc id, ref CORINFO_CONST_LOOKUP pLookup) + { + pLookup.accessType = InfoAccessType.IAT_VALUE; + + switch (id) + { + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NEW: + { + var type = HandleToObject(pResolvedToken.hClass); + _compilation.AddType(type); + _compilation.MarkAsConstructed(type); + + pLookup.addr = (void*)ObjectToHandle(_compilation.GetReadyToRunHelper(ReadyToRunHelperId.NewHelper, type)); + } + break; + default: + throw new NotImplementedException(); + } + } + + byte* getHelperName(IntPtr _this, CorInfoHelpFunc helpFunc) + { throw new NotImplementedException(); } + + CorInfoInitClassResult initClass(IntPtr _this, CORINFO_FIELD_STRUCT_* field, CORINFO_METHOD_STRUCT_* method, CORINFO_CONTEXT_STRUCT* context, [MarshalAs(UnmanagedType.Bool)]bool speculative) + { + // TODO: Cctor triggers + return CorInfoInitClassResult.CORINFO_INITCLASS_NOT_REQUIRED; + } + + void classMustBeLoadedBeforeCodeIsRun(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { + } + + CORINFO_CLASS_STRUCT_* getBuiltinClass(IntPtr _this, CorInfoClassId classId) + { throw new NotImplementedException(); } + CorInfoType getTypeForPrimitiveValueClass(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool canCast(IntPtr _this, CORINFO_CLASS_STRUCT_* child, CORINFO_CLASS_STRUCT_* parent) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool areTypesEquivalent(IntPtr _this, CORINFO_CLASS_STRUCT_* cls1, CORINFO_CLASS_STRUCT_* cls2) + { throw new NotImplementedException(); } + CORINFO_CLASS_STRUCT_* mergeClasses(IntPtr _this, CORINFO_CLASS_STRUCT_* cls1, CORINFO_CLASS_STRUCT_* cls2) + { throw new NotImplementedException(); } + CORINFO_CLASS_STRUCT_* getParentType(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + CorInfoType getChildType(IntPtr _this, CORINFO_CLASS_STRUCT_* clsHnd, ref CORINFO_CLASS_STRUCT_* clsRet) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool satisfiesClassConstraints(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool isSDArray(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + uint getArrayRank(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + void* getArrayInitializationData(IntPtr _this, CORINFO_FIELD_STRUCT_* field, uint size) + { throw new NotImplementedException(); } + CorInfoIsAccessAllowedResult canAccessClass(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, ref CORINFO_HELPER_DESC pAccessHelper) + { throw new NotImplementedException(); } + + byte* getFieldName(IntPtr _this, CORINFO_FIELD_STRUCT_* ftn, byte** moduleName) + { + var field = HandleToObject(ftn); + if (moduleName != null) + { + throw new NotImplementedException(); + } + + return (byte*)GetPin(StringToUTF8(field.Name)); + } + + CORINFO_CLASS_STRUCT_* getFieldClass(IntPtr _this, CORINFO_FIELD_STRUCT_* field) + { throw new NotImplementedException(); } + + CorInfoType getFieldType(IntPtr _this, CORINFO_FIELD_STRUCT_* field, ref CORINFO_CLASS_STRUCT_* structType, CORINFO_CLASS_STRUCT_* memberParent) + { + var fieldDesc = HandleToObject(field); + return asCorInfoType(fieldDesc.FieldType, out structType); + } + + uint getFieldOffset(IntPtr _this, CORINFO_FIELD_STRUCT_* field) + { + var fieldDesc = HandleToObject(field); + + Debug.Assert(fieldDesc.Offset != FieldAndOffset.InvalidOffset); + + return (uint)fieldDesc.Offset; + } + + [return: MarshalAs(UnmanagedType.I1)] + bool isWriteBarrierHelperRequired(IntPtr _this, CORINFO_FIELD_STRUCT_* field) + { throw new NotImplementedException(); } + + void getFieldInfo(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, CORINFO_ACCESS_FLAGS flags, ref CORINFO_FIELD_INFO pResult) + { +#if DEBUG + // In debug, write some bogus data to the struct to ensure we have filled everything + // properly. + fixed (CORINFO_FIELD_INFO* tmp = &pResult) + MemoryHelper.FillMemory((byte*)tmp, 0xcc, Marshal.SizeOf(typeof(CORINFO_FIELD_INFO))); +#endif + + Debug.Assert(((int)flags & ((int)CORINFO_ACCESS_FLAGS.CORINFO_ACCESS_GET | + (int)CORINFO_ACCESS_FLAGS.CORINFO_ACCESS_SET | + (int)CORINFO_ACCESS_FLAGS.CORINFO_ACCESS_ADDRESS | + (int)CORINFO_ACCESS_FLAGS.CORINFO_ACCESS_INIT_ARRAY)) != 0); + + var field = HandleToObject(pResolvedToken.hField); + + CORINFO_FIELD_ACCESSOR fieldAccessor; + CORINFO_FIELD_FLAGS fieldFlags = (CORINFO_FIELD_FLAGS)0; + + if (field.IsStatic) + { + fieldFlags |= CORINFO_FIELD_FLAGS.CORINFO_FLG_FIELD_STATIC; + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_ADDRESS; + + // TODO: Shared statics/HasFieldRVA + throw new NotImplementedException(); + } + else + { + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_INSTANCE; + } + + if (field.IsInitOnly) + fieldFlags |= CORINFO_FIELD_FLAGS.CORINFO_FLG_FIELD_FINAL; + + pResult.fieldAccessor = fieldAccessor; + pResult.fieldFlags = fieldFlags; + pResult.fieldType = getFieldType(_this, pResolvedToken.hField, ref pResult.structType, pResolvedToken.hClass); + pResult.accessAllowed = CorInfoIsAccessAllowedResult.CORINFO_ACCESS_ALLOWED; + pResult.offset = (uint)field.Offset; + + // TODO: We need to implement access checks for fields and methods. See JitInterface.cpp in mrtjit + // and STS::AccessCheck::CanAccess. + } + + [return: MarshalAs(UnmanagedType.I1)] + bool isFieldStatic(IntPtr _this, CORINFO_FIELD_STRUCT_* fldHnd) + { + return HandleToObject(fldHnd).IsStatic; + } + + void getBoundaries(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref uint cILOffsets, ref uint* pILOffsets, BoundaryTypes* implicitBoundaries) + { + // TODO: Debugging + cILOffsets = 0; + pILOffsets = null; + *implicitBoundaries = BoundaryTypes.DEFAULT_BOUNDARIES; + } + void setBoundaries(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, uint cMap, OffsetMapping* pMap) + { + // TODO: Debugging + } + void getVars(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref uint cVars, ILVarInfo** vars, [MarshalAs(UnmanagedType.U1)] ref bool extendOthers) + { + // TODO: Debugging + + cVars = 0; + *vars = null; + + // Just tell the JIT to extend everything. + extendOthers = true; + } + void setVars(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, uint cVars, NativeVarInfo* vars) + { + // TODO: Debugging + } + + void* allocateArray(IntPtr _this, uint cBytes) + { + return (void *)Marshal.AllocCoTaskMem((int)cBytes); + } + + void freeArray(IntPtr _this, void* array) + { + Marshal.FreeCoTaskMem((IntPtr)array); + } + + CORINFO_ARG_LIST_STRUCT_* getArgNext(IntPtr _this, CORINFO_ARG_LIST_STRUCT_* args) + { + return (CORINFO_ARG_LIST_STRUCT_*)((int)args + 1); + } + + CorInfoTypeWithMod getArgType(IntPtr _this, CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_STRUCT_* args, ref CORINFO_CLASS_STRUCT_* vcTypeRet) + { + int index = (int)args; + Object sigObj = HandleToObject((IntPtr)sig->pSig); + + MethodSignature methodSig = sigObj as MethodSignature; + + if (methodSig != null) + { + TypeDesc type = methodSig[index]; + + CorInfoType corInfoType = asCorInfoType(type, out vcTypeRet); + return (CorInfoTypeWithMod)corInfoType; + } + else + { + TypeDesc type = ((TypeDesc[])sigObj)[index]; + + // TODO: Pinning + CorInfoType corInfoType = asCorInfoType(type, out vcTypeRet); + return (CorInfoTypeWithMod)corInfoType; + } + } + + CORINFO_CLASS_STRUCT_* getArgClass(IntPtr _this, CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_STRUCT_* args) + { + int index = (int)args; + Object sigObj = HandleToObject((IntPtr)sig->pSig); + + MethodSignature methodSig = sigObj as MethodSignature; + if (methodSig != null) + { + TypeDesc type = methodSig[index]; + return ObjectToHandle(type); + } + else + { + TypeDesc type = methodSig[index]; + + // TODO: Pinning + return ObjectToHandle(type); + } + } + + CorInfoType getHFAType(IntPtr _this, CORINFO_CLASS_STRUCT_* hClass) + { throw new NotImplementedException(); } + HRESULT GetErrorHRESULT(IntPtr _this, _EXCEPTION_POINTERS* pExceptionPointers) + { throw new NotImplementedException(); } + uint GetErrorMessage(IntPtr _this, short* buffer, uint bufferLength) + { throw new NotImplementedException(); } + int FilterException(IntPtr _this, _EXCEPTION_POINTERS* pExceptionPointers) + { throw new NotImplementedException(); } + void HandleException(IntPtr _this, _EXCEPTION_POINTERS* pExceptionPointers) + { throw new NotImplementedException(); } + void ThrowExceptionForJitResult(IntPtr _this, HRESULT result) + { throw new NotImplementedException(); } + void ThrowExceptionForHelper(IntPtr _this, ref CORINFO_HELPER_DESC throwHelper) + { throw new NotImplementedException(); } + void getEEInfo(IntPtr _this, ref CORINFO_EE_INFO pEEInfoOut) + { throw new NotImplementedException(); } + + [return: MarshalAs(UnmanagedType.LPWStr)] + string getJitTimeLogFilename(IntPtr _this) + { + return null; + } + + mdToken getMethodDefFromMethod(IntPtr _this, CORINFO_METHOD_STRUCT_* hMethod) + { throw new NotImplementedException(); } + + static byte[] StringToUTF8(string s) + { + int byteCount = Encoding.UTF8.GetByteCount(s); + byte[] bytes = new byte[byteCount + 1]; + Encoding.UTF8.GetBytes(s, 0, s.Length, bytes, 0); + return bytes; + } + + byte* getMethodName(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, byte** moduleName) + { + MethodDesc method = HandleToObject(ftn); + + if (moduleName != null) + { + EcmaType ecmaType = method.OwningType.GetTypeDefinition() as EcmaType; + if (ecmaType != null) + *moduleName = (byte *)GetPin(StringToUTF8(ecmaType.Name)); + else + *moduleName = (byte*)GetPin(StringToUTF8("unknown")); + } + + return (byte *)GetPin(StringToUTF8(method.Name)); + } + + uint getMethodHash(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn) + { + return (uint)HandleToObject(ftn).GetHashCode(); + } + + byte* findNameOfToken(IntPtr _this, CORINFO_MODULE_STRUCT_* moduleHandle, mdToken token, byte* szFQName, UIntPtr FQNameCapacity) + { throw new NotImplementedException(); } + int getIntConfigValue(IntPtr _this, String name, int defaultValue) + { throw new NotImplementedException(); } + short* getStringConfigValue(IntPtr _this, String name) + { throw new NotImplementedException(); } + void freeStringConfigValue(IntPtr _this, short* value) + { throw new NotImplementedException(); } + uint getThreadTLSIndex(IntPtr _this, ref void* ppIndirection) + { throw new NotImplementedException(); } + void* getInlinedCallFrameVptr(IntPtr _this, ref void* ppIndirection) + { throw new NotImplementedException(); } + int* getAddrOfCaptureThreadGlobal(IntPtr _this, ref void* ppIndirection) + { throw new NotImplementedException(); } + SIZE_T* getAddrModuleDomainID(IntPtr _this, CORINFO_MODULE_STRUCT_* module) + { throw new NotImplementedException(); } + void* getHelperFtn(IntPtr _this, CorInfoHelpFunc ftnNum, ref void* ppIndirection) + { throw new NotImplementedException(); } + void getFunctionEntryPoint(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref CORINFO_CONST_LOOKUP pResult, CORINFO_ACCESS_FLAGS accessFlags) + { throw new NotImplementedException(); } + void getFunctionFixedEntryPoint(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref CORINFO_CONST_LOOKUP pResult) + { throw new NotImplementedException(); } + void* getMethodSync(IntPtr _this, CORINFO_METHOD_STRUCT_* ftn, ref void* ppIndirection) + { throw new NotImplementedException(); } + CorInfoHelpFunc getLazyStringLiteralHelper(IntPtr _this, CORINFO_MODULE_STRUCT_* handle) + { throw new NotImplementedException(); } + CORINFO_MODULE_STRUCT_* embedModuleHandle(IntPtr _this, CORINFO_MODULE_STRUCT_* handle, ref void* ppIndirection) + { throw new NotImplementedException(); } + CORINFO_CLASS_STRUCT_* embedClassHandle(IntPtr _this, CORINFO_CLASS_STRUCT_* handle, ref void* ppIndirection) + { throw new NotImplementedException(); } + CORINFO_METHOD_STRUCT_* embedMethodHandle(IntPtr _this, CORINFO_METHOD_STRUCT_* handle, ref void* ppIndirection) + { throw new NotImplementedException(); } + CORINFO_FIELD_STRUCT_* embedFieldHandle(IntPtr _this, CORINFO_FIELD_STRUCT_* handle, ref void* ppIndirection) + { throw new NotImplementedException(); } + void embedGenericHandle(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, [MarshalAs(UnmanagedType.Bool)]bool fEmbedParent, ref CORINFO_GENERICHANDLE_RESULT pResult) + { throw new NotImplementedException(); } + CORINFO_LOOKUP_KIND getLocationOfThisType(IntPtr _this, CORINFO_METHOD_STRUCT_* context) + { throw new NotImplementedException(); } + void* getPInvokeUnmanagedTarget(IntPtr _this, CORINFO_METHOD_STRUCT_* method, ref void* ppIndirection) + { throw new NotImplementedException(); } + void* getAddressOfPInvokeFixup(IntPtr _this, CORINFO_METHOD_STRUCT_* method, ref void* ppIndirection) + { throw new NotImplementedException(); } + void* GetCookieForPInvokeCalliSig(IntPtr _this, CORINFO_SIG_INFO* szMetaSig, ref void* ppIndirection) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.I1)] + bool canGetCookieForPInvokeCalliSig(IntPtr _this, CORINFO_SIG_INFO* szMetaSig) + { throw new NotImplementedException(); } + CORINFO_JUST_MY_CODE_HANDLE_* getJustMyCodeHandle(IntPtr _this, CORINFO_METHOD_STRUCT_* method, ref CORINFO_JUST_MY_CODE_HANDLE_** ppIndirection) + { throw new NotImplementedException(); } + void GetProfilingHandle(IntPtr _this, [MarshalAs(UnmanagedType.Bool)] ref bool pbHookFunction, ref void* pProfilerHandle, [MarshalAs(UnmanagedType.Bool)] ref bool pbIndirectedHandles) + { throw new NotImplementedException(); } + + void getCallInfo(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESOLVED_TOKEN* pConstrainedResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, CORINFO_CALLINFO_FLAGS flags, ref CORINFO_CALL_INFO pResult) + { + // TODO: Constrained calls + if (pConstrainedResolvedToken != null) + throw new NotImplementedException(); + + MethodDesc method = HandleToObject(pResolvedToken.hMethod); + + // TODO: Interface methods + if (method.IsVirtual && method.OwningType.IsInterface) + throw new NotImplementedException(); + + pResult.hMethod = pResolvedToken.hMethod; + pResult.methodFlags = getMethodAttribsInternal(method); + + pResult.classFlags = getClassAttribsInternal(method.OwningType); + + Get_CORINFO_SIG_INFO(method, out pResult.sig); + + pResult.verMethodFlags = pResult.methodFlags; + pResult.verSig = pResult.sig; + + pResult.accessAllowed = CorInfoIsAccessAllowedResult.CORINFO_ACCESS_ALLOWED; + + // TODO: Constraint calls + pResult.thisTransform = CORINFO_THIS_TRANSFORM.CORINFO_NO_THIS_TRANSFORM; + + pResult.kind = CORINFO_CALL_KIND.CORINFO_CALL; + pResult._nullInstanceCheck = 0; + + // TODO: Generics + // pResult.contextHandle; + // pResult._exactContextNeedsRuntimeLookup + + // TODO: CORINFO_VIRTUALCALL_STUB + // TODO: CORINFO_CALL_CODE_POINTER + pResult.codePointerOrStubLookup.constLookup.accessType = InfoAccessType.IAT_VALUE; + + if (method.IsVirtual) + { + _compilation.AddVirtualSlot(method); + pResult.codePointerOrStubLookup.constLookup.addr = + (void *)ObjectToHandle(_compilation.GetReadyToRunHelper(ReadyToRunHelperId.VirtualCall, method)); + } + else + { + _compilation.AddMethod(method); + pResult.codePointerOrStubLookup.constLookup.addr = pResolvedToken.hMethod; + } + + + // TODO: Generics + // pResult.instParamLookup + } + + [return: MarshalAs(UnmanagedType.Bool)] + bool canAccessFamily(IntPtr _this, CORINFO_METHOD_STRUCT_* hCaller, CORINFO_CLASS_STRUCT_* hInstanceType) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.Bool)] + bool isRIDClassDomainID(IntPtr _this, CORINFO_CLASS_STRUCT_* cls) + { throw new NotImplementedException(); } + uint getClassDomainID(IntPtr _this, CORINFO_CLASS_STRUCT_* cls, ref void* ppIndirection) + { throw new NotImplementedException(); } + void* getFieldAddress(IntPtr _this, CORINFO_FIELD_STRUCT_* field, ref void* ppIndirection) + { throw new NotImplementedException(); } + IntPtr getVarArgsHandle(IntPtr _this, CORINFO_SIG_INFO* pSig, ref void* ppIndirection) + { throw new NotImplementedException(); } + [return: MarshalAs(UnmanagedType.I1)] + bool canGetVarArgsHandle(IntPtr _this, CORINFO_SIG_INFO* pSig) + { throw new NotImplementedException(); } + InfoAccessType constructStringLiteral(IntPtr _this, CORINFO_MODULE_STRUCT_* module, mdToken metaTok, ref void* ppValue) + { throw new NotImplementedException(); } + InfoAccessType emptyStringLiteral(IntPtr _this, ref void* ppValue) + { throw new NotImplementedException(); } + uint getFieldThreadLocalStoreID(IntPtr _this, CORINFO_FIELD_STRUCT_* field, ref void* ppIndirection) + { throw new NotImplementedException(); } + void setOverride(IntPtr _this, IntPtr pOverride, CORINFO_METHOD_STRUCT_* currentMethod) + { throw new NotImplementedException(); } + void addActiveDependency(IntPtr _this, CORINFO_MODULE_STRUCT_* moduleFrom, CORINFO_MODULE_STRUCT_* moduleTo) + { throw new NotImplementedException(); } + CORINFO_METHOD_STRUCT_* GetDelegateCtor(IntPtr _this, CORINFO_METHOD_STRUCT_* methHnd, CORINFO_CLASS_STRUCT_* clsHnd, CORINFO_METHOD_STRUCT_* targetMethodHnd, ref DelegateCtorArgs pCtorData) + { throw new NotImplementedException(); } + void MethodCompileComplete(IntPtr _this, CORINFO_METHOD_STRUCT_* methHnd) + { throw new NotImplementedException(); } + void* getTailCallCopyArgsThunk(IntPtr _this, CORINFO_SIG_INFO* pSig, CorInfoHelperTailCallSpecialHandling flags) + { throw new NotImplementedException(); } + + delegate IntPtr _ClrVirtualAlloc(IntPtr lpAddress, IntPtr dwSize, uint flAllocationType, uint flProtect); + static IntPtr ClrVirtualAlloc(IntPtr lpAddress, IntPtr dwSize, uint flAllocationType, uint flProtect) + { + return Marshal.AllocCoTaskMem((int)dwSize); + } + _ClrVirtualAlloc _clrVirtualAlloc; + + delegate bool _ClrVirtualFree(IntPtr lpAddress, IntPtr dwSize, uint dwFreeType); + static bool ClrVirtualFree(IntPtr lpAddress, IntPtr dwSize, uint dwFreeType) + { + Marshal.FreeCoTaskMem(lpAddress); + return true; + } + _ClrVirtualFree _clrVirtualFree; + + IntPtr _memoryManager; + + void* getMemoryManager(IntPtr _this) + { + if (_memoryManager != new IntPtr(0)) + return (void *)_memoryManager; + + int vtableSlots = 14; + IntPtr* vtable = (IntPtr*)Marshal.AllocCoTaskMem(sizeof(IntPtr) * vtableSlots); + for (int i = 0; i < vtableSlots; i++) vtable[i] = new IntPtr(0); + + // JIT only ever uses ClrVirtualAlloc/ClrVirtualFree + vtable[3] = Marshal.GetFunctionPointerForDelegate<_ClrVirtualAlloc>(_clrVirtualAlloc = new _ClrVirtualAlloc(ClrVirtualAlloc)); + vtable[4] = Marshal.GetFunctionPointerForDelegate<_ClrVirtualFree>(_clrVirtualFree = new _ClrVirtualFree(ClrVirtualFree)); + + IntPtr instance = Marshal.AllocCoTaskMem(sizeof(IntPtr)); + *(IntPtr**)instance = vtable; + + return (void*)(_memoryManager = instance); + } + + byte[] _code; + byte[] _coldCode; + byte[] _roData; + + void allocMem(IntPtr _this, uint hotCodeSize, uint coldCodeSize, uint roDataSize, uint xcptnsCount, CorJitAllocMemFlag flag, ref void* hotCodeBlock, ref void* coldCodeBlock, ref void* roDataBlock) + { + hotCodeBlock = (void *)GetPin(_code = new byte[hotCodeSize]); + + if (coldCodeSize != 0) + coldCodeBlock = (void *)GetPin(_coldCode = new byte[coldCodeSize]); + + if (roDataSize != 0) + roDataBlock = (void*)GetPin(_roData = new byte[roDataSize]); + } + + void reserveUnwindInfo(IntPtr _this, [MarshalAs(UnmanagedType.Bool)]bool isFunclet, [MarshalAs(UnmanagedType.Bool)]bool isColdCode, uint unwindSize) + { + } + + void allocUnwindInfo(IntPtr _this, byte* pHotCode, byte* pColdCode, uint startOffset, uint endOffset, uint unwindSize, byte* pUnwindBlock, CorJitFuncKind funcKind) + { + // TODO: Unwind Info + } + + void* allocGCInfo(IntPtr _this, UIntPtr size) + { + // TODO: GC Info + return (void *)GetPin(new byte[(int)size]); + } + + void yieldExecution(IntPtr _this) + { + // Nothing to do + } + + void setEHcount(IntPtr _this, uint cEH) + { + // TODO: EH + } + + void setEHinfo(IntPtr _this, uint EHnumber, ref CORINFO_EH_CLAUSE clause) + { + // TODO: EH + } + + [return: MarshalAs(UnmanagedType.Bool)] + bool logMsg(IntPtr _this, uint level, byte* fmt, IntPtr args) + { + // TODO: Use Encoding.GetString(byte* bytes, int byteCount) + // Console.WriteLine(new String((sbyte*)fmt)); + return false; + } + + int doAssert(IntPtr _this, byte* szFile, int iLine, byte* szExpr) + { + // TODO: Use Encoding.GetString(byte* bytes, int byteCount) + Log.WriteLine(new String((sbyte*)szFile) + ":" + iLine); + Log.WriteLine(new String((sbyte*)szExpr)); + + return 1; + } + + void reportFatalError(IntPtr _this, CorJitResult result) + { throw new NotImplementedException(); } + HRESULT allocBBProfileBuffer(IntPtr _this, uint count, ref ProfileBuffer* profileBuffer) + { throw new NotImplementedException(); } + HRESULT getBBProfileData(IntPtr _this, CORINFO_METHOD_STRUCT_* ftnHnd, ref uint count, ref ProfileBuffer* profileBuffer, ref uint numRuns) + { throw new NotImplementedException(); } + + void recordCallSite(IntPtr _this, uint instrOffset, CORINFO_SIG_INFO* callSig, CORINFO_METHOD_STRUCT_* methodHandle) + { + } + + List _relocs; + + int findKnownBlock(void *location, out int offset) + { + fixed (byte * pCode = _code) + { + if (pCode <= (byte*)location && (byte*)location < pCode + _code.Length) + { + offset = (int)((byte*)location - pCode); + return 0; + } + } + + if (_coldCode != null) + { + fixed (byte* pColdCode = _coldCode) + { + if (pColdCode <= (byte*)location && (byte*)location < pColdCode + _coldCode.Length) + { + offset = (int)((byte*)location - pColdCode); + return 1; + } + } + } + + if (_roData != null) + { + fixed (byte* pROData = _roData) + { + if (pROData <= (byte*)location && (byte*)location < pROData + _roData.Length) + { + offset = (int)((byte*)location - pROData); + return 2; + } + } + } + + offset = 0; + return -1; + } + + void recordRelocation(IntPtr _this, void* location, void* target, ushort fRelocType, ushort slotNum, int addlDelta) + { + Relocation reloc; + + reloc.RelocType = fRelocType; + + int locationBlock = findKnownBlock(location, out reloc.Offset); + Debug.Assert(locationBlock >= 0); + reloc.Block = (sbyte)locationBlock; + + reloc.Target = HandleToObject((IntPtr)target); + reloc.Delta = addlDelta; + + if (_relocs == null) + _relocs = new List(_code.Length / 32 + 1); + _relocs.Add(reloc); + } + + ushort getRelocTypeHint(IntPtr _this, void* target) + { throw new NotImplementedException(); } + void getModuleNativeEntryPointRange(IntPtr _this, ref void* pStart, ref void* pEnd) + { throw new NotImplementedException(); } + + uint getExpectedTargetArchitecture(IntPtr _this) + { + return 0x8664; // AMD64 + } + } +} diff --git a/src/JitInterface/src/CorInfoTypes.cs b/src/JitInterface/src/CorInfoTypes.cs new file mode 100644 index 00000000000..6dd5ac6c430 --- /dev/null +++ b/src/JitInterface/src/CorInfoTypes.cs @@ -0,0 +1,1354 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Runtime.InteropServices; + +namespace Internal.JitInterface +{ + public static class CORINFO + { + // CORINFO_MAXINDIRECTIONS is the maximum number of + // indirections used by runtime lookups. + // This accounts for up to 2 indirections to get at a dictionary followed by a possible spill slot + public const uint MAXINDIRECTIONS = 4; + public const ushort USEHELPER = 0xffff; + } + + public struct CORINFO_METHOD_STRUCT_ + { + internal static unsafe CORINFO_METHOD_STRUCT_* Construct(int i) + { + return (CORINFO_METHOD_STRUCT_*)((i+1) << 4); + } + + internal static unsafe int GetValue(CORINFO_METHOD_STRUCT_* val) + { + return ((int)val - 1) >> 4; + } + } + + public struct CORINFO_FIELD_STRUCT_ + { + internal static unsafe CORINFO_FIELD_STRUCT_* Construct(int i) + { + return (CORINFO_FIELD_STRUCT_*)((i+1) << 4); + } + internal static unsafe int GetValue(CORINFO_FIELD_STRUCT_* val) + { + return ((int)val - 1) >> 4; + } + } + + public struct CORINFO_CLASS_STRUCT_ + { + internal static unsafe CORINFO_CLASS_STRUCT_* Construct(int i) + { + return (CORINFO_CLASS_STRUCT_*)((i+1) << 4); + } + + internal static unsafe int GetValue(CORINFO_CLASS_STRUCT_* val) + { + return ((int)val - 1) >> 4; + } + } + + public struct CORINFO_ARG_LIST_STRUCT_ + { + } + + public struct CORINFO_MODULE_STRUCT_ + { + internal static unsafe CORINFO_MODULE_STRUCT_* Construct(int i) + { + return (CORINFO_MODULE_STRUCT_*)((i+1) << 4); + } + internal static unsafe int GetValue(CORINFO_MODULE_STRUCT_* val) + { + return ((int)val - 1) >> 4; + } + } + + public struct CORINFO_ASSEMBLY_STRUCT_ + { + } + + public struct CORINFO_CONTEXT_STRUCT + { + } + + public struct CORINFO_GENERIC_STRUCT_ + { + } + + public struct CORINFO_JUST_MY_CODE_HANDLE_ + { + } + + public struct CORINFO_VarArgInfo + { + } + + public enum _EXCEPTION_POINTERS + { } + + public unsafe struct CORINFO_SIG_INST + { + public uint classInstCount; + public CORINFO_CLASS_STRUCT_** classInst; // (representative, not exact) instantiation for class type variables in signature + public uint methInstCount; + public CORINFO_CLASS_STRUCT_** methInst; // (representative, not exact) instantiation for method type variables in signature + } + + public enum mdToken : uint + { } + + public enum CorTokenType + { + mdtModule = 0x00000000, + mdtTypeRef = 0x01000000, + mdtTypeDef = 0x02000000, + mdtFieldDef = 0x04000000, + mdtMethodDef = 0x06000000, + mdtParamDef = 0x08000000, + mdtInterfaceImpl = 0x09000000, + mdtMemberRef = 0x0a000000, + mdtCustomAttribute = 0x0c000000, + mdtPermission = 0x0e000000, + mdtSignature = 0x11000000, + mdtEvent = 0x14000000, + mdtProperty = 0x17000000, + mdtMethodImpl = 0x19000000, + mdtModuleRef = 0x1a000000, + mdtTypeSpec = 0x1b000000, + mdtAssembly = 0x20000000, + mdtAssemblyRef = 0x23000000, + mdtFile = 0x26000000, + mdtExportedType = 0x27000000, + mdtManifestResource = 0x28000000, + mdtGenericParam = 0x2a000000, + mdtMethodSpec = 0x2b000000, + mdtGenericParamConstraint = 0x2c000000, + + mdtString = 0x70000000, + mdtName = 0x71000000, + mdtBaseType = 0x72000000, + } + + public enum SIZE_T : ulong { } // Really should be IntPtr + + public enum GSCookie : ulong { } // Really should be IntPtr + + public enum HRESULT { } + + public unsafe struct CORINFO_SIG_INFO + { + public CorInfoCallConv callConv; + public CORINFO_CLASS_STRUCT_* retTypeClass; // if the return type is a value class, this is its handle (enums are normalized) + public CORINFO_CLASS_STRUCT_* retTypeSigClass;// returns the value class as it is in the sig (enums are not converted to primitives) + public byte _retType; + public byte flags; // used by IL stubs code + public ushort numArgs; + public CORINFO_SIG_INST sigInst; // information about how type variables are being instantiated in generic code + public CORINFO_ARG_LIST_STRUCT_* args; + public byte* pSig; + public uint cbSig; + public CORINFO_MODULE_STRUCT_* scope; // passed to getArgClass + public mdToken token; + + public CorInfoType retType { get { return (CorInfoType)_retType; } set { _retType = (byte)value; } } + CorInfoCallConv getCallConv() { return (CorInfoCallConv)((callConv & CorInfoCallConv.CORINFO_CALLCONV_MASK)); } + bool hasThis() { return ((callConv & CorInfoCallConv.CORINFO_CALLCONV_HASTHIS) != 0); } + bool hasExplicitThis() { return ((callConv & CorInfoCallConv.CORINFO_CALLCONV_EXPLICITTHIS) != 0); } + uint totalILArgs() { return (uint)(numArgs + (hasThis() ? 1 : 0)); } + bool isVarArg() { return ((getCallConv() == CorInfoCallConv.CORINFO_CALLCONV_VARARG) || (getCallConv() == CorInfoCallConv.CORINFO_CALLCONV_NATIVEVARARG)); } + bool hasTypeArg() { return ((callConv & CorInfoCallConv.CORINFO_CALLCONV_PARAMTYPE) != 0); } + }; + + //---------------------------------------------------------------------------- + // Looking up handles and addresses. + // + // When the JIT requests a handle, the EE may direct the JIT that it must + // access the handle in a variety of ways. These are packed as + // CORINFO_CONST_LOOKUP + // or CORINFO_LOOKUP (contains either a CORINFO_CONST_LOOKUP or a CORINFO_RUNTIME_LOOKUP) + // + // Constant Lookups v. Runtime Lookups (i.e. when will Runtime Lookups be generated?) + // ----------------------------------------------------------------------------------- + // + // CORINFO_LOOKUP_KIND is part of the result type of embedGenericHandle, + // getVirtualCallInfo and any other functions that may require a + // runtime lookup when compiling shared generic code. + // + // CORINFO_LOOKUP_KIND indicates whether a particular token in the instruction stream can be: + // (a) Mapped to a handle (type, field or method) at compile-time (!needsRuntimeLookup) + // (b) Must be looked up at run-time, and if so which runtime lookup technique should be used (see below) + // + // If the JIT or EE does not support code sharing for generic code, then + // all CORINFO_LOOKUP results will be "constant lookups", i.e. + // the needsRuntimeLookup of CORINFO_LOOKUP.lookupKind.needsRuntimeLookup + // will be false. + // + // Constant Lookups + // ---------------- + // + // Constant Lookups are either: + // IAT_VALUE: immediate (relocatable) values, + // IAT_PVALUE: immediate values access via an indirection through an immediate (relocatable) address + // IAT_PPVALUE: immediate values access via a double indirection through an immediate (relocatable) address + // + // Runtime Lookups + // --------------- + // + // CORINFO_LOOKUP_KIND is part of the result type of embedGenericHandle, + // getVirtualCallInfo and any other functions that may require a + // runtime lookup when compiling shared generic code. + // + // CORINFO_LOOKUP_KIND indicates whether a particular token in the instruction stream can be: + // (a) Mapped to a handle (type, field or method) at compile-time (!needsRuntimeLookup) + // (b) Must be looked up at run-time using the class dictionary + // stored in the vtable of the this pointer (needsRuntimeLookup && THISOBJ) + // (c) Must be looked up at run-time using the method dictionary + // stored in the method descriptor parameter passed to a generic + // method (needsRuntimeLookup && METHODPARAM) + // (d) Must be looked up at run-time using the class dictionary stored + // in the vtable parameter passed to a method in a generic + // struct (needsRuntimeLookup && CLASSPARAM) + + public unsafe struct CORINFO_CONST_LOOKUP + { + // If the handle is obtained at compile-time, then this handle is the "exact" handle (class, method, or field) + // Otherwise, it's a representative... + // If accessType is + // IAT_VALUE --> "handle" stores the real handle or "addr " stores the computed address + // IAT_PVALUE --> "addr" stores a pointer to a location which will hold the real handle + // IAT_PPVALUE --> "addr" stores a double indirection to a location which will hold the real handle + + public InfoAccessType accessType; + + // _value represent the union of handle and addr + private IntPtr _value; + public CORINFO_GENERIC_STRUCT_* handle { get { return (CORINFO_GENERIC_STRUCT_*)_value; } set { _value = (IntPtr)value; } } + public void* addr { get { return (void*)_value; } set { _value = (IntPtr)value; } } + }; + + public enum CORINFO_RUNTIME_LOOKUP_KIND + { + CORINFO_LOOKUP_THISOBJ, + CORINFO_LOOKUP_METHODPARAM, + CORINFO_LOOKUP_CLASSPARAM, + } + + public struct CORINFO_LOOKUP_KIND + { + private byte _needsRuntimeLookup; + public bool needsRuntimeLookup { get { return _needsRuntimeLookup != 0; } set { _needsRuntimeLookup = value ? (byte)1 : (byte)0; } } + public CORINFO_RUNTIME_LOOKUP_KIND runtimeLookupKind; + } + + // CORINFO_RUNTIME_LOOKUP indicates the details of the runtime lookup + // operation to be performed. + // + + public unsafe struct CORINFO_RUNTIME_LOOKUP + { + // This is signature you must pass back to the runtime lookup helper + public void* signature; + + // Here is the helper you must call. It is one of CORINFO_HELP_RUNTIMEHANDLE_* helpers. + public CorInfoHelpFunc helper; + + // Number of indirections to get there + // CORINFO_USEHELPER = don't know how to get it, so use helper function at run-time instead + // 0 = use the this pointer itself (e.g. token is C inside code in sealed class C) + // or method desc itself (e.g. token is method void M::mymeth() inside code in M::mymeth) + // Otherwise, follow each byte-offset stored in the "offsets[]" array (may be negative) + public ushort indirections; + + // If set, test for null and branch to helper if null + public byte _testForNull; + public bool testForNull { get { return _testForNull != 0; } set { _testForNull = value ? (byte)1 : (byte)0; } } + + // If set, test the lowest bit and dereference if set (see code:FixupPointer) + public byte _testForFixup; + public bool testForFixup { get { return _testForFixup != 0; } set { _testForFixup = value ? (byte)1 : (byte)0; } } + + public SIZE_T offset0; + public SIZE_T offset1; + public SIZE_T offset2; + public SIZE_T offset3; + } + + // Result of calling embedGenericHandle + [StructLayout(LayoutKind.Explicit)] + public struct CORINFO_LOOKUP + { + [FieldOffset(0)] + public CORINFO_LOOKUP_KIND lookupKind; + + // If kind.needsRuntimeLookup then this indicates how to do the lookup + [FieldOffset(8)] + public CORINFO_RUNTIME_LOOKUP runtimeLookup; + + // If the handle is obtained at compile-time, then this handle is the "exact" handle (class, method, or field) + // Otherwise, it's a representative... If accessType is + // IAT_VALUE --> "handle" stores the real handle or "addr " stores the computed address + // IAT_PVALUE --> "addr" stores a pointer to a location which will hold the real handle + // IAT_PPVALUE --> "addr" stores a double indirection to a location which will hold the real handle + [FieldOffset(8)] + public CORINFO_CONST_LOOKUP constLookup; + } + + public unsafe struct CORINFO_RESOLVED_TOKEN + { + // + // [In] arguments of resolveToken + // + public CORINFO_CONTEXT_STRUCT* tokenContext; //Context for resolution of generic arguments + public CORINFO_MODULE_STRUCT_* tokenScope; + public mdToken token; //The source token + public CorInfoTokenKind tokenType; + + // + // [Out] arguments of resolveToken. + // - Type handle is always non-NULL. + // - At most one of method and field handles is non-NULL (according to the token type). + // - Method handle is an instantiating stub only for generic methods. Type handle + // is required to provide the full context for methods in generic types. + // + public CORINFO_CLASS_STRUCT_* hClass; + public CORINFO_METHOD_STRUCT_* hMethod; + public CORINFO_FIELD_STRUCT_* hField; + + // + // [Out] TypeSpec and MethodSpec signatures for generics. NULL otherwise. + // + public byte* pTypeSpec; + public uint cbTypeSpec; + public byte* pMethodSpec; + public uint cbMethodSpec; + } + + + // Flags computed by a runtime compiler + public enum CorInfoMethodRuntimeFlags + { + CORINFO_FLG_BAD_INLINEE = 0x00000001, // The method is not suitable for inlining + CORINFO_FLG_VERIFIABLE = 0x00000002, // The method has verifiable code + CORINFO_FLG_UNVERIFIABLE = 0x00000004, // The method has unverifiable code + }; + + // The enumeration is returned in 'getSig' + + public enum CorInfoCallConv + { + // These correspond to CorCallingConvention + + CORINFO_CALLCONV_DEFAULT = 0x0, + CORINFO_CALLCONV_C = 0x1, + CORINFO_CALLCONV_STDCALL = 0x2, + CORINFO_CALLCONV_THISCALL = 0x3, + CORINFO_CALLCONV_FASTCALL = 0x4, + CORINFO_CALLCONV_VARARG = 0x5, + CORINFO_CALLCONV_FIELD = 0x6, + CORINFO_CALLCONV_LOCAL_SIG = 0x7, + CORINFO_CALLCONV_PROPERTY = 0x8, + CORINFO_CALLCONV_NATIVEVARARG = 0xb, // used ONLY for IL stub PInvoke vararg calls + + CORINFO_CALLCONV_MASK = 0x0f, // Calling convention is bottom 4 bits + CORINFO_CALLCONV_GENERIC = 0x10, + CORINFO_CALLCONV_HASTHIS = 0x20, + CORINFO_CALLCONV_EXPLICITTHIS = 0x40, + CORINFO_CALLCONV_PARAMTYPE = 0x80, // Passed last. Same as CORINFO_GENERICS_CTXT_FROM_PARAMTYPEARG + } + + public enum CorInfoUnmanagedCallConv + { + // These correspond to CorUnmanagedCallingConvention + + CORINFO_UNMANAGED_CALLCONV_UNKNOWN, + CORINFO_UNMANAGED_CALLCONV_C, + CORINFO_UNMANAGED_CALLCONV_STDCALL, + CORINFO_UNMANAGED_CALLCONV_THISCALL, + CORINFO_UNMANAGED_CALLCONV_FASTCALL + } + + public enum CORINFO_CALLINFO_FLAGS + { + CORINFO_CALLINFO_NONE = 0x0000, + CORINFO_CALLINFO_ALLOWINSTPARAM = 0x0001, // Can the compiler generate code to pass an instantiation parameters? Simple compilers should not use this flag + CORINFO_CALLINFO_CALLVIRT = 0x0002, // Is it a virtual call? + CORINFO_CALLINFO_KINDONLY = 0x0004, // This is set to only query the kind of call to perform, without getting any other information + CORINFO_CALLINFO_VERIFICATION = 0x0008, // Gets extra verification information. + CORINFO_CALLINFO_SECURITYCHECKS = 0x0010, // Perform security checks. + CORINFO_CALLINFO_LDFTN = 0x0020, // Resolving target of LDFTN + } + + // Bit-twiddling of contexts assumes word-alignment of method handles and type handles + // If this ever changes, some other encoding will be needed + public enum CorInfoContextFlags + { + CORINFO_CONTEXTFLAGS_METHOD = 0x00, // CORINFO_CONTEXT_HANDLE is really a CORINFO_METHOD_HANDLE + CORINFO_CONTEXTFLAGS_CLASS = 0x01, // CORINFO_CONTEXT_HANDLE is really a CORINFO_CLASS_HANDLE + CORINFO_CONTEXTFLAGS_MASK = 0x01 + }; + + public enum CorInfoSigInfoFlags + { + CORINFO_SIGFLAG_IS_LOCAL_SIG = 0x01, + CORINFO_SIGFLAG_IL_STUB = 0x02, + }; + + // These are returned from getMethodOptions + public enum CorInfoOptions + { + CORINFO_OPT_INIT_LOCALS = 0x00000010, // zero initialize all variables + + CORINFO_GENERICS_CTXT_FROM_THIS = 0x00000020, // is this shared generic code that access the generic context from the this pointer? If so, then if the method has SEH then the 'this' pointer must always be reported and kept alive. + CORINFO_GENERICS_CTXT_FROM_METHODDESC = 0x00000040, // is this shared generic code that access the generic context from the ParamTypeArg(that is a MethodDesc)? If so, then if the method has SEH then the 'ParamTypeArg' must always be reported and kept alive. Same as CORINFO_CALLCONV_PARAMTYPE + CORINFO_GENERICS_CTXT_FROM_METHODTABLE = 0x00000080, // is this shared generic code that access the generic context from the ParamTypeArg(that is a MethodTable)? If so, then if the method has SEH then the 'ParamTypeArg' must always be reported and kept alive. Same as CORINFO_CALLCONV_PARAMTYPE + CORINFO_GENERICS_CTXT_MASK = (CORINFO_GENERICS_CTXT_FROM_THIS | + CORINFO_GENERICS_CTXT_FROM_METHODDESC | + CORINFO_GENERICS_CTXT_FROM_METHODTABLE), + CORINFO_GENERICS_CTXT_KEEP_ALIVE = 0x00000100, // Keep the generics context alive throughout the method even if there is no explicit use, and report its location to the CLR + + } + + enum CorInfoIntrinsics + { + CORINFO_INTRINSIC_Sin, + CORINFO_INTRINSIC_Cos, + CORINFO_INTRINSIC_Sqrt, + CORINFO_INTRINSIC_Abs, + CORINFO_INTRINSIC_Round, + CORINFO_INTRINSIC_GetChar, // fetch character out of string + CORINFO_INTRINSIC_Array_GetDimLength, // Get number of elements in a given dimension of an array + CORINFO_INTRINSIC_Array_Get, // Get the value of an element in an array + CORINFO_INTRINSIC_Array_Address, // Get the address of an element in an array + CORINFO_INTRINSIC_Array_Set, // Set the value of an element in an array + CORINFO_INTRINSIC_StringGetChar, // fetch character out of string + CORINFO_INTRINSIC_StringLength, // get the length + CORINFO_INTRINSIC_InitializeArray, // initialize an array from static data + CORINFO_INTRINSIC_GetTypeFromHandle, + CORINFO_INTRINSIC_RTH_GetValueInternal, + CORINFO_INTRINSIC_TypeEQ, + CORINFO_INTRINSIC_TypeNEQ, + CORINFO_INTRINSIC_Object_GetType, + CORINFO_INTRINSIC_StubHelpers_GetStubContext, +// #ifdef _WIN64 + CORINFO_INTRINSIC_StubHelpers_GetStubContextAddr, +// #endif + CORINFO_INTRINSIC_StubHelpers_GetNDirectTarget, + CORINFO_INTRINSIC_InterlockedAdd32, + CORINFO_INTRINSIC_InterlockedAdd64, + CORINFO_INTRINSIC_InterlockedXAdd32, + CORINFO_INTRINSIC_InterlockedXAdd64, + CORINFO_INTRINSIC_InterlockedXchg32, + CORINFO_INTRINSIC_InterlockedXchg64, + CORINFO_INTRINSIC_InterlockedCmpXchg32, + CORINFO_INTRINSIC_InterlockedCmpXchg64, + CORINFO_INTRINSIC_MemoryBarrier, + CORINFO_INTRINSIC_GetCurrentManagedThread, + CORINFO_INTRINSIC_GetManagedThreadId, + + CORINFO_INTRINSIC_Count, + CORINFO_INTRINSIC_Illegal = -1, // Not a true intrinsic, + } + + // Can a value be accessed directly from JITed code. + public enum InfoAccessType + { + IAT_VALUE, // The info value is directly available + IAT_PVALUE, // The value needs to be accessed via an indirection + IAT_PPVALUE // The value needs to be accessed via a double indirection + } + + public enum CorInfoGCType + { + TYPE_GC_NONE, // no embedded objectrefs + TYPE_GC_REF, // Is an object ref + TYPE_GC_BYREF, // Is an interior pointer - promote it but don't scan it + TYPE_GC_OTHER // requires type-specific treatment + } + + public enum CorInfoClassId + { + CLASSID_SYSTEM_OBJECT, + CLASSID_TYPED_BYREF, + CLASSID_TYPE_HANDLE, + CLASSID_FIELD_HANDLE, + CLASSID_METHOD_HANDLE, + CLASSID_STRING, + CLASSID_ARGUMENT_HANDLE, + CLASSID_RUNTIME_TYPE, + } + public enum CorInfoInline + { + INLINE_PASS = 0, // Inlining OK + + // failures are negative + INLINE_FAIL = -1, // Inlining not OK for this case only + INLINE_NEVER = -2, // This method should never be inlined, regardless of context + } + + public enum CorInfoInlineRestrictions + { + INLINE_RESPECT_BOUNDARY = 0x00000001, // You can inline if there are no calls from the method being inlined + INLINE_NO_CALLEE_LDSTR = 0x00000002, // You can inline only if you guarantee that if inlinee does an ldstr + // inlinee's module will never see that string (by any means). + // This is due to how we implement the NoStringInterningAttribute + // (by reusing the fixup table). + INLINE_SAME_THIS = 0x00000004, // You can inline only if the callee is on the same this reference as caller +#if MDIL + INLINE_NOT_FOR_MDIL = 0x00000008, // You cannot inline this method for MDIL +#endif + } + + // If you add more values here, keep it in sync with TailCallTypeMap in ..\vm\ClrEtwAll.man + // and the string enum in CEEInfo::reportTailCallDecision in ..\vm\JITInterface.cpp + public enum CorInfoTailCall + { + TAILCALL_OPTIMIZED = 0, // Optimized tail call (epilog + jmp) + TAILCALL_RECURSIVE = 1, // Optimized into a loop (only when a method tail calls itself) + TAILCALL_HELPER = 2, // Helper assisted tail call (call to JIT_TailCall) + + // failures are negative + TAILCALL_FAIL = -1, // Couldn't do a tail call + } + + public enum CorInfoCanSkipVerificationResult + { + CORINFO_VERIFICATION_CANNOT_SKIP = 0, // Cannot skip verification during jit time. + CORINFO_VERIFICATION_CAN_SKIP = 1, // Can skip verification during jit time. + CORINFO_VERIFICATION_RUNTIME_CHECK = 2, // Cannot skip verification during jit time, + // but need to insert a callout to the VM to ask during runtime + // whether to raise a verification or not (if the method is unverifiable). + CORINFO_VERIFICATION_DONT_JIT = 3, // Cannot skip verification during jit time, + // but do not jit the method if is is unverifiable. + } + + public enum CorInfoInitClassResult + { + CORINFO_INITCLASS_NOT_REQUIRED = 0x00, // No class initialization required, but the class is not actually initialized yet + // (e.g. we are guaranteed to run the static constructor in method prolog) + CORINFO_INITCLASS_INITIALIZED = 0x01, // Class initialized + CORINFO_INITCLASS_SPECULATIVE = 0x02, // Class may be initialized speculatively + CORINFO_INITCLASS_USE_HELPER = 0x04, // The JIT must insert class initialization helper call. + CORINFO_INITCLASS_DONT_INLINE = 0x08, // The JIT should not inline the method requesting the class initialization. The class + // initialization requires helper class now, but will not require initialization + // if the method is compiled standalone. Or the method cannot be inlined due to some + // requirement around class initialization such as shared generics. + } + + public enum CORINFO_ACCESS_FLAGS + { + CORINFO_ACCESS_ANY = 0x0000, // Normal access + CORINFO_ACCESS_THIS = 0x0001, // Accessed via the this reference + CORINFO_ACCESS_UNWRAP = 0x0002, // Accessed via an unwrap reference + + CORINFO_ACCESS_NONNULL = 0x0004, // Instance is guaranteed non-null + + CORINFO_ACCESS_LDFTN = 0x0010, // Accessed via ldftn + + // Field access flags + CORINFO_ACCESS_GET = 0x0100, // Field get (ldfld) + CORINFO_ACCESS_SET = 0x0200, // Field set (stfld) + CORINFO_ACCESS_ADDRESS = 0x0400, // Field address (ldflda) + CORINFO_ACCESS_INIT_ARRAY = 0x0800, // Field use for InitializeArray + CORINFO_ACCESS_INLINECHECK = 0x8000, // Return fieldFlags and fieldAccessor only. Used by JIT64 during inlining. + } + + + // these are the attribute flags for fields and methods (getMethodAttribs) + [Flags] + enum CorInfoFlag : uint + { + // CORINFO_FLG_UNUSED = 0x00000001, + // CORINFO_FLG_UNUSED = 0x00000002, + CORINFO_FLG_PROTECTED = 0x00000004, + CORINFO_FLG_STATIC = 0x00000008, + CORINFO_FLG_FINAL = 0x00000010, + CORINFO_FLG_SYNCH = 0x00000020, + CORINFO_FLG_VIRTUAL = 0x00000040, + // CORINFO_FLG_UNUSED = 0x00000080, + CORINFO_FLG_NATIVE = 0x00000100, + // CORINFO_FLG_UNUSED = 0x00000200, + CORINFO_FLG_ABSTRACT = 0x00000400, + + CORINFO_FLG_EnC = 0x00000800, // member was added by Edit'n'Continue + + // These are internal flags that can only be on methods + CORINFO_FLG_FORCEINLINE = 0x00010000, // The method should be inlined if possible. + CORINFO_FLG_SHAREDINST = 0x00020000, // the code for this method is shared between different generic instantiations (also set on classes/types) + CORINFO_FLG_DELEGATE_INVOKE = 0x00040000, // "Delegate + CORINFO_FLG_PINVOKE = 0x00080000, // Is a P/Invoke call + CORINFO_FLG_SECURITYCHECK = 0x00100000, // Is one of the security routines that does a stackwalk (e.g. Assert, Demand) + CORINFO_FLG_NOGCCHECK = 0x00200000, // This method is FCALL that has no GC check. Don't put alone in loops + CORINFO_FLG_INTRINSIC = 0x00400000, // This method MAY have an intrinsic ID + CORINFO_FLG_CONSTRUCTOR = 0x00800000, // This method is an instance or type initializer + // CORINFO_FLG_UNUSED = 0x01000000, + // CORINFO_FLG_UNUSED = 0x02000000, + CORINFO_FLG_NOSECURITYWRAP = 0x04000000, // The method requires no security checks + CORINFO_FLG_DONT_INLINE = 0x10000000, // The method should not be inlined + CORINFO_FLG_DONT_INLINE_CALLER = 0x20000000, // The method should not be inlined, nor should its callers. It cannot be tail called. + // CORINFO_FLG_UNUSED = 0x40000000, + + // These are internal flags that can only be on Classes + CORINFO_FLG_VALUECLASS = 0x00010000, // is the class a value class + // This flag is define din the Methods section, but is also valid on classes. + // CORINFO_FLG_SHAREDINST = 0x00020000, // This class is satisfies TypeHandle::IsCanonicalSubtype + CORINFO_FLG_VAROBJSIZE = 0x00040000, // the object size varies depending of constructor args + CORINFO_FLG_ARRAY = 0x00080000, // class is an array class (initialized differently) + CORINFO_FLG_OVERLAPPING_FIELDS = 0x00100000, // struct or class has fields that overlap (aka union) + CORINFO_FLG_INTERFACE = 0x00200000, // it is an interface + CORINFO_FLG_CONTEXTFUL = 0x00400000, // is this a contextful class? + CORINFO_FLG_CUSTOMLAYOUT = 0x00800000, // does this struct have custom layout? + CORINFO_FLG_CONTAINS_GC_PTR = 0x01000000, // does the class contain a gc ptr ? + CORINFO_FLG_DELEGATE = 0x02000000, // is this a subclass of delegate or multicast delegate ? + CORINFO_FLG_MARSHAL_BYREF = 0x04000000, // is this a subclass of MarshalByRef ? + CORINFO_FLG_CONTAINS_STACK_PTR = 0x08000000, // This class has a stack pointer inside it + CORINFO_FLG_VARIANCE = 0x10000000, // MethodTable::HasVariance (sealed does *not* mean uncast-able) + CORINFO_FLG_BEFOREFIELDINIT = 0x20000000, // Additional flexibility for when to run .cctor (see code:#ClassConstructionFlags) + CORINFO_FLG_GENERIC_TYPE_VARIABLE = 0x40000000, // This is really a handle for a variable type + CORINFO_FLG_UNSAFE_VALUECLASS = 0x80000000, // Unsafe (C++'s /GS) value type + } + + + //---------------------------------------------------------------------------- + // Exception handling + + // These are the flags set on an CORINFO_EH_CLAUSE + public enum CORINFO_EH_CLAUSE_FLAGS + { + CORINFO_EH_CLAUSE_NONE = 0, + CORINFO_EH_CLAUSE_FILTER = 0x0001, // If this bit is on, then this EH entry is for a filter + CORINFO_EH_CLAUSE_FINALLY = 0x0002, // This clause is a finally clause + CORINFO_EH_CLAUSE_FAULT = 0x0004, // This clause is a fault clause +#if REDHAWK + CORINFO_EH_CLAUSE_METHOD_BOUNDARY = 0x0008, // This clause indicates the boundary of an inlined method + CORINFO_EH_CLAUSE_FAIL_FAST = 0x0010, // This clause will cause the exception to go unhandled + CORINFO_EH_CLAUSE_INDIRECT_TYPE_REFERENCE = 0x0020, // This clause is typed, but type reference is indirect. +#endif + }; + + public struct CORINFO_EH_CLAUSE + { + public CORINFO_EH_CLAUSE_FLAGS Flags; + public uint TryOffset; + public uint TryLength; + public uint HandlerOffset; + public uint HandlerLength; + public uint ClassTokenOrOffset; + /* union + { + DWORD ClassToken; // use for type-based exception handlers + DWORD FilterOffset; // use for filter-based exception handlers (COR_ILEXCEPTION_FILTER is set) + #ifdef REDHAWK + void * EETypeReference; // use to hold a ref to the EEType for type-based exception handlers. + #endif + };*/ + } + + public struct ProfileBuffer // Also defined here: code:CORBBTPROF_BLOCK_DATA + { + public uint ILOffset; + public uint ExecutionCount; + } + + // The enumeration is returned in 'getSig','getType', getArgType methods + public enum CorInfoType + { + CORINFO_TYPE_UNDEF = 0x0, + CORINFO_TYPE_VOID = 0x1, + CORINFO_TYPE_BOOL = 0x2, + CORINFO_TYPE_CHAR = 0x3, + CORINFO_TYPE_BYTE = 0x4, + CORINFO_TYPE_UBYTE = 0x5, + CORINFO_TYPE_SHORT = 0x6, + CORINFO_TYPE_USHORT = 0x7, + CORINFO_TYPE_INT = 0x8, + CORINFO_TYPE_UINT = 0x9, + CORINFO_TYPE_LONG = 0xa, + CORINFO_TYPE_ULONG = 0xb, + CORINFO_TYPE_NATIVEINT = 0xc, + CORINFO_TYPE_NATIVEUINT = 0xd, + CORINFO_TYPE_FLOAT = 0xe, + CORINFO_TYPE_DOUBLE = 0xf, + CORINFO_TYPE_STRING = 0x10, // Not used, should remove + CORINFO_TYPE_PTR = 0x11, + CORINFO_TYPE_BYREF = 0x12, + CORINFO_TYPE_VALUECLASS = 0x13, + CORINFO_TYPE_CLASS = 0x14, + CORINFO_TYPE_REFANY = 0x15, + + // CORINFO_TYPE_VAR is for a generic type variable. + // Generic type variables only appear when the JIT is doing + // verification (not NOT compilation) of generic code + // for the EE, in which case we're running + // the JIT in "import only" mode. + + CORINFO_TYPE_VAR = 0x16, + CORINFO_TYPE_COUNT, // number of jit types + } + + public enum CorInfoIsAccessAllowedResult + { + CORINFO_ACCESS_ALLOWED = 0, // Call allowed + CORINFO_ACCESS_ILLEGAL = 1, // Call not allowed + CORINFO_ACCESS_RUNTIME_CHECK = 2, // Ask at runtime whether to allow the call or not + } + + //---------------------------------------------------------------------------- + // Embedding type, method and field handles (for "ldtoken" or to pass back to helpers) + + // Result of calling embedGenericHandle + public unsafe struct CORINFO_GENERICHANDLE_RESULT + { + public CORINFO_LOOKUP lookup; + + // compileTimeHandle is guaranteed to be either NULL or a handle that is usable during compile time. + // It must not be embedded in the code because it might not be valid at run-time. + public CORINFO_GENERIC_STRUCT_* compileTimeHandle; + + // Type of the result + public CorInfoGenericHandleType handleType; + } + + public enum CorInfoGenericHandleType + { + CORINFO_HANDLETYPE_UNKNOWN, + CORINFO_HANDLETYPE_CLASS, + CORINFO_HANDLETYPE_METHOD, + CORINFO_HANDLETYPE_FIELD + } + + /* data to optimize delegate construction */ + public unsafe struct DelegateCtorArgs + { + public void* pMethod; + public void* pArg3; + public void* pArg4; + public void* pArg5; + } + + // When using CORINFO_HELPER_TAILCALL, the JIT needs to pass certain special + // calling convention/argument passing/handling details to the helper + public enum CorInfoHelperTailCallSpecialHandling + { + CORINFO_TAILCALL_NORMAL = 0x00000000, + CORINFO_TAILCALL_STUB_DISPATCH_ARG = 0x00000001, + } + + /*****************************************************************************/ + // These are flags passed to ICorJitInfo::allocMem + // to guide the memory allocation for the code, readonly data, and read-write data + public enum CorJitAllocMemFlag + { + CORJIT_ALLOCMEM_DEFAULT_CODE_ALIGN = 0x00000000, // The code will be use the normal alignment + CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN = 0x00000001, // The code will be 16-byte aligned + } + + public enum CorJitFuncKind + { + CORJIT_FUNC_ROOT, // The main/root function (always id==0) + CORJIT_FUNC_HANDLER, // a funclet associated with an EH handler (finally, fault, catch, filter handler) + CORJIT_FUNC_FILTER // a funclet associated with an EH filter + } + + + public unsafe struct CORINFO_METHOD_INFO + { + public CORINFO_METHOD_STRUCT_* ftn; + public CORINFO_MODULE_STRUCT_* scope; + public byte* ILCode; + public uint ILCodeSize; + public uint maxStack; + public uint EHcount; + public CorInfoOptions options; + public CorInfoRegionKind regionKind; + public CORINFO_SIG_INFO args; + public CORINFO_SIG_INFO locals; + } + // + // what type of code region we are in + // + public enum CorInfoRegionKind + { + CORINFO_REGION_NONE, + CORINFO_REGION_HOT, + CORINFO_REGION_COLD, + CORINFO_REGION_JIT, + } + + // This is for use when the JIT is compiling an instantiation + // of generic code. The JIT needs to know if the generic code itself + // (which can be verified once and for all independently of the + // instantiations) passed verification. + public enum CorInfoInstantiationVerification + { + // The method is NOT a concrete instantiation (eg. List.Add()) of a method + // in a generic class or a generic method. It is either the typical instantiation + // (eg. List.Add()) or entirely non-generic. + INSTVER_NOT_INSTANTIATION = 0, + + // The method is an instantiation of a method in a generic class or a generic method, + // and the generic class was successfully verified + INSTVER_GENERIC_PASSED_VERIFICATION = 1, + + // The method is an instantiation of a method in a generic class or a generic method, + // and the generic class failed verification + INSTVER_GENERIC_FAILED_VERIFICATION = 2, + }; + + public enum CorInfoTypeWithMod + { + CORINFO_TYPE_MASK = 0x3F, // lower 6 bits are type mask + CORINFO_TYPE_MOD_PINNED = 0x40, // can be applied to CLASS, or BYREF to indiate pinned + }; + + public struct CORINFO_HELPER_ARG + { + public IntPtr argHandle; +#if MDIL + public uint token; +#endif + public CorInfoAccessAllowedHelperArgType argType; + } + + public enum CorInfoAccessAllowedHelperArgType + { + CORINFO_HELPER_ARG_TYPE_Invalid = 0, + CORINFO_HELPER_ARG_TYPE_Field = 1, + CORINFO_HELPER_ARG_TYPE_Method = 2, + CORINFO_HELPER_ARG_TYPE_Class = 3, + CORINFO_HELPER_ARG_TYPE_Module = 4, + CORINFO_HELPER_ARG_TYPE_Const = 5, + } + + public struct CORINFO_HELPER_DESC + { + public CorInfoHelpFunc helperNum; + public uint numArgs; + public CORINFO_HELPER_ARG args0; + public CORINFO_HELPER_ARG args1; + public CORINFO_HELPER_ARG args2; + public CORINFO_HELPER_ARG args3; + } + + + public enum CORINFO_OS + { + CORINFO_WINNT, + CORINFO_PAL, + } + + + // For some highly optimized paths, the JIT must generate code that directly + // manipulates internal EE data structures. The getEEInfo() helper returns + // this structure containing the needed offsets and values. + public struct CORINFO_EE_INFO + { + // Information about the InlinedCallFrame structure layout + public struct InlinedCallFrameInfo + { + // Size of the Frame structure + public uint size; + + public uint offsetOfGSCookie; + public uint offsetOfFrameVptr; + public uint offsetOfFrameLink; + public uint offsetOfCallSiteSP; + public uint offsetOfCalleeSavedFP; + public uint offsetOfCallTarget; + public uint offsetOfReturnAddress; + } + public InlinedCallFrameInfo inlinedCallFrameInfo; + + // Offsets into the Thread structure + public uint offsetOfThreadFrame; // offset of the current Frame + public uint offsetOfGCState; // offset of the preemptive/cooperative state of the Thread + + // Delegate offsets + public uint offsetOfDelegateInstance; + public uint offsetOfDelegateFirstTarget; + + // Remoting offsets + public uint offsetOfTransparentProxyRP; + public uint offsetOfRealProxyServer; + + // Array offsets + public uint offsetOfObjArrayData; + + public CORINFO_OS osType; + public uint osMajor; + public uint osMinor; + public uint osBuild; + } + + public enum CORINFO_THIS_TRANSFORM + { + CORINFO_NO_THIS_TRANSFORM, + CORINFO_BOX_THIS, + CORINFO_DEREF_THIS + }; + + //---------------------------------------------------------------------------- + // getCallInfo and CORINFO_CALL_INFO: The EE instructs the JIT about how to make a call + // + // callKind + // -------- + // + // CORINFO_CALL : + // Indicates that the JIT can use getFunctionEntryPoint to make a call, + // i.e. there is nothing abnormal about the call. The JITs know what to do if they get this. + // Except in the case of constraint calls (see below), [targetMethodHandle] will hold + // the CORINFO_METHOD_HANDLE that a call to findMethod would + // have returned. + // This flag may be combined with nullInstanceCheck=TRUE for uses of callvirt on methods that can + // be resolved at compile-time (non-virtual, final or sealed). + // + // CORINFO_CALL_CODE_POINTER (shared generic code only) : + // Indicates that the JIT should do an indirect call to the entrypoint given by address, which may be specified + // as a runtime lookup by CORINFO_CALL_INFO::codePointerLookup. + // [targetMethodHandle] will not hold a valid value. + // This flag may be combined with nullInstanceCheck=TRUE for uses of callvirt on methods whose target method can + // be resolved at compile-time but whose instantiation can be resolved only through runtime lookup. + // + // CORINFO_VIRTUALCALL_STUB (interface calls) : + // Indicates that the EE supports "stub dispatch" and request the JIT to make a + // "stub dispatch" call (an indirect call through CORINFO_CALL_INFO::stubLookup, + // similar to CORINFO_CALL_CODE_POINTER). + // "Stub dispatch" is a specialized calling sequence (that may require use of NOPs) + // which allow the runtime to determine the call-site after the call has been dispatched. + // If the call is too complex for the JIT (e.g. because + // fetching the dispatch stub requires a runtime lookup, i.e. lookupKind.needsRuntimeLookup + // is set) then the JIT is allowed to implement the call as if it were CORINFO_VIRTUALCALL_LDVIRTFTN + // [targetMethodHandle] will hold the CORINFO_METHOD_HANDLE that a call to findMethod would + // have returned. + // This flag is always accompanied by nullInstanceCheck=TRUE. + // + // CORINFO_VIRTUALCALL_LDVIRTFTN (virtual generic methods) : + // Indicates that the EE provides no way to implement the call directly and + // that the JIT should use a LDVIRTFTN sequence (as implemented by CORINFO_HELP_VIRTUAL_FUNC_PTR) + // followed by an indirect call. + // [targetMethodHandle] will hold the CORINFO_METHOD_HANDLE that a call to findMethod would + // have returned. + // This flag is always accompanied by nullInstanceCheck=TRUE though typically the null check will + // be implicit in the access through the instance pointer. + // + // CORINFO_VIRTUALCALL_VTABLE (regular virtual methods) : + // Indicates that the EE supports vtable dispatch and that the JIT should use getVTableOffset etc. + // to implement the call. + // [targetMethodHandle] will hold the CORINFO_METHOD_HANDLE that a call to findMethod would + // have returned. + // This flag is always accompanied by nullInstanceCheck=TRUE though typically the null check will + // be implicit in the access through the instance pointer. + // + // thisTransform and constraint calls + // ---------------------------------- + // + // For evertyhing besides "constrained." calls "thisTransform" is set to + // CORINFO_NO_THIS_TRANSFORM. + // + // For "constrained." calls the EE attempts to resolve the call at compile + // time to a more specific method, or (shared generic code only) to a runtime lookup + // for a code pointer for the more specific method. + // + // In order to permit this, the "this" pointer supplied for a "constrained." call + // is a byref to an arbitrary type (see the IL spec). The "thisTransform" field + // will indicate how the JIT must transform the "this" pointer in order + // to be able to call the resolved method: + // + // CORINFO_NO_THIS_TRANSFORM --> Leave it as a byref to an unboxed value type + // CORINFO_BOX_THIS --> Box it to produce an object + // CORINFO_DEREF_THIS --> Deref the byref to get an object reference + // + // In addition, the "kind" field will be set as follows for constraint calls: + + // CORINFO_CALL --> the call was resolved at compile time, and + // can be compiled like a normal call. + // CORINFO_CALL_CODE_POINTER --> the call was resolved, but the target address will be + // computed at runtime. Only returned for shared generic code. + // CORINFO_VIRTUALCALL_STUB, + // CORINFO_VIRTUALCALL_LDVIRTFTN, + // CORINFO_VIRTUALCALL_VTABLE --> usual values indicating that a virtual call must be made + + public enum CORINFO_CALL_KIND + { + CORINFO_CALL, + CORINFO_CALL_CODE_POINTER, + CORINFO_VIRTUALCALL_STUB, + CORINFO_VIRTUALCALL_LDVIRTFTN, + CORINFO_VIRTUALCALL_VTABLE + }; + + + public unsafe struct CORINFO_CALL_INFO + { + public CORINFO_METHOD_STRUCT_* hMethod; //target method handle + public uint methodFlags; //flags for the target method + + public uint classFlags; //flags for CORINFO_RESOLVED_TOKEN::hClass + + public CORINFO_SIG_INFO sig; + + //Verification information + public uint verMethodFlags; // flags for CORINFO_RESOLVED_TOKEN::hMethod + public CORINFO_SIG_INFO verSig; + //All of the regular method data is the same... hMethod might not be the same as CORINFO_RESOLVED_TOKEN::hMethod + + + //If set to: + // - CORINFO_ACCESS_ALLOWED - The access is allowed. + // - CORINFO_ACCESS_ILLEGAL - This access cannot be allowed (i.e. it is public calling private). The + // JIT may either insert the callsiteCalloutHelper into the code (as per a verification error) or + // call throwExceptionFromHelper on the callsiteCalloutHelper. In this case callsiteCalloutHelper + // is guaranteed not to return. + // - CORINFO_ACCESS_RUNTIME_CHECK - The jit must insert the callsiteCalloutHelper at the call site. + // the helper may return + public CorInfoIsAccessAllowedResult accessAllowed; + public CORINFO_HELPER_DESC callsiteCalloutHelper; + + // See above section on constraintCalls to understand when these are set to unusual values. + public CORINFO_THIS_TRANSFORM thisTransform; + + public CORINFO_CALL_KIND kind; + public uint _nullInstanceCheck; + public bool nullInstanceCheck { get { return _nullInstanceCheck != 0; } set { _nullInstanceCheck = value ? (byte)1 : (byte)0; } } + + // Context for inlining and hidden arg + public CORINFO_CONTEXT_STRUCT* contextHandle; + public uint _exactContextNeedsRuntimeLookup; // Set if contextHandle is approx handle. Runtime lookup is required to get the exact handle. + public bool exactContextNeedsRuntimeLookup { get { return _exactContextNeedsRuntimeLookup != 0; } set { _exactContextNeedsRuntimeLookup = value ? (byte)1 : (byte)0; } } + + // If kind.CORINFO_VIRTUALCALL_STUB then stubLookup will be set. + // If kind.CORINFO_CALL_CODE_POINTER then entryPointLookup will be set. + public CORINFO_LOOKUP codePointerOrStubLookup; + + // Used by Ready-to-Run + public CORINFO_CONST_LOOKUP instParamLookup; + + } + + + //---------------------------------------------------------------------------- + // getFieldInfo and CORINFO_FIELD_INFO: The EE instructs the JIT about how to access a field + + public enum CORINFO_FIELD_ACCESSOR + { + CORINFO_FIELD_INSTANCE, // regular instance field at given offset from this-ptr + CORINFO_FIELD_INSTANCE_WITH_BASE, // instance field with base offset (used by Ready-to-Run) + CORINFO_FIELD_INSTANCE_HELPER, // instance field accessed using helper (arguments are this, FieldDesc * and the value) + CORINFO_FIELD_INSTANCE_ADDR_HELPER, // instance field accessed using address-of helper (arguments are this and FieldDesc *) + + CORINFO_FIELD_STATIC_ADDRESS, // field at given address + CORINFO_FIELD_STATIC_RVA_ADDRESS, // RVA field at given address + CORINFO_FIELD_STATIC_SHARED_STATIC_HELPER, // static field accessed using the "shared static" helper (arguments are ModuleID + ClassID) + CORINFO_FIELD_STATIC_GENERICS_STATIC_HELPER, // static field access using the "generic static" helper (argument is MethodTable *) + CORINFO_FIELD_STATIC_ADDR_HELPER, // static field accessed using address-of helper (argument is FieldDesc *) + CORINFO_FIELD_STATIC_TLS, // unmanaged TLS access + + CORINFO_FIELD_INTRINSIC_ZERO, // intrinsic zero (IntPtr.Zero, UIntPtr.Zero) + CORINFO_FIELD_INTRINSIC_EMPTY_STRING, // intrinsic emptry string (String.Empty) + } + + // Set of flags returned in CORINFO_FIELD_INFO::fieldFlags + public enum CORINFO_FIELD_FLAGS + { + CORINFO_FLG_FIELD_STATIC = 0x00000001, + CORINFO_FLG_FIELD_UNMANAGED = 0x00000002, // RVA field + CORINFO_FLG_FIELD_FINAL = 0x00000004, + CORINFO_FLG_FIELD_STATIC_IN_HEAP = 0x00000008, // See code:#StaticFields. This static field is in the GC heap as a boxed object + CORINFO_FLG_FIELD_SAFESTATIC_BYREF_RETURN = 0x00000010, // Field can be returned safely (has GC heap lifetime) + CORINFO_FLG_FIELD_INITCLASS = 0x00000020, // initClass has to be called before accessing the field + CORINFO_FLG_FIELD_PROTECTED = 0x00000040, + } + + public unsafe struct CORINFO_FIELD_INFO + { + public CORINFO_FIELD_ACCESSOR fieldAccessor; + public CORINFO_FIELD_FLAGS fieldFlags; + + // Helper to use if the field access requires it + public CorInfoHelpFunc helper; + + // Field offset if there is one + public uint offset; + + public CorInfoType fieldType; + public CORINFO_CLASS_STRUCT_* structType; //possibly null + + //See CORINFO_CALL_INFO.accessAllowed + public CorInfoIsAccessAllowedResult accessAllowed; + public CORINFO_HELPER_DESC accessCalloutHelper; + + // Used by Ready-to-Run + public CORINFO_CONST_LOOKUP fieldLookup; + + }; + + + // DEBUGGER DATQA + public enum BoundaryTypes + { + NO_BOUNDARIES = 0x00, // No implicit boundaries + STACK_EMPTY_BOUNDARIES = 0x01, // Boundary whenever the IL evaluation stack is empty + NOP_BOUNDARIES = 0x02, // Before every CEE_NOP instruction + CALL_SITE_BOUNDARIES = 0x04, // Before every CEE_CALL, CEE_CALLVIRT, etc instruction + + // Set of boundaries that debugger should always reasonably ask the JIT for. + DEFAULT_BOUNDARIES = STACK_EMPTY_BOUNDARIES | NOP_BOUNDARIES | CALL_SITE_BOUNDARIES + } + + // Note that SourceTypes can be OR'd together - it's possible that + // a sequence point will also be a stack_empty point, and/or a call site. + // The debugger will check to see if a boundary offset's source field & + // SEQUENCE_POINT is true to determine if the boundary is a sequence point. + [Flags] + public enum SourceTypes + { + SOURCE_TYPE_INVALID = 0x00, // To indicate that nothing else applies + SEQUENCE_POINT = 0x01, // The debugger asked for it. + STACK_EMPTY = 0x02, // The stack is empty here + CALL_SITE = 0x04, // This is a call site. + NATIVE_END_OFFSET_UNKNOWN = 0x08, // Indicates a epilog endpoint + CALL_INSTRUCTION = 0x10 // The actual instruction of a call. + + }; + + public struct OffsetMapping + { + public uint nativeOffset; + public uint ilOffset; + public SourceTypes source; // The debugger needs this so that + // we don't put Edit and Continue breakpoints where + // the stack isn't empty. We can put regular breakpoints + // there, though, so we need a way to discriminate + // between offsets. + }; + + public struct ILVarInfo + { + public uint startOffset; + public uint endOffset; + public uint varNumber; + }; + + public struct NativeVarInfo + { + public uint startOffset; + public uint endOffset; + public uint varNumber; + public VarLoc loc; + }; + + + // VarLoc describes the location of a native variable. Note that currently, VLT_REG_BYREF and VLT_STK_BYREF + // are only used for value types on X64. + + public enum VarLocType + { + VLT_REG, // variable is in a register + VLT_REG_BYREF, // address of the variable is in a register + VLT_REG_FP, // variable is in an fp register + VLT_STK, // variable is on the stack (memory addressed relative to the frame-pointer) + VLT_STK_BYREF, // address of the variable is on the stack (memory addressed relative to the frame-pointer) + VLT_REG_REG, // variable lives in two registers + VLT_REG_STK, // variable lives partly in a register and partly on the stack + VLT_STK_REG, // reverse of VLT_REG_STK + VLT_STK2, // variable lives in two slots on the stack + VLT_FPSTK, // variable lives on the floating-point stack + VLT_FIXED_VA, // variable is a fixed argument in a varargs function (relative to VARARGS_HANDLE) + + VLT_COUNT, + VLT_INVALID, +#if MDIL + VLT_MDIL_SYMBOLIC = 0x20 +#endif + + }; + + public struct VarLoc + { + public VarLocType vlType; + + public int A; // Representing a union in C# is difficult. + public int B; + public int C; + /* + union + { + // VLT_REG/VLT_REG_FP -- Any pointer-sized enregistered value (TYP_INT, TYP_REF, etc) + // eg. EAX + // VLT_REG_BYREF -- the specified register contains the address of the variable + // eg. [EAX] + + struct + { + RegNum vlrReg; + } vlReg; + + // VLT_STK -- Any 32 bit value which is on the stack + // eg. [ESP+0x20], or [EBP-0x28] + // VLT_STK_BYREF -- the specified stack location contains the address of the variable + // eg. mov EAX, [ESP+0x20]; [EAX] + + struct + { + RegNum vlsBaseReg; + signed vlsOffset; + } vlStk; + + // VLT_REG_REG -- TYP_LONG with both DWords enregistred + // eg. RBM_EAXEDX + + struct + { + RegNum vlrrReg1; + RegNum vlrrReg2; + } vlRegReg; + + // VLT_REG_STK -- Partly enregistered TYP_LONG + // eg { LowerDWord=EAX UpperDWord=[ESP+0x8] } + + struct + { + RegNum vlrsReg; + struct + { + RegNum vlrssBaseReg; + signed vlrssOffset; + } vlrsStk; + } vlRegStk; + + // VLT_STK_REG -- Partly enregistered TYP_LONG + // eg { LowerDWord=[ESP+0x8] UpperDWord=EAX } + + struct + { + struct + { + RegNum vlsrsBaseReg; + signed vlsrsOffset; + } vlsrStk; + RegNum vlsrReg; + } vlStkReg; + + // VLT_STK2 -- Any 64 bit value which is on the stack, + // in 2 successsive DWords. + // eg 2 DWords at [ESP+0x10] + + struct + { + RegNum vls2BaseReg; + signed vls2Offset; + } vlStk2; + + // VLT_FPSTK -- enregisterd TYP_DOUBLE (on the FP stack) + // eg. ST(3). Actually it is ST("FPstkHeigth - vpFpStk") + + struct + { + unsigned vlfReg; + } vlFPstk; + + // VLT_FIXED_VA -- fixed argument of a varargs function. + // The argument location depends on the size of the variable + // arguments (...). Inspecting the VARARGS_HANDLE indicates the + // location of the first arg. This argument can then be accessed + // relative to the position of the first arg + + struct + { + unsigned vlfvOffset; + } vlFixedVarArg; + + // VLT_MEMORY + + struct + { + void *rpValue; // pointer to the in-process + // location of the value. + } vlMemory; + };*/ + }; + + + // This enum is used for JIT to tell EE where this token comes from. + // E.g. Depending on different opcodes, we might allow/disallow certain types of tokens or + // return different types of handles (e.g. boxed vs. regular entrypoints) + public enum CorInfoTokenKind + { + CORINFO_TOKENKIND_Class = 0x01, + CORINFO_TOKENKIND_Method = 0x02, + CORINFO_TOKENKIND_Field = 0x04, + CORINFO_TOKENKIND_Mask = 0x07, + + // token comes from CEE_LDTOKEN + CORINFO_TOKENKIND_Ldtoken = 0x10 | CORINFO_TOKENKIND_Class | CORINFO_TOKENKIND_Method | CORINFO_TOKENKIND_Field, + + // token comes from CEE_CASTCLASS or CEE_ISINST + CORINFO_TOKENKIND_Casting = 0x20 | CORINFO_TOKENKIND_Class, + + // token comes from CEE_NEWARR + CORINFO_TOKENKIND_Newarr = 0x40 | CORINFO_TOKENKIND_Class, + + // token comes from CEE_BOX + CORINFO_TOKENKIND_Box = 0x80 | CORINFO_TOKENKIND_Class, + + // token comes from CEE_CONSTRAINED + CORINFO_TOKENKIND_Constrained = 0x100 | CORINFO_TOKENKIND_Class, + }; + + // These are error codes returned by CompileMethod + public enum CorJitResult + {/* + // Note that I dont use FACILITY_NULL for the facility number, + // we may want to get a 'real' facility number + CORJIT_OK = NO_ERROR, + CORJIT_BADCODE = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NULL, 1), + CORJIT_OUTOFMEM = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NULL, 2), + CORJIT_INTERNALERROR = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NULL, 3), + CORJIT_SKIPPED = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NULL, 4), + CORJIT_RECOVERABLEERROR = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NULL, 5), + CORJIT_SKIPMDIL = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NULL, 6)*/ + }; + + [Flags] + public enum CorJitFlag : uint + { + CORJIT_FLG_SPEED_OPT = 0x00000001, + CORJIT_FLG_SIZE_OPT = 0x00000002, + CORJIT_FLG_DEBUG_CODE = 0x00000004, // generate "debuggable" code (no code-mangling optimizations) + CORJIT_FLG_DEBUG_EnC = 0x00000008, // We are in Edit-n-Continue mode + CORJIT_FLG_DEBUG_INFO = 0x00000010, // generate line and local-var info + CORJIT_FLG_MIN_OPT = 0x00000020, // disable all jit optimizations (not necesarily debuggable code) + CORJIT_FLG_GCPOLL_CALLS = 0x00000040, // Emit calls to JIT_POLLGC for thread suspension. + CORJIT_FLG_MCJIT_BACKGROUND = 0x00000080, // Calling from multicore JIT background thread, do not call JitComplete + + CORJIT_FLG_USE_SSE3_4 = 0x00000200, + CORJIT_FLG_USE_AVX = 0x00000400, + CORJIT_FLG_USE_AVX2 = 0x00000800, + CORJIT_FLG_USE_AVX_512 = 0x00001000, + CORJIT_FLG_FEATURE_SIMD = 0x00002000, + + CORJIT_FLG_READYTORUN = 0x00010000, // Use version-resilient code generation + + CORJIT_FLG_PROF_ENTERLEAVE = 0x00020000, // Instrument prologues/epilogues + CORJIT_FLG_PROF_REJIT_NOPS = 0x00040000, // Insert NOPs to ensure code is re-jitable + CORJIT_FLG_PROF_NO_PINVOKE_INLINE + = 0x00080000, // Disables PInvoke inlining + CORJIT_FLG_SKIP_VERIFICATION = 0x00100000, // (lazy) skip verification - determined without doing a full resolve. See comment below + CORJIT_FLG_PREJIT = 0x00200000, // jit or prejit is the execution engine. + CORJIT_FLG_RELOC = 0x00400000, // Generate relocatable code + CORJIT_FLG_IMPORT_ONLY = 0x00800000, // Only import the function + CORJIT_FLG_IL_STUB = 0x01000000, // method is an IL stub + CORJIT_FLG_PROCSPLIT = 0x02000000, // JIT should separate code into hot and cold sections + CORJIT_FLG_BBINSTR = 0x04000000, // Collect basic block profile information + CORJIT_FLG_BBOPT = 0x08000000, // Optimize method based on profile information + CORJIT_FLG_FRAMED = 0x10000000, // All methods have an EBP frame + CORJIT_FLG_ALIGN_LOOPS = 0x20000000, // add NOPs before loops to align them at 16 byte boundaries + CORJIT_FLG_PUBLISH_SECRET_PARAM= 0x40000000, // JIT must place stub secret param into local 0. (used by IL stubs) + CORJIT_FLG_GCPOLL_INLINE = 0x80000000, // JIT must inline calls to GCPoll when possible + }; +} diff --git a/src/JitInterface/src/ThunkGenerator/Program.cs b/src/JitInterface/src/ThunkGenerator/Program.cs new file mode 100644 index 00000000000..902cd8a2238 --- /dev/null +++ b/src/JitInterface/src/ThunkGenerator/Program.cs @@ -0,0 +1,311 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using System.Diagnostics; + +namespace Thunkerator +{ + // Parse type replacement section for normal types + // Parse type replacement section for return value types + + public static class StringExtensions + { + public static string Canonicalize(this string current) + { + string untrimmed = ""; + while (untrimmed != current) + { + untrimmed = current; + current = current.Replace(" *", "*"); + current = current.Replace("* ", "*"); + current = current.Replace(" ,", ","); + current = current.Replace(", ", ","); + current = current.Replace(" ", " "); + current = current.Replace("\t", " "); + } + + return current.Trim(); + } + } + + class TypeReplacement + { + public TypeReplacement(string line) + { + string[] typenames = line.Split(','); + if ((typenames.Length < 1) || (typenames.Length > 3)) + { + throw new Exception("Wrong number of type name entries"); + } + ThunkTypeName = typenames[0].Canonicalize(); + + if (typenames.Length > 1) + { + ManagedTypeName = typenames[1].Canonicalize(); + } + else + { + ManagedTypeName = ThunkTypeName; + } + + if (typenames.Length > 2) + { + NativeTypeName = typenames[2].Canonicalize(); + } + else + { + NativeTypeName = ThunkTypeName; + } + } + public readonly string ThunkTypeName; + public readonly string NativeTypeName; + public readonly string ManagedTypeName; + } + + class Parameter + { + public Parameter(string name, TypeReplacement type) + { + Type = type; + Name = name; + if (name.StartsWith("*")) + throw new Exception("Names not allowed to start with *"); + } + + public readonly string Name; + public readonly TypeReplacement Type; + } + + class FunctionDecl + { + public FunctionDecl(string line, Dictionary ThunkReturnTypes, Dictionary ThunkTypes) + { + int indexOfOpenParen = line.IndexOf('('); + int indexOfCloseParen = line.IndexOf(')'); + string returnTypeAndFunctionName = line.Substring(0, indexOfOpenParen).Canonicalize(); + int indexOfLastWhitespaceInReturnTypeAndFunctionName = returnTypeAndFunctionName.LastIndexOfAny(new char[] { ' ', '*' }); + FunctionName = returnTypeAndFunctionName.Substring(indexOfLastWhitespaceInReturnTypeAndFunctionName + 1).Canonicalize(); + if (FunctionName.StartsWith("*")) + throw new Exception("Names not allowed to start with *"); + string returnType = returnTypeAndFunctionName.Substring(0, indexOfLastWhitespaceInReturnTypeAndFunctionName + 1).Canonicalize(); + + if (!ThunkReturnTypes.TryGetValue(returnType, out ReturnType)) + { + throw new Exception(String.Format("Type {0} unknown", returnType)); + } + + string parameterList = line.Substring(indexOfOpenParen + 1, indexOfCloseParen - indexOfOpenParen - 1).Canonicalize(); + string[] parametersString = parameterList.Length == 0 ? new string[0] : parameterList.Split(','); + List parameters = new List(); + + foreach (string parameterString in parametersString) + { + int indexOfLastWhitespaceInParameter = parameterString.LastIndexOfAny(new char[] { ' ', '*' }); + string paramName = parameterString.Substring(indexOfLastWhitespaceInParameter + 1).Canonicalize(); + string paramType = parameterString.Substring(0, indexOfLastWhitespaceInParameter + 1).Canonicalize(); + TypeReplacement tr; + if (!ThunkTypes.TryGetValue(paramType, out tr)) + { + throw new Exception(String.Format("Type {0} unknown", paramType)); + } + parameters.Add(new Parameter(paramName, tr)); + } + + Parameters = parameters.ToArray(); + } + + public readonly string FunctionName; + public readonly TypeReplacement ReturnType; + public readonly Parameter[] Parameters; + } + + class Program + { + enum ParseMode + { + RETURNTYPES, + NORMALTYPES, + FUNCTIONS, + IFDEFING + } + static IEnumerable ParseInput(TextReader tr) + { + Dictionary ThunkReturnTypes = new Dictionary(); + Dictionary ThunkTypes = new Dictionary(); + ParseMode currentParseMode = ParseMode.FUNCTIONS; + ParseMode oldParseMode = ParseMode.FUNCTIONS; + List functions = new List(); + int currentLineIndex = 1; + for (string currentLine = tr.ReadLine(); currentLine != null; currentLine = tr.ReadLine(), currentLineIndex++) + { + try + { + if (currentLine.Length == 0) + { + continue; // Its an empty line, ignore + } + + if (currentLine[0] == ';') + { + continue; // Its a comment + } + + if (currentLine == "RETURNTYPES") + { + currentParseMode = ParseMode.RETURNTYPES; + continue; + } + if (currentLine == "NORMALTYPES") + { + currentParseMode = ParseMode.NORMALTYPES; + continue; + } + if (currentLine == "FUNCTIONS") + { + currentParseMode = ParseMode.FUNCTIONS; + continue; + } + + if (currentLine == "#endif") + { + currentParseMode = oldParseMode; + continue; + } + + if (currentLine.StartsWith("#if")) + { + oldParseMode = currentParseMode; + currentParseMode = ParseMode.IFDEFING; + } + + if (currentParseMode == ParseMode.IFDEFING) + { + continue; + } + + switch (currentParseMode) + { + case ParseMode.NORMALTYPES: + case ParseMode.RETURNTYPES: + TypeReplacement t = new TypeReplacement(currentLine); + if (currentParseMode == ParseMode.NORMALTYPES) + { + ThunkTypes.Add(t.ThunkTypeName, t); + ThunkReturnTypes.Add(t.ThunkTypeName, t); + } + if (currentParseMode == ParseMode.RETURNTYPES) + { + ThunkReturnTypes[t.ThunkTypeName] = t; + } + break; + + case ParseMode.FUNCTIONS: + functions.Add(new FunctionDecl(currentLine, ThunkReturnTypes, ThunkTypes)); + break; + } + } + catch (Exception e) + { + Console.Error.WriteLine("Error parsing line {0} : {1}", currentLineIndex, e.Message); + } + } + + return functions.AsReadOnly(); + } + + static void WriteManagedThunkInterface(TextWriter tr, IEnumerable functionData) + { + // Write header + tr.Write(@" +// DO NOT EDIT THIS FILE! It IS AUTOGENERATED +using System; +using System.Runtime.InteropServices; + +namespace Internal.JitInterface +{ + unsafe class CorInfoBase + { +"); + + foreach (FunctionDecl decl in functionData) + { + string returnType = decl.ReturnType.ManagedTypeName; + int marshalAs = returnType.LastIndexOf(']'); + string returnTypeWithVirtual = returnType.Insert((marshalAs != -1) ? marshalAs + 1 : 0, "public virtual "); + + tr.Write(" " + returnTypeWithVirtual + " " + decl.FunctionName + "("); + tr.Write("IntPtr _this"); + foreach (Parameter param in decl.Parameters) + { + tr.Write(", "); + tr.Write(param.Type.ManagedTypeName + " " + param.Name); + } + tr.WriteLine(")"); + tr.WriteLine(" { throw new NotImplementedException(); }"); + } + tr.WriteLine(); + + foreach (FunctionDecl decl in functionData) + { + tr.WriteLine(" [UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)]"); + + string returnType = decl.ReturnType.ManagedTypeName; + int marshalAs = returnType.LastIndexOf(']'); + string returnTypeWithDelegate = returnType.Insert((marshalAs != -1) ? (marshalAs + 1) : 0, "delegate "); + + tr.Write(" " + returnTypeWithDelegate + " " + "_" + decl.FunctionName + "("); + tr.Write("IntPtr _this"); + foreach (Parameter param in decl.Parameters) + { + tr.Write(", "); + tr.Write(param.Type.ManagedTypeName + " " + param.Name); + } + tr.WriteLine(");"); + } + tr.WriteLine(); + + int total = functionData.Count(); + tr.WriteLine(@" Object[] _keepalive; + + protected IntPtr CreateUnmanagedInstance() + { + IntPtr * vtable = (IntPtr *)Marshal.AllocCoTaskMem(sizeof(IntPtr) * " + total + @"); + Object[] keepalive = new Object[" + total + @"]; + Delegate d; + + _keepalive = keepalive; +"); + + int index = 0; + foreach (FunctionDecl decl in functionData) + { + tr.WriteLine(" d = new _" + decl.FunctionName + "(" + decl.FunctionName + ");"); + tr.WriteLine(" vtable[" + index + "] = Marshal.GetFunctionPointerForDelegate(d);"); + tr.WriteLine(" keepalive[" + index + "] = d;"); + index++; + } + + tr.WriteLine(@" + IntPtr instance = Marshal.AllocCoTaskMem(sizeof(IntPtr)); + *(IntPtr**)instance = vtable; + return instance; + } + } +} +"); + } + + static void Main(string[] args) + { + IEnumerable functions = ParseInput(new StreamReader(args[0])); + using (TextWriter tw = new StreamWriter(args[1])) + { + Console.WriteLine("Generating {0}", args[1]); + WriteManagedThunkInterface(tw, functions); + } + } + } +} diff --git a/src/JitInterface/src/ThunkGenerator/ThunkInput.txt b/src/JitInterface/src/ThunkGenerator/ThunkInput.txt new file mode 100644 index 00000000000..3ca583502f9 --- /dev/null +++ b/src/JitInterface/src/ThunkGenerator/ThunkInput.txt @@ -0,0 +1,317 @@ +; Copyright (c) Microsoft. All rights reserved. +; Licensed under the MIT license. See LICENSE file in the project root for full license information. +; +; Thunk generator input file for generating the thunks from the C++ version of the +; jit interface to COM, into managed, and from COM to C++. +; +; The format of this file is as follows. +; There are NORMALTYPES, RETURNTYPES, and FUNCTIONS regions +; In the NORMALTYPES/RETURNTYPES region, each type is described. If a type is +; described in the NORMALTYPES section, but isn't described in the RETURNTYPES section +; then the NORMALTYPES description can be used for a return value. +; +; TYPES have three fields +; ThunkDescriptionType,ManagedType,NativeType +; If either ManagedType or NativeType are missing, then that form is replaced with ThunkDescriptionType. +; This feature allows reduction in type for enums and other types where the same type can be used in managed an native +; +; Specification of a custom native type is done to allow multiple translations of the same native type to managed. +; i.e. +; REFIntPointer,ref int *,int** +; and +; PointerToIntPointer,int**,int** +; +; Following the TYPES sections, there is the FUNCTIONS section +; Each function that is to be part of the interface is written here. The format is basically the C++ format +; without support for inline comments or sal annotations. +; +; Also, note that an empty line is ignored, and a line that begins with a ; is ignored. +; +; If the boilerplate around the individual functions needs adjustment, edit the thunk generator source code, and +; rebuild with rebuildthunkgen.cmd in the the ThunkGenerator subdir, then rebuildthunks.cmd +; If this file is editted, rebuild with rebuildthunks.cmd -- DO NOT RUN from within a razzle window. +; +NORMALTYPES +void +IEEMemoryManager*,void* +LPVOID,void* +void* +const void *,void* +HRESULT +SIZE_T* +int +INT,int +INT32,int +ULONG32,uint +ULONG,uint +DWORD,uint +unsigned,uint +unsigned int, uint +size_t,UIntPtr +SIZE_T,UIntPtr +WORD,ushort +BOOL,[MarshalAs(UnmanagedType.Bool)]bool +bool,[MarshalAs(UnmanagedType.I1)]bool +const char *,byte* +mdMethodDef,mdToken +mdToken +BYTE*,byte* +GSCookie* +GSCookie** + +BOOL*,[MarshalAs(UnmanagedType.Bool)] ref bool +bool*,[MarshalAs(UnmanagedType.U1)] ref bool +ULONG*,ref uint +void **,ref void* +VOIDSTARSTAR,void **,void ** +ULONG32*,ref uint +LONG*,int* +char*,byte* +const char**,byte** +WCHAR**,short** +LPCSTR,byte* +LPWSTR,short* +LPCWSTR,short* +wchar_t*,short* +const wchar_t*,String + +DWORD**,ref uint* +unsigned*,ref uint +DWORD*,ref uint +CORINFO_CONST_LOOKUP*,ref CORINFO_CONST_LOOKUP +CORINFO_EH_CLAUSE*,ref CORINFO_EH_CLAUSE +const CORINFO_EH_CLAUSE*,ref CORINFO_EH_CLAUSE +CORINFO_SIG_INFO* +CORINFO_RESOLVED_TOKEN*,ref CORINFO_RESOLVED_TOKEN +CORINFO_RESOLVED_TOKEN_PTR,CORINFO_RESOLVED_TOKEN*,CORINFO_RESOLVED_TOKEN* +CORINFO_EE_INFO*,ref CORINFO_EE_INFO +CORINFO_GENERICHANDLE_RESULT*,ref CORINFO_GENERICHANDLE_RESULT +CORINFO_METHOD_INFO*,ref CORINFO_METHOD_INFO +CORINFO_FIELD_INFO*,ref CORINFO_FIELD_INFO +CORINFO_CALL_INFO*,ref CORINFO_CALL_INFO +DelegateCtorArgs*,ref DelegateCtorArgs +ICorDynamicInfo*,IntPtr +va_list,IntPtr +CORINFO_HELPER_DESC*,ref CORINFO_HELPER_DESC +const CORINFO_HELPER_DESC*,ref CORINFO_HELPER_DESC +int*,ref int +unsigned int*,ref uint + +CORINFO_JUST_MY_CODE_HANDLE**,ref CORINFO_JUST_MY_CODE_HANDLE_** + +ICorJitInfo::ProfileBuffer**,ref ProfileBuffer* + +; Enums +CorInfoCanSkipVerificationResult +CorInfoClassId +CorInfoHelperTailCallSpecialHandling +CorInfoHelpFunc +CorInfoInitClassResult +CorInfoInline +CorInfoInstantiationVerification +CorInfoIntrinsics +CorInfoIsAccessAllowedResult +CorInfoMethodRuntimeFlags +CorInfoTailCall +CorInfoType +CorInfoTypeWithMod +CorInfoUnmanagedCallConv +InfoAccessType +CORINFO_LOOKUP_KIND +CORINFO_ACCESS_FLAGS +CORINFO_CALLINFO_FLAGS +CorJitAllocMemFlag +CorJitFuncKind +CorJitResult + +; Handle types +CORINFO_MODULE_HANDLE,CORINFO_MODULE_STRUCT_* +CORINFO_METHOD_HANDLE,CORINFO_METHOD_STRUCT_* +CORINFO_FIELD_HANDLE,CORINFO_FIELD_STRUCT_* +CORINFO_CLASS_HANDLE,CORINFO_CLASS_STRUCT_* +CORINFO_ASSEMBLY_HANDLE,CORINFO_ASSEMBLY_STRUCT_* +CORINFO_JUST_MY_CODE_HANDLE,CORINFO_JUST_MY_CODE_HANDLE_* +CORINFO_MODULE_HANDLE*,ref CORINFO_MODULE_STRUCT_* +CORINFO_MODULE_HANDLE_STAR,CORINFO_MODULE_STRUCT_**,CORINFO_MODULE_STRUCT_** +CORINFO_CLASS_HANDLE*,ref CORINFO_CLASS_STRUCT_* +CORINFO_ARG_LIST_HANDLE,CORINFO_ARG_LIST_STRUCT_* +CORINFO_VARARGS_HANDLE,IntPtr +CORINFO_CONTEXT_HANDLE,CORINFO_CONTEXT_STRUCT* + +ICorDebugInfo::OffsetMapping*,OffsetMapping* +ICorDebugInfo::ILVarInfo**,ILVarInfo** +ICorDebugInfo::NativeVarInfo*,NativeVarInfo* +ICorDebugInfo::BoundaryTypes*,BoundaryTypes* + +struct _EXCEPTION_POINTERS*,_EXCEPTION_POINTERS* + +RETURNTYPES +BOOL,[return: MarshalAs(UnmanagedType.Bool)]bool +bool,[return: MarshalAs(UnmanagedType.I1)]bool +LPCWSTR,[return: MarshalAs(UnmanagedType.LPWStr)]string +; NOTE in managed SIZE_T is an enum that is 64bits in size, and returning one of those causing mcg to do the wrong thing. +size_t,byte*,size_t + +FUNCTIONS + DWORD getMethodAttribs( CORINFO_METHOD_HANDLE ftn ); + void setMethodAttribs( CORINFO_METHOD_HANDLE ftn, CorInfoMethodRuntimeFlags attribs ); + void getMethodSig( CORINFO_METHOD_HANDLE ftn, CORINFO_SIG_INFO *sig, CORINFO_CLASS_HANDLE memberParent ); + bool getMethodInfo( CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info ); + CorInfoInline canInline( CORINFO_METHOD_HANDLE callerHnd, CORINFO_METHOD_HANDLE calleeHnd, DWORD* pRestrictions ); + void reportInliningDecision(CORINFO_METHOD_HANDLE inlinerHnd, CORINFO_METHOD_HANDLE inlineeHnd, CorInfoInline inlineResult, const char * reason); + bool canTailCall( CORINFO_METHOD_HANDLE callerHnd, CORINFO_METHOD_HANDLE declaredCalleeHnd, CORINFO_METHOD_HANDLE exactCalleeHnd, bool fIsTailPrefix ); + void reportTailCallDecision(CORINFO_METHOD_HANDLE callerHnd, CORINFO_METHOD_HANDLE calleeHnd, bool fIsTailPrefix, CorInfoTailCall tailCallResult, const char * reason); + void getEHinfo( CORINFO_METHOD_HANDLE ftn, unsigned EHnumber, CORINFO_EH_CLAUSE* clause ); + CORINFO_CLASS_HANDLE getMethodClass( CORINFO_METHOD_HANDLE method ); + CORINFO_MODULE_HANDLE getMethodModule( CORINFO_METHOD_HANDLE method ); + void getMethodVTableOffset( CORINFO_METHOD_HANDLE method, unsigned* offsetOfIndirection, unsigned* offsetAfterIndirection ); + CorInfoIntrinsics getIntrinsicID( CORINFO_METHOD_HANDLE method ); + bool isInSIMDModule( CORINFO_CLASS_HANDLE classHnd ); + CorInfoUnmanagedCallConv getUnmanagedCallConv( CORINFO_METHOD_HANDLE method ); + BOOL pInvokeMarshalingRequired( CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO* callSiteSig ); + BOOL satisfiesMethodConstraints( CORINFO_CLASS_HANDLE parent, CORINFO_METHOD_HANDLE method ); + BOOL isCompatibleDelegate( CORINFO_CLASS_HANDLE objCls, CORINFO_CLASS_HANDLE methodParentCls, CORINFO_METHOD_HANDLE method, CORINFO_CLASS_HANDLE delegateCls, BOOL *pfIsOpenDelegate ); + BOOL isDelegateCreationAllowed( CORINFO_CLASS_HANDLE delegateHnd, CORINFO_METHOD_HANDLE calleeHnd ); + CorInfoInstantiationVerification isInstantiationOfVerifiedGeneric( CORINFO_METHOD_HANDLE method ); + void initConstraintsForVerification( CORINFO_METHOD_HANDLE method, BOOL *pfHasCircularClassConstraints, BOOL *pfHasCircularMethodConstraint ); + CorInfoCanSkipVerificationResult canSkipMethodVerification( CORINFO_METHOD_HANDLE ftnHandle ); + void methodMustBeLoadedBeforeCodeIsRun( CORINFO_METHOD_HANDLE method ); + CORINFO_METHOD_HANDLE mapMethodDeclToMethodImpl( CORINFO_METHOD_HANDLE method ); + void getGSCookie( GSCookie * pCookieVal, GSCookie ** ppCookieVal ); + void resolveToken(CORINFO_RESOLVED_TOKEN * pResolvedToken); + void findSig( CORINFO_MODULE_HANDLE module, unsigned sigTOK, CORINFO_CONTEXT_HANDLE context, CORINFO_SIG_INFO *sig ); + void findCallSiteSig( CORINFO_MODULE_HANDLE module,unsigned methTOK, CORINFO_CONTEXT_HANDLE context, CORINFO_SIG_INFO *sig) + CORINFO_CLASS_HANDLE getTokenTypeAsHandle(CORINFO_RESOLVED_TOKEN* pResolvedToken) + CorInfoCanSkipVerificationResult canSkipVerification(CORINFO_MODULE_HANDLE module) + BOOL isValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK) + BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK) + BOOL shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) + CorInfoType asCorInfoType(CORINFO_CLASS_HANDLE cls) + const char* getClassName(CORINFO_CLASS_HANDLE cls) + int appendClassName(WCHAR** ppBuf, int* pnBufLen, CORINFO_CLASS_HANDLE cls, BOOL fNamespace, BOOL fFullInst, BOOL fAssembly) + BOOL isValueClass(CORINFO_CLASS_HANDLE cls) + BOOL canInlineTypeCheckWithObjectVTable(CORINFO_CLASS_HANDLE cls) + DWORD getClassAttribs(CORINFO_CLASS_HANDLE cls) + BOOL isStructRequiringStackAllocRetBuf(CORINFO_CLASS_HANDLE cls) + CORINFO_MODULE_HANDLE getClassModule(CORINFO_CLASS_HANDLE cls) + CORINFO_ASSEMBLY_HANDLE getModuleAssembly(CORINFO_MODULE_HANDLE mod) + const char* getAssemblyName(CORINFO_ASSEMBLY_HANDLE assem) + void* LongLifetimeMalloc(size_t sz) + void LongLifetimeFree(void* obj) + size_t getClassModuleIdForStatics(CORINFO_CLASS_HANDLE cls, CORINFO_MODULE_HANDLE_STAR pModule, VOIDSTARSTAR ppIndirection) + unsigned getClassSize(CORINFO_CLASS_HANDLE cls) + unsigned getClassAlignmentRequirement(CORINFO_CLASS_HANDLE cls, BOOL fDoubleAlignHint) + unsigned getClassGClayout(CORINFO_CLASS_HANDLE cls, BYTE* gcPtrs) + unsigned getClassNumInstanceFields(CORINFO_CLASS_HANDLE cls) + CORINFO_FIELD_HANDLE getFieldInClass(CORINFO_CLASS_HANDLE clsHnd, INT num) + BOOL checkMethodModifier(CORINFO_METHOD_HANDLE hMethod, LPCSTR modifier, BOOL fOptional) + CorInfoHelpFunc getNewHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle) + CorInfoHelpFunc getNewArrHelper(CORINFO_CLASS_HANDLE arrayCls) + CorInfoHelpFunc getCastingHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken, bool fThrowing) + CorInfoHelpFunc getSharedCCtorHelper(CORINFO_CLASS_HANDLE clsHnd) + CorInfoHelpFunc getSecurityPrologHelper(CORINFO_METHOD_HANDLE ftn) + CORINFO_CLASS_HANDLE getTypeForBox(CORINFO_CLASS_HANDLE cls) + CorInfoHelpFunc getBoxHelper(CORINFO_CLASS_HANDLE cls) + CorInfoHelpFunc getUnBoxHelper(CORINFO_CLASS_HANDLE cls) + void getReadyToRunHelper(CORINFO_RESOLVED_TOKEN * pResolvedToken, CorInfoHelpFunc id, CORINFO_CONST_LOOKUP *pLookup) + const char* getHelperName(CorInfoHelpFunc helpFunc) + CorInfoInitClassResult initClass(CORINFO_FIELD_HANDLE field, CORINFO_METHOD_HANDLE method, CORINFO_CONTEXT_HANDLE context, BOOL speculative) + void classMustBeLoadedBeforeCodeIsRun(CORINFO_CLASS_HANDLE cls) + CORINFO_CLASS_HANDLE getBuiltinClass(CorInfoClassId classId) + CorInfoType getTypeForPrimitiveValueClass(CORINFO_CLASS_HANDLE cls) + BOOL canCast(CORINFO_CLASS_HANDLE child, CORINFO_CLASS_HANDLE parent) + BOOL areTypesEquivalent(CORINFO_CLASS_HANDLE cls1, CORINFO_CLASS_HANDLE cls2) + CORINFO_CLASS_HANDLE mergeClasses(CORINFO_CLASS_HANDLE cls1, CORINFO_CLASS_HANDLE cls2) + CORINFO_CLASS_HANDLE getParentType(CORINFO_CLASS_HANDLE cls) + CorInfoType getChildType(CORINFO_CLASS_HANDLE clsHnd, CORINFO_CLASS_HANDLE* clsRet) + BOOL satisfiesClassConstraints(CORINFO_CLASS_HANDLE cls) + BOOL isSDArray(CORINFO_CLASS_HANDLE cls) + unsigned getArrayRank(CORINFO_CLASS_HANDLE cls) + void* getArrayInitializationData(CORINFO_FIELD_HANDLE field, DWORD size) + CorInfoIsAccessAllowedResult canAccessClass(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_HELPER_DESC* pAccessHelper) + const char* getFieldName(CORINFO_FIELD_HANDLE ftn, const char** moduleName) + CORINFO_CLASS_HANDLE getFieldClass(CORINFO_FIELD_HANDLE field) + CorInfoType getFieldType(CORINFO_FIELD_HANDLE field, CORINFO_CLASS_HANDLE* structType, CORINFO_CLASS_HANDLE memberParent) + unsigned getFieldOffset(CORINFO_FIELD_HANDLE field) + bool isWriteBarrierHelperRequired(CORINFO_FIELD_HANDLE field) + void getFieldInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_ACCESS_FLAGS flags, CORINFO_FIELD_INFO* pResult) + bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) + void getBoundaries(CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, DWORD** pILOffsets, ICorDebugInfo::BoundaryTypes* implictBoundaries) + void setBoundaries(CORINFO_METHOD_HANDLE ftn, ULONG32 cMap, ICorDebugInfo::OffsetMapping* pMap) + void getVars(CORINFO_METHOD_HANDLE ftn, ULONG32* cVars, ICorDebugInfo::ILVarInfo** vars, bool* extendOthers) + void setVars(CORINFO_METHOD_HANDLE ftn, ULONG32 cVars, ICorDebugInfo::NativeVarInfo* vars) + void*allocateArray(ULONG cBytes); + void freeArray(void*array); + CORINFO_ARG_LIST_HANDLE getArgNext(CORINFO_ARG_LIST_HANDLE args); + CorInfoTypeWithMod getArgType(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_HANDLE args, CORINFO_CLASS_HANDLE* vcTypeRet); + CORINFO_CLASS_HANDLE getArgClass(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_HANDLE args); + CorInfoType getHFAType(CORINFO_CLASS_HANDLE hClass); + HRESULT GetErrorHRESULT(struct _EXCEPTION_POINTERS *pExceptionPointers); + ULONG GetErrorMessage(LPWSTR buffer, ULONG bufferLength); + int FilterException(struct _EXCEPTION_POINTERS* pExceptionPointers); + void HandleException(struct _EXCEPTION_POINTERS* pExceptionPointers); + void ThrowExceptionForJitResult(HRESULT result); + void ThrowExceptionForHelper(const CORINFO_HELPER_DESC* throwHelper); + void getEEInfo(CORINFO_EE_INFO* pEEInfoOut); + LPCWSTR getJitTimeLogFilename(); + mdMethodDef getMethodDefFromMethod(CORINFO_METHOD_HANDLE hMethod); + const char* getMethodName(CORINFO_METHOD_HANDLE ftn, const char **moduleName); + unsigned getMethodHash(CORINFO_METHOD_HANDLE ftn); + size_t findNameOfToken(CORINFO_MODULE_HANDLE moduleHandle,mdToken token, char * szFQName,size_t FQNameCapacity); + int getIntConfigValue(const wchar_t *name, int defaultValue); + wchar_t *getStringConfigValue(const wchar_t *name); + void freeStringConfigValue(wchar_t *value); + DWORD getThreadTLSIndex(void **ppIndirection); + const void * getInlinedCallFrameVptr(void **ppIndirection); + LONG * getAddrOfCaptureThreadGlobal(void **ppIndirection); + SIZE_T* getAddrModuleDomainID(CORINFO_MODULE_HANDLE module); + void* getHelperFtn (CorInfoHelpFunc ftnNum, void **ppIndirection); + void getFunctionEntryPoint(CORINFO_METHOD_HANDLE ftn, CORINFO_CONST_LOOKUP * pResult, CORINFO_ACCESS_FLAGS accessFlags); + void getFunctionFixedEntryPoint(CORINFO_METHOD_HANDLE ftn, CORINFO_CONST_LOOKUP * pResult); + void* getMethodSync(CORINFO_METHOD_HANDLE ftn, void **ppIndirection); + CorInfoHelpFunc getLazyStringLiteralHelper(CORINFO_MODULE_HANDLE handle); + CORINFO_MODULE_HANDLE embedModuleHandle(CORINFO_MODULE_HANDLE handle, void **ppIndirection); + CORINFO_CLASS_HANDLE embedClassHandle(CORINFO_CLASS_HANDLE handle, void **ppIndirection); + CORINFO_METHOD_HANDLE embedMethodHandle(CORINFO_METHOD_HANDLE handle, void **ppIndirection); + CORINFO_FIELD_HANDLE embedFieldHandle(CORINFO_FIELD_HANDLE handle, void **ppIndirection); + void embedGenericHandle(CORINFO_RESOLVED_TOKEN * pResolvedToken, BOOL fEmbedParent, CORINFO_GENERICHANDLE_RESULT * pResult); + CORINFO_LOOKUP_KIND getLocationOfThisType(CORINFO_METHOD_HANDLE context); + void* getPInvokeUnmanagedTarget(CORINFO_METHOD_HANDLE method, void **ppIndirection); + void* getAddressOfPInvokeFixup(CORINFO_METHOD_HANDLE method, void **ppIndirection); + LPVOID GetCookieForPInvokeCalliSig(CORINFO_SIG_INFO* szMetaSig, void ** ppIndirection); + bool canGetCookieForPInvokeCalliSig(CORINFO_SIG_INFO* szMetaSig); + CORINFO_JUST_MY_CODE_HANDLE getJustMyCodeHandle(CORINFO_METHOD_HANDLE method, CORINFO_JUST_MY_CODE_HANDLE**ppIndirection); + void GetProfilingHandle(BOOL *pbHookFunction, void **pProfilerHandle, BOOL *pbIndirectedHandles); + void getCallInfo(CORINFO_RESOLVED_TOKEN * pResolvedToken, CORINFO_RESOLVED_TOKEN * pConstrainedResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_CALLINFO_FLAGS flags, CORINFO_CALL_INFO *pResult); + BOOL canAccessFamily(CORINFO_METHOD_HANDLE hCaller, CORINFO_CLASS_HANDLE hInstanceType); + BOOL isRIDClassDomainID(CORINFO_CLASS_HANDLE cls); + unsigned getClassDomainID (CORINFO_CLASS_HANDLE cls, void **ppIndirection); + void* getFieldAddress(CORINFO_FIELD_HANDLE field, void **ppIndirection); + CORINFO_VARARGS_HANDLE getVarArgsHandle(CORINFO_SIG_INFO *pSig, void **ppIndirection); + bool canGetVarArgsHandle(CORINFO_SIG_INFO *pSig); + InfoAccessType constructStringLiteral(CORINFO_MODULE_HANDLE module, mdToken metaTok, void **ppValue); + InfoAccessType emptyStringLiteral(void **ppValue); + DWORD getFieldThreadLocalStoreID (CORINFO_FIELD_HANDLE field, void **ppIndirection); + void setOverride(ICorDynamicInfo *pOverride, CORINFO_METHOD_HANDLE currentMethod); + void addActiveDependency(CORINFO_MODULE_HANDLE moduleFrom, CORINFO_MODULE_HANDLE moduleTo); + CORINFO_METHOD_HANDLE GetDelegateCtor(CORINFO_METHOD_HANDLE methHnd, CORINFO_CLASS_HANDLE clsHnd, CORINFO_METHOD_HANDLE targetMethodHnd, DelegateCtorArgs * pCtorData); + void MethodCompileComplete(CORINFO_METHOD_HANDLE methHnd); + void* getTailCallCopyArgsThunk (CORINFO_SIG_INFO *pSig, CorInfoHelperTailCallSpecialHandling flags); + IEEMemoryManager* getMemoryManager(); + void allocMem( ULONG hotCodeSize, ULONG coldCodeSize, ULONG roDataSize, ULONG xcptnsCount, CorJitAllocMemFlag flag, void** hotCodeBlock, void** coldCodeBlock, void** roDataBlock ); + void reserveUnwindInfo(BOOL isFunclet, BOOL isColdCode, ULONG unwindSize) + void allocUnwindInfo(BYTE* pHotCode, BYTE* pColdCode, ULONG startOffset, ULONG endOffset, ULONG unwindSize, BYTE* pUnwindBlock, CorJitFuncKind funcKind) + void* allocGCInfo(size_t size) + void yieldExecution() + void setEHcount(unsigned cEH) + void setEHinfo(unsigned EHnumber, const CORINFO_EH_CLAUSE* clause) + BOOL logMsg(unsigned level, const char* fmt, va_list args) + int doAssert(const char* szFile, int iLine, const char* szExpr) + void reportFatalError(CorJitResult result) + HRESULT allocBBProfileBuffer(ULONG count, ICorJitInfo::ProfileBuffer** profileBuffer) + HRESULT getBBProfileData(CORINFO_METHOD_HANDLE ftnHnd, ULONG* count, ICorJitInfo::ProfileBuffer** profileBuffer, ULONG* numRuns) + void recordCallSite(ULONG instrOffset, CORINFO_SIG_INFO* callSig, CORINFO_METHOD_HANDLE methodHandle) + void recordRelocation(void* location, void* target, WORD fRelocType, WORD slotNum, INT32 addlDelta) + WORD getRelocTypeHint(void* target) + void getModuleNativeEntryPointRange(void** pStart, void** pEnd) + DWORD getExpectedTargetArchitecture() diff --git a/src/JitInterface/src/ThunkGenerator/corinfo.h b/src/JitInterface/src/ThunkGenerator/corinfo.h new file mode 100644 index 00000000000..9fdfd87afc8 --- /dev/null +++ b/src/JitInterface/src/ThunkGenerator/corinfo.h @@ -0,0 +1,3645 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +// + +/*****************************************************************************\ +* * +* CorInfo.h - EE / Code generator interface * +* * +******************************************************************************* +* +* This file exposes CLR runtime functionality. It can be used by compilers, +* both Just-in-time and ahead-of-time, to generate native code which +* executes in the runtime environment. +******************************************************************************* + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE +// +// The JIT/EE interface is versioned. By "interface", we mean mean any and all communication between the +// JIT and the EE. Any time a change is made to the interface, the JIT/EE interface version identifier +// must be updated. See code:JITEEVersionIdentifier for more information. +// +// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE +// +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#EEJitContractDetails + +The semantic contract between the EE and the JIT should be documented here It is incomplete, but as time goes +on, that hopefully will change + +See file:../../doc/BookOfTheRuntime/JIT/JIT%20Design.doc for details on the JIT compiler. See +code:EEStartup#TableOfContents for information on the runtime as a whole. + +------------------------------------------------------------------------------- +#Tokens + +The tokens in IL stream needs to be resolved to EE handles (CORINFO_CLASS/METHOD/FIELD_HANDLE) that +the runtime operates with. ICorStaticInfo::resolveToken is the method that resolves the found in IL stream +to set of EE handles (CORINFO_RESOLVED_TOKEN). All other APIs take resolved token as input. This design +avoids redundant token resolutions. + +The token validation is done as part of token resolution. The JIT is not required to do explicit upfront +token validation. + +------------------------------------------------------------------------------- +#ClassConstruction + +First of all class contruction comes in two flavors precise and 'beforeFieldInit'. In C# you get the former +if you declare an explicit class constructor method and the later if you declaratively initialize static +fields. Precise class construction guarentees that the .cctor is run precisely before the first access to any +method or field of the class. 'beforeFieldInit' semantics guarentees only that the .cctor will be run some +time before the first static field access (note that calling methods (static or insance) or accessing +instance fields does not cause .cctors to be run). + +Next you need to know that there are two kinds of code generation that can happen in the JIT: appdomain +neutral and appdomain specialized. The difference between these two kinds of code is how statics are handled. +For appdomain specific code, the address of a particular static variable is embeded in the code. This makes +it usable only for one appdomain (since every appdomain gets a own copy of its statics). Appdomain neutral +code calls a helper that looks up static variables off of a thread local variable. Thus the same code can be +used by mulitple appdomains in the same process. + +Generics also introduce a similar issue. Code for generic classes might be specialised for a particular set +of type arguments, or it could use helpers to access data that depends on type parameters and thus be shared +across several instantiations of the generic type. + +Thus there four cases + + * BeforeFieldInitCCtor - Unshared code. Cctors are only called when static fields are fetched. At the + time the method that touches the static field is JITed (or fixed up in the case of NGENed code), the + .cctor is called. + * BeforeFieldInitCCtor - Shared code. Since the same code is used for multiple classes, the act of JITing + the code can not be used as a hook. However, it is also the case that since the code is shared, it + can not wire in a particular address for the static and thus needs to use a helper that looks up the + correct address based on the thread ID. This helper does the .cctor check, and thus no additional + cctor logic is needed. + * PreciseCCtor - Unshared code. Any time a method is JITTed (or fixed up in the case of NGEN), a cctor + check for the class of the method being JITTed is done. In addition the JIT inserts explicit checks + before any static field accesses. Instance methods and fields do NOT have hooks because a .ctor + method must be called before the instance can be created. + * PreciseCctor - Shared code .cctor checks are placed in the prolog of every .ctor and static method. All + methods that access static fields have an explicit .cctor check before use. Again instance methods + don't have hooks because a .ctor would have to be called first. + +Technically speaking, however the optimization of avoiding checks on instance methods is flawed. It requires +that a .ctor always preceed a call to an instance methods. This break down when + + * A NULL is passed to an instance method. + * A .ctor does not call its superclasses .ctor. This allows an instance to be created without necessarily + calling all the .cctors of all the superclasses. A virtual call can then be made to a instance of a + superclass without necessarily calling the superclass's .cctor. + * The class is a value class (which exists without a .ctor being called) + +Nevertheless, the cost of plugging these holes is considered to high and the benefit is low. + +---------------------------------------------------------------------- + +#ClassConstructionFlags + +Thus the JIT's cctor responsibilities require it to check with the EE on every static field access using +initClass and before jitting any method to see if a .cctor check must be placed in the prolog. + + * CORINFO_FLG_BEFOREFIELDINIT indicate the class has beforeFieldInit semantics. The jit does not strictly + need this information however, it is valuable in optimizing static field fetch helper calls. Helper + call for classes with BeforeFieldInit semantics can be hoisted before other side effects where + classes with precise .cctor semantics do not allow this optimization. + +Inlining also complicates things. Because the class could have precise semantics it is also required that the +inlining of any constructor or static method must also do the initClass check. The inliner has the option of +inserting any required runtime check or simply not inlining the function. + +------------------------------------------------------------------------------- + +#StaticFields + +The first 4 options are mutially exclusive + + * CORINFO_FLG_HELPER If the field has this set, then the JIT must call getFieldHelper and call the + returned helper with the object ref (for an instance field) and a fieldDesc. Note that this should be + able to handle ANY field so to get a JIT up quickly, it has the option of using helper calls for all + field access (and skip the complexity below). Note that for statics it is assumed that you will + alwasy ask for the ADDRESSS helper and to the fetch in the JIT. + + * CORINFO_FLG_SHARED_HELPER This is currently only used for static fields. If this bit is set it means + that the field is feched by a helper call that takes a module identifier (see getModuleDomainID) and + a class identifier (see getClassDomainID) as arguments. The exact helper to call is determined by + getSharedStaticBaseHelper. The return value is of this function is the base of all statics in the + module. The offset from getFieldOffset must be added to this value to get the address of the field + itself. (see also CORINFO_FLG_STATIC_IN_HEAP). + + + * CORINFO_FLG_GENERICS_STATIC This is currently only used for static fields (of generic type). This + function is intended to be called with a Generic handle as a argument (from embedGenericHandle). The + exact helper to call is determined by getSharedStaticBaseHelper. The returned value is the base of + all statics in the class. The offset from getFieldOffset must be added to this value to get the + address of the (see also CORINFO_FLG_STATIC_IN_HEAP). + + * CORINFO_FLG_TLS This indicate that the static field is a Windows style Thread Local Static. (We also + have managed thread local statics, which work through the HELPER. Support for this is considered + legacy, and going forward, the EE should + + * This is a normal static field. Its address in in memory is determined by getFieldAddress. (see + also CORINFO_FLG_STATIC_IN_HEAP). + + +This last field can modify any of the cases above except CORINFO_FLG_HELPER + +CORINFO_FLG_STATIC_IN_HEAP This is currently only used for static fields of value classes. If the field has +this set then after computing what would normally be the field, what you actually get is a object poitner +(that must be reported to the GC) to a boxed version of the value. Thus the actual field address is computed +by addr = (*addr+sizeof(OBJECTREF)) + +Instance fields + + * CORINFO_FLG_HELPER This is used if the class is MarshalByRef, which means that the object might be a + proxyt to the real object in some other appdomain or process. If the field has this set, then the JIT + must call getFieldHelper and call the returned helper with the object ref. If the helper returned is + helpers that are for structures the args are as follows + + * CORINFO_HELP_GETFIELDSTRUCT - args are: retBuff, object, fieldDesc + * CORINFO_HELP_SETFIELDSTRUCT - args are object fieldDesc value + +The other GET helpers take an object fieldDesc and return the value The other SET helpers take an object +fieldDesc and value + + Note that unlike static fields there is no helper to take the address of a field because in general there + is no address for proxies (LDFLDA is illegal on proxies). + + CORINFO_FLG_EnC This is to support adding new field for edit and continue. This field also indicates that + a helper is needed to access this field. However this helper is always CORINFO_HELP_GETFIELDADDR, and + this helper always takes the object and field handle and returns the address of the field. It is the + JIT's responcibility to do the fetch or set. + +------------------------------------------------------------------------------- + +TODO: Talk about initializing strutures before use + + +******************************************************************************* +*/ + +#ifndef _COR_INFO_H_ +#define _COR_INFO_H_ + +#include +#include + + +// CorInfoHelpFunc defines the set of helpers (accessed via the ICorDynamicInfo::getHelperFtn()) +// These helpers can be called by native code which executes in the runtime. +// Compilers can emit calls to these helpers. +// +// The signatures of the helpers are below (see RuntimeHelperArgumentCheck) +// +// NOTE: CorInfoHelpFunc is closely related to MdilHelpFunc!!! +// +// - changing the order of jit helper ordinals works fine +// However: +// - adding a jit helpers requires usually the addition of a corresponding MdilHelper +// - removing a jit helper (or changing its arguments) should be done only sparingly +// and needs discussion with an "MDIL person". +// Please have a look also at the comment prepending the definition of MdilHelpFunc +// + +enum CorInfoHelpFunc +{ + CORINFO_HELP_UNDEF, // invalid value. This should never be used + + /* Arithmetic helpers */ + + CORINFO_HELP_DIV, // For the ARM 32-bit integer divide uses a helper call :-( + CORINFO_HELP_MOD, + CORINFO_HELP_UDIV, + CORINFO_HELP_UMOD, + + CORINFO_HELP_LLSH, + CORINFO_HELP_LRSH, + CORINFO_HELP_LRSZ, + CORINFO_HELP_LMUL, + CORINFO_HELP_LMUL_OVF, + CORINFO_HELP_ULMUL_OVF, + CORINFO_HELP_LDIV, + CORINFO_HELP_LMOD, + CORINFO_HELP_ULDIV, + CORINFO_HELP_ULMOD, + CORINFO_HELP_LNG2DBL, // Convert a signed int64 to a double + CORINFO_HELP_ULNG2DBL, // Convert a unsigned int64 to a double + CORINFO_HELP_DBL2INT, + CORINFO_HELP_DBL2INT_OVF, + CORINFO_HELP_DBL2LNG, + CORINFO_HELP_DBL2LNG_OVF, + CORINFO_HELP_DBL2UINT, + CORINFO_HELP_DBL2UINT_OVF, + CORINFO_HELP_DBL2ULNG, + CORINFO_HELP_DBL2ULNG_OVF, + CORINFO_HELP_FLTREM, + CORINFO_HELP_DBLREM, + CORINFO_HELP_FLTROUND, + CORINFO_HELP_DBLROUND, + + /* Allocating a new object. Always use ICorClassInfo::getNewHelper() to decide + which is the right helper to use to allocate an object of a given type. */ + + CORINFO_HELP_NEW_CROSSCONTEXT, // cross context new object + CORINFO_HELP_NEWFAST, + CORINFO_HELP_NEWSFAST, // allocator for small, non-finalizer, non-array object + CORINFO_HELP_NEWSFAST_ALIGN8, // allocator for small, non-finalizer, non-array object, 8 byte aligned + CORINFO_HELP_NEW_MDARR, // multi-dim array helper (with or without lower bounds) + CORINFO_HELP_NEWARR_1_DIRECT, // helper for any one dimensional array creation + CORINFO_HELP_NEWARR_1_OBJ, // optimized 1-D object arrays + CORINFO_HELP_NEWARR_1_VC, // optimized 1-D value class arrays + CORINFO_HELP_NEWARR_1_ALIGN8, // like VC, but aligns the array start + + CORINFO_HELP_STRCNS, // create a new string literal +#if !defined(RYUJIT_CTPBUILD) + CORINFO_HELP_STRCNS_CURRENT_MODULE, // create a new string literal from the current module (used by NGen code) +#endif + /* Object model */ + + CORINFO_HELP_INITCLASS, // Initialize class if not already initialized + CORINFO_HELP_INITINSTCLASS, // Initialize class for instantiated type + + // Use ICorClassInfo::getCastingHelper to determine + // the right helper to use + + CORINFO_HELP_ISINSTANCEOFINTERFACE, // Optimized helper for interfaces + CORINFO_HELP_ISINSTANCEOFARRAY, // Optimized helper for arrays + CORINFO_HELP_ISINSTANCEOFCLASS, // Optimized helper for classes + CORINFO_HELP_ISINSTANCEOFANY, // Slow helper for any type + + CORINFO_HELP_CHKCASTINTERFACE, + CORINFO_HELP_CHKCASTARRAY, + CORINFO_HELP_CHKCASTCLASS, + CORINFO_HELP_CHKCASTANY, + CORINFO_HELP_CHKCASTCLASS_SPECIAL, // Optimized helper for classes. Assumes that the trivial cases + // has been taken care of by the inlined check + + CORINFO_HELP_BOX, + CORINFO_HELP_BOX_NULLABLE, // special form of boxing for Nullable + CORINFO_HELP_UNBOX, + CORINFO_HELP_UNBOX_NULLABLE, // special form of unboxing for Nullable + CORINFO_HELP_GETREFANY, // Extract the byref from a TypedReference, checking that it is the expected type + + CORINFO_HELP_ARRADDR_ST, // assign to element of object array with type-checking + CORINFO_HELP_LDELEMA_REF, // does a precise type comparision and returns address + + /* Exceptions */ + + CORINFO_HELP_THROW, // Throw an exception object + CORINFO_HELP_RETHROW, // Rethrow the currently active exception + CORINFO_HELP_USER_BREAKPOINT, // For a user program to break to the debugger + CORINFO_HELP_RNGCHKFAIL, // array bounds check failed + CORINFO_HELP_OVERFLOW, // throw an overflow exception + CORINFO_HELP_THROWDIVZERO, // throw a divide by zero exception +#ifndef RYUJIT_CTPBUILD + CORINFO_HELP_THROWNULLREF, // throw a null reference exception +#endif + + CORINFO_HELP_INTERNALTHROW, // Support for really fast jit + CORINFO_HELP_VERIFICATION, // Throw a VerificationException + CORINFO_HELP_SEC_UNMGDCODE_EXCPT, // throw a security unmanaged code exception + CORINFO_HELP_FAIL_FAST, // Kill the process avoiding any exceptions or stack and data dependencies (use for GuardStack unsafe buffer checks) + + CORINFO_HELP_METHOD_ACCESS_EXCEPTION,//Throw an access exception due to a failed member/class access check. + CORINFO_HELP_FIELD_ACCESS_EXCEPTION, + CORINFO_HELP_CLASS_ACCESS_EXCEPTION, + + CORINFO_HELP_ENDCATCH, // call back into the EE at the end of a catch block + + /* Synchronization */ + + CORINFO_HELP_MON_ENTER, + CORINFO_HELP_MON_EXIT, + CORINFO_HELP_MON_ENTER_STATIC, + CORINFO_HELP_MON_EXIT_STATIC, + + CORINFO_HELP_GETCLASSFROMMETHODPARAM, // Given a generics method handle, returns a class handle + CORINFO_HELP_GETSYNCFROMCLASSHANDLE, // Given a generics class handle, returns the sync monitor + // in its ManagedClassObject + + /* Security callout support */ + + CORINFO_HELP_SECURITY_PROLOG, // Required if CORINFO_FLG_SECURITYCHECK is set, or CORINFO_FLG_NOSECURITYWRAP is not set + CORINFO_HELP_SECURITY_PROLOG_FRAMED, // Slow version of CORINFO_HELP_SECURITY_PROLOG. Used for instrumentation. + + CORINFO_HELP_METHOD_ACCESS_CHECK, // Callouts to runtime security access checks + CORINFO_HELP_FIELD_ACCESS_CHECK, + CORINFO_HELP_CLASS_ACCESS_CHECK, + + CORINFO_HELP_DELEGATE_SECURITY_CHECK, // Callout to delegate security transparency check + + /* Verification runtime callout support */ + + CORINFO_HELP_VERIFICATION_RUNTIME_CHECK, // Do a Demand for UnmanagedCode permission at runtime + + /* GC support */ + + CORINFO_HELP_STOP_FOR_GC, // Call GC (force a GC) + CORINFO_HELP_POLL_GC, // Ask GC if it wants to collect + + CORINFO_HELP_STRESS_GC, // Force a GC, but then update the JITTED code to be a noop call + CORINFO_HELP_CHECK_OBJ, // confirm that ECX is a valid object pointer (debugging only) + + /* GC Write barrier support */ + + CORINFO_HELP_ASSIGN_REF, // universal helpers with F_CALL_CONV calling convention + CORINFO_HELP_CHECKED_ASSIGN_REF, + CORINFO_HELP_ASSIGN_REF_ENSURE_NONHEAP, // Do the store, and ensure that the target was not in the heap. + + CORINFO_HELP_ASSIGN_BYREF, + CORINFO_HELP_ASSIGN_STRUCT, + + + /* Accessing fields */ + + // For COM object support (using COM get/set routines to update object) + // and EnC and cross-context support + CORINFO_HELP_GETFIELD8, + CORINFO_HELP_SETFIELD8, + CORINFO_HELP_GETFIELD16, + CORINFO_HELP_SETFIELD16, + CORINFO_HELP_GETFIELD32, + CORINFO_HELP_SETFIELD32, + CORINFO_HELP_GETFIELD64, + CORINFO_HELP_SETFIELD64, + CORINFO_HELP_GETFIELDOBJ, + CORINFO_HELP_SETFIELDOBJ, + CORINFO_HELP_GETFIELDSTRUCT, + CORINFO_HELP_SETFIELDSTRUCT, + CORINFO_HELP_GETFIELDFLOAT, + CORINFO_HELP_SETFIELDFLOAT, + CORINFO_HELP_GETFIELDDOUBLE, + CORINFO_HELP_SETFIELDDOUBLE, + + CORINFO_HELP_GETFIELDADDR, + + CORINFO_HELP_GETSTATICFIELDADDR_CONTEXT, // Helper for context-static fields + CORINFO_HELP_GETSTATICFIELDADDR_TLS, // Helper for PE TLS fields + + // There are a variety of specialized helpers for accessing static fields. The JIT should use + // ICorClassInfo::getSharedStaticsOrCCtorHelper to determine which helper to use + + // Helpers for regular statics + CORINFO_HELP_GETGENERICS_GCSTATIC_BASE, + CORINFO_HELP_GETGENERICS_NONGCSTATIC_BASE, + CORINFO_HELP_GETSHARED_GCSTATIC_BASE, + CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE, + CORINFO_HELP_GETSHARED_GCSTATIC_BASE_NOCTOR, + CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE_NOCTOR, + CORINFO_HELP_GETSHARED_GCSTATIC_BASE_DYNAMICCLASS, + CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE_DYNAMICCLASS, + // Helper to class initialize shared generic with dynamicclass, but not get static field address + CORINFO_HELP_CLASSINIT_SHARED_DYNAMICCLASS, + + // Helpers for thread statics + CORINFO_HELP_GETGENERICS_GCTHREADSTATIC_BASE, + CORINFO_HELP_GETGENERICS_NONGCTHREADSTATIC_BASE, + CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE, + CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE, + CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR, + CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR, + CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_DYNAMICCLASS, + CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_DYNAMICCLASS, + + /* Debugger */ + + CORINFO_HELP_DBG_IS_JUST_MY_CODE, // Check if this is "JustMyCode" and needs to be stepped through. + + /* Profiling enter/leave probe addresses */ + CORINFO_HELP_PROF_FCN_ENTER, // record the entry to a method (caller) + CORINFO_HELP_PROF_FCN_LEAVE, // record the completion of current method (caller) + CORINFO_HELP_PROF_FCN_TAILCALL, // record the completionof current method through tailcall (caller) + + /* Miscellaneous */ + + CORINFO_HELP_BBT_FCN_ENTER, // record the entry to a method for collecting Tuning data + + CORINFO_HELP_PINVOKE_CALLI, // Indirect pinvoke call + CORINFO_HELP_TAILCALL, // Perform a tail call + + CORINFO_HELP_GETCURRENTMANAGEDTHREADID, + + CORINFO_HELP_INIT_PINVOKE_FRAME, // initialize an inlined PInvoke Frame for the JIT-compiler + + CORINFO_HELP_MEMSET, // Init block of memory + CORINFO_HELP_MEMCPY, // Copy block of memory + + CORINFO_HELP_RUNTIMEHANDLE_METHOD, // determine a type/field/method handle at run-time + CORINFO_HELP_RUNTIMEHANDLE_METHOD_LOG,// determine a type/field/method handle at run-time, with IBC logging + CORINFO_HELP_RUNTIMEHANDLE_CLASS, // determine a type/field/method handle at run-time + CORINFO_HELP_RUNTIMEHANDLE_CLASS_LOG,// determine a type/field/method handle at run-time, with IBC logging + + // These helpers are required for MDIL backward compatibility only. They are not used by current JITed code. + CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE_OBSOLETE, // Convert from a TypeHandle (native structure pointer) to RuntimeTypeHandle at run-time +#if defined(RYUJIT_CTPBUILD) + CORINFO_HELP_METHODDESC_TO_RUNTIMEMETHODHANDLE_MAYBENULL_OBSOLETE, // Convert from a MethodDesc (native structure pointer) to RuntimeMethodHandle at run-time +#endif + CORINFO_HELP_METHODDESC_TO_RUNTIMEMETHODHANDLE_OBSOLETE, // Convert from a MethodDesc (native structure pointer) to RuntimeMethodHandle at run-time + CORINFO_HELP_FIELDDESC_TO_RUNTIMEFIELDHANDLE_OBSOLETE, // Convert from a FieldDesc (native structure pointer) to RuntimeFieldHandle at run-time + + CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, // Convert from a TypeHandle (native structure pointer) to RuntimeType at run-time + CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL, // Convert from a TypeHandle (native structure pointer) to RuntimeType at run-time, the type may be null + CORINFO_HELP_METHODDESC_TO_STUBRUNTIMEMETHOD, // Convert from a MethodDesc (native structure pointer) to RuntimeMethodHandle at run-time + CORINFO_HELP_FIELDDESC_TO_STUBRUNTIMEFIELD, // Convert from a FieldDesc (native structure pointer) to RuntimeFieldHandle at run-time + + CORINFO_HELP_VIRTUAL_FUNC_PTR, // look up a virtual method at run-time + //CORINFO_HELP_VIRTUAL_FUNC_PTR_LOG, // look up a virtual method at run-time, with IBC logging + +#ifndef RYUJIT_CTPBUILD + // Not a real helpers. Instead of taking handle arguments, these helpers point to a small stub that loads the handle argument and calls the static helper. + CORINFO_HELP_READYTORUN_NEW, + CORINFO_HELP_READYTORUN_NEWARR_1, + CORINFO_HELP_READYTORUN_ISINSTANCEOF, + CORINFO_HELP_READYTORUN_CHKCAST, + CORINFO_HELP_READYTORUN_STATIC_BASE, + CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, + CORINFO_HELP_READYTORUN_DELEGATE_CTOR, +#endif + +#ifdef REDHAWK + // these helpers are arbitrary since we don't have any relation to the actual CLR corinfo.h. + CORINFO_HELP_PINVOKE, // transition to preemptive mode for a pinvoke, frame in EAX + CORINFO_HELP_PINVOKE_2, // transition to preemptive mode for a pinvoke, frame in ESI / R10 + CORINFO_HELP_PINVOKE_RETURN, // return to cooperative mode from a pinvoke + CORINFO_HELP_REVERSE_PINVOKE, // transition to cooperative mode for a callback from native + CORINFO_HELP_REVERSE_PINVOKE_RETURN,// return to preemptive mode to return to native from managed + CORINFO_HELP_REGISTER_MODULE, // module load notification + CORINFO_HELP_CREATECOMMANDLINE, // get the command line from the system and return it for Main + CORINFO_HELP_VSD_INITIAL_TARGET, // all VSD indirection cells initially point to this function + CORINFO_HELP_NEW_FINALIZABLE, // allocate finalizable object + CORINFO_HELP_SHUTDOWN, // called when Main returns from a managed executable + CORINFO_HELP_CHECKARRAYSTORE, // checks that an array element assignment is of the right type + CORINFO_HELP_CHECK_VECTOR_ELEM_ADDR,// does a precise type check on the array element type + CORINFO_HELP_FLT2INT_OVF, // checked float->int conversion + CORINFO_HELP_FLT2LNG, // float->long conversion + CORINFO_HELP_FLT2LNG_OVF, // checked float->long conversion + CORINFO_HELP_FLTREM_REV, // Bartok helper for float remainder - uses reversed param order from CLR helper + CORINFO_HELP_DBLREM_REV, // Bartok helper for double remainder - uses reversed param order from CLR helper + CORINFO_HELP_HIJACKFORGCSTRESS, // this helper hijacks the caller for GC stress + CORINFO_HELP_INIT_GCSTRESS, // this helper initializes the runtime for GC stress + CORINFO_HELP_SUPPRESS_GCSTRESS, // disables gc stress + CORINFO_HELP_UNSUPPRESS_GCSTRESS, // re-enables gc stress + CORINFO_HELP_THROW_INTRA, // Throw an exception object to a hander within the method + CORINFO_HELP_THROW_INTER, // Throw an exception object to a hander within the caller + CORINFO_HELP_THROW_ARITHMETIC, // Throw the classlib-defined arithmetic exception + CORINFO_HELP_THROW_DIVIDE_BY_ZERO, // Throw the classlib-defined divide by zero exception + CORINFO_HELP_THROW_INDEX, // Throw the classlib-defined index out of range exception + CORINFO_HELP_THROW_OVERFLOW, // Throw the classlib-defined overflow exception + CORINFO_HELP_EHJUMP_SCALAR, // Helper to jump to a handler in a different method for EH dispatch. + CORINFO_HELP_EHJUMP_OBJECT, // Helper to jump to a handler in a different method for EH dispatch. + CORINFO_HELP_EHJUMP_BYREF, // Helper to jump to a handler in a different method for EH dispatch. + CORINFO_HELP_EHJUMP_SCALAR_GCSTRESS,// Helper to jump to a handler in a different method for EH dispatch. + CORINFO_HELP_EHJUMP_OBJECT_GCSTRESS,// Helper to jump to a handler in a different method for EH dispatch. + CORINFO_HELP_EHJUMP_BYREF_GCSTRESS, // Helper to jump to a handler in a different method for EH dispatch. + + // Bartok emits code with destination in ECX rather than EDX and only ever uses EDX as the reference + // register. It also only ever specifies the checked version. + CORINFO_HELP_CHECKED_ASSIGN_REF_EDX, // EDX hold GC ptr, want do a 'mov [ECX], EDX' and inform GC +#endif // REDHAWK + + CORINFO_HELP_EE_PRESTUB, // Not real JIT helper. Used in native images. + + CORINFO_HELP_EE_PRECODE_FIXUP, // Not real JIT helper. Used for Precode fixup in native images. + CORINFO_HELP_EE_PINVOKE_FIXUP, // Not real JIT helper. Used for PInvoke target fixup in native images. + CORINFO_HELP_EE_VSD_FIXUP, // Not real JIT helper. Used for VSD cell fixup in native images. + CORINFO_HELP_EE_EXTERNAL_FIXUP, // Not real JIT helper. Used for to fixup external method thunks in native images. + CORINFO_HELP_EE_VTABLE_FIXUP, // Not real JIT helper. Used for inherited vtable slot fixup in native images. + + CORINFO_HELP_EE_REMOTING_THUNK, // Not real JIT helper. Used for remoting precode in native images. + + CORINFO_HELP_EE_PERSONALITY_ROUTINE,// Not real JIT helper. Used in native images. + CORINFO_HELP_EE_PERSONALITY_ROUTINE_FILTER_FUNCLET,// Not real JIT helper. Used in native images to detect filter funclets. + + // + // Keep platform-specific helpers at the end so that the ids for the platform neutral helpers stay same accross platforms + // + +#if defined(_TARGET_X86_) || defined(_HOST_X86_) || defined(REDHAWK) // _HOST_X86_ is for altjit + // NOGC_WRITE_BARRIERS JIT helper calls + // Unchecked versions EDX is required to point into GC heap + CORINFO_HELP_ASSIGN_REF_EAX, // EAX holds GC ptr, do a 'mov [EDX], EAX' and inform GC + CORINFO_HELP_ASSIGN_REF_EBX, // EBX holds GC ptr, do a 'mov [EDX], EBX' and inform GC + CORINFO_HELP_ASSIGN_REF_ECX, // ECX holds GC ptr, do a 'mov [EDX], ECX' and inform GC + CORINFO_HELP_ASSIGN_REF_ESI, // ESI holds GC ptr, do a 'mov [EDX], ESI' and inform GC + CORINFO_HELP_ASSIGN_REF_EDI, // EDI holds GC ptr, do a 'mov [EDX], EDI' and inform GC + CORINFO_HELP_ASSIGN_REF_EBP, // EBP holds GC ptr, do a 'mov [EDX], EBP' and inform GC + + CORINFO_HELP_CHECKED_ASSIGN_REF_EAX, // These are the same as ASSIGN_REF above ... + CORINFO_HELP_CHECKED_ASSIGN_REF_EBX, // ... but also check if EDX points into heap. + CORINFO_HELP_CHECKED_ASSIGN_REF_ECX, + CORINFO_HELP_CHECKED_ASSIGN_REF_ESI, + CORINFO_HELP_CHECKED_ASSIGN_REF_EDI, + CORINFO_HELP_CHECKED_ASSIGN_REF_EBP, +#endif + +#if defined(MDIL) && defined(_TARGET_ARM_) + CORINFO_HELP_ALLOCA, // this is a "pseudo" helper call for MDIL on ARM; it is NOT implemented in the VM! + // Instead the MDIL binder generates "inline" code for it. +#endif // MDIL && _TARGET_ARM_ + + CORINFO_HELP_LOOP_CLONE_CHOICE_ADDR, // Return the reference to a counter to decide to take cloned path in debug stress. + CORINFO_HELP_DEBUG_LOG_LOOP_CLONING, // Print a message that a loop cloning optimization has occurred in debug mode. + + CORINFO_HELP_COUNT, +}; + +//This describes the signature for a helper method. +enum CorInfoHelpSig +{ + CORINFO_HELP_SIG_UNDEF, + CORINFO_HELP_SIG_NO_ALIGN_STUB, + CORINFO_HELP_SIG_NO_UNWIND_STUB, + CORINFO_HELP_SIG_REG_ONLY, + CORINFO_HELP_SIG_4_STACK, + CORINFO_HELP_SIG_8_STACK, + CORINFO_HELP_SIG_12_STACK, + CORINFO_HELP_SIG_16_STACK, + CORINFO_HELP_SIG_8_VA, //2 arguments plus varargs + + CORINFO_HELP_SIG_EBPCALL, //special calling convention that uses EDX and + //EBP as arguments + + CORINFO_HELP_SIG_CANNOT_USE_ALIGN_STUB, + + CORINFO_HELP_SIG_COUNT +}; + + + +// MdilHelpFunc defines the set of helpers in a stable fashion; thereby allowing the VM +// to change the ordinals of any helper value without invalidating MDIL images. +// To avoid "accidental" changes of MdilHelpFunc values the enum uses explicit values; +// once a value has been assigned and published, it cannot be easily taken back (only +// in connection with MDIL/CTL/CLR versioning restrictions) +// +// The client side binder will convert the MDIL helper back into the VM specific helper number. +// +// The association between MDIL helpers and "corinfo" helpers is defined in inc\jithelpers.h +// The signatures of the MDIL helpers are defined in inc\MDILHelpers.h (using CorInfoHelpSig) +// TritonToDo: use a more precise/detailed signature mechanism +// Please note that some jit helpers (or groups of related helpers) are represented +// by MDIL instruction(s) instead and therefore don't have a corresponding MDIL helper. + +enum MdilHelpFunc +{ + MDIL_HELP_UNDEF = 0x00, // invalid value. This should never be used + + /* Arithmetic helpers */ + + MDIL_HELP_DIV = 0x01, // For the ARM 32-bit integer divide uses a helper call :-( + MDIL_HELP_MOD = 0x02, + MDIL_HELP_UDIV = 0x03, + MDIL_HELP_UMOD = 0x04, + + MDIL_HELP_LLSH = 0x05, + MDIL_HELP_LRSH = 0x06, + MDIL_HELP_LRSZ = 0x07, + MDIL_HELP_LMUL = 0x08, + MDIL_HELP_LMUL_OVF = 0x09, + MDIL_HELP_ULMUL_OVF = 0x0A, + MDIL_HELP_LDIV = 0x0B, + MDIL_HELP_LMOD = 0x0C, + MDIL_HELP_ULDIV = 0x0D, + MDIL_HELP_ULMOD = 0x0E, + MDIL_HELP_LNG2DBL = 0x0F, // Convert a signed int64 to a double + MDIL_HELP_ULNG2DBL = 0x10, // Convert a unsigned int64 to a double + MDIL_HELP_DBL2INT = 0x11, + MDIL_HELP_DBL2INT_OVF = 0x12, + MDIL_HELP_DBL2LNG = 0x13, + MDIL_HELP_DBL2LNG_OVF = 0x14, + MDIL_HELP_DBL2UINT = 0x15, + MDIL_HELP_DBL2UINT_OVF = 0x16, + MDIL_HELP_DBL2ULNG = 0x17, + MDIL_HELP_DBL2ULNG_OVF = 0x18, + MDIL_HELP_FLTREM = 0x19, + MDIL_HELP_DBLREM = 0x1A, + MDIL_HELP_FLTROUND = 0x1B, + MDIL_HELP_DBLROUND = 0x1C, + + /* Allocating a new object. Always use ICorClassInfo::getNewHelper() to decide + which is the right helper to use to allocate an object of a given type. */ + MDIL_HELP_NEW_CROSSCONTEXT = 0x1D, // cross context new object + MDIL_HELP_NEWFAST = 0x1E, + MDIL_HELP_NEWSFAST = 0x1F, // allocator for small, non-finalizer, non-array object + MDIL_HELP_NEWSFAST_ALIGN8 = 0x20, // allocator for small, non-finalizer, non-array object, 8 byte aligned + MDIL_HELP_NEW_MDARR = 0x21, // multi-dim array helper (with or without lower bounds) + MDIL_HELP_STRCNS = 0x22, // create a new string literal + + /* Object model */ + + MDIL_HELP_INITCLASS = 0x23, // Initialize class if not already initialized + MDIL_HELP_INITINSTCLASS = 0x24, // Initialize class for instantiated type + + // Use ICorClassInfo::getCastingHelper to determine + // the right helper to use + + MDIL_HELP_ISINSTANCEOFINTERFACE = 0x25, // Optimized helper for interfaces + MDIL_HELP_ISINSTANCEOFARRAY = 0x26, // Optimized helper for arrays + MDIL_HELP_ISINSTANCEOFCLASS = 0x27, // Optimized helper for classes + MDIL_HELP_CHKCASTINTERFACE = 0x28, + MDIL_HELP_CHKCASTARRAY = 0x29, + MDIL_HELP_CHKCASTCLASS = 0x2A, + MDIL_HELP_CHKCASTCLASS_SPECIAL = 0x2B, // Optimized helper for classes. Assumes that the trivial cases + // has been taken care of by the inlined check + MDIL_HELP_UNBOX_NULLABLE = 0x2C, // special form of unboxing for Nullable + MDIL_HELP_GETREFANY = 0x2D, // Extract the byref from a TypedReference, checking that it is the expected type + + MDIL_HELP_ARRADDR_ST = 0x2E, // assign to element of object array with type-checking + MDIL_HELP_LDELEMA_REF = 0x2F, // does a precise type comparision and returns address + + /* Exceptions */ + MDIL_HELP_USER_BREAKPOINT = 0x30, // For a user program to break to the debugger + MDIL_HELP_RNGCHKFAIL = 0x31, // array bounds check failed + MDIL_HELP_OVERFLOW = 0x32, // throw an overflow exception + + MDIL_HELP_INTERNALTHROW = 0x33, // Support for really fast jit + MDIL_HELP_VERIFICATION = 0x34, // Throw a VerificationException + MDIL_HELP_SEC_UNMGDCODE_EXCPT= 0x35, // throw a security unmanaged code exception + MDIL_HELP_FAIL_FAST = 0x36, // Kill the process avoiding any exceptions or stack and data dependencies (use for GuardStack unsafe buffer checks) + + MDIL_HELP_METHOD_ACCESS_EXCEPTION = 0x37, //Throw an access exception due to a failed member/class access check. + MDIL_HELP_FIELD_ACCESS_EXCEPTION = 0x38, + MDIL_HELP_CLASS_ACCESS_EXCEPTION = 0x39, + + MDIL_HELP_ENDCATCH = 0x3A, // call back into the EE at the end of a catch block + + /* Synchronization */ + + MDIL_HELP_MON_ENTER = 0x3B, + MDIL_HELP_MON_EXIT = 0x3C, + MDIL_HELP_MON_ENTER_STATIC = 0x3D, + MDIL_HELP_MON_EXIT_STATIC = 0x3E, + + MDIL_HELP_GETCLASSFROMMETHODPARAM = 0x3F, // Given a generics method handle, returns a class handle + MDIL_HELP_GETSYNCFROMCLASSHANDLE = 0x40, // Given a generics class handle, returns the sync monitor + // in its ManagedClassObject + + /* Security callout support */ + + MDIL_HELP_SECURITY_PROLOG = 0x41, // Required if CORINFO_FLG_SECURITYCHECK is set, or CORINFO_FLG_NOSECURITYWRAP is not set + MDIL_HELP_SECURITY_PROLOG_FRAMED = 0x42, // Slow version of MDIL_HELP_SECURITY_PROLOG. Used for instrumentation. + + MDIL_HELP_METHOD_ACCESS_CHECK = 0x43, // Callouts to runtime security access checks + MDIL_HELP_FIELD_ACCESS_CHECK = 0x44, + MDIL_HELP_CLASS_ACCESS_CHECK = 0x45, + + MDIL_HELP_DELEGATE_SECURITY_CHECK= 0x46, // Callout to delegate security transparency check + + /* Verification runtime callout support */ + + MDIL_HELP_VERIFICATION_RUNTIME_CHECK=0x47, // Do a Demand for UnmanagedCode permission at runtime + + /* GC support */ + + MDIL_HELP_STOP_FOR_GC = 0x48, // Call GC (force a GC) + MDIL_HELP_POLL_GC = 0x49, // Ask GC if it wants to collect + + MDIL_HELP_STRESS_GC = 0x4A, // Force a GC, but then update the JITTED code to be a noop call + MDIL_HELP_CHECK_OBJ = 0x4B, // confirm that ECX is a valid object pointer (debugging only) + + /* GC Write barrier support */ + + MDIL_HELP_ASSIGN_REF = 0x4C, // universal helpers with F_CALL_CONV calling convention + MDIL_HELP_CHECKED_ASSIGN_REF = 0x4D, + + MDIL_HELP_ASSIGN_BYREF = 0x4E, + MDIL_HELP_ASSIGN_STRUCT = 0x4F, + + + /* Accessing fields */ + + // For COM object support (using COM get/set routines to update object) + // and EnC and cross-context support + MDIL_HELP_GETFIELD32 = 0x50, + MDIL_HELP_SETFIELD32 = 0x51, + MDIL_HELP_GETFIELD64 = 0x52, + MDIL_HELP_SETFIELD64 = 0x53, + MDIL_HELP_GETFIELDOBJ = 0x54, + MDIL_HELP_SETFIELDOBJ = 0x55, + MDIL_HELP_GETFIELDSTRUCT = 0x56, + MDIL_HELP_SETFIELDSTRUCT = 0x57, + MDIL_HELP_GETFIELDFLOAT = 0x58, + MDIL_HELP_SETFIELDFLOAT = 0x59, + MDIL_HELP_GETFIELDDOUBLE = 0x5A, + MDIL_HELP_SETFIELDDOUBLE = 0x5B, + + MDIL_HELP_GETFIELDADDR = 0x5C, + + MDIL_HELP_GETSTATICFIELDADDR_CONTEXT = 0x5D, // Helper for context-static fields + MDIL_HELP_GETSTATICFIELDADDR_TLS = 0x5E, // Helper for PE TLS fields + + // There are a variety of specialized helpers for accessing static fields. The JIT should use + // ICorClassInfo::getSharedStaticsOrCCtorHelper to determine which helper to use + + /* Debugger */ + + MDIL_HELP_DBG_IS_JUST_MY_CODE= 0x5F, // Check if this is "JustMyCode" and needs to be stepped through. + + /* Profiling enter/leave probe addresses */ + MDIL_HELP_PROF_FCN_ENTER = 0x60, // record the entry to a method (caller) + MDIL_HELP_PROF_FCN_LEAVE = 0x61, // record the completion of current method (caller) + MDIL_HELP_PROF_FCN_TAILCALL = 0x62, // record the completionof current method through tailcall (caller) + + /* Miscellaneous */ + + MDIL_HELP_BBT_FCN_ENTER = 0x63, // record the entry to a method for collecting Tuning data + + MDIL_HELP_PINVOKE_CALLI = 0x64, // Indirect pinvoke call + MDIL_HELP_TAILCALL = 0x65, // Perform a tail call + + MDIL_HELP_GETCURRENTMANAGEDTHREADID = 0x66, + + MDIL_HELP_INIT_PINVOKE_FRAME = 0x67, // initialize an inlined PInvoke Frame for the JIT-compiler + MDIL_HELP_CHECK_PINVOKE_DOMAIN = 0x68, // check which domain the pinvoke call is in + + MDIL_HELP_MEMSET = 0x69, // Init block of memory + MDIL_HELP_MEMCPY = 0x6A, // Copy block of memory + + MDIL_HELP_RUNTIMEHANDLE_METHOD = 0x6B, // determine a type/field/method handle at run-time + MDIL_HELP_RUNTIMEHANDLE_METHOD_LOG = 0x6C, // determine a type/field/method handle at run-time, with IBC logging + MDIL_HELP_RUNTIMEHANDLE_CLASS = 0x6D, // determine a type/field/method handle at run-time + MDIL_HELP_RUNTIMEHANDLE_CLASS_LOG = 0x6E, // determine a type/field/method handle at run-time, with IBC logging + MDIL_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE = 0x6F, // Convert from a TypeHandle (native structure pointer) to RuntimeTypeHandle at run-time + MDIL_HELP_METHODDESC_TO_RUNTIMEMETHODHANDLE = 0x70, // Convert from a MethodDesc (native structure pointer) to RuntimeMethodHandle at run-time + MDIL_HELP_FIELDDESC_TO_RUNTIMEFIELDHANDLE = 0x71, // Convert from a FieldDesc (native structure pointer) to RuntimeFieldHandle at run-time + MDIL_HELP_TYPEHANDLE_TO_RUNTIMETYPE = 0x72, // Convert from a TypeHandle (native structure pointer) to RuntimeType at run-time + MDIL_HELP_METHODDESC_TO_STUBRUNTIMEMETHOD = 0x73, // Convert from a MethodDesc (native structure pointer) to RuntimeMethodHandle at run-time + MDIL_HELP_FIELDDESC_TO_STUBRUNTIMEFIELD = 0x74, // Convert from a FieldDesc (native structure pointer) to RuntimeFieldHandle at run-time + + MDIL_HELP_VIRTUAL_FUNC_PTR = 0x75, // look up a virtual method at run-time + + MDIL_HELP_EE_PRESTUB = 0x76, // Not real JIT helper. Used in native images. + + MDIL_HELP_EE_PRECODE_FIXUP = 0x77, // Not real JIT helper. Used for Precode fixup in native images. + MDIL_HELP_EE_PINVOKE_FIXUP = 0x78, // Not real JIT helper. Used for PInvoke target fixup in native images. + MDIL_HELP_EE_VSD_FIXUP = 0x79, // Not real JIT helper. Used for VSD cell fixup in native images. + MDIL_HELP_EE_EXTERNAL_FIXUP = 0x7A, // Not real JIT helper. Used for to fixup external method thunks in native images. + MDIL_HELP_EE_VTABLE_FIXUP = 0x7B, // Not real JIT helper. Used for inherited vtable slot fixup in native images. + + MDIL_HELP_EE_REMOTING_THUNK = 0x7C, // Not real JIT helper. Used for remoting precode in native images. + + MDIL_HELP_EE_PERSONALITY_ROUTINE=0x7D, // Not real JIT helper. Used in native images. + + // + // Keep platform-specific helpers at the end so that the ids for the platform neutral helpers stay same accross platforms + // + +#if defined(_TARGET_X86_) || defined(_HOST_X86_) || defined(REDHAWK) // _HOST_X86_ is for altjit + // NOGC_WRITE_BARRIERS JIT helper calls + // Unchecked versions EDX is required to point into GC heap + MDIL_HELP_ASSIGN_REF_EAX = 0x7E, // EAX holds GC ptr, do a 'mov [EDX], EAX' and inform GC + MDIL_HELP_ASSIGN_REF_EBX = 0x7F, // EBX holds GC ptr, do a 'mov [EDX], EBX' and inform GC + MDIL_HELP_ASSIGN_REF_ECX = 0x80, // ECX holds GC ptr, do a 'mov [EDX], ECX' and inform GC + MDIL_HELP_ASSIGN_REF_ESI = 0x81, // ESI holds GC ptr, do a 'mov [EDX], ESI' and inform GC + MDIL_HELP_ASSIGN_REF_EDI = 0x82, // EDI holds GC ptr, do a 'mov [EDX], EDI' and inform GC + MDIL_HELP_ASSIGN_REF_EBP = 0x83, // EBP holds GC ptr, do a 'mov [EDX], EBP' and inform GC + + MDIL_HELP_CHECKED_ASSIGN_REF_EAX = 0x84, // These are the same as ASSIGN_REF above ... + MDIL_HELP_CHECKED_ASSIGN_REF_EBX = 0x85, // ... but also check if EDX points into heap. + MDIL_HELP_CHECKED_ASSIGN_REF_ECX = 0x86, + MDIL_HELP_CHECKED_ASSIGN_REF_ESI = 0x87, + MDIL_HELP_CHECKED_ASSIGN_REF_EDI = 0x88, + MDIL_HELP_CHECKED_ASSIGN_REF_EBP = 0x89, +#endif + + MDIL_HELP_ASSIGN_REF_ENSURE_NONHEAP = 0x8A, // Do the store, and ensure that the target was not in the heap. + +#if !defined(_TARGET_X86_) + MDIL_HELP_EE_PERSONALITY_ROUTINE_FILTER_FUNCLET = 0x90, +#endif + +#if defined(_TARGET_ARM_) + MDIL_HELP_ALLOCA = 0x9A, // this is a "pseudo" helper call for MDIL on ARM; it is NOT implemented in the VM! + // Instead the MDIL binder generates "inline" code for it. +#endif // _TARGET_ARM_ + + MDIL_HELP_GETFIELD8 = 0xA0, + MDIL_HELP_SETFIELD8 = 0xA1, + MDIL_HELP_GETFIELD16 = 0xA2, + MDIL_HELP_SETFIELD16 = 0xA3, + +#ifdef REDHAWK + // these helpers are arbitrary since we don't have any relation to the actual CLR corinfo.h. + MDIL_HELP_PINVOKE = 0xB0, // transition to preemptive mode for a pinvoke, frame in EAX + MDIL_HELP_PINVOKE_2 = 0xB1, // transition to preemptive mode for a pinvoke, frame in ESI / R10 + MDIL_HELP_PINVOKE_RETURN = 0xB2, // return to cooperative mode from a pinvoke + MDIL_HELP_REVERSE_PINVOKE = 0xB3, // transition to cooperative mode for a callback from native + MDIL_HELP_REVERSE_PINVOKE_RETURN = 0xB4, // return to preemptive mode to return to native from managed + MDIL_HELP_REGISTER_MODULE = 0xB5, // module load notification + MDIL_HELP_CREATECOMMANDLINE = 0xB6, // get the command line from the system and return it for Main + MDIL_HELP_VSD_INITIAL_TARGET = 0xB7, // all VSD indirection cells initially point to this function + MDIL_HELP_NEW_FINALIZABLE = 0xB8, // allocate finalizable object + MDIL_HELP_SHUTDOWN = 0xB9, // called when Main returns from a managed executable + MDIL_HELP_CHECKARRAYSTORE = 0xBA, // checks that an array element assignment is of the right type + MDIL_HELP_CHECK_VECTOR_ELEM_ADDR = 0xBB, // does a precise type check on the array element type + MDIL_HELP_FLT2INT_OVF = 0xBC, // checked float->int conversion + MDIL_HELP_FLT2LNG = 0xBD, // float->long conversion + MDIL_HELP_FLT2LNG_OVF = 0xBE, // checked float->long conversion + MDIL_HELP_FLTREM_REV = 0xBF, // Bartok helper for float remainder - uses reversed param order from CLR helper + MDIL_HELP_DBLREM_REV = 0xC0, // Bartok helper for double remainder - uses reversed param order from CLR helper + MDIL_HELP_HIJACKFORGCSTRESS = 0xC1, // this helper hijacks the caller for GC stress + MDIL_HELP_INIT_GCSTRESS = 0xC2, // this helper initializes the runtime for GC stress + MDIL_HELP_SUPPRESS_GCSTRESS = 0xC3, // disables gc stress + MDIL_HELP_UNSUPPRESS_GCSTRESS= 0xC4, // re-enables gc stress + MDIL_HELP_THROW_INTRA = 0xC5, // Throw an exception object to a hander within the method + MDIL_HELP_THROW_INTER = 0xC6, // Throw an exception object to a hander within the caller + MDIL_HELP_THROW_ARITHMETIC = 0xC7, // Throw the classlib-defined arithmetic exception + MDIL_HELP_THROW_DIVIDE_BY_ZERO = 0xC8, // Throw the classlib-defined divide by zero exception + MDIL_HELP_THROW_INDEX = 0xC9, // Throw the classlib-defined index out of range exception + MDIL_HELP_THROW_OVERFLOW = 0xCA, // Throw the classlib-defined overflow exception + MDIL_HELP_EHJUMP_SCALAR = 0xCB, // Helper to jump to a handler in a different method for EH dispatch. + MDIL_HELP_EHJUMP_OBJECT = 0xCC, // Helper to jump to a handler in a different method for EH dispatch. + MDIL_HELP_EHJUMP_BYREF = 0xCD, // Helper to jump to a handler in a different method for EH dispatch. + MDIL_HELP_EHJUMP_SCALAR_GCSTRESS = 0xCE, // Helper to jump to a handler in a different method for EH dispatch. + MDIL_HELP_EHJUMP_OBJECT_GCSTRESS = 0XCF, // Helper to jump to a handler in a different method for EH dispatch. + MDIL_HELP_EHJUMP_BYREF_GCSTRESS = 0xD0, // Helper to jump to a handler in a different method for EH dispatch. + + // Bartok emits code with destination in ECX rather than EDX and only ever uses EDX as the reference + // register. It also only ever specifies the checked version. + MDIL_HELP_CHECKED_ASSIGN_REF_EDX = 0xD1, // EDX hold GC ptr, want do a 'mov [ECX], EDX' and inform GC + MDIL_HELP_COUNT = MDIL_HELP_CHECKED_ASSIGN_REF_EDX+1, +#else + MDIL_HELP_COUNT = 0xA4, +#endif // REDHAWK + + + +}; + + +// The enumeration is returned in 'getSig','getType', getArgType methods +enum CorInfoType +{ + CORINFO_TYPE_UNDEF = 0x0, + CORINFO_TYPE_VOID = 0x1, + CORINFO_TYPE_BOOL = 0x2, + CORINFO_TYPE_CHAR = 0x3, + CORINFO_TYPE_BYTE = 0x4, + CORINFO_TYPE_UBYTE = 0x5, + CORINFO_TYPE_SHORT = 0x6, + CORINFO_TYPE_USHORT = 0x7, + CORINFO_TYPE_INT = 0x8, + CORINFO_TYPE_UINT = 0x9, + CORINFO_TYPE_LONG = 0xa, + CORINFO_TYPE_ULONG = 0xb, + CORINFO_TYPE_NATIVEINT = 0xc, + CORINFO_TYPE_NATIVEUINT = 0xd, + CORINFO_TYPE_FLOAT = 0xe, + CORINFO_TYPE_DOUBLE = 0xf, + CORINFO_TYPE_STRING = 0x10, // Not used, should remove + CORINFO_TYPE_PTR = 0x11, + CORINFO_TYPE_BYREF = 0x12, + CORINFO_TYPE_VALUECLASS = 0x13, + CORINFO_TYPE_CLASS = 0x14, + CORINFO_TYPE_REFANY = 0x15, + + // CORINFO_TYPE_VAR is for a generic type variable. + // Generic type variables only appear when the JIT is doing + // verification (not NOT compilation) of generic code + // for the EE, in which case we're running + // the JIT in "import only" mode. + + CORINFO_TYPE_VAR = 0x16, + CORINFO_TYPE_COUNT, // number of jit types +}; + +enum CorInfoTypeWithMod +{ + CORINFO_TYPE_MASK = 0x3F, // lower 6 bits are type mask + CORINFO_TYPE_MOD_PINNED = 0x40, // can be applied to CLASS, or BYREF to indiate pinned +}; + +inline CorInfoType strip(CorInfoTypeWithMod val) { + return CorInfoType(val & CORINFO_TYPE_MASK); +} + +// The enumeration is returned in 'getSig' + +enum CorInfoCallConv +{ + // These correspond to CorCallingConvention + + CORINFO_CALLCONV_DEFAULT = 0x0, + CORINFO_CALLCONV_C = 0x1, + CORINFO_CALLCONV_STDCALL = 0x2, + CORINFO_CALLCONV_THISCALL = 0x3, + CORINFO_CALLCONV_FASTCALL = 0x4, + CORINFO_CALLCONV_VARARG = 0x5, + CORINFO_CALLCONV_FIELD = 0x6, + CORINFO_CALLCONV_LOCAL_SIG = 0x7, + CORINFO_CALLCONV_PROPERTY = 0x8, + CORINFO_CALLCONV_NATIVEVARARG = 0xb, // used ONLY for IL stub PInvoke vararg calls + + CORINFO_CALLCONV_MASK = 0x0f, // Calling convention is bottom 4 bits + CORINFO_CALLCONV_GENERIC = 0x10, + CORINFO_CALLCONV_HASTHIS = 0x20, + CORINFO_CALLCONV_EXPLICITTHIS=0x40, + CORINFO_CALLCONV_PARAMTYPE = 0x80, // Passed last. Same as CORINFO_GENERICS_CTXT_FROM_PARAMTYPEARG +}; + +enum CorInfoUnmanagedCallConv +{ + // These correspond to CorUnmanagedCallingConvention + + CORINFO_UNMANAGED_CALLCONV_UNKNOWN, + CORINFO_UNMANAGED_CALLCONV_C, + CORINFO_UNMANAGED_CALLCONV_STDCALL, + CORINFO_UNMANAGED_CALLCONV_THISCALL, + CORINFO_UNMANAGED_CALLCONV_FASTCALL +}; + +// These are returned from getMethodOptions +enum CorInfoOptions +{ + CORINFO_OPT_INIT_LOCALS = 0x00000010, // zero initialize all variables + + CORINFO_GENERICS_CTXT_FROM_THIS = 0x00000020, // is this shared generic code that access the generic context from the this pointer? If so, then if the method has SEH then the 'this' pointer must always be reported and kept alive. + CORINFO_GENERICS_CTXT_FROM_METHODDESC = 0x00000040, // is this shared generic code that access the generic context from the ParamTypeArg(that is a MethodDesc)? If so, then if the method has SEH then the 'ParamTypeArg' must always be reported and kept alive. Same as CORINFO_CALLCONV_PARAMTYPE + CORINFO_GENERICS_CTXT_FROM_METHODTABLE = 0x00000080, // is this shared generic code that access the generic context from the ParamTypeArg(that is a MethodTable)? If so, then if the method has SEH then the 'ParamTypeArg' must always be reported and kept alive. Same as CORINFO_CALLCONV_PARAMTYPE + CORINFO_GENERICS_CTXT_MASK = (CORINFO_GENERICS_CTXT_FROM_THIS | + CORINFO_GENERICS_CTXT_FROM_METHODDESC | + CORINFO_GENERICS_CTXT_FROM_METHODTABLE), + CORINFO_GENERICS_CTXT_KEEP_ALIVE = 0x00000100, // Keep the generics context alive throughout the method even if there is no explicit use, and report its location to the CLR + +}; + +// +// what type of code region we are in +// +enum CorInfoRegionKind +{ + CORINFO_REGION_NONE, + CORINFO_REGION_HOT, + CORINFO_REGION_COLD, + CORINFO_REGION_JIT, +}; + + +// these are the attribute flags for fields and methods (getMethodAttribs) +enum CorInfoFlag +{ +// CORINFO_FLG_UNUSED = 0x00000001, +// CORINFO_FLG_UNUSED = 0x00000002, + CORINFO_FLG_PROTECTED = 0x00000004, + CORINFO_FLG_STATIC = 0x00000008, + CORINFO_FLG_FINAL = 0x00000010, + CORINFO_FLG_SYNCH = 0x00000020, + CORINFO_FLG_VIRTUAL = 0x00000040, +// CORINFO_FLG_UNUSED = 0x00000080, + CORINFO_FLG_NATIVE = 0x00000100, +// CORINFO_FLG_UNUSED = 0x00000200, + CORINFO_FLG_ABSTRACT = 0x00000400, + + CORINFO_FLG_EnC = 0x00000800, // member was added by Edit'n'Continue + + // These are internal flags that can only be on methods + CORINFO_FLG_FORCEINLINE = 0x00010000, // The method should be inlined if possible. + CORINFO_FLG_SHAREDINST = 0x00020000, // the code for this method is shared between different generic instantiations (also set on classes/types) + CORINFO_FLG_DELEGATE_INVOKE = 0x00040000, // "Delegate + CORINFO_FLG_PINVOKE = 0x00080000, // Is a P/Invoke call + CORINFO_FLG_SECURITYCHECK = 0x00100000, // Is one of the security routines that does a stackwalk (e.g. Assert, Demand) + CORINFO_FLG_NOGCCHECK = 0x00200000, // This method is FCALL that has no GC check. Don't put alone in loops + CORINFO_FLG_INTRINSIC = 0x00400000, // This method MAY have an intrinsic ID + CORINFO_FLG_CONSTRUCTOR = 0x00800000, // This method is an instance or type initializer +// CORINFO_FLG_UNUSED = 0x01000000, +// CORINFO_FLG_UNUSED = 0x02000000, + CORINFO_FLG_NOSECURITYWRAP = 0x04000000, // The method requires no security checks + CORINFO_FLG_DONT_INLINE = 0x10000000, // The method should not be inlined + CORINFO_FLG_DONT_INLINE_CALLER = 0x20000000, // The method should not be inlined, nor should its callers. It cannot be tail called. +// CORINFO_FLG_UNUSED = 0x40000000, + + // These are internal flags that can only be on Classes + CORINFO_FLG_VALUECLASS = 0x00010000, // is the class a value class +// This flag is define din the Methods section, but is also valid on classes. +// CORINFO_FLG_SHAREDINST = 0x00020000, // This class is satisfies TypeHandle::IsCanonicalSubtype + CORINFO_FLG_VAROBJSIZE = 0x00040000, // the object size varies depending of constructor args + CORINFO_FLG_ARRAY = 0x00080000, // class is an array class (initialized differently) + CORINFO_FLG_OVERLAPPING_FIELDS = 0x00100000, // struct or class has fields that overlap (aka union) + CORINFO_FLG_INTERFACE = 0x00200000, // it is an interface + CORINFO_FLG_CONTEXTFUL = 0x00400000, // is this a contextful class? + CORINFO_FLG_CUSTOMLAYOUT = 0x00800000, // does this struct have custom layout? + CORINFO_FLG_CONTAINS_GC_PTR = 0x01000000, // does the class contain a gc ptr ? + CORINFO_FLG_DELEGATE = 0x02000000, // is this a subclass of delegate or multicast delegate ? + CORINFO_FLG_MARSHAL_BYREF = 0x04000000, // is this a subclass of MarshalByRef ? + CORINFO_FLG_CONTAINS_STACK_PTR = 0x08000000, // This class has a stack pointer inside it + CORINFO_FLG_VARIANCE = 0x10000000, // MethodTable::HasVariance (sealed does *not* mean uncast-able) + CORINFO_FLG_BEFOREFIELDINIT = 0x20000000, // Additional flexibility for when to run .cctor (see code:#ClassConstructionFlags) + CORINFO_FLG_GENERIC_TYPE_VARIABLE = 0x40000000, // This is really a handle for a variable type + CORINFO_FLG_UNSAFE_VALUECLASS = 0x80000000, // Unsafe (C++'s /GS) value type +}; + +// Flags computed by a runtime compiler +enum CorInfoMethodRuntimeFlags +{ + CORINFO_FLG_BAD_INLINEE = 0x00000001, // The method is not suitable for inlining + CORINFO_FLG_VERIFIABLE = 0x00000002, // The method has verifiable code + CORINFO_FLG_UNVERIFIABLE = 0x00000004, // The method has unverifiable code +}; + + +enum CORINFO_ACCESS_FLAGS +{ + CORINFO_ACCESS_ANY = 0x0000, // Normal access + CORINFO_ACCESS_THIS = 0x0001, // Accessed via the this reference + CORINFO_ACCESS_UNWRAP = 0x0002, // Accessed via an unwrap reference + + CORINFO_ACCESS_NONNULL = 0x0004, // Instance is guaranteed non-null + + CORINFO_ACCESS_LDFTN = 0x0010, // Accessed via ldftn + + // Field access flags + CORINFO_ACCESS_GET = 0x0100, // Field get (ldfld) + CORINFO_ACCESS_SET = 0x0200, // Field set (stfld) + CORINFO_ACCESS_ADDRESS = 0x0400, // Field address (ldflda) + CORINFO_ACCESS_INIT_ARRAY = 0x0800, // Field use for InitializeArray + CORINFO_ACCESS_INLINECHECK= 0x8000, // Return fieldFlags and fieldAccessor only. Used by JIT64 during inlining. +}; + +// These are the flags set on an CORINFO_EH_CLAUSE +enum CORINFO_EH_CLAUSE_FLAGS +{ + CORINFO_EH_CLAUSE_NONE = 0, + CORINFO_EH_CLAUSE_FILTER = 0x0001, // If this bit is on, then this EH entry is for a filter + CORINFO_EH_CLAUSE_FINALLY = 0x0002, // This clause is a finally clause + CORINFO_EH_CLAUSE_FAULT = 0x0004, // This clause is a fault clause +#ifdef REDHAWK + CORINFO_EH_CLAUSE_METHOD_BOUNDARY = 0x0008, // This clause indicates the boundary of an inlined method + CORINFO_EH_CLAUSE_FAIL_FAST = 0x0010, // This clause will cause the exception to go unhandled + CORINFO_EH_CLAUSE_INDIRECT_TYPE_REFERENCE = 0x0020, // This clause is typed, but type reference is indirect. +#endif +}; + +// This enumeration is passed to InternalThrow +enum CorInfoException +{ + CORINFO_NullReferenceException, + CORINFO_DivideByZeroException, + CORINFO_InvalidCastException, + CORINFO_IndexOutOfRangeException, + CORINFO_OverflowException, + CORINFO_SynchronizationLockException, + CORINFO_ArrayTypeMismatchException, + CORINFO_RankException, + CORINFO_ArgumentNullException, + CORINFO_ArgumentException, + CORINFO_Exception_Count, +}; + + +// This enumeration is returned by getIntrinsicID. Methods corresponding to +// these values will have "well-known" specified behavior. Calls to these +// methods could be replaced with inlined code corresponding to the +// specified behavior (without having to examine the IL beforehand). + +enum CorInfoIntrinsics +{ + CORINFO_INTRINSIC_Sin, + CORINFO_INTRINSIC_Cos, + CORINFO_INTRINSIC_Sqrt, + CORINFO_INTRINSIC_Abs, + CORINFO_INTRINSIC_Round, + CORINFO_INTRINSIC_GetChar, // fetch character out of string + CORINFO_INTRINSIC_Array_GetDimLength, // Get number of elements in a given dimension of an array + CORINFO_INTRINSIC_Array_Get, // Get the value of an element in an array + CORINFO_INTRINSIC_Array_Address, // Get the address of an element in an array + CORINFO_INTRINSIC_Array_Set, // Set the value of an element in an array + CORINFO_INTRINSIC_StringGetChar, // fetch character out of string + CORINFO_INTRINSIC_StringLength, // get the length + CORINFO_INTRINSIC_InitializeArray, // initialize an array from static data + CORINFO_INTRINSIC_GetTypeFromHandle, + CORINFO_INTRINSIC_RTH_GetValueInternal, + CORINFO_INTRINSIC_TypeEQ, + CORINFO_INTRINSIC_TypeNEQ, + CORINFO_INTRINSIC_Object_GetType, + CORINFO_INTRINSIC_StubHelpers_GetStubContext, +#ifdef _WIN64 + CORINFO_INTRINSIC_StubHelpers_GetStubContextAddr, +#endif // _WIN64 + CORINFO_INTRINSIC_StubHelpers_GetNDirectTarget, + CORINFO_INTRINSIC_InterlockedAdd32, + CORINFO_INTRINSIC_InterlockedAdd64, + CORINFO_INTRINSIC_InterlockedXAdd32, + CORINFO_INTRINSIC_InterlockedXAdd64, + CORINFO_INTRINSIC_InterlockedXchg32, + CORINFO_INTRINSIC_InterlockedXchg64, + CORINFO_INTRINSIC_InterlockedCmpXchg32, + CORINFO_INTRINSIC_InterlockedCmpXchg64, + CORINFO_INTRINSIC_MemoryBarrier, + CORINFO_INTRINSIC_GetCurrentManagedThread, + CORINFO_INTRINSIC_GetManagedThreadId, + + CORINFO_INTRINSIC_Count, + CORINFO_INTRINSIC_Illegal = -1, // Not a true intrinsic, +}; + +// Can a value be accessed directly from JITed code. +enum InfoAccessType +{ + IAT_VALUE, // The info value is directly available + IAT_PVALUE, // The value needs to be accessed via an indirection + IAT_PPVALUE // The value needs to be accessed via a double indirection +}; + +enum CorInfoGCType +{ + TYPE_GC_NONE, // no embedded objectrefs + TYPE_GC_REF, // Is an object ref + TYPE_GC_BYREF, // Is an interior pointer - promote it but don't scan it + TYPE_GC_OTHER // requires type-specific treatment +}; + +enum CorInfoClassId +{ + CLASSID_SYSTEM_OBJECT, + CLASSID_TYPED_BYREF, + CLASSID_TYPE_HANDLE, + CLASSID_FIELD_HANDLE, + CLASSID_METHOD_HANDLE, + CLASSID_STRING, + CLASSID_ARGUMENT_HANDLE, + CLASSID_RUNTIME_TYPE, +}; + +enum CorInfoInline +{ + INLINE_PASS = 0, // Inlining OK + + // failures are negative + INLINE_FAIL = -1, // Inlining not OK for this case only + INLINE_NEVER = -2, // This method should never be inlined, regardless of context +}; + +enum CorInfoInlineRestrictions +{ + INLINE_RESPECT_BOUNDARY = 0x00000001, // You can inline if there are no calls from the method being inlined + INLINE_NO_CALLEE_LDSTR = 0x00000002, // You can inline only if you guarantee that if inlinee does an ldstr + // inlinee's module will never see that string (by any means). + // This is due to how we implement the NoStringInterningAttribute + // (by reusing the fixup table). + INLINE_SAME_THIS = 0x00000004, // You can inline only if the callee is on the same this reference as caller +}; + + +// If you add more values here, keep it in sync with TailCallTypeMap in ..\vm\ClrEtwAll.man +// and the string enum in CEEInfo::reportTailCallDecision in ..\vm\JITInterface.cpp +enum CorInfoTailCall +{ + TAILCALL_OPTIMIZED = 0, // Optimized tail call (epilog + jmp) + TAILCALL_RECURSIVE = 1, // Optimized into a loop (only when a method tail calls itself) + TAILCALL_HELPER = 2, // Helper assisted tail call (call to JIT_TailCall) + + // failures are negative + TAILCALL_FAIL = -1, // Couldn't do a tail call +}; + +enum CorInfoCanSkipVerificationResult +{ + CORINFO_VERIFICATION_CANNOT_SKIP = 0, // Cannot skip verification during jit time. + CORINFO_VERIFICATION_CAN_SKIP = 1, // Can skip verification during jit time. + CORINFO_VERIFICATION_RUNTIME_CHECK = 2, // Cannot skip verification during jit time, + // but need to insert a callout to the VM to ask during runtime + // whether to raise a verification or not (if the method is unverifiable). + CORINFO_VERIFICATION_DONT_JIT = 3, // Cannot skip verification during jit time, + // but do not jit the method if is is unverifiable. +}; + +enum CorInfoInitClassResult +{ + CORINFO_INITCLASS_NOT_REQUIRED = 0x00, // No class initialization required, but the class is not actually initialized yet + // (e.g. we are guaranteed to run the static constructor in method prolog) + CORINFO_INITCLASS_INITIALIZED = 0x01, // Class initialized + CORINFO_INITCLASS_SPECULATIVE = 0x02, // Class may be initialized speculatively + CORINFO_INITCLASS_USE_HELPER = 0x04, // The JIT must insert class initialization helper call. + CORINFO_INITCLASS_DONT_INLINE = 0x08, // The JIT should not inline the method requesting the class initialization. The class + // initialization requires helper class now, but will not require initialization + // if the method is compiled standalone. Or the method cannot be inlined due to some + // requirement around class initialization such as shared generics. +}; + +// Reason codes for making indirect calls +#define INDIRECT_CALL_REASONS() \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_UNKNOWN) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_EXOTIC) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_PINVOKE) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_GENERIC) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_NO_CODE) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_FIXUPS) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_STUB) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_REMOTING) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_CER) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_RESTORE_METHOD) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_RESTORE_FIRST_CALL) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_RESTORE_VALUE_TYPE) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_RESTORE) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_CANT_PATCH) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_PROFILING) \ + INDIRECT_CALL_REASON_FUNC(CORINFO_INDIRECT_CALL_OTHER_LOADER_MODULE) \ + +enum CorInfoIndirectCallReason +{ + #undef INDIRECT_CALL_REASON_FUNC + #define INDIRECT_CALL_REASON_FUNC(x) x, + INDIRECT_CALL_REASONS() + + #undef INDIRECT_CALL_REASON_FUNC + + CORINFO_INDIRECT_CALL_COUNT +}; + +// This is for use when the JIT is compiling an instantiation +// of generic code. The JIT needs to know if the generic code itself +// (which can be verified once and for all independently of the +// instantiations) passed verification. +enum CorInfoInstantiationVerification +{ + // The method is NOT a concrete instantiation (eg. List.Add()) of a method + // in a generic class or a generic method. It is either the typical instantiation + // (eg. List.Add()) or entirely non-generic. + INSTVER_NOT_INSTANTIATION = 0, + + // The method is an instantiation of a method in a generic class or a generic method, + // and the generic class was successfully verified + INSTVER_GENERIC_PASSED_VERIFICATION = 1, + + // The method is an instantiation of a method in a generic class or a generic method, + // and the generic class failed verification + INSTVER_GENERIC_FAILED_VERIFICATION = 2, +}; + +// When using CORINFO_HELPER_TAILCALL, the JIT needs to pass certain special +// calling convention/argument passing/handling details to the helper +enum CorInfoHelperTailCallSpecialHandling +{ + CORINFO_TAILCALL_NORMAL = 0x00000000, + CORINFO_TAILCALL_STUB_DISPATCH_ARG = 0x00000001, +}; + + +inline bool dontInline(CorInfoInline val) { + return(val < 0); +} + +// Cookie types consumed by the code generator (these are opaque values +// not inspected by the code generator): + +typedef struct CORINFO_ASSEMBLY_STRUCT_* CORINFO_ASSEMBLY_HANDLE; +typedef struct CORINFO_MODULE_STRUCT_* CORINFO_MODULE_HANDLE; +typedef struct CORINFO_DEPENDENCY_STRUCT_* CORINFO_DEPENDENCY_HANDLE; +typedef struct CORINFO_CLASS_STRUCT_* CORINFO_CLASS_HANDLE; +typedef struct CORINFO_METHOD_STRUCT_* CORINFO_METHOD_HANDLE; +typedef struct CORINFO_FIELD_STRUCT_* CORINFO_FIELD_HANDLE; +typedef struct CORINFO_ARG_LIST_STRUCT_* CORINFO_ARG_LIST_HANDLE; // represents a list of argument types +typedef struct CORINFO_JUST_MY_CODE_HANDLE_*CORINFO_JUST_MY_CODE_HANDLE; +typedef struct CORINFO_PROFILING_STRUCT_* CORINFO_PROFILING_HANDLE; // a handle guaranteed to be unique per process +typedef struct CORINFO_GENERIC_STRUCT_* CORINFO_GENERIC_HANDLE; // a generic handle (could be any of the above) + +// what is actually passed on the varargs call +typedef struct CORINFO_VarArgInfo * CORINFO_VARARGS_HANDLE; + +// Generic tokens are resolved with respect to a context, which is usually the method +// being compiled. The CORINFO_CONTEXT_HANDLE indicates which exact instantiation +// (or the open instantiation) is being referred to. +// CORINFO_CONTEXT_HANDLE is more tightly scoped than CORINFO_MODULE_HANDLE. For cases +// where the exact instantiation does not matter, CORINFO_MODULE_HANDLE is used. +typedef CORINFO_METHOD_HANDLE CORINFO_CONTEXT_HANDLE; + +typedef struct CORINFO_DEPENDENCY_STRUCT_ +{ + CORINFO_MODULE_HANDLE moduleFrom; + CORINFO_MODULE_HANDLE moduleTo; +} CORINFO_DEPENDENCY; + +// Bit-twiddling of contexts assumes word-alignment of method handles and type handles +// If this ever changes, some other encoding will be needed +enum CorInfoContextFlags +{ + CORINFO_CONTEXTFLAGS_METHOD = 0x00, // CORINFO_CONTEXT_HANDLE is really a CORINFO_METHOD_HANDLE + CORINFO_CONTEXTFLAGS_CLASS = 0x01, // CORINFO_CONTEXT_HANDLE is really a CORINFO_CLASS_HANDLE + CORINFO_CONTEXTFLAGS_MASK = 0x01 +}; + +#define MAKE_CLASSCONTEXT(c) (CORINFO_CONTEXT_HANDLE((size_t) (c) | CORINFO_CONTEXTFLAGS_CLASS)) +#define MAKE_METHODCONTEXT(m) (CORINFO_CONTEXT_HANDLE((size_t) (m) | CORINFO_CONTEXTFLAGS_METHOD)) + +enum CorInfoSigInfoFlags +{ + CORINFO_SIGFLAG_IS_LOCAL_SIG = 0x01, + CORINFO_SIGFLAG_IL_STUB = 0x02, +}; + +struct CORINFO_SIG_INST +{ + unsigned classInstCount; + CORINFO_CLASS_HANDLE * classInst; // (representative, not exact) instantiation for class type variables in signature + unsigned methInstCount; + CORINFO_CLASS_HANDLE * methInst; // (representative, not exact) instantiation for method type variables in signature +}; + +struct CORINFO_SIG_INFO +{ + CorInfoCallConv callConv; + CORINFO_CLASS_HANDLE retTypeClass; // if the return type is a value class, this is its handle (enums are normalized) + CORINFO_CLASS_HANDLE retTypeSigClass;// returns the value class as it is in the sig (enums are not converted to primitives) + CorInfoType retType : 8; + unsigned flags : 8; // used by IL stubs code + unsigned numArgs : 16; + struct CORINFO_SIG_INST sigInst; // information about how type variables are being instantiated in generic code + CORINFO_ARG_LIST_HANDLE args; + PCCOR_SIGNATURE pSig; + unsigned cbSig; + CORINFO_MODULE_HANDLE scope; // passed to getArgClass + mdToken token; + + CorInfoCallConv getCallConv() { return CorInfoCallConv((callConv & CORINFO_CALLCONV_MASK)); } + bool hasThis() { return ((callConv & CORINFO_CALLCONV_HASTHIS) != 0); } + bool hasExplicitThis() { return ((callConv & CORINFO_CALLCONV_EXPLICITTHIS) != 0); } + unsigned totalILArgs() { return (numArgs + hasThis()); } + bool isVarArg() { return ((getCallConv() == CORINFO_CALLCONV_VARARG) || (getCallConv() == CORINFO_CALLCONV_NATIVEVARARG)); } + bool hasTypeArg() { return ((callConv & CORINFO_CALLCONV_PARAMTYPE) != 0); } +}; + +#ifdef MDIL +struct CORINFO_EH_CLAUSE; +struct InlineContext; +#endif + +struct CORINFO_METHOD_INFO +{ + CORINFO_METHOD_HANDLE ftn; + CORINFO_MODULE_HANDLE scope; + BYTE * ILCode; + unsigned ILCodeSize; + unsigned maxStack; + unsigned EHcount; + CorInfoOptions options; + CorInfoRegionKind regionKind; + CORINFO_SIG_INFO args; + CORINFO_SIG_INFO locals; +}; + +//---------------------------------------------------------------------------- +// Looking up handles and addresses. +// +// When the JIT requests a handle, the EE may direct the JIT that it must +// access the handle in a variety of ways. These are packed as +// CORINFO_CONST_LOOKUP +// or CORINFO_LOOKUP (contains either a CORINFO_CONST_LOOKUP or a CORINFO_RUNTIME_LOOKUP) +// +// Constant Lookups v. Runtime Lookups (i.e. when will Runtime Lookups be generated?) +// ----------------------------------------------------------------------------------- +// +// CORINFO_LOOKUP_KIND is part of the result type of embedGenericHandle, +// getVirtualCallInfo and any other functions that may require a +// runtime lookup when compiling shared generic code. +// +// CORINFO_LOOKUP_KIND indicates whether a particular token in the instruction stream can be: +// (a) Mapped to a handle (type, field or method) at compile-time (!needsRuntimeLookup) +// (b) Must be looked up at run-time, and if so which runtime lookup technique should be used (see below) +// +// If the JIT or EE does not support code sharing for generic code, then +// all CORINFO_LOOKUP results will be "constant lookups", i.e. +// the needsRuntimeLookup of CORINFO_LOOKUP.lookupKind.needsRuntimeLookup +// will be false. +// +// Constant Lookups +// ---------------- +// +// Constant Lookups are either: +// IAT_VALUE: immediate (relocatable) values, +// IAT_PVALUE: immediate values access via an indirection through an immediate (relocatable) address +// IAT_PPVALUE: immediate values access via a double indirection through an immediate (relocatable) address +// +// Runtime Lookups +// --------------- +// +// CORINFO_LOOKUP_KIND is part of the result type of embedGenericHandle, +// getVirtualCallInfo and any other functions that may require a +// runtime lookup when compiling shared generic code. +// +// CORINFO_LOOKUP_KIND indicates whether a particular token in the instruction stream can be: +// (a) Mapped to a handle (type, field or method) at compile-time (!needsRuntimeLookup) +// (b) Must be looked up at run-time using the class dictionary +// stored in the vtable of the this pointer (needsRuntimeLookup && THISOBJ) +// (c) Must be looked up at run-time using the method dictionary +// stored in the method descriptor parameter passed to a generic +// method (needsRuntimeLookup && METHODPARAM) +// (d) Must be looked up at run-time using the class dictionary stored +// in the vtable parameter passed to a method in a generic +// struct (needsRuntimeLookup && CLASSPARAM) + +struct CORINFO_CONST_LOOKUP +{ + // If the handle is obtained at compile-time, then this handle is the "exact" handle (class, method, or field) + // Otherwise, it's a representative... + // If accessType is + // IAT_VALUE --> "handle" stores the real handle or "addr " stores the computed address + // IAT_PVALUE --> "addr" stores a pointer to a location which will hold the real handle + // IAT_PPVALUE --> "addr" stores a double indirection to a location which will hold the real handle + + InfoAccessType accessType; + union + { + CORINFO_GENERIC_HANDLE handle; + void * addr; + }; +}; + +enum CORINFO_RUNTIME_LOOKUP_KIND +{ + CORINFO_LOOKUP_THISOBJ, + CORINFO_LOOKUP_METHODPARAM, + CORINFO_LOOKUP_CLASSPARAM, +}; + +struct CORINFO_LOOKUP_KIND +{ + bool needsRuntimeLookup; + CORINFO_RUNTIME_LOOKUP_KIND runtimeLookupKind; +} ; + +// CORINFO_RUNTIME_LOOKUP indicates the details of the runtime lookup +// operation to be performed. +// +// CORINFO_MAXINDIRECTIONS is the maximum number of +// indirections used by runtime lookups. +// This accounts for up to 2 indirections to get at a dictionary followed by a possible spill slot +// +#define CORINFO_MAXINDIRECTIONS 4 +#define CORINFO_USEHELPER ((WORD) 0xffff) + +struct CORINFO_RUNTIME_LOOKUP +{ + // This is signature you must pass back to the runtime lookup helper + LPVOID signature; + + // Here is the helper you must call. It is one of CORINFO_HELP_RUNTIMEHANDLE_* helpers. + CorInfoHelpFunc helper; + + // Number of indirections to get there + // CORINFO_USEHELPER = don't know how to get it, so use helper function at run-time instead + // 0 = use the this pointer itself (e.g. token is C inside code in sealed class C) + // or method desc itself (e.g. token is method void M::mymeth() inside code in M::mymeth) + // Otherwise, follow each byte-offset stored in the "offsets[]" array (may be negative) + WORD indirections; + + // If set, test for null and branch to helper if null + bool testForNull; + + // If set, test the lowest bit and dereference if set (see code:FixupPointer) + bool testForFixup; + + SIZE_T offsets[CORINFO_MAXINDIRECTIONS]; +} ; + +// Result of calling embedGenericHandle +struct CORINFO_LOOKUP +{ + CORINFO_LOOKUP_KIND lookupKind; + + union + { + // If kind.needsRuntimeLookup then this indicates how to do the lookup + CORINFO_RUNTIME_LOOKUP runtimeLookup; + + // If the handle is obtained at compile-time, then this handle is the "exact" handle (class, method, or field) + // Otherwise, it's a representative... If accessType is + // IAT_VALUE --> "handle" stores the real handle or "addr " stores the computed address + // IAT_PVALUE --> "addr" stores a pointer to a location which will hold the real handle + // IAT_PPVALUE --> "addr" stores a double indirection to a location which will hold the real handle + CORINFO_CONST_LOOKUP constLookup; + }; +}; + +enum CorInfoGenericHandleType +{ + CORINFO_HANDLETYPE_UNKNOWN, + CORINFO_HANDLETYPE_CLASS, + CORINFO_HANDLETYPE_METHOD, + CORINFO_HANDLETYPE_FIELD +}; + +//---------------------------------------------------------------------------- +// Embedding type, method and field handles (for "ldtoken" or to pass back to helpers) + +// Result of calling embedGenericHandle +struct CORINFO_GENERICHANDLE_RESULT +{ + CORINFO_LOOKUP lookup; + + // compileTimeHandle is guaranteed to be either NULL or a handle that is usable during compile time. + // It must not be embedded in the code because it might not be valid at run-time. + CORINFO_GENERIC_HANDLE compileTimeHandle; + + // Type of the result + CorInfoGenericHandleType handleType; +}; + +#define CORINFO_ACCESS_ALLOWED_MAX_ARGS 4 + +enum CorInfoAccessAllowedHelperArgType +{ + CORINFO_HELPER_ARG_TYPE_Invalid = 0, + CORINFO_HELPER_ARG_TYPE_Field = 1, + CORINFO_HELPER_ARG_TYPE_Method = 2, + CORINFO_HELPER_ARG_TYPE_Class = 3, + CORINFO_HELPER_ARG_TYPE_Module = 4, + CORINFO_HELPER_ARG_TYPE_Const = 5, +}; +struct CORINFO_HELPER_ARG +{ + union + { + CORINFO_FIELD_HANDLE fieldHandle; + CORINFO_METHOD_HANDLE methodHandle; + CORINFO_CLASS_HANDLE classHandle; + CORINFO_MODULE_HANDLE moduleHandle; + size_t constant; + }; +#ifdef MDIL + DWORD token; +#endif + CorInfoAccessAllowedHelperArgType argType; + + void Set(CORINFO_METHOD_HANDLE handle) + { + argType = CORINFO_HELPER_ARG_TYPE_Method; + methodHandle = handle; + } + + void Set(CORINFO_FIELD_HANDLE handle) + { + argType = CORINFO_HELPER_ARG_TYPE_Field; + fieldHandle = handle; + } + + void Set(CORINFO_CLASS_HANDLE handle) + { + argType = CORINFO_HELPER_ARG_TYPE_Class; + classHandle = handle; + } + + void Set(size_t value) + { + argType = CORINFO_HELPER_ARG_TYPE_Const; + constant = value; + } +}; + +struct CORINFO_HELPER_DESC +{ + CorInfoHelpFunc helperNum; + unsigned numArgs; + CORINFO_HELPER_ARG args[CORINFO_ACCESS_ALLOWED_MAX_ARGS]; +}; + +//---------------------------------------------------------------------------- +// getCallInfo and CORINFO_CALL_INFO: The EE instructs the JIT about how to make a call +// +// callKind +// -------- +// +// CORINFO_CALL : +// Indicates that the JIT can use getFunctionEntryPoint to make a call, +// i.e. there is nothing abnormal about the call. The JITs know what to do if they get this. +// Except in the case of constraint calls (see below), [targetMethodHandle] will hold +// the CORINFO_METHOD_HANDLE that a call to findMethod would +// have returned. +// This flag may be combined with nullInstanceCheck=TRUE for uses of callvirt on methods that can +// be resolved at compile-time (non-virtual, final or sealed). +// +// CORINFO_CALL_CODE_POINTER (shared generic code only) : +// Indicates that the JIT should do an indirect call to the entrypoint given by address, which may be specified +// as a runtime lookup by CORINFO_CALL_INFO::codePointerLookup. +// [targetMethodHandle] will not hold a valid value. +// This flag may be combined with nullInstanceCheck=TRUE for uses of callvirt on methods whose target method can +// be resolved at compile-time but whose instantiation can be resolved only through runtime lookup. +// +// CORINFO_VIRTUALCALL_STUB (interface calls) : +// Indicates that the EE supports "stub dispatch" and request the JIT to make a +// "stub dispatch" call (an indirect call through CORINFO_CALL_INFO::stubLookup, +// similar to CORINFO_CALL_CODE_POINTER). +// "Stub dispatch" is a specialized calling sequence (that may require use of NOPs) +// which allow the runtime to determine the call-site after the call has been dispatched. +// If the call is too complex for the JIT (e.g. because +// fetching the dispatch stub requires a runtime lookup, i.e. lookupKind.needsRuntimeLookup +// is set) then the JIT is allowed to implement the call as if it were CORINFO_VIRTUALCALL_LDVIRTFTN +// [targetMethodHandle] will hold the CORINFO_METHOD_HANDLE that a call to findMethod would +// have returned. +// This flag is always accompanied by nullInstanceCheck=TRUE. +// +// CORINFO_VIRTUALCALL_LDVIRTFTN (virtual generic methods) : +// Indicates that the EE provides no way to implement the call directly and +// that the JIT should use a LDVIRTFTN sequence (as implemented by CORINFO_HELP_VIRTUAL_FUNC_PTR) +// followed by an indirect call. +// [targetMethodHandle] will hold the CORINFO_METHOD_HANDLE that a call to findMethod would +// have returned. +// This flag is always accompanied by nullInstanceCheck=TRUE though typically the null check will +// be implicit in the access through the instance pointer. +// +// CORINFO_VIRTUALCALL_VTABLE (regular virtual methods) : +// Indicates that the EE supports vtable dispatch and that the JIT should use getVTableOffset etc. +// to implement the call. +// [targetMethodHandle] will hold the CORINFO_METHOD_HANDLE that a call to findMethod would +// have returned. +// This flag is always accompanied by nullInstanceCheck=TRUE though typically the null check will +// be implicit in the access through the instance pointer. +// +// thisTransform and constraint calls +// ---------------------------------- +// +// For evertyhing besides "constrained." calls "thisTransform" is set to +// CORINFO_NO_THIS_TRANSFORM. +// +// For "constrained." calls the EE attempts to resolve the call at compile +// time to a more specific method, or (shared generic code only) to a runtime lookup +// for a code pointer for the more specific method. +// +// In order to permit this, the "this" pointer supplied for a "constrained." call +// is a byref to an arbitrary type (see the IL spec). The "thisTransform" field +// will indicate how the JIT must transform the "this" pointer in order +// to be able to call the resolved method: +// +// CORINFO_NO_THIS_TRANSFORM --> Leave it as a byref to an unboxed value type +// CORINFO_BOX_THIS --> Box it to produce an object +// CORINFO_DEREF_THIS --> Deref the byref to get an object reference +// +// In addition, the "kind" field will be set as follows for constraint calls: + +// CORINFO_CALL --> the call was resolved at compile time, and +// can be compiled like a normal call. +// CORINFO_CALL_CODE_POINTER --> the call was resolved, but the target address will be +// computed at runtime. Only returned for shared generic code. +// CORINFO_VIRTUALCALL_STUB, +// CORINFO_VIRTUALCALL_LDVIRTFTN, +// CORINFO_VIRTUALCALL_VTABLE --> usual values indicating that a virtual call must be made + +enum CORINFO_CALL_KIND +{ + CORINFO_CALL, + CORINFO_CALL_CODE_POINTER, + CORINFO_VIRTUALCALL_STUB, + CORINFO_VIRTUALCALL_LDVIRTFTN, + CORINFO_VIRTUALCALL_VTABLE +}; + + + +enum CORINFO_THIS_TRANSFORM +{ + CORINFO_NO_THIS_TRANSFORM, + CORINFO_BOX_THIS, + CORINFO_DEREF_THIS +}; + +enum CORINFO_CALLINFO_FLAGS +{ + CORINFO_CALLINFO_NONE = 0x0000, + CORINFO_CALLINFO_ALLOWINSTPARAM = 0x0001, // Can the compiler generate code to pass an instantiation parameters? Simple compilers should not use this flag + CORINFO_CALLINFO_CALLVIRT = 0x0002, // Is it a virtual call? + CORINFO_CALLINFO_KINDONLY = 0x0004, // This is set to only query the kind of call to perform, without getting any other information + CORINFO_CALLINFO_VERIFICATION = 0x0008, // Gets extra verification information. + CORINFO_CALLINFO_SECURITYCHECKS = 0x0010, // Perform security checks. + CORINFO_CALLINFO_LDFTN = 0x0020, // Resolving target of LDFTN +}; + +enum CorInfoIsAccessAllowedResult +{ + CORINFO_ACCESS_ALLOWED = 0, // Call allowed + CORINFO_ACCESS_ILLEGAL = 1, // Call not allowed + CORINFO_ACCESS_RUNTIME_CHECK = 2, // Ask at runtime whether to allow the call or not +}; + + +// This enum is used for JIT to tell EE where this token comes from. +// E.g. Depending on different opcodes, we might allow/disallow certain types of tokens or +// return different types of handles (e.g. boxed vs. regular entrypoints) +enum CorInfoTokenKind +{ + CORINFO_TOKENKIND_Class = 0x01, + CORINFO_TOKENKIND_Method = 0x02, + CORINFO_TOKENKIND_Field = 0x04, + CORINFO_TOKENKIND_Mask = 0x07, + + // token comes from CEE_LDTOKEN + CORINFO_TOKENKIND_Ldtoken = 0x10 | CORINFO_TOKENKIND_Class | CORINFO_TOKENKIND_Method | CORINFO_TOKENKIND_Field, + + // token comes from CEE_CASTCLASS or CEE_ISINST + CORINFO_TOKENKIND_Casting = 0x20 | CORINFO_TOKENKIND_Class, + + // token comes from CEE_NEWARR + CORINFO_TOKENKIND_Newarr = 0x40 | CORINFO_TOKENKIND_Class, + + // token comes from CEE_BOX + CORINFO_TOKENKIND_Box = 0x80 | CORINFO_TOKENKIND_Class, + + // token comes from CEE_CONSTRAINED + CORINFO_TOKENKIND_Constrained = 0x100 | CORINFO_TOKENKIND_Class, +}; + +struct CORINFO_RESOLVED_TOKEN +{ + // + // [In] arguments of resolveToken + // + CORINFO_CONTEXT_HANDLE tokenContext; //Context for resolution of generic arguments + CORINFO_MODULE_HANDLE tokenScope; + mdToken token; //The source token + CorInfoTokenKind tokenType; + + // + // [Out] arguments of resolveToken. + // - Type handle is always non-NULL. + // - At most one of method and field handles is non-NULL (according to the token type). + // - Method handle is an instantiating stub only for generic methods. Type handle + // is required to provide the full context for methods in generic types. + // + CORINFO_CLASS_HANDLE hClass; + CORINFO_METHOD_HANDLE hMethod; + CORINFO_FIELD_HANDLE hField; + + // + // [Out] TypeSpec and MethodSpec signatures for generics. NULL otherwise. + // + PCCOR_SIGNATURE pTypeSpec; + ULONG cbTypeSpec; + PCCOR_SIGNATURE pMethodSpec; + ULONG cbMethodSpec; +}; + +struct CORINFO_CALL_INFO +{ + CORINFO_METHOD_HANDLE hMethod; //target method handle + unsigned methodFlags; //flags for the target method + + unsigned classFlags; //flags for CORINFO_RESOLVED_TOKEN::hClass + + CORINFO_SIG_INFO sig; + + //Verification information + unsigned verMethodFlags; // flags for CORINFO_RESOLVED_TOKEN::hMethod + CORINFO_SIG_INFO verSig; + //All of the regular method data is the same... hMethod might not be the same as CORINFO_RESOLVED_TOKEN::hMethod + + + //If set to: + // - CORINFO_ACCESS_ALLOWED - The access is allowed. + // - CORINFO_ACCESS_ILLEGAL - This access cannot be allowed (i.e. it is public calling private). The + // JIT may either insert the callsiteCalloutHelper into the code (as per a verification error) or + // call throwExceptionFromHelper on the callsiteCalloutHelper. In this case callsiteCalloutHelper + // is guaranteed not to return. + // - CORINFO_ACCESS_RUNTIME_CHECK - The jit must insert the callsiteCalloutHelper at the call site. + // the helper may return + CorInfoIsAccessAllowedResult accessAllowed; + CORINFO_HELPER_DESC callsiteCalloutHelper; + + // See above section on constraintCalls to understand when these are set to unusual values. + CORINFO_THIS_TRANSFORM thisTransform; + + CORINFO_CALL_KIND kind; + BOOL nullInstanceCheck; + + // Context for inlining and hidden arg + CORINFO_CONTEXT_HANDLE contextHandle; + BOOL exactContextNeedsRuntimeLookup; // Set if contextHandle is approx handle. Runtime lookup is required to get the exact handle. + + // If kind.CORINFO_VIRTUALCALL_STUB then stubLookup will be set. + // If kind.CORINFO_CALL_CODE_POINTER then entryPointLookup will be set. + union + { + CORINFO_LOOKUP stubLookup; + + CORINFO_LOOKUP codePointerLookup; + }; + +#ifndef RYUJIT_CTPBUILD + CORINFO_CONST_LOOKUP instParamLookup; // Used by Ready-to-Run +#endif +}; + +//---------------------------------------------------------------------------- +// getFieldInfo and CORINFO_FIELD_INFO: The EE instructs the JIT about how to access a field + +enum CORINFO_FIELD_ACCESSOR +{ + CORINFO_FIELD_INSTANCE, // regular instance field at given offset from this-ptr +#ifndef RYUJIT_CTPBUILD + CORINFO_FIELD_INSTANCE_WITH_BASE, // instance field with base offset (used by Ready-to-Run) +#endif + CORINFO_FIELD_INSTANCE_HELPER, // instance field accessed using helper (arguments are this, FieldDesc * and the value) + CORINFO_FIELD_INSTANCE_ADDR_HELPER, // instance field accessed using address-of helper (arguments are this and FieldDesc *) + + CORINFO_FIELD_STATIC_ADDRESS, // field at given address + CORINFO_FIELD_STATIC_RVA_ADDRESS, // RVA field at given address + CORINFO_FIELD_STATIC_SHARED_STATIC_HELPER, // static field accessed using the "shared static" helper (arguments are ModuleID + ClassID) + CORINFO_FIELD_STATIC_GENERICS_STATIC_HELPER, // static field access using the "generic static" helper (argument is MethodTable *) + CORINFO_FIELD_STATIC_ADDR_HELPER, // static field accessed using address-of helper (argument is FieldDesc *) + CORINFO_FIELD_STATIC_TLS, // unmanaged TLS access + + CORINFO_FIELD_INTRINSIC_ZERO, // intrinsic zero (IntPtr.Zero, UIntPtr.Zero) + CORINFO_FIELD_INTRINSIC_EMPTY_STRING, // intrinsic emptry string (String.Empty) +}; + +// Set of flags returned in CORINFO_FIELD_INFO::fieldFlags +enum CORINFO_FIELD_FLAGS +{ + CORINFO_FLG_FIELD_STATIC = 0x00000001, + CORINFO_FLG_FIELD_UNMANAGED = 0x00000002, // RVA field + CORINFO_FLG_FIELD_FINAL = 0x00000004, + CORINFO_FLG_FIELD_STATIC_IN_HEAP = 0x00000008, // See code:#StaticFields. This static field is in the GC heap as a boxed object + CORINFO_FLG_FIELD_SAFESTATIC_BYREF_RETURN = 0x00000010, // Field can be returned safely (has GC heap lifetime) + CORINFO_FLG_FIELD_INITCLASS = 0x00000020, // initClass has to be called before accessing the field + CORINFO_FLG_FIELD_PROTECTED = 0x00000040, +}; + +struct CORINFO_FIELD_INFO +{ + CORINFO_FIELD_ACCESSOR fieldAccessor; + unsigned fieldFlags; + + // Helper to use if the field access requires it + CorInfoHelpFunc helper; + + // Field offset if there is one + DWORD offset; + + CorInfoType fieldType; + CORINFO_CLASS_HANDLE structType; //possibly null + + //See CORINFO_CALL_INFO.accessAllowed + CorInfoIsAccessAllowedResult accessAllowed; + CORINFO_HELPER_DESC accessCalloutHelper; + +#ifndef RYUJIT_CTPBUILD + CORINFO_CONST_LOOKUP fieldLookup; // Used by Ready-to-Run +#endif +}; + +//---------------------------------------------------------------------------- +// Exception handling + +struct CORINFO_EH_CLAUSE +{ + CORINFO_EH_CLAUSE_FLAGS Flags; + DWORD TryOffset; + DWORD TryLength; + DWORD HandlerOffset; + DWORD HandlerLength; + union + { + DWORD ClassToken; // use for type-based exception handlers + DWORD FilterOffset; // use for filter-based exception handlers (COR_ILEXCEPTION_FILTER is set) +#ifdef REDHAWK + void * EETypeReference; // use to hold a ref to the EEType for type-based exception handlers. +#endif + }; +}; + +enum CORINFO_OS +{ + CORINFO_WINNT, + CORINFO_PAL, +}; + +struct CORINFO_CPU +{ + DWORD dwCPUType; + DWORD dwFeatures; + DWORD dwExtendedFeatures; +}; + +// For some highly optimized paths, the JIT must generate code that directly +// manipulates internal EE data structures. The getEEInfo() helper returns +// this structure containing the needed offsets and values. +struct CORINFO_EE_INFO +{ + // Information about the InlinedCallFrame structure layout + struct InlinedCallFrameInfo + { + // Size of the Frame structure + unsigned size; + + unsigned offsetOfGSCookie; + unsigned offsetOfFrameVptr; + unsigned offsetOfFrameLink; + unsigned offsetOfCallSiteSP; + unsigned offsetOfCalleeSavedFP; + unsigned offsetOfCallTarget; + unsigned offsetOfReturnAddress; + } + inlinedCallFrameInfo; + + // Offsets into the Thread structure + unsigned offsetOfThreadFrame; // offset of the current Frame + unsigned offsetOfGCState; // offset of the preemptive/cooperative state of the Thread + + // Delegate offsets + unsigned offsetOfDelegateInstance; + unsigned offsetOfDelegateFirstTarget; + + // Remoting offsets + unsigned offsetOfTransparentProxyRP; + unsigned offsetOfRealProxyServer; + +#ifndef RYUJIT_CTPBUILD + // Array offsets + unsigned offsetOfObjArrayData; +#endif + + CORINFO_OS osType; + unsigned osMajor; + unsigned osMinor; + unsigned osBuild; +}; + +// This is used to indicate that a finally has been called +// "locally" by the try block +enum { LCL_FINALLY_MARK = 0xFC }; // FC = "Finally Call" + +/********************************************************************************** + * The following is the internal structure of an object that the compiler knows about + * when it generates code + **********************************************************************************/ +#include + +#define CORINFO_PAGE_SIZE 0x1000 // the page size on the machine + +// @TODO: put this in the CORINFO_EE_INFO data structure +#define MAX_UNCHECKED_OFFSET_FOR_NULL_OBJECT ((32*1024)-1) // when generating JIT code + +typedef void* CORINFO_MethodPtr; // a generic method pointer + +struct CORINFO_Object +{ + CORINFO_MethodPtr *methTable; // the vtable for the object +}; + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4200) // disable zero-sized array warning +#endif +struct CORINFO_String : public CORINFO_Object +{ + unsigned stringLen; + const wchar_t chars[0]; // actually of variable size +}; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +struct CORINFO_Array : public CORINFO_Object +{ + unsigned length; +#ifdef _WIN64 + unsigned alignpad; +#endif // _WIN64 + +#if 0 + /* Multi-dimensional arrays have the lengths and bounds here */ + unsigned dimLength[length]; + unsigned dimBound[length]; +#endif + + union + { + __int8 i1Elems[1]; // actually of variable size + unsigned __int8 u1Elems[1]; + __int16 i2Elems[1]; + unsigned __int16 u2Elems[1]; + __int32 i4Elems[1]; + unsigned __int32 u4Elems[1]; + float r4Elems[1]; + }; +}; + +#include +struct CORINFO_Array8 : public CORINFO_Object +{ + unsigned length; +#ifdef _WIN64 + unsigned alignpad; +#endif // _WIN64 + + union + { + double r8Elems[1]; + __int64 i8Elems[1]; + unsigned __int64 u8Elems[1]; + }; +}; + +#include + +struct CORINFO_RefArray : public CORINFO_Object +{ + unsigned length; +#ifdef _WIN64 + unsigned alignpad; +#endif // _WIN64 +#if defined(RYUJIT_CTPBUILD) + CORINFO_CLASS_HANDLE cls; +#endif + +#if 0 + /* Multi-dimensional arrays have the lengths and bounds here */ + unsigned dimLength[length]; + unsigned dimBound[length]; +#endif + + CORINFO_Object* refElems[1]; // actually of variable size; +}; + +struct CORINFO_RefAny +{ + void * dataPtr; + CORINFO_CLASS_HANDLE type; +}; + +// The jit assumes the CORINFO_VARARGS_HANDLE is a pointer to a subclass of this +struct CORINFO_VarArgInfo +{ + unsigned argBytes; // number of bytes the arguments take up. + // (The CORINFO_VARARGS_HANDLE counts as an arg) +}; + +#include + +enum CorInfoSecurityRuntimeChecks +{ + CORINFO_ACCESS_SECURITY_NONE = 0, + CORINFO_ACCESS_SECURITY_TRANSPARENCY = 0x0001 // check that transparency rules are enforced between the caller and callee +}; + + +/* data to optimize delegate construction */ +struct DelegateCtorArgs +{ + void * pMethod; + void * pArg3; + void * pArg4; + void * pArg5; +}; + +// use offsetof to get the offset of the fields above +#include // offsetof +#ifndef offsetof +#define offsetof(s,m) ((size_t)&(((s *)0)->m)) +#endif + +// Guard-stack cookie for preventing against stack buffer overruns +typedef SIZE_T GSCookie; + +/**********************************************************************************/ +// DebugInfo types shared by JIT-EE interface and EE-Debugger interface + +class ICorDebugInfo +{ +public: + /*----------------------------- Boundary-info ---------------------------*/ + + enum MappingTypes + { + NO_MAPPING = -1, + PROLOG = -2, + EPILOG = -3, + MAX_MAPPING_VALUE = -3 // Sentinal value. This should be set to the largest magnitude value in the enum + // so that the compression routines know the enum's range. + }; + + enum BoundaryTypes + { + NO_BOUNDARIES = 0x00, // No implicit boundaries + STACK_EMPTY_BOUNDARIES = 0x01, // Boundary whenever the IL evaluation stack is empty + NOP_BOUNDARIES = 0x02, // Before every CEE_NOP instruction + CALL_SITE_BOUNDARIES = 0x04, // Before every CEE_CALL, CEE_CALLVIRT, etc instruction + + // Set of boundaries that debugger should always reasonably ask the JIT for. + DEFAULT_BOUNDARIES = STACK_EMPTY_BOUNDARIES | NOP_BOUNDARIES | CALL_SITE_BOUNDARIES + }; + + // Note that SourceTypes can be OR'd together - it's possible that + // a sequence point will also be a stack_empty point, and/or a call site. + // The debugger will check to see if a boundary offset's source field & + // SEQUENCE_POINT is true to determine if the boundary is a sequence point. + + enum SourceTypes + { + SOURCE_TYPE_INVALID = 0x00, // To indicate that nothing else applies + SEQUENCE_POINT = 0x01, // The debugger asked for it. + STACK_EMPTY = 0x02, // The stack is empty here + CALL_SITE = 0x04, // This is a call site. + NATIVE_END_OFFSET_UNKNOWN = 0x08, // Indicates a epilog endpoint + CALL_INSTRUCTION = 0x10 // The actual instruction of a call. + + }; + + struct OffsetMapping + { + DWORD nativeOffset; + DWORD ilOffset; + SourceTypes source; // The debugger needs this so that + // we don't put Edit and Continue breakpoints where + // the stack isn't empty. We can put regular breakpoints + // there, though, so we need a way to discriminate + // between offsets. + }; + + /*------------------------------ Var-info -------------------------------*/ + + // Note: The debugger needs to target register numbers on platforms other than which the debugger itself + // is running. To this end it maintains its own values for REGNUM_SP and REGNUM_AMBIENT_SP across multiple + // platforms. So any change here that may effect these values should be reflected in the definitions + // contained in debug/inc/DbgIPCEvents.h. + enum RegNum + { +#ifdef _TARGET_X86_ + REGNUM_EAX, + REGNUM_ECX, + REGNUM_EDX, + REGNUM_EBX, + REGNUM_ESP, + REGNUM_EBP, + REGNUM_ESI, + REGNUM_EDI, +#elif _TARGET_ARM_ + REGNUM_R0, + REGNUM_R1, + REGNUM_R2, + REGNUM_R3, + REGNUM_R4, + REGNUM_R5, + REGNUM_R6, + REGNUM_R7, + REGNUM_R8, + REGNUM_R9, + REGNUM_R10, + REGNUM_R11, + REGNUM_R12, + REGNUM_SP, + REGNUM_LR, + REGNUM_PC, +#elif _TARGET_ARM64_ + REGNUM_X0, + REGNUM_X1, + REGNUM_X2, + REGNUM_X3, + REGNUM_X4, + REGNUM_X5, + REGNUM_X6, + REGNUM_X7, + REGNUM_X8, + REGNUM_X9, + REGNUM_X10, + REGNUM_X11, + REGNUM_X12, + REGNUM_X13, + REGNUM_X14, + REGNUM_X15, + REGNUM_X16, + REGNUM_X17, + REGNUM_X18, + REGNUM_X19, + REGNUM_X20, + REGNUM_X21, + REGNUM_X22, + REGNUM_X23, + REGNUM_X24, + REGNUM_X25, + REGNUM_X26, + REGNUM_X27, + REGNUM_X28, + REGNUM_FP, + REGNUM_LR, + REGNUM_SP, + REGNUM_PC, +#elif _TARGET_AMD64_ + REGNUM_RAX, + REGNUM_RCX, + REGNUM_RDX, + REGNUM_RBX, + REGNUM_RSP, + REGNUM_RBP, + REGNUM_RSI, + REGNUM_RDI, + REGNUM_R8, + REGNUM_R9, + REGNUM_R10, + REGNUM_R11, + REGNUM_R12, + REGNUM_R13, + REGNUM_R14, + REGNUM_R15, +#else + PORTABILITY_WARNING("Register numbers not defined on this platform") +#endif + REGNUM_COUNT, + REGNUM_AMBIENT_SP, // ambient SP support. Ambient SP is the original SP in the non-BP based frame. + // Ambient SP should not change even if there are push/pop operations in the method. + +#ifdef _TARGET_X86_ + REGNUM_FP = REGNUM_EBP, + REGNUM_SP = REGNUM_ESP, +#elif _TARGET_AMD64_ + REGNUM_SP = REGNUM_RSP, +#elif _TARGET_ARM_ +#ifdef REDHAWK + REGNUM_FP = REGNUM_R7, +#else + REGNUM_FP = REGNUM_R11, +#endif //REDHAWK +#elif _TARGET_ARM64_ + //Nothing to do here. FP is already alloted. +#else + // RegNum values should be properly defined for this platform + REGNUM_FP = 0, + REGNUM_SP = 1, +#endif + + }; + + // VarLoc describes the location of a native variable. Note that currently, VLT_REG_BYREF and VLT_STK_BYREF + // are only used for value types on X64. + + enum VarLocType + { + VLT_REG, // variable is in a register + VLT_REG_BYREF, // address of the variable is in a register + VLT_REG_FP, // variable is in an fp register + VLT_STK, // variable is on the stack (memory addressed relative to the frame-pointer) + VLT_STK_BYREF, // address of the variable is on the stack (memory addressed relative to the frame-pointer) + VLT_REG_REG, // variable lives in two registers + VLT_REG_STK, // variable lives partly in a register and partly on the stack + VLT_STK_REG, // reverse of VLT_REG_STK + VLT_STK2, // variable lives in two slots on the stack + VLT_FPSTK, // variable lives on the floating-point stack + VLT_FIXED_VA, // variable is a fixed argument in a varargs function (relative to VARARGS_HANDLE) + + VLT_COUNT, + VLT_INVALID, +#ifdef MDIL + VLT_MDIL_SYMBOLIC = 0x20 +#endif + + }; + + struct VarLoc + { + VarLocType vlType; + + union + { + // VLT_REG/VLT_REG_FP -- Any pointer-sized enregistered value (TYP_INT, TYP_REF, etc) + // eg. EAX + // VLT_REG_BYREF -- the specified register contains the address of the variable + // eg. [EAX] + + struct + { + RegNum vlrReg; + } vlReg; + + // VLT_STK -- Any 32 bit value which is on the stack + // eg. [ESP+0x20], or [EBP-0x28] + // VLT_STK_BYREF -- the specified stack location contains the address of the variable + // eg. mov EAX, [ESP+0x20]; [EAX] + + struct + { + RegNum vlsBaseReg; + signed vlsOffset; + } vlStk; + + // VLT_REG_REG -- TYP_LONG with both DWords enregistred + // eg. RBM_EAXEDX + + struct + { + RegNum vlrrReg1; + RegNum vlrrReg2; + } vlRegReg; + + // VLT_REG_STK -- Partly enregistered TYP_LONG + // eg { LowerDWord=EAX UpperDWord=[ESP+0x8] } + + struct + { + RegNum vlrsReg; + struct + { + RegNum vlrssBaseReg; + signed vlrssOffset; + } vlrsStk; + } vlRegStk; + + // VLT_STK_REG -- Partly enregistered TYP_LONG + // eg { LowerDWord=[ESP+0x8] UpperDWord=EAX } + + struct + { + struct + { + RegNum vlsrsBaseReg; + signed vlsrsOffset; + } vlsrStk; + RegNum vlsrReg; + } vlStkReg; + + // VLT_STK2 -- Any 64 bit value which is on the stack, + // in 2 successsive DWords. + // eg 2 DWords at [ESP+0x10] + + struct + { + RegNum vls2BaseReg; + signed vls2Offset; + } vlStk2; + + // VLT_FPSTK -- enregisterd TYP_DOUBLE (on the FP stack) + // eg. ST(3). Actually it is ST("FPstkHeigth - vpFpStk") + + struct + { + unsigned vlfReg; + } vlFPstk; + + // VLT_FIXED_VA -- fixed argument of a varargs function. + // The argument location depends on the size of the variable + // arguments (...). Inspecting the VARARGS_HANDLE indicates the + // location of the first arg. This argument can then be accessed + // relative to the position of the first arg + + struct + { + unsigned vlfvOffset; + } vlFixedVarArg; + + // VLT_MEMORY + + struct + { + void *rpValue; // pointer to the in-process + // location of the value. + } vlMemory; + }; + }; + + // This is used to report implicit/hidden arguments + + enum + { + VARARGS_HND_ILNUM = -1, // Value for the CORINFO_VARARGS_HANDLE varNumber + RETBUF_ILNUM = -2, // Pointer to the return-buffer + TYPECTXT_ILNUM = -3, // ParamTypeArg for CORINFO_GENERICS_CTXT_FROM_PARAMTYPEARG + + UNKNOWN_ILNUM = -4, // Unknown variable + + MAX_ILNUM = -4 // Sentinal value. This should be set to the largest magnitude value in th enum + // so that the compression routines know the enum's range. + }; + + struct ILVarInfo + { + DWORD startOffset; + DWORD endOffset; + DWORD varNumber; + }; + + struct NativeVarInfo + { + DWORD startOffset; + DWORD endOffset; + DWORD varNumber; + VarLoc loc; + }; +}; + +/**********************************************************************************/ +// Some compilers cannot arbitrarily allow the handler nesting level to grow +// arbitrarily during Edit'n'Continue. +// This is the maximum nesting level that a compiler needs to support for EnC + +const int MAX_EnC_HANDLER_NESTING_LEVEL = 6; + +// +// This interface is logically split into sections for each class of information +// (ICorMethodInfo, ICorModuleInfo, etc.). This split used to exist physically as well +// using virtual inheritance, but was eliminated to improve efficiency of the JIT-EE +// interface calls. +// +class ICorStaticInfo +{ +public: + /**********************************************************************************/ + // + // ICorMethodInfo + // + /**********************************************************************************/ + + // return flags (defined above, CORINFO_FLG_PUBLIC ...) + virtual DWORD getMethodAttribs ( + CORINFO_METHOD_HANDLE ftn /* IN */ + ) = 0; + + // sets private JIT flags, which can be, retrieved using getAttrib. + virtual void setMethodAttribs ( + CORINFO_METHOD_HANDLE ftn, /* IN */ + CorInfoMethodRuntimeFlags attribs /* IN */ + ) = 0; + + // Given a method descriptor ftnHnd, extract signature information into sigInfo + // + // 'memberParent' is typically only set when verifying. It should be the + // result of calling getMemberParent. + virtual void getMethodSig ( + CORINFO_METHOD_HANDLE ftn, /* IN */ + CORINFO_SIG_INFO *sig, /* OUT */ + CORINFO_CLASS_HANDLE memberParent = NULL /* IN */ + ) = 0; + + /********************************************************************* + * Note the following methods can only be used on functions known + * to be IL. This includes the method being compiled and any method + * that 'getMethodInfo' returns true for + *********************************************************************/ + + // return information about a method private to the implementation + // returns false if method is not IL, or is otherwise unavailable. + // This method is used to fetch data needed to inline functions + virtual bool getMethodInfo ( + CORINFO_METHOD_HANDLE ftn, /* IN */ + CORINFO_METHOD_INFO* info /* OUT */ + ) = 0; + + // Decides if you have any limitations for inlining. If everything's OK, it will return + // INLINE_PASS and will fill out pRestrictions with a mask of restrictions the caller of this + // function must respect. If caller passes pRestrictions = NULL, if there are any restrictions + // INLINE_FAIL will be returned + // + // The callerHnd must be the immediate caller (i.e. when we have a chain of inlined calls) + // + // The inlined method need not be verified + + virtual CorInfoInline canInline ( + CORINFO_METHOD_HANDLE callerHnd, /* IN */ + CORINFO_METHOD_HANDLE calleeHnd, /* IN */ + DWORD* pRestrictions /* OUT */ + ) = 0; + + // Reports whether or not a method can be inlined, and why. canInline is responsible for reporting all + // inlining results when it returns INLINE_FAIL and INLINE_NEVER. All other results are reported by the + // JIT. + virtual void reportInliningDecision (CORINFO_METHOD_HANDLE inlinerHnd, + CORINFO_METHOD_HANDLE inlineeHnd, + CorInfoInline inlineResult, + const char * reason) = 0; + + + // Returns false if the call is across security boundaries thus we cannot tailcall + // + // The callerHnd must be the immediate caller (i.e. when we have a chain of inlined calls) + virtual bool canTailCall ( + CORINFO_METHOD_HANDLE callerHnd, /* IN */ + CORINFO_METHOD_HANDLE declaredCalleeHnd, /* IN */ + CORINFO_METHOD_HANDLE exactCalleeHnd, /* IN */ + bool fIsTailPrefix /* IN */ + ) = 0; + + // Reports whether or not a method can be tail called, and why. + // canTailCall is responsible for reporting all results when it returns + // false. All other results are reported by the JIT. + virtual void reportTailCallDecision (CORINFO_METHOD_HANDLE callerHnd, + CORINFO_METHOD_HANDLE calleeHnd, + bool fIsTailPrefix, + CorInfoTailCall tailCallResult, + const char * reason) = 0; + + // get individual exception handler + virtual void getEHinfo( + CORINFO_METHOD_HANDLE ftn, /* IN */ + unsigned EHnumber, /* IN */ + CORINFO_EH_CLAUSE* clause /* OUT */ + ) = 0; + + // return class it belongs to + virtual CORINFO_CLASS_HANDLE getMethodClass ( + CORINFO_METHOD_HANDLE method + ) = 0; + + // return module it belongs to + virtual CORINFO_MODULE_HANDLE getMethodModule ( + CORINFO_METHOD_HANDLE method + ) = 0; + + // This function returns the offset of the specified method in the + // vtable of it's owning class or interface. + virtual void getMethodVTableOffset ( + CORINFO_METHOD_HANDLE method, /* IN */ + unsigned* offsetOfIndirection, /* OUT */ + unsigned* offsetAfterIndirection /* OUT */ + ) = 0; + + // If a method's attributes have (getMethodAttribs) CORINFO_FLG_INTRINSIC set, + // getIntrinsicID() returns the intrinsic ID. + virtual CorInfoIntrinsics getIntrinsicID( + CORINFO_METHOD_HANDLE method + ) = 0; + +#ifndef RYUJIT_CTPBUILD + // Is the given module the System.Numerics.Vectors module? + // This defaults to false. + virtual bool isInSIMDModule( + CORINFO_CLASS_HANDLE classHnd + ) { return false; } +#endif // RYUJIT_CTPBUILD + + // return the unmanaged calling convention for a PInvoke + virtual CorInfoUnmanagedCallConv getUnmanagedCallConv( + CORINFO_METHOD_HANDLE method + ) = 0; + + // return if any marshaling is required for PInvoke methods. Note that + // method == 0 => calli. The call site sig is only needed for the varargs or calli case + virtual BOOL pInvokeMarshalingRequired( + CORINFO_METHOD_HANDLE method, + CORINFO_SIG_INFO* callSiteSig + ) = 0; + + // Check constraints on method type arguments (only). + // The parent class should be checked separately using satisfiesClassConstraints(parent). + virtual BOOL satisfiesMethodConstraints( + CORINFO_CLASS_HANDLE parent, // the exact parent of the method + CORINFO_METHOD_HANDLE method + ) = 0; + + // Given a delegate target class, a target method parent class, a target method, + // a delegate class, check if the method signature is compatible with the Invoke method of the delegate + // (under the typical instantiation of any free type variables in the memberref signatures). + virtual BOOL isCompatibleDelegate( + CORINFO_CLASS_HANDLE objCls, /* type of the delegate target, if any */ + CORINFO_CLASS_HANDLE methodParentCls, /* exact parent of the target method, if any */ + CORINFO_METHOD_HANDLE method, /* (representative) target method, if any */ + CORINFO_CLASS_HANDLE delegateCls, /* exact type of the delegate */ + BOOL *pfIsOpenDelegate /* is the delegate open */ + ) = 0; + + // Determines whether the delegate creation obeys security transparency rules + virtual BOOL isDelegateCreationAllowed ( + CORINFO_CLASS_HANDLE delegateHnd, + CORINFO_METHOD_HANDLE calleeHnd + ) = 0; + + + // Indicates if the method is an instance of the generic + // method that passes (or has passed) verification + virtual CorInfoInstantiationVerification isInstantiationOfVerifiedGeneric ( + CORINFO_METHOD_HANDLE method /* IN */ + ) = 0; + + // Loads the constraints on a typical method definition, detecting cycles; + // for use in verification. + virtual void initConstraintsForVerification( + CORINFO_METHOD_HANDLE method, /* IN */ + BOOL *pfHasCircularClassConstraints, /* OUT */ + BOOL *pfHasCircularMethodConstraint /* OUT */ + ) = 0; + + // Returns enum whether the method does not require verification + // Also see ICorModuleInfo::canSkipVerification + virtual CorInfoCanSkipVerificationResult canSkipMethodVerification ( + CORINFO_METHOD_HANDLE ftnHandle + ) = 0; + + // load and restore the method + virtual void methodMustBeLoadedBeforeCodeIsRun( + CORINFO_METHOD_HANDLE method + ) = 0; + + virtual CORINFO_METHOD_HANDLE mapMethodDeclToMethodImpl( + CORINFO_METHOD_HANDLE method + ) = 0; + + // Returns the global cookie for the /GS unsafe buffer checks + // The cookie might be a constant value (JIT), or a handle to memory location (Ngen) + virtual void getGSCookie( + GSCookie * pCookieVal, // OUT + GSCookie ** ppCookieVal // OUT + ) = 0; + +#ifdef MDIL + virtual unsigned getNumTypeParameters( + CORINFO_METHOD_HANDLE method + ) = 0; + + virtual CorElementType getTypeOfTypeParameter( + CORINFO_METHOD_HANDLE method, + unsigned index + ) = 0; + + virtual CORINFO_CLASS_HANDLE getTypeParameter( + CORINFO_METHOD_HANDLE method, + bool classTypeParameter, + unsigned index + ) = 0; + + virtual unsigned getStructTypeToken( + InlineContext *context, + CORINFO_ARG_LIST_HANDLE argList + ) = 0; + + virtual unsigned getEnclosingClassToken( + InlineContext *context, + CORINFO_METHOD_HANDLE method + ) = 0; + + virtual CorInfoType getFieldElementType( + unsigned fieldToken, + CORINFO_MODULE_HANDLE scope, + CORINFO_METHOD_HANDLE methHnd + ) = 0; + + // tokens in inlined methods may need to be translated, + // for example if they are in a generic method we need to fill in type parameters, + // or in one from another module we need to translate tokens so they are valid + // in module + // tokens in dynamic methods (IL stubs) are always translated because + // as generated they are not backed by any metadata + + // this is called at the start of an inline expansion + virtual InlineContext *computeInlineContext( + InlineContext *outerContext, + unsigned inlinedMethodToken, + unsigned constraintTypeRef, + CORINFO_METHOD_HANDLE methHnd + ) = 0; + + // this does the actual translation + virtual unsigned translateToken( + InlineContext *inlineContext, + CORINFO_MODULE_HANDLE scopeHnd, + unsigned token + ) = 0; + + virtual unsigned getCurrentMethodToken( + InlineContext *inlineContext, + CORINFO_METHOD_HANDLE method + ) = 0; + + // computes flags for an IL stub method + virtual unsigned getStubMethodFlags( + CORINFO_METHOD_HANDLE method + ) = 0; +#endif + + + /**********************************************************************************/ + // + // ICorModuleInfo + // + /**********************************************************************************/ + + // Resolve metadata token into runtime method handles. + virtual void resolveToken(/* IN, OUT */ CORINFO_RESOLVED_TOKEN * pResolvedToken) = 0; + +#ifdef MDIL + // Given a field or method token metaTOK return its parent token + // we still need this in MDIL, for example for static field access we need the + // token of the enclosing type + virtual unsigned getMemberParent(CORINFO_MODULE_HANDLE scopeHnd, unsigned metaTOK) = 0; + + // given a token representing an MD array of structs, get the element type token + virtual unsigned getArrayElementToken(CORINFO_MODULE_HANDLE scopeHnd, unsigned metaTOK) = 0; +#endif // MDIL + + // Signature information about the call sig + virtual void findSig ( + CORINFO_MODULE_HANDLE module, /* IN */ + unsigned sigTOK, /* IN */ + CORINFO_CONTEXT_HANDLE context, /* IN */ + CORINFO_SIG_INFO *sig /* OUT */ + ) = 0; + + // for Varargs, the signature at the call site may differ from + // the signature at the definition. Thus we need a way of + // fetching the call site information + virtual void findCallSiteSig ( + CORINFO_MODULE_HANDLE module, /* IN */ + unsigned methTOK, /* IN */ + CORINFO_CONTEXT_HANDLE context, /* IN */ + CORINFO_SIG_INFO *sig /* OUT */ + ) = 0; + + virtual CORINFO_CLASS_HANDLE getTokenTypeAsHandle ( + CORINFO_RESOLVED_TOKEN * pResolvedToken /* IN */) = 0; + + // Returns true if the module does not require verification + // + // If fQuickCheckOnlyWithoutCommit=TRUE, the function only checks that the + // module does not currently require verification in the current AppDomain. + // This decision could change in the future, and so should not be cached. + // If it is cached, it should only be used as a hint. + // This is only used by ngen for calculating certain hints. + // + + // Returns enum whether the module does not require verification + // Also see ICorMethodInfo::canSkipMethodVerification(); + virtual CorInfoCanSkipVerificationResult canSkipVerification ( + CORINFO_MODULE_HANDLE module /* IN */ + ) = 0; + + // Checks if the given metadata token is valid + virtual BOOL isValidToken ( + CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK /* IN */ + ) = 0; + + // Checks if the given metadata token is valid StringRef + virtual BOOL isValidStringRef ( + CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK /* IN */ + ) = 0; + + virtual BOOL shouldEnforceCallvirtRestriction( + CORINFO_MODULE_HANDLE scope + ) = 0; +#ifdef MDIL + virtual unsigned getTypeTokenForFieldOrMethod( + unsigned fieldOrMethodToken + ) = 0; + + virtual unsigned getTokenForType(CORINFO_CLASS_HANDLE cls) = 0; +#endif + + /**********************************************************************************/ + // + // ICorClassInfo + // + /**********************************************************************************/ + + // If the value class 'cls' is isomorphic to a primitive type it will + // return that type, otherwise it will return CORINFO_TYPE_VALUECLASS + virtual CorInfoType asCorInfoType ( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // for completeness + virtual const char* getClassName ( + CORINFO_CLASS_HANDLE cls + ) = 0; + + + // Append a (possibly truncated) representation of the type cls to the preallocated buffer ppBuf of length pnBufLen + // If fNamespace=TRUE, include the namespace/enclosing classes + // If fFullInst=TRUE (regardless of fNamespace and fAssembly), include namespace and assembly for any type parameters + // If fAssembly=TRUE, suffix with a comma and the full assembly qualification + // return size of representation + virtual int appendClassName( + __deref_inout_ecount(*pnBufLen) WCHAR** ppBuf, + int* pnBufLen, + CORINFO_CLASS_HANDLE cls, + BOOL fNamespace, + BOOL fFullInst, + BOOL fAssembly + ) = 0; + + // Quick check whether the type is a value class. Returns the same value as getClassAttribs(cls) & CORINFO_FLG_VALUECLASS, except faster. + virtual BOOL isValueClass(CORINFO_CLASS_HANDLE cls) = 0; + + // If this method returns true, JIT will do optimization to inline the check for + // GetTypeFromHandle(handle) == obj.GetType() + virtual BOOL canInlineTypeCheckWithObjectVTable(CORINFO_CLASS_HANDLE cls) = 0; + + // return flags (defined above, CORINFO_FLG_PUBLIC ...) + virtual DWORD getClassAttribs ( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // Returns "TRUE" iff "cls" is a struct type such that return buffers used for returning a value + // of this type must be stack-allocated. This will generally be true only if the struct + // contains GC pointers, and does not exceed some size limit. Maintaining this as an invariant allows + // an optimization: the JIT may assume that return buffer pointers for return types for which this predicate + // returns TRUE are always stack allocated, and thus, that stores to the GC-pointer fields of such return + // buffers do not require GC write barriers. + virtual BOOL isStructRequiringStackAllocRetBuf(CORINFO_CLASS_HANDLE cls) = 0; + + virtual CORINFO_MODULE_HANDLE getClassModule ( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // Returns the assembly that contains the module "mod". + virtual CORINFO_ASSEMBLY_HANDLE getModuleAssembly ( + CORINFO_MODULE_HANDLE mod + ) = 0; + + // Returns the name of the assembly "assem". + virtual const char* getAssemblyName ( + CORINFO_ASSEMBLY_HANDLE assem + ) = 0; + + // Allocate and delete process-lifetime objects. Should only be + // referred to from static fields, lest a leak occur. + // Note that "LongLifetimeFree" does not execute destructors, if "obj" + // is an array of a struct type with a destructor. + virtual void* LongLifetimeMalloc(size_t sz) = 0; + virtual void LongLifetimeFree(void* obj) = 0; + + virtual size_t getClassModuleIdForStatics ( + CORINFO_CLASS_HANDLE cls, + CORINFO_MODULE_HANDLE *pModule, + void **ppIndirection + ) = 0; + + // return the number of bytes needed by an instance of the class + virtual unsigned getClassSize ( + CORINFO_CLASS_HANDLE cls + ) = 0; + + virtual unsigned getClassAlignmentRequirement ( + CORINFO_CLASS_HANDLE cls, + BOOL fDoubleAlignHint = FALSE + ) = 0; + + // This is only called for Value classes. It returns a boolean array + // in representing of 'cls' from a GC perspective. The class is + // assumed to be an array of machine words + // (of length // getClassSize(cls) / sizeof(void*)), + // 'gcPtrs' is a poitner to an array of BYTEs of this length. + // getClassGClayout fills in this array so that gcPtrs[i] is set + // to one of the CorInfoGCType values which is the GC type of + // the i-th machine word of an object of type 'cls' + // returns the number of GC pointers in the array + virtual unsigned getClassGClayout ( + CORINFO_CLASS_HANDLE cls, /* IN */ + BYTE *gcPtrs /* OUT */ + ) = 0; + + // returns the number of instance fields in a class + virtual unsigned getClassNumInstanceFields ( + CORINFO_CLASS_HANDLE cls /* IN */ + ) = 0; + + virtual CORINFO_FIELD_HANDLE getFieldInClass( + CORINFO_CLASS_HANDLE clsHnd, + INT num + ) = 0; + + virtual BOOL checkMethodModifier( + CORINFO_METHOD_HANDLE hMethod, + LPCSTR modifier, + BOOL fOptional + ) = 0; + + // returns the "NEW" helper optimized for "newCls." + virtual CorInfoHelpFunc getNewHelper( + CORINFO_RESOLVED_TOKEN * pResolvedToken, + CORINFO_METHOD_HANDLE callerHandle + ) = 0; + + // returns the newArr (1-Dim array) helper optimized for "arrayCls." + virtual CorInfoHelpFunc getNewArrHelper( + CORINFO_CLASS_HANDLE arrayCls + ) = 0; + + // returns the optimized "IsInstanceOf" or "ChkCast" helper + virtual CorInfoHelpFunc getCastingHelper( + CORINFO_RESOLVED_TOKEN * pResolvedToken, + bool fThrowing + ) = 0; + + // returns helper to trigger static constructor + virtual CorInfoHelpFunc getSharedCCtorHelper( + CORINFO_CLASS_HANDLE clsHnd + ) = 0; + + virtual CorInfoHelpFunc getSecurityPrologHelper( + CORINFO_METHOD_HANDLE ftn + ) = 0; + + // This is not pretty. Boxing nullable actually returns + // a boxed not a boxed Nullable. This call allows the verifier + // to call back to the EE on the 'box' instruction and get the transformed + // type to use for verification. + virtual CORINFO_CLASS_HANDLE getTypeForBox( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // returns the correct box helper for a particular class. Note + // that if this returns CORINFO_HELP_BOX, the JIT can assume + // 'standard' boxing (allocate object and copy), and optimize + virtual CorInfoHelpFunc getBoxHelper( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // returns the unbox helper. If 'helperCopies' points to a true + // value it means the JIT is requesting a helper that unboxes the + // value into a particular location and thus has the signature + // void unboxHelper(void* dest, CORINFO_CLASS_HANDLE cls, Object* obj) + // Otherwise (it is null or points at a FALSE value) it is requesting + // a helper that returns a poitner to the unboxed data + // void* unboxHelper(CORINFO_CLASS_HANDLE cls, Object* obj) + // The EE has the option of NOT returning the copy style helper + // (But must be able to always honor the non-copy style helper) + // The EE set 'helperCopies' on return to indicate what kind of + // helper has been created. + + virtual CorInfoHelpFunc getUnBoxHelper( + CORINFO_CLASS_HANDLE cls + ) = 0; + +#ifndef RYUJIT_CTPBUILD + virtual void getReadyToRunHelper( + CORINFO_RESOLVED_TOKEN * pResolvedToken, + CorInfoHelpFunc id, + CORINFO_CONST_LOOKUP * pLookup + ) = 0; +#endif + + virtual const char* getHelperName( + CorInfoHelpFunc + ) = 0; + + // This function tries to initialize the class (run the class constructor). + // this function returns whether the JIT must insert helper calls before + // accessing static field or method. + // + // See code:ICorClassInfo#ClassConstruction. + virtual CorInfoInitClassResult initClass( + CORINFO_FIELD_HANDLE field, // Non-NULL - inquire about cctor trigger before static field access + // NULL - inquire about cctor trigger in method prolog + CORINFO_METHOD_HANDLE method, // Method referencing the field or prolog + CORINFO_CONTEXT_HANDLE context, // Exact context of method + BOOL speculative = FALSE // TRUE means don't actually run it + ) = 0; + + // This used to be called "loadClass". This records the fact + // that the class must be loaded (including restored if necessary) before we execute the + // code that we are currently generating. When jitting code + // the function loads the class immediately. When zapping code + // the zapper will if necessary use the call to record the fact that we have + // to do a fixup/restore before running the method currently being generated. + // + // This is typically used to ensure value types are loaded before zapped + // code that manipulates them is executed, so that the GC can access information + // about those value types. + virtual void classMustBeLoadedBeforeCodeIsRun( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // returns the class handle for the special builtin classes + virtual CORINFO_CLASS_HANDLE getBuiltinClass ( + CorInfoClassId classId + ) = 0; + + // "System.Int32" ==> CORINFO_TYPE_INT.. + virtual CorInfoType getTypeForPrimitiveValueClass( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // TRUE if child is a subtype of parent + // if parent is an interface, then does child implement / extend parent + virtual BOOL canCast( + CORINFO_CLASS_HANDLE child, // subtype (extends parent) + CORINFO_CLASS_HANDLE parent // base type + ) = 0; + + // TRUE if cls1 and cls2 are considered equivalent types. + virtual BOOL areTypesEquivalent( + CORINFO_CLASS_HANDLE cls1, + CORINFO_CLASS_HANDLE cls2 + ) = 0; + + // returns is the intersection of cls1 and cls2. + virtual CORINFO_CLASS_HANDLE mergeClasses( + CORINFO_CLASS_HANDLE cls1, + CORINFO_CLASS_HANDLE cls2 + ) = 0; + + // Given a class handle, returns the Parent type. + // For COMObjectType, it returns Class Handle of System.Object. + // Returns 0 if System.Object is passed in. + virtual CORINFO_CLASS_HANDLE getParentType ( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // Returns the CorInfoType of the "child type". If the child type is + // not a primitive type, *clsRet will be set. + // Given an Array of Type Foo, returns Foo. + // Given BYREF Foo, returns Foo + virtual CorInfoType getChildType ( + CORINFO_CLASS_HANDLE clsHnd, + CORINFO_CLASS_HANDLE *clsRet + ) = 0; + + // Check constraints on type arguments of this class and parent classes + virtual BOOL satisfiesClassConstraints( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // Check if this is a single dimensional array type + virtual BOOL isSDArray( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // Get the numbmer of dimensions in an array + virtual unsigned getArrayRank( + CORINFO_CLASS_HANDLE cls + ) = 0; + + // Get static field data for an array + virtual void * getArrayInitializationData( + CORINFO_FIELD_HANDLE field, + DWORD size + ) = 0; + + // Check Visibility rules. + virtual CorInfoIsAccessAllowedResult canAccessClass( + CORINFO_RESOLVED_TOKEN * pResolvedToken, + CORINFO_METHOD_HANDLE callerHandle, + CORINFO_HELPER_DESC *pAccessHelper /* If canAccessMethod returns something other + than ALLOWED, then this is filled in. */ + ) = 0; + + /**********************************************************************************/ + // + // ICorFieldInfo + // + /**********************************************************************************/ + + // this function is for debugging only. It returns the field name + // and if 'moduleName' is non-null, it sets it to something that will + // says which method (a class name, or a module name) + virtual const char* getFieldName ( + CORINFO_FIELD_HANDLE ftn, /* IN */ + const char **moduleName /* OUT */ + ) = 0; + + // return class it belongs to + virtual CORINFO_CLASS_HANDLE getFieldClass ( + CORINFO_FIELD_HANDLE field + ) = 0; + + // Return the field's type, if it is CORINFO_TYPE_VALUECLASS 'structType' is set + // the field's value class (if 'structType' == 0, then don't bother + // the structure info). + // + // 'memberParent' is typically only set when verifying. It should be the + // result of calling getMemberParent. + virtual CorInfoType getFieldType( + CORINFO_FIELD_HANDLE field, + CORINFO_CLASS_HANDLE *structType, + CORINFO_CLASS_HANDLE memberParent = NULL /* IN */ + ) = 0; + + // return the data member's instance offset + virtual unsigned getFieldOffset( + CORINFO_FIELD_HANDLE field + ) = 0; + + // TODO: jit64 should be switched to the same plan as the i386 jits - use + // getClassGClayout to figure out the need for writebarrier helper, and inline the copying. + // The interpretted value class copy is slow. Once this happens, USE_WRITE_BARRIER_HELPERS + virtual bool isWriteBarrierHelperRequired( + CORINFO_FIELD_HANDLE field) = 0; + + virtual void getFieldInfo (CORINFO_RESOLVED_TOKEN * pResolvedToken, + CORINFO_METHOD_HANDLE callerHandle, + CORINFO_ACCESS_FLAGS flags, + CORINFO_FIELD_INFO *pResult + ) = 0; +#ifdef MDIL + virtual DWORD getFieldOrdinal(CORINFO_MODULE_HANDLE tokenScope, + unsigned fieldToken) = 0; +#endif + + // Returns true iff "fldHnd" represents a static field. + virtual bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) = 0; + + /*********************************************************************************/ + // + // ICorDebugInfo + // + /*********************************************************************************/ + + // Query the EE to find out where interesting break points + // in the code are. The native compiler will ensure that these places + // have a corresponding break point in native code. + // + // Note that unless CORJIT_FLG_DEBUG_CODE is specified, this function will + // be used only as a hint and the native compiler should not change its + // code generation. + virtual void getBoundaries( + CORINFO_METHOD_HANDLE ftn, // [IN] method of interest + unsigned int *cILOffsets, // [OUT] size of pILOffsets + DWORD **pILOffsets, // [OUT] IL offsets of interest + // jit MUST free with freeArray! + ICorDebugInfo::BoundaryTypes *implictBoundaries // [OUT] tell jit, all boundries of this type + ) = 0; + + // Report back the mapping from IL to native code, + // this map should include all boundaries that 'getBoundaries' + // reported as interesting to the debugger. + + // Note that debugger (and profiler) is assuming that all of the + // offsets form a contiguous block of memory, and that the + // OffsetMapping is sorted in order of increasing native offset. + virtual void setBoundaries( + CORINFO_METHOD_HANDLE ftn, // [IN] method of interest + ULONG32 cMap, // [IN] size of pMap + ICorDebugInfo::OffsetMapping *pMap // [IN] map including all points of interest. + // jit allocated with allocateArray, EE frees + ) = 0; + + // Query the EE to find out the scope of local varables. + // normally the JIT would trash variables after last use, but + // under debugging, the JIT needs to keep them live over their + // entire scope so that they can be inspected. + // + // Note that unless CORJIT_FLG_DEBUG_CODE is specified, this function will + // be used only as a hint and the native compiler should not change its + // code generation. + virtual void getVars( + CORINFO_METHOD_HANDLE ftn, // [IN] method of interest + ULONG32 *cVars, // [OUT] size of 'vars' + ICorDebugInfo::ILVarInfo **vars, // [OUT] scopes of variables of interest + // jit MUST free with freeArray! + bool *extendOthers // [OUT] it TRUE, then assume the scope + // of unmentioned vars is entire method + ) = 0; + + // Report back to the EE the location of every variable. + // note that the JIT might split lifetimes into different + // locations etc. + + virtual void setVars( + CORINFO_METHOD_HANDLE ftn, // [IN] method of interest + ULONG32 cVars, // [IN] size of 'vars' + ICorDebugInfo::NativeVarInfo *vars // [IN] map telling where local vars are stored at what points + // jit allocated with allocateArray, EE frees + ) = 0; + + /*-------------------------- Misc ---------------------------------------*/ + + // Used to allocate memory that needs to handed to the EE. + // For eg, use this to allocated memory for reporting debug info, + // which will be handed to the EE by setVars() and setBoundaries() + virtual void * allocateArray( + ULONG cBytes + ) = 0; + + // JitCompiler will free arrays passed by the EE using this + // For eg, The EE returns memory in getVars() and getBoundaries() + // to the JitCompiler, which the JitCompiler should release using + // freeArray() + virtual void freeArray( + void *array + ) = 0; + + /*********************************************************************************/ + // + // ICorArgInfo + // + /*********************************************************************************/ + + // advance the pointer to the argument list. + // a ptr of 0, is special and always means the first argument + virtual CORINFO_ARG_LIST_HANDLE getArgNext ( + CORINFO_ARG_LIST_HANDLE args /* IN */ + ) = 0; + + // Get the type of a particular argument + // CORINFO_TYPE_UNDEF is returned when there are no more arguments + // If the type returned is a primitive type (or an enum) *vcTypeRet set to NULL + // otherwise it is set to the TypeHandle associted with the type + // Enumerations will always look their underlying type (probably should fix this) + // Otherwise vcTypeRet is the type as would be seen by the IL, + // The return value is the type that is used for calling convention purposes + // (Thus if the EE wants a value class to be passed like an int, then it will + // return CORINFO_TYPE_INT + virtual CorInfoTypeWithMod getArgType ( + CORINFO_SIG_INFO* sig, /* IN */ + CORINFO_ARG_LIST_HANDLE args, /* IN */ + CORINFO_CLASS_HANDLE *vcTypeRet /* OUT */ + ) = 0; + + // If the Arg is a CORINFO_TYPE_CLASS fetch the class handle associated with it + virtual CORINFO_CLASS_HANDLE getArgClass ( + CORINFO_SIG_INFO* sig, /* IN */ + CORINFO_ARG_LIST_HANDLE args /* IN */ + ) = 0; + + // Returns type of HFA for valuetype + virtual CorInfoType getHFAType ( + CORINFO_CLASS_HANDLE hClass + ) = 0; + + /***************************************************************************** + * ICorErrorInfo contains methods to deal with SEH exceptions being thrown + * from the corinfo interface. These methods may be called when an exception + * with code EXCEPTION_COMPLUS is caught. + *****************************************************************************/ + + // Returns the HRESULT of the current exception + virtual HRESULT GetErrorHRESULT( + struct _EXCEPTION_POINTERS *pExceptionPointers + ) = 0; + + // Fetches the message of the current exception + // Returns the size of the message (including terminating null). This can be + // greater than bufferLength if the buffer is insufficient. + virtual ULONG GetErrorMessage( + __inout_ecount(bufferLength) LPWSTR buffer, + ULONG bufferLength + ) = 0; + + // returns EXCEPTION_EXECUTE_HANDLER if it is OK for the compile to handle the + // exception, abort some work (like the inlining) and continue compilation + // returns EXCEPTION_CONTINUE_SEARCH if exception must always be handled by the EE + // things like ThreadStoppedException ... + // returns EXCEPTION_CONTINUE_EXECUTION if exception is fixed up by the EE + + virtual int FilterException( + struct _EXCEPTION_POINTERS *pExceptionPointers + ) = 0; + + // Cleans up internal EE tracking when an exception is caught. + virtual void HandleException( + struct _EXCEPTION_POINTERS *pExceptionPointers + ) = 0; + + virtual void ThrowExceptionForJitResult( + HRESULT result) = 0; + + //Throws an exception defined by the given throw helper. + virtual void ThrowExceptionForHelper( + const CORINFO_HELPER_DESC * throwHelper) = 0; + +/***************************************************************************** + * ICorStaticInfo contains EE interface methods which return values that are + * constant from invocation to invocation. Thus they may be embedded in + * persisted information like statically generated code. (This is of course + * assuming that all code versions are identical each time.) + *****************************************************************************/ + + // Return details about EE internal data structures + virtual void getEEInfo( + CORINFO_EE_INFO *pEEInfoOut + ) = 0; + + // Returns name of the JIT timer log + virtual LPCWSTR getJitTimeLogFilename() = 0; + +#ifdef RYUJIT_CTPBUILD + // Logs a SQM event for a JITting a very large method. + virtual void logSQMLongJitEvent(unsigned mcycles, unsigned msec, unsigned ilSize, unsigned numBasicBlocks, bool minOpts, + CORINFO_METHOD_HANDLE methodHnd) = 0; +#endif // RYUJIT_CTPBUILD + + /*********************************************************************************/ + // + // Diagnostic methods + // + /*********************************************************************************/ + + // this function is for debugging only. Returns method token. + // Returns mdMethodDefNil for dynamic methods. + virtual mdMethodDef getMethodDefFromMethod( + CORINFO_METHOD_HANDLE hMethod + ) = 0; + + // this function is for debugging only. It returns the method name + // and if 'moduleName' is non-null, it sets it to something that will + // says which method (a class name, or a module name) + virtual const char* getMethodName ( + CORINFO_METHOD_HANDLE ftn, /* IN */ + const char **moduleName /* OUT */ + ) = 0; + + // this function is for debugging only. It returns a value that + // is will always be the same for a given method. It is used + // to implement the 'jitRange' functionality + virtual unsigned getMethodHash ( + CORINFO_METHOD_HANDLE ftn /* IN */ + ) = 0; + + // this function is for debugging only. + virtual size_t findNameOfToken ( + CORINFO_MODULE_HANDLE module, /* IN */ + mdToken metaTOK, /* IN */ + __out_ecount (FQNameCapacity) char * szFQName, /* OUT */ + size_t FQNameCapacity /* IN */ + ) = 0; + +#if !defined(RYUJIT_CTPBUILD) + /*************************************************************************/ + // + // Configuration values - Allows querying of the CLR configuration. + // + /*************************************************************************/ + + // Return an integer ConfigValue if any. + // + virtual int getIntConfigValue( + const wchar_t *name, + int defaultValue + ) = 0; + + // Return a string ConfigValue if any. + // + virtual wchar_t *getStringConfigValue( + const wchar_t *name + ) = 0; + + // Free a string ConfigValue returned by the runtime. + // JITs using the getStringConfigValue query are required + // to return the string values to the runtime for deletion. + // this avoid leaking the memory in the JIT. + virtual void freeStringConfigValue( + wchar_t *value + ) = 0; +#endif // RYUJIT_CTPBUILD +}; + +/***************************************************************************** + * ICorDynamicInfo contains EE interface methods which return values that may + * change from invocation to invocation. They cannot be embedded in persisted + * data; they must be requeried each time the EE is run. + *****************************************************************************/ + +class ICorDynamicInfo : public ICorStaticInfo +{ +public: + + // + // These methods return values to the JIT which are not constant + // from session to session. + // + // These methods take an extra parameter : void **ppIndirection. + // If a JIT supports generation of prejit code (install-o-jit), it + // must pass a non-null value for this parameter, and check the + // resulting value. If *ppIndirection is NULL, code should be + // generated normally. If non-null, then the value of + // *ppIndirection is an address in the cookie table, and the code + // generator needs to generate an indirection through the table to + // get the resulting value. In this case, the return result of the + // function must NOT be directly embedded in the generated code. + // + // Note that if a JIT does not support prejit code generation, it + // may ignore the extra parameter & pass the default of NULL - the + // prejit ICorDynamicInfo implementation will see this & generate + // an error if the jitter is used in a prejit scenario. + // + + // Return details about EE internal data structures + + virtual DWORD getThreadTLSIndex( + void **ppIndirection = NULL + ) = 0; + + virtual const void * getInlinedCallFrameVptr( + void **ppIndirection = NULL + ) = 0; + + virtual LONG * getAddrOfCaptureThreadGlobal( + void **ppIndirection = NULL + ) = 0; + + virtual SIZE_T* getAddrModuleDomainID(CORINFO_MODULE_HANDLE module) = 0; + + // return the native entry point to an EE helper (see CorInfoHelpFunc) + virtual void* getHelperFtn ( + CorInfoHelpFunc ftnNum, + void **ppIndirection = NULL + ) = 0; + + // return a callable address of the function (native code). This function + // may return a different value (depending on whether the method has + // been JITed or not. + virtual void getFunctionEntryPoint( + CORINFO_METHOD_HANDLE ftn, /* IN */ + CORINFO_CONST_LOOKUP * pResult, /* OUT */ + CORINFO_ACCESS_FLAGS accessFlags = CORINFO_ACCESS_ANY) = 0; + + // return a directly callable address. This can be used similarly to the + // value returned by getFunctionEntryPoint() except that it is + // guaranteed to be multi callable entrypoint. + virtual void getFunctionFixedEntryPoint( + CORINFO_METHOD_HANDLE ftn, + CORINFO_CONST_LOOKUP * pResult) = 0; + + // get the synchronization handle that is passed to monXstatic function + virtual void* getMethodSync( + CORINFO_METHOD_HANDLE ftn, + void **ppIndirection = NULL + ) = 0; + +#if defined(RYUJIT_CTPBUILD) + // These entry points must be called if a handle is being embedded in + // the code to be passed to a JIT helper function. (as opposed to just + // being passed back into the ICorInfo interface.) + + // a module handle may not always be available. A call to embedModuleHandle should always + // be preceeded by a call to canEmbedModuleHandleForHelper. A dynamicMethod does not have a module + virtual bool canEmbedModuleHandleForHelper( + CORINFO_MODULE_HANDLE handle + ) = 0; +#else + // get slow lazy string literal helper to use (CORINFO_HELP_STRCNS*). + // Returns CORINFO_HELP_UNDEF if lazy string literal helper cannot be used. + virtual CorInfoHelpFunc getLazyStringLiteralHelper( + CORINFO_MODULE_HANDLE handle + ) = 0; +#endif + virtual CORINFO_MODULE_HANDLE embedModuleHandle( + CORINFO_MODULE_HANDLE handle, + void **ppIndirection = NULL + ) = 0; + + virtual CORINFO_CLASS_HANDLE embedClassHandle( + CORINFO_CLASS_HANDLE handle, + void **ppIndirection = NULL + ) = 0; + + virtual CORINFO_METHOD_HANDLE embedMethodHandle( + CORINFO_METHOD_HANDLE handle, + void **ppIndirection = NULL + ) = 0; + + virtual CORINFO_FIELD_HANDLE embedFieldHandle( + CORINFO_FIELD_HANDLE handle, + void **ppIndirection = NULL + ) = 0; + + // Given a module scope (module), a method handle (context) and + // a metadata token (metaTOK), fetch the handle + // (type, field or method) associated with the token. + // If this is not possible at compile-time (because the current method's + // code is shared and the token contains generic parameters) + // then indicate how the handle should be looked up at run-time. + // + virtual void embedGenericHandle( + CORINFO_RESOLVED_TOKEN * pResolvedToken, + BOOL fEmbedParent, // TRUE - embeds parent type handle of the field/method handle + CORINFO_GENERICHANDLE_RESULT * pResult) = 0; + + // Return information used to locate the exact enclosing type of the current method. + // Used only to invoke .cctor method from code shared across generic instantiations + // !needsRuntimeLookup statically known (enclosing type of method itself) + // needsRuntimeLookup: + // CORINFO_LOOKUP_THISOBJ use vtable pointer of 'this' param + // CORINFO_LOOKUP_CLASSPARAM use vtable hidden param + // CORINFO_LOOKUP_METHODPARAM use enclosing type of method-desc hidden param + virtual CORINFO_LOOKUP_KIND getLocationOfThisType( + CORINFO_METHOD_HANDLE context + ) = 0; + + // return the unmanaged target *if method has already been prelinked.* + virtual void* getPInvokeUnmanagedTarget( + CORINFO_METHOD_HANDLE method, + void **ppIndirection = NULL + ) = 0; + + // return address of fixup area for late-bound PInvoke calls. + virtual void* getAddressOfPInvokeFixup( + CORINFO_METHOD_HANDLE method, + void **ppIndirection = NULL + ) = 0; + + // Generate a cookie based on the signature that would needs to be passed + // to CORINFO_HELP_PINVOKE_CALLI + virtual LPVOID GetCookieForPInvokeCalliSig( + CORINFO_SIG_INFO* szMetaSig, + void ** ppIndirection = NULL + ) = 0; + + // returns true if a VM cookie can be generated for it (might be false due to cross-module + // inlining, in which case the inlining should be aborted) + virtual bool canGetCookieForPInvokeCalliSig( + CORINFO_SIG_INFO* szMetaSig + ) = 0; + + // Gets a handle that is checked to see if the current method is + // included in "JustMyCode" + virtual CORINFO_JUST_MY_CODE_HANDLE getJustMyCodeHandle( + CORINFO_METHOD_HANDLE method, + CORINFO_JUST_MY_CODE_HANDLE**ppIndirection = NULL + ) = 0; + + // Gets a method handle that can be used to correlate profiling data. + // This is the IP of a native method, or the address of the descriptor struct + // for IL. Always guaranteed to be unique per process, and not to move. */ + virtual void GetProfilingHandle( + BOOL *pbHookFunction, + void **pProfilerHandle, + BOOL *pbIndirectedHandles + ) = 0; + + // Returns instructions on how to make the call. See code:CORINFO_CALL_INFO for possible return values. + virtual void getCallInfo( + // Token info + CORINFO_RESOLVED_TOKEN * pResolvedToken, + + //Generics info + CORINFO_RESOLVED_TOKEN * pConstrainedResolvedToken, + + //Security info + CORINFO_METHOD_HANDLE callerHandle, + + //Jit info + CORINFO_CALLINFO_FLAGS flags, + + //out params + CORINFO_CALL_INFO *pResult + ) = 0; + + virtual BOOL canAccessFamily(CORINFO_METHOD_HANDLE hCaller, + CORINFO_CLASS_HANDLE hInstanceType) = 0; + + // Returns TRUE if the Class Domain ID is the RID of the class (currently true for every class + // except reflection emitted classes and generics) + virtual BOOL isRIDClassDomainID(CORINFO_CLASS_HANDLE cls) = 0; + + // returns the class's domain ID for accessing shared statics + virtual unsigned getClassDomainID ( + CORINFO_CLASS_HANDLE cls, + void **ppIndirection = NULL + ) = 0; + + + // return the data's address (for static fields only) + virtual void* getFieldAddress( + CORINFO_FIELD_HANDLE field, + void **ppIndirection = NULL + ) = 0; + + // registers a vararg sig & returns a VM cookie for it (which can contain other stuff) + virtual CORINFO_VARARGS_HANDLE getVarArgsHandle( + CORINFO_SIG_INFO *pSig, + void **ppIndirection = NULL + ) = 0; + + // returns true if a VM cookie can be generated for it (might be false due to cross-module + // inlining, in which case the inlining should be aborted) + virtual bool canGetVarArgsHandle( + CORINFO_SIG_INFO *pSig + ) = 0; + + // Allocate a string literal on the heap and return a handle to it + virtual InfoAccessType constructStringLiteral( + CORINFO_MODULE_HANDLE module, + mdToken metaTok, + void **ppValue + ) = 0; + + virtual InfoAccessType emptyStringLiteral( + void **ppValue + ) = 0; + + // (static fields only) given that 'field' refers to thread local store, + // return the ID (TLS index), which is used to find the begining of the + // TLS data area for the particular DLL 'field' is associated with. + virtual DWORD getFieldThreadLocalStoreID ( + CORINFO_FIELD_HANDLE field, + void **ppIndirection = NULL + ) = 0; + + // Sets another object to intercept calls to "self" and current method being compiled + virtual void setOverride( + ICorDynamicInfo *pOverride, + CORINFO_METHOD_HANDLE currentMethod + ) = 0; + + // Adds an active dependency from the context method's module to the given module + // This is internal callback for the EE. JIT should not call it directly. + virtual void addActiveDependency( + CORINFO_MODULE_HANDLE moduleFrom, + CORINFO_MODULE_HANDLE moduleTo + ) = 0; + + virtual CORINFO_METHOD_HANDLE GetDelegateCtor( + CORINFO_METHOD_HANDLE methHnd, + CORINFO_CLASS_HANDLE clsHnd, + CORINFO_METHOD_HANDLE targetMethodHnd, + DelegateCtorArgs * pCtorData + ) = 0; + + virtual void MethodCompileComplete( + CORINFO_METHOD_HANDLE methHnd + ) = 0; + + // return a thunk that will copy the arguments for the given signature. + virtual void* getTailCallCopyArgsThunk ( + CORINFO_SIG_INFO *pSig, + CorInfoHelperTailCallSpecialHandling flags + ) = 0; +}; + +/**********************************************************************************/ + +// It would be nicer to use existing IMAGE_REL_XXX constants instead of defining our own here... +#define IMAGE_REL_BASED_REL32 0x10 +#define IMAGE_REL_BASED_THUMB_BRANCH24 0x13 + +#endif // _COR_INFO_H_ diff --git a/src/JitInterface/src/ThunkGenerator/corjit.h b/src/JitInterface/src/ThunkGenerator/corjit.h new file mode 100644 index 00000000000..fca22311dd6 --- /dev/null +++ b/src/JitInterface/src/ThunkGenerator/corjit.h @@ -0,0 +1,617 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*****************************************************************************\ +* * +* CorJit.h - EE / JIT interface * +* * +* Version 1.0 * +******************************************************************************* +* * +* * +* * +\*****************************************************************************/ + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE +// +// The JIT/EE interface is versioned. By "interface", we mean mean any and all communication between the +// JIT and the EE. Any time a change is made to the interface, the JIT/EE interface version identifier +// must be updated. See code:JITEEVersionIdentifier for more information. +// +// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE +// +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef _COR_JIT_H_ +#define _COR_JIT_H_ + +#include + +#define CORINFO_STACKPROBE_DEPTH 256*sizeof(UINT_PTR) // Guaranteed stack until an fcall/unmanaged + // code can set up a frame. Please make sure + // this is less than a page. This is due to + // 2 reasons: + // + // If we need to probe more than a page + // size, we need one instruction per page + // (7 bytes per instruction) + // + // The JIT wants some safe space so it doesn't + // have to put a probe on every call site. It achieves + // this by probing n bytes more than CORINFO_STACKPROBE_DEPTH + // If it hasn't used more than n for its own stuff, it + // can do a call without doing any other probe + // + // In any case, we do really expect this define to be + // small, as setting up a frame should be only pushing + // a couple of bytes on the stack + // + // There is a compile time assert + // in the x86 jit to protect you from this + // + + + + +/*****************************************************************************/ + // These are error codes returned by CompileMethod +enum CorJitResult +{ + // Note that I dont use FACILITY_NULL for the facility number, + // we may want to get a 'real' facility number + CORJIT_OK = NO_ERROR, + CORJIT_BADCODE = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_NULL, 1), + CORJIT_OUTOFMEM = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_NULL, 2), + CORJIT_INTERNALERROR = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_NULL, 3), + CORJIT_SKIPPED = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_NULL, 4), + CORJIT_RECOVERABLEERROR = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_NULL, 5), + CORJIT_SKIPMDIL = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_NULL, 6) +}; + + +/* values for flags in compileMethod */ + +enum CorJitFlag +{ + CORJIT_FLG_SPEED_OPT = 0x00000001, + CORJIT_FLG_SIZE_OPT = 0x00000002, + CORJIT_FLG_DEBUG_CODE = 0x00000004, // generate "debuggable" code (no code-mangling optimizations) + CORJIT_FLG_DEBUG_EnC = 0x00000008, // We are in Edit-n-Continue mode + CORJIT_FLG_DEBUG_INFO = 0x00000010, // generate line and local-var info + CORJIT_FLG_MIN_OPT = 0x00000020, // disable all jit optimizations (not necesarily debuggable code) + CORJIT_FLG_GCPOLL_CALLS = 0x00000040, // Emit calls to JIT_POLLGC for thread suspension. + CORJIT_FLG_MCJIT_BACKGROUND = 0x00000080, // Calling from multicore JIT background thread, do not call JitComplete + +#ifdef FEATURE_LEGACYNETCF + + CORJIT_FLG_NETCF_QUIRKS = 0x00000100, // Mimic .NetCF JIT's quirks for generated code (currently just inlining heuristics) + +#else // FEATURE_LEGACYNETCF + + CORJIT_FLG_UNUSED1 = 0x00000100, + +#endif // FEATURE_LEGACYNETCF + +#if defined(_TARGET_X86_) + + CORJIT_FLG_PINVOKE_RESTORE_ESP = 0x00000200, // Restore ESP after returning from inlined PInvoke + CORJIT_FLG_TARGET_P4 = 0x00000400, + CORJIT_FLG_USE_FCOMI = 0x00000800, // Generated code may use fcomi(p) instruction + CORJIT_FLG_USE_CMOV = 0x00001000, // Generated code may use cmov instruction + CORJIT_FLG_USE_SSE2 = 0x00002000, // Generated code may use SSE-2 instructions + +#elif defined(_TARGET_AMD64_) + + CORJIT_FLG_USE_SSE3_4 = 0x00000200, + CORJIT_FLG_USE_AVX = 0x00000400, + CORJIT_FLG_USE_AVX2 = 0x00000800, + CORJIT_FLG_USE_AVX_512 = 0x00001000, + CORJIT_FLG_FEATURE_SIMD = 0x00002000, + +#else // !defined(_TARGET_X86_) && !defined(_TARGET_AMD64_) + + CORJIT_FLG_UNUSED2 = 0x00000200, + CORJIT_FLG_UNUSED3 = 0x00000400, + CORJIT_FLG_UNUSED4 = 0x00000800, + CORJIT_FLG_UNUSED5 = 0x00001000, + CORJIT_FLG_UNUSED6 = 0x00002000, + +#endif // !defined(_TARGET_X86_) && !defined(_TARGET_AMD64_) + +#ifdef MDIL + CORJIT_FLG_MDIL = 0x00004000, // Generate MDIL code instead of machine code +#else // MDIL + CORJIT_FLG_UNUSED7 = 0x00004000, +#endif // MDIL + +#ifdef MDIL + // Safe to overlap with CORJIT_FLG_MAKEFINALCODE below. Not used by the JIT, used internally by NGen only. + CORJIT_FLG_MINIMAL_MDIL = 0x00008000, // Generate MDIL code suitable for use to bind other assemblies. + + // Safe to overlap with CORJIT_FLG_READYTORUN below. Not used by the JIT, used internally by NGen only. + CORJIT_FLG_NO_MDIL = 0x00010000, // Generate an MDIL section but no code or CTL. Not used by the JIT, used internally by NGen only. +#endif // MDIL + +#if defined(FEATURE_INTERPRETER) + CORJIT_FLG_MAKEFINALCODE = 0x00008000, // Use the final code generator, i.e., not the interpreter. +#endif // FEATURE_INTERPRETER + +#ifdef FEATURE_READYTORUN_COMPILER + CORJIT_FLG_READYTORUN = 0x00010000, // Use version-resilient code generation +#endif + + CORJIT_FLG_PROF_ENTERLEAVE = 0x00020000, // Instrument prologues/epilogues + CORJIT_FLG_PROF_REJIT_NOPS = 0x00040000, // Insert NOPs to ensure code is re-jitable + CORJIT_FLG_PROF_NO_PINVOKE_INLINE + = 0x00080000, // Disables PInvoke inlining + CORJIT_FLG_SKIP_VERIFICATION = 0x00100000, // (lazy) skip verification - determined without doing a full resolve. See comment below + CORJIT_FLG_PREJIT = 0x00200000, // jit or prejit is the execution engine. + CORJIT_FLG_RELOC = 0x00400000, // Generate relocatable code + CORJIT_FLG_IMPORT_ONLY = 0x00800000, // Only import the function + CORJIT_FLG_IL_STUB = 0x01000000, // method is an IL stub + CORJIT_FLG_PROCSPLIT = 0x02000000, // JIT should separate code into hot and cold sections + CORJIT_FLG_BBINSTR = 0x04000000, // Collect basic block profile information + CORJIT_FLG_BBOPT = 0x08000000, // Optimize method based on profile information + CORJIT_FLG_FRAMED = 0x10000000, // All methods have an EBP frame + CORJIT_FLG_ALIGN_LOOPS = 0x20000000, // add NOPs before loops to align them at 16 byte boundaries + CORJIT_FLG_PUBLISH_SECRET_PARAM= 0x40000000, // JIT must place stub secret param into local 0. (used by IL stubs) + CORJIT_FLG_GCPOLL_INLINE = 0x80000000, // JIT must inline calls to GCPoll when possible +}; + +enum CorJitFlag2 +{ +#ifdef FEATURE_STACK_SAMPLING + CORJIT_FLG2_SAMPLING_JIT_BACKGROUND + = 0x00000001, // JIT is being invoked as a result of stack sampling for hot methods in the background +#endif +}; + +/***************************************************************************** +Here is how CORJIT_FLG_SKIP_VERIFICATION should be interepreted. +Note that even if any method is inlined, it need not be verified. + +if (CORJIT_FLG_SKIP_VERIFICATION is passed in to ICorJitCompiler::compileMethod()) +{ + No verification needs to be done. + Just compile the method, generating unverifiable code if necessary +} +else +{ + switch(ICorMethodInfo::isInstantiationOfVerifiedGeneric()) + { + case INSTVER_NOT_INSTANTIATION: + + // + // Non-generic case, or open generic instantiation + // + + switch(canSkipMethodVerification()) + { + case CORINFO_VERIFICATION_CANNOT_SKIP: + { + ICorMethodInfo::initConstraintsForVerification(&circularConstraints) + if (circularConstraints) + { + Just emit code to call CORINFO_HELP_VERIFICATION + The IL will not be compiled + } + else + { + Verify the method. + if (unverifiable code is detected) + { + In place of branches with unverifiable code, emit code to call CORINFO_HELP_VERIFICATION + Mark the method (and any of its instantiations) as unverifiable + } + Compile the rest of the verifiable code + } + } + + case CORINFO_VERIFICATION_CAN_SKIP: + { + No verification needs to be done. + Just compile the method, generating unverifiable code if necessary + } + + case CORINFO_VERIFICATION_RUNTIME_CHECK: + { + ICorMethodInfo::initConstraintsForVerification(&circularConstraints) + if (circularConstraints) + { + Just emit code to call CORINFO_HELP_VERIFICATION + The IL will not be compiled + + TODO: This could be changed to call CORINFO_HELP_VERIFICATION_RUNTIME_CHECK + } + else + { + Verify the method. + if (unverifiable code is detected) + { + In the prolog, emit code to call CORINFO_HELP_VERIFICATION_RUNTIME_CHECK + Mark the method (and any of its instantiations) as unverifiable + } + Compile the method, generating unverifiable code if necessary + } + } + case CORINFO_VERIFICATION_DONT_JIT: + { + ICorMethodInfo::initConstraintsForVerification(&circularConstraints) + if (circularConstraints) + { + Just emit code to call CORINFO_HELP_VERIFICATION + The IL will not be compiled + } + else + { + Verify the method. + if (unverifiable code is detected) + { + Fail the jit + } + } + } + } + + case INSTVER_GENERIC_PASSED_VERIFICATION: + { + This cannot ever happen because the VM would pass in CORJIT_FLG_SKIP_VERIFICATION. + } + + case INSTVER_GENERIC_FAILED_VERIFICATION: + + switch(canSkipMethodVerification()) + { + case CORINFO_VERIFICATION_CANNOT_SKIP: + { + This cannot be supported because the compiler does not know which branches should call CORINFO_HELP_VERIFICATION. + The CLR will throw a VerificationException instead of trying to compile this method + } + + case CORINFO_VERIFICATION_CAN_SKIP: + { + This cannot ever happen because the CLR would pass in CORJIT_FLG_SKIP_VERIFICATION. + } + + case CORINFO_VERIFICATION_RUNTIME_CHECK: + { + No verification needs to be done. + In the prolog, emit code to call CORINFO_HELP_VERIFICATION_RUNTIME_CHECK + Compile the method, generating unverifiable code if necessary + } + case CORINFO_VERIFICATION_DONT_JIT: + { + Fail the jit + } + } + } +} + +*/ + +/*****************************************************************************/ +// These are flags passed to ICorJitInfo::allocMem +// to guide the memory allocation for the code, readonly data, and read-write data +enum CorJitAllocMemFlag +{ + CORJIT_ALLOCMEM_DEFAULT_CODE_ALIGN = 0x00000000, // The code will be use the normal alignment + CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN = 0x00000001, // The code will be 16-byte aligned +}; + +enum CorJitFuncKind +{ + CORJIT_FUNC_ROOT, // The main/root function (always id==0) + CORJIT_FUNC_HANDLER, // a funclet associated with an EH handler (finally, fault, catch, filter handler) + CORJIT_FUNC_FILTER // a funclet associated with an EH filter +}; + +#if !defined(FEATURE_USE_ASM_GC_WRITE_BARRIERS) && defined(FEATURE_COUNT_GC_WRITE_BARRIERS) +// We have a performance-investigation mode (defined by the FEATURE settings above) in which the +// JIT adds an argument of this enumeration to checked write barrier calls, to classify them. +enum CheckedWriteBarrierKinds { + CWBKind_Unclassified, // Not one of the ones below. + CWBKind_RetBuf, // Store through a return buffer pointer argument. + CWBKind_ByRefArg, // Store through a by-ref argument (not an implicit return buffer). + CWBKind_OtherByRefLocal, // Store through a by-ref local variable. + CWBKind_AddrOfLocal, // Store through the address of a local (arguably a bug that this happens at all). +}; +#endif + +class ICorJitCompiler; +class ICorJitInfo; + +struct IEEMemoryManager; + +extern "C" ICorJitCompiler* __stdcall getJit(); + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE +// +// #JITEEVersionIdentifier +// +// This GUID represents the version of the JIT/EE interface. Any time the interface between the JIT and +// the EE changes (by adding or removing methods to any interface shared between them), this GUID should +// be changed. This is the identifier verified by ICorJitCompiler::getVersionIdentifier(). +// +// You can use "uuidgen.exe -s" to generate this value. +// +// **** NOTE TO INTEGRATORS: +// +// If there is a merge conflict here, because the version changed in two different places, you must +// create a **NEW** GUID, not simply choose one or the other! +// +// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE +// +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#if !defined(SELECTANY) + #define SELECTANY extern __declspec(selectany) +#endif + +#if !defined(RYUJIT_CTPBUILD) + +// Update this one +SELECTANY const GUID JITEEVersionIdentifier = { /* 8e31af35-be80-4484-a91a-b096a08a49fe */ + 0x8e31af35, + 0xbe80, + 0x4484, + { 0xa9, 0x1a, 0xb0, 0x96, 0xa0, 0x8a, 0x49, 0xfe } + }; + +#else +// Leave this one alone +// We need it to build a .NET 4.5.1 compatible JIT for the RyuJIT CTP releases +SELECTANY const GUID JITEEVersionIdentifier = { /* 72d8f09d-1052-4466-94e9-d095b370bdae */ + 0x72d8f09d, + 0x1052, + 0x4466, + {0x94, 0xe9, 0xd0, 0x95, 0xb3, 0x70, 0xbd, 0xae} +}; +#endif + +// #EEToJitInterface +// ICorJitCompiler is the interface that the EE uses to get IL bytecode converted to native code. Note that +// to accomplish this the JIT has to call back to the EE to get symbolic information. The code:ICorJitInfo +// type passed as 'comp' to compileMethod is the mechanism to get this information. This is often the more +// interesting interface. +// +// +class ICorJitCompiler +{ +public: + // compileMethod is the main routine to ask the JIT Compiler to create native code for a method. The + // method to be compiled is passed in the 'info' parameter, and the code:ICorJitInfo is used to allow the + // JIT to resolve tokens, and make any other callbacks needed to create the code. nativeEntry, and + // nativeSizeOfCode are just for convenience because the JIT asks the EE for the memory to emit code into + // (see code:ICorJitInfo.allocMem), so really the EE already knows where the method starts and how big + // it is (in fact, it could be in more than one chunk). + // + // * In the 32 bit jit this is implemented by code:CILJit.compileMethod + // * For the 64 bit jit this is implemented by code:PreJit.compileMethod + // + // Note: Obfuscators that are hacking the JIT depend on this method having __stdcall calling convention + virtual CorJitResult __stdcall compileMethod ( + ICorJitInfo *comp, /* IN */ + struct CORINFO_METHOD_INFO *info, /* IN */ + unsigned /* code:CorJitFlag */ flags, /* IN */ + BYTE **nativeEntry, /* OUT */ + ULONG *nativeSizeOfCode /* OUT */ + ) = 0; + + // Some JIT compilers (most notably Phoenix), cache information about EE structures from one invocation + // of the compiler to the next. This can be a problem when appdomains are unloaded, as some of this + // cached information becomes stale. The code:ICorJitCompiler.isCacheCleanupRequired is called by the EE + // early first to see if jit needs these notifications, and if so, the EE will call ClearCache is called + // whenever the compiler should abandon its cache (eg on appdomain unload) + virtual void clearCache() = 0; + virtual BOOL isCacheCleanupRequired() = 0; + + // Do any appropriate work at process shutdown. Default impl is to do nothing. + virtual void ProcessShutdownWork(ICorStaticInfo* info) {}; + + // The EE asks the JIT for a "version identifier". This represents the version of the JIT/EE interface. + // If the JIT doesn't implement the same JIT/EE interface expected by the EE (because the JIT doesn't + // return the version identifier that the EE expects), then the EE fails to load the JIT. + // + virtual void getVersionIdentifier( + GUID* versionIdentifier /* OUT */ + ) = 0; + +#ifndef RYUJIT_CTPBUILD + // When the EE loads the System.Numerics.Vectors assembly, it asks the JIT what length (in bytes) of + // SIMD vector it supports as an intrinsic type. Zero means that the JIT does not support SIMD + // intrinsics, so the EE should use the default size (i.e. the size of the IL implementation). + virtual unsigned getMaxIntrinsicSIMDVectorLength(DWORD cpuCompileFlags) { return 0; } + + // IL obfuscators sometimes interpose on the EE-JIT interface. This function allows the VM to + // tell the JIT to use a particular ICorJitCompiler to implement the methods of this interface, + // and not to implement those methods itself. The JIT must not return this method when getJit() + // is called. Instead, it must pass along all calls to this interface from within its own + // ICorJitCompiler implementation. If 'realJitCompiler' is nullptr, then the JIT should resume + // executing all the functions itself. + virtual void setRealJit(ICorJitCompiler* realJitCompiler) { } +#endif // !RYUJIT_CTPBUILD + +}; + +//------------------------------------------------------------------------------------------ +// #JitToEEInterface +// +// ICorJitInfo is the main interface that the JIT uses to call back to the EE and get information. It is +// the companion to code:ICorJitCompiler#EEToJitInterface. The concrete implementation of this in the +// runtime is the code:CEEJitInfo type. There is also a version of this for the NGEN case. +// +// See code:ICorMethodInfo#EEJitContractDetails for subtle conventions used by this interface. +// +// There is more information on the JIT in the book of the runtime entry +// http://devdiv/sites/CLR/Product%20Documentation/2.0/BookOfTheRuntime/JIT/JIT%20Design.doc +// +class ICorJitInfo : public ICorDynamicInfo +{ +public: + // return memory manager that the JIT can use to allocate a regular memory + virtual IEEMemoryManager* getMemoryManager() = 0; + + // get a block of memory for the code, readonly data, and read-write data + virtual void allocMem ( + ULONG hotCodeSize, /* IN */ + ULONG coldCodeSize, /* IN */ + ULONG roDataSize, /* IN */ + ULONG xcptnsCount, /* IN */ + CorJitAllocMemFlag flag, /* IN */ + void ** hotCodeBlock, /* OUT */ + void ** coldCodeBlock, /* OUT */ + void ** roDataBlock /* OUT */ + ) = 0; + + // Reserve memory for the method/funclet's unwind information. + // Note that this must be called before allocMem. It should be + // called once for the main method, once for every funclet, and + // once for every block of cold code for which allocUnwindInfo + // will be called. + // + // This is necessary because jitted code must allocate all the + // memory needed for the unwindInfo at the allocMem call. + // For prejitted code we split up the unwinding information into + // separate sections .rdata and .pdata. + // + virtual void reserveUnwindInfo ( + BOOL isFunclet, /* IN */ + BOOL isColdCode, /* IN */ + ULONG unwindSize /* IN */ + ) = 0; + + // Allocate and initialize the .rdata and .pdata for this method or + // funclet, and get the block of memory needed for the machine-specific + // unwind information (the info for crawling the stack frame). + // Note that allocMem must be called first. + // + // Parameters: + // + // pHotCode main method code buffer, always filled in + // pColdCode cold code buffer, only filled in if this is cold code, + // null otherwise + // startOffset start of code block, relative to appropriate code buffer + // (e.g. pColdCode if cold, pHotCode if hot). + // endOffset end of code block, relative to appropriate code buffer + // unwindSize size of unwind info pointed to by pUnwindBlock + // pUnwindBlock pointer to unwind info + // funcKind type of funclet (main method code, handler, filter) + // + virtual void allocUnwindInfo ( + BYTE * pHotCode, /* IN */ + BYTE * pColdCode, /* IN */ + ULONG startOffset, /* IN */ + ULONG endOffset, /* IN */ + ULONG unwindSize, /* IN */ + BYTE * pUnwindBlock, /* IN */ + CorJitFuncKind funcKind /* IN */ + ) = 0; + + // Get a block of memory needed for the code manager information, + // (the info for enumerating the GC pointers while crawling the + // stack frame). + // Note that allocMem must be called first + virtual void * allocGCInfo ( + size_t size /* IN */ + ) = 0; + + virtual void yieldExecution() = 0; + + // Indicate how many exception handler blocks are to be returned. + // This is guaranteed to be called before any 'setEHinfo' call. + // Note that allocMem must be called before this method can be called. + virtual void setEHcount ( + unsigned cEH /* IN */ + ) = 0; + + // Set the values for one particular exception handler block. + // + // Handler regions should be lexically contiguous. + // This is because FinallyIsUnwinding() uses lexicality to + // determine if a "finally" clause is executing. + virtual void setEHinfo ( + unsigned EHnumber, /* IN */ + const CORINFO_EH_CLAUSE *clause /* IN */ + ) = 0; + + // Level -> fatalError, Level 2 -> Error, Level 3 -> Warning + // Level 4 means happens 10 times in a run, level 5 means 100, level 6 means 1000 ... + // returns non-zero if the logging succeeded + virtual BOOL logMsg(unsigned level, const char* fmt, va_list args) = 0; + + // do an assert. will return true if the code should retry (DebugBreak) + // returns false, if the assert should be igored. + virtual int doAssert(const char* szFile, int iLine, const char* szExpr) = 0; + + virtual void reportFatalError(CorJitResult result) = 0; + + struct ProfileBuffer // Also defined here: code:CORBBTPROF_BLOCK_DATA + { + ULONG ILOffset; + ULONG ExecutionCount; + }; + + // allocate a basic block profile buffer where execution counts will be stored + // for jitted basic blocks. + virtual HRESULT allocBBProfileBuffer ( + ULONG count, // The number of basic blocks that we have + ProfileBuffer ** profileBuffer + ) = 0; + + // get profile information to be used for optimizing the current method. The format + // of the buffer is the same as the format the JIT passes to allocBBProfileBuffer. + virtual HRESULT getBBProfileData( + CORINFO_METHOD_HANDLE ftnHnd, + ULONG * count, // The number of basic blocks that we have + ProfileBuffer ** profileBuffer, + ULONG * numRuns + ) = 0; + +#if !defined(RYUJIT_CTPBUILD) + // Associates a native call site, identified by its offset in the native code stream, with + // the signature information and method handle the JIT used to lay out the call site. If + // the call site has no signature information (e.g. a helper call) or has no method handle + // (e.g. a CALLI P/Invoke), then null should be passed instead. + virtual void recordCallSite( + ULONG instrOffset, /* IN */ + CORINFO_SIG_INFO * callSig, /* IN */ + CORINFO_METHOD_HANDLE methodHandle /* IN */ + ) = 0; +#endif // !defined(RYUJIT_CTPBUILD) + + // A relocation is recorded if we are pre-jitting. + // A jump thunk may be inserted if we are jitting + virtual void recordRelocation( + void * location, /* IN */ + void * target, /* IN */ + WORD fRelocType, /* IN */ + WORD slotNum = 0, /* IN */ + INT32 addlDelta = 0 /* IN */ + ) = 0; + + virtual WORD getRelocTypeHint(void * target) = 0; + + // A callback to identify the range of address known to point to + // compiler-generated native entry points that call back into + // MSIL. + virtual void getModuleNativeEntryPointRange( + void ** pStart, /* OUT */ + void ** pEnd /* OUT */ + ) = 0; + + // For what machine does the VM expect the JIT to generate code? The VM + // returns one of the IMAGE_FILE_MACHINE_* values. Note that if the VM + // is cross-compiling (such as the case for crossgen), it will return a + // different value than if it was compiling for the host architecture. + // + virtual DWORD getExpectedTargetArchitecture() = 0; +}; + +/**********************************************************************************/ +#endif // _COR_CORJIT_H_