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
19const 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//
27const unsigned byref_OFFSET_FLAG = 0x1; // the offset is an interior ptr
28const unsigned pinned_OFFSET_FLAG = 0x2; // the offset is a pinned ptr
29#if !defined(_TARGET_X86_) || !defined(WIN64EXCEPTIONS)
30const unsigned this_OFFSET_FLAG = 0x2; // the offset is "this"
31#endif
32
33//-----------------------------------------------------------------------------
34// The current GCInfo Version
35//-----------------------------------------------------------------------------
36
37#define GCINFO_VERSION 2
38
39#define MIN_GCINFO_VERSION_WITH_RETURN_KIND 2
40#define MIN_GCINFO_VERSION_WITH_REV_PINVOKE_FRAME 2
41
42inline BOOL GCInfoEncodesReturnKind(UINT32 version=GCINFO_VERSION)
43{
44 return version >= MIN_GCINFO_VERSION_WITH_RETURN_KIND;
45}
46
47inline BOOL GCInfoEncodesRevPInvokeFrame(UINT32 version=GCINFO_VERSION)
48{
49 return version >= MIN_GCINFO_VERSION_WITH_REV_PINVOKE_FRAME;
50}
51
52//-----------------------------------------------------------------------------
53// GCInfoToken: A wrapper that contains the GcInfo data and version number.
54//
55// The version# is not stored in the GcInfo structure -- because it is
56// wasteful to store the version once for every method.
57// Instead, the version# istracked per range-section of generated/loaded methods.
58//
59// The GCInfo version is computed as :
60// 1) The current GCINFO_VERSION for JITted and Ngened images
61// 2) A function of the Ready - to - run major version stored in READYTORUN_HEADER
62// for ready - to - run images.ReadyToRunJitManager::JitTokenToGCInfoVersion()
63// provides the GcInfo version for any Method.
64//-----------------------------------------------------------------------------
65
66struct GCInfoToken
67{
68 PTR_VOID Info;
69 UINT32 Version;
70
71 BOOL IsReturnKindAvailable()
72 {
73 return GCInfoEncodesReturnKind(Version);
74 }
75 BOOL IsReversePInvokeFrameAvailable()
76 {
77 return GCInfoEncodesRevPInvokeFrame(Version);
78 }
79
80 static UINT32 ReadyToRunVersionToGcInfoVersion(UINT32 readyToRunMajorVersion)
81 {
82 // GcInfo version is 1 up to ReadyTorun version 1.x
83 // GcInfo version is current from ReadyToRun version 2.0
84 return (readyToRunMajorVersion == 1) ? 1 : GCINFO_VERSION;
85 }
86};
87
88/*****************************************************************************/
89#endif //_GCINFO_H_
90/*****************************************************************************/
91