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// This file is the interface to NGen (*N*ative code *G*eneration),
6// which compiles IL modules to machine code ahead-of-time.
7// This avoids the need for JIT compiling the code at program startup.
8//
9
10
11#ifndef _NGEN_H_
12#define _NGEN_H_
13
14#include "mscorsvc.h"
15
16// Log size default of 10 MB.
17#define DEFAULT_SERVICE_LOG_SIZE (10 * 1024 * 1024)
18// NGEN.log is smaller 1MB
19#define DEFAULT_MACHINE_WIDE_LOG_SIZE (1 * 1024 * 1024)
20// User specific log is yet smaller 200KB
21#define DEFAULT_USER_WIDE_LOG_SIZE (200 * 1024)
22// Log size default of 100 KB. This should be big enough to hold some log info from roughly 100
23// ngen events. (Roughly 200KB of space including secondary log file.)
24#define DEFAULT_APPLOCAL_WIDE_LOG_SIZE (100*1024)
25
26#define NGEN_LOG_HEADER_TEXT W("To learn about increasing the verbosity of the NGen log files please see http://go.microsoft.com/fwlink/?linkid=210113\r\n")
27
28// supported debug info types
29enum DebugType
30{
31 DT_NIL,
32 DT_PDB
33};
34
35//
36// IMPORTANT * IMPORTANT * IMPORTANT * IMPORTANT * IMPORTANT * IMPORTANT
37//
38// This structure cannot have any fields removed from it!!!
39//
40// IMPORTANT * IMPORTANT * IMPORTANT * IMPORTANT * IMPORTANT * IMPORTANT
41//
42// NGening a module invokes the runtime against which the module was built.
43// Thus this structure needs to be backwards-compatible.
44//
45// If additional options need to be added to this structure,
46// add them to the end of the structure and make sure you update
47// logic throughout the runtime to look at a different size in the dwSize
48// field. This is how we'll 'version' this structure.
49//
50// If you are adding a code-generation flag (like debug or prof), use
51// fInstrument as a template (but be sure to add your new flag as the
52// last element in the struct).
53
54typedef struct _NGenOptions
55{
56 DWORD dwSize; // Size of the structure. Used to version the structure
57
58 // V1
59
60 bool fDebug; // Generate debuggable code and debug information
61 bool fDebugOpt; // Generate debugging information, but optimized code
62 bool fProf; // Generate instrumented code for profiling (call graphs)
63
64 bool fSilent; // Dont spew text output
65 LPCWSTR lpszExecutableFileName; // Name of the module to ngen
66
67 // V2 (Whidbey)
68
69 bool fInstrument; // Generate instrumented code for basic-block profiling
70
71 // No longer supported
72 bool fWholeProgram; // Do cross function optimizations (whole program)
73
74 // No longer supported
75 bool fProfInfo; // Embed working set profiling data into the image
76
77 LPCWSTR lpszRepositoryDir; // Directory for repository of native images
78 RepositoryFlags repositoryFlags;
79
80 // No longer supported
81 DebugType dtRequested; // the requested debug type
82 LPCWSTR lpszDebugDir; // the name of the output debug dir for the above
83
84 // No longer supported
85 bool fNoInstall; // Creates stand alone ngen-images that can be installed in the NIC later
86
87 // No longer supported
88 bool fEmitFixups; // Support for Vulcan
89 bool fFatHeaders;
90
91 // Diagnostic flags
92 bool fVerbose; // print verbose descriptions of native images
93 unsigned uStats; // image stats mask
94
95#define LAST_WHIDBEY_NGENOPTION uStats
96
97 // V4
98 bool fNgenLastRetry; // Ngen has previously failed and this is the last retry
99
100 // V4.5
101 bool fAutoNGen; // This is an automatically generated NGen request
102
103 // Blue
104 bool fRepositoryOnly;// Install from repository only, no real NGen
105
106} NGenOptions;
107
108// Function pointer types that we use to dynamically bind to the appropriate runtime version
109extern "C" typedef HRESULT STDAPICALLTYPE
110 NGenCreateZapperAPI(
111 HANDLE* hZapper,
112 NGenOptions *options);
113typedef NGenCreateZapperAPI *PNGenCreateZapper;
114
115extern "C" typedef HRESULT STDAPICALLTYPE
116 NGenTryEnumerateFusionCacheAPI(
117 HANDLE hZapper,
118 LPCWSTR assemblyName,
119 bool fPrint,
120 bool fDelete);
121typedef NGenTryEnumerateFusionCacheAPI *PNGenTryEnumerateFusionCache;
122
123// The return type should really be HRESULT.
124// However, it is BOOL for backwards-compatibility
125extern "C" typedef BOOL STDAPICALLTYPE
126 NGenCompileAPI(
127 HANDLE hZapper,
128 LPCWSTR path);
129typedef NGenCompileAPI *PNGenCompile;
130
131extern "C" typedef HRESULT STDAPICALLTYPE
132 NGenFreeZapperAPI(
133 HANDLE hZapper);
134typedef NGenFreeZapperAPI *PNGenFreeZapper;
135
136class ILocalServerLifetime
137{
138public:
139 virtual void AddRefServerProcess() = 0;
140 virtual void ReleaseServerProcess() = 0;
141};
142
143struct ICorSvcLogger;
144
145extern "C" typedef HRESULT STDAPICALLTYPE
146 NGenCreateNGenWorkerAPI(
147 ICorSvcWorker **pCorSvcWorker,
148 ILocalServerLifetime *pLocalServerLifetime,
149 ICorSvcLogger *pCorSvcLogger
150 );
151typedef NGenCreateNGenWorkerAPI *PNGenCreateNGenWorker;
152
153#endif
154