Merge pull request #7189 from pgavlin/x86-cmp-long
[platform/upstream/coreclr.git] / src / inc / gcinfo.h
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5
6 /*****************************************************************************/
7 #ifndef _GCINFO_H_
8 #define _GCINFO_H_
9 /*****************************************************************************/
10
11 #include "daccess.h"
12 #include "windef.h"     // For BYTE
13
14 // Some declarations in this file are used on non-x86 platforms, but most are x86-specific.
15
16 // Use the lower 2 bits of the offsets stored in the tables
17 // to encode properties
18
19 const unsigned        OFFSET_MASK  = 0x3;  // mask to access the low 2 bits
20
21 //
22 //  Note for untracked locals the flags allowed are "pinned" and "byref"
23 //   and for tracked locals the flags allowed are "this" and "byref"
24 //  Note that these definitions should also match the definitions of
25 //   GC_CALL_INTERIOR and GC_CALL_PINNED in VM/gc.h
26 //
27 const unsigned  byref_OFFSET_FLAG  = 0x1;  // the offset is an interior ptr
28 const unsigned pinned_OFFSET_FLAG  = 0x2;  // the offset is a pinned ptr
29 const unsigned   this_OFFSET_FLAG  = 0x2;  // the offset is "this"
30
31 //-----------------------------------------------------------------------------
32 // The current GCInfo Version
33 //-----------------------------------------------------------------------------
34
35 #if defined(_TARGET_X86_) && !defined(FEATURE_CORECLR)
36 // X86 GcInfo encoding is yet to be changed for Desktop JIT32.          
37 #define GCINFO_VERSION 1
38 #else
39 #define GCINFO_VERSION 2
40 #endif // _TARGET_X86_
41
42 #define MIN_GCINFO_VERSION_WITH_RETURN_KIND 2
43 #define MIN_GCINFO_VERSION_WITH_REV_PINVOKE_FRAME 2
44
45 inline BOOL GCInfoEncodesReturnKind(UINT32 version=GCINFO_VERSION)
46 {
47     return version >= MIN_GCINFO_VERSION_WITH_RETURN_KIND;
48 }
49
50 inline BOOL GCInfoEncodesRevPInvokeFrame(UINT32 version=GCINFO_VERSION)
51 {
52     return version >= MIN_GCINFO_VERSION_WITH_REV_PINVOKE_FRAME;
53 }
54
55 //-----------------------------------------------------------------------------
56 // GCInfoToken: A wrapper that contains the GcInfo data and version number.
57 //
58 // The version# is not stored in the GcInfo structure -- because it is
59 // wasteful to store the version once for every method.
60 // Instead, the version# istracked per range-section of generated/loaded methods.
61 //
62 // The GCInfo version is computed as :
63 // 1) The current GCINFO_VERSION for JITted and Ngened images
64 // 2) A function of the Ready - to - run major version stored in READYTORUN_HEADER
65 //   for ready - to - run images.ReadyToRunJitManager::JitTokenToGCInfoVersion()
66 //   provides the GcInfo version for any Method. 
67 //-----------------------------------------------------------------------------
68
69 struct GCInfoToken
70 {
71     PTR_VOID Info;
72     UINT32 Version;
73
74     BOOL IsReturnKindAvailable() 
75     {
76         return GCInfoEncodesReturnKind(Version);
77     }
78     BOOL IsReversePInvokeFrameAvailable() 
79     {
80         return GCInfoEncodesRevPInvokeFrame(Version);
81     }
82
83     static UINT32 ReadyToRunVersionToGcInfoVersion(UINT32 readyToRunMajorVersion)
84     {
85         // GcInfo version is 1 up to ReadyTorun version 1.x
86         // GcInfo version is current from  ReadyToRun version 2.0
87         return (readyToRunMajorVersion == 1) ? 1 : GCINFO_VERSION;
88     }
89 };
90
91 /*****************************************************************************/
92 #endif //_GCINFO_H_
93 /*****************************************************************************/