Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/mono/thirdparty/hostfxr.h
10278 views
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
4
#ifndef __HOSTFXR_H__
5
#define __HOSTFXR_H__
6
7
#include <stddef.h>
8
#include <stdint.h>
9
10
#if defined(_WIN32)
11
#define HOSTFXR_CALLTYPE __cdecl
12
#ifdef _WCHAR_T_DEFINED
13
typedef wchar_t char_t;
14
#else
15
typedef unsigned short char_t;
16
#endif
17
#else
18
#define HOSTFXR_CALLTYPE
19
typedef char char_t;
20
#endif
21
22
enum hostfxr_delegate_type
23
{
24
hdt_com_activation,
25
hdt_load_in_memory_assembly,
26
hdt_winrt_activation,
27
hdt_com_register,
28
hdt_com_unregister,
29
hdt_load_assembly_and_get_function_pointer,
30
hdt_get_function_pointer,
31
};
32
33
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_main_fn)(const int argc, const char_t **argv);
34
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_main_startupinfo_fn)(
35
const int argc,
36
const char_t **argv,
37
const char_t *host_path,
38
const char_t *dotnet_root,
39
const char_t *app_path);
40
typedef int32_t(HOSTFXR_CALLTYPE* hostfxr_main_bundle_startupinfo_fn)(
41
const int argc,
42
const char_t** argv,
43
const char_t* host_path,
44
const char_t* dotnet_root,
45
const char_t* app_path,
46
int64_t bundle_header_offset);
47
48
typedef void(HOSTFXR_CALLTYPE *hostfxr_error_writer_fn)(const char_t *message);
49
50
//
51
// Sets a callback which is to be used to write errors to.
52
//
53
// Parameters:
54
// error_writer
55
// A callback function which will be invoked every time an error is to be reported.
56
// Or nullptr to unregister previously registered callback and return to the default behavior.
57
// Return value:
58
// The previously registered callback (which is now unregistered), or nullptr if no previous callback
59
// was registered
60
//
61
// The error writer is registered per-thread, so the registration is thread-local. On each thread
62
// only one callback can be registered. Subsequent registrations overwrite the previous ones.
63
//
64
// By default no callback is registered in which case the errors are written to stderr.
65
//
66
// Each call to the error writer is sort of like writing a single line (the EOL character is omitted).
67
// Multiple calls to the error writer may occur for one failure.
68
//
69
// If the hostfxr invokes functions in hostpolicy as part of its operation, the error writer
70
// will be propagated to hostpolicy for the duration of the call. This means that errors from
71
// both hostfxr and hostpolicy will be reporter through the same error writer.
72
//
73
typedef hostfxr_error_writer_fn(HOSTFXR_CALLTYPE *hostfxr_set_error_writer_fn)(hostfxr_error_writer_fn error_writer);
74
75
typedef void* hostfxr_handle;
76
struct hostfxr_initialize_parameters
77
{
78
size_t size;
79
const char_t *host_path;
80
const char_t *dotnet_root;
81
};
82
83
//
84
// Initializes the hosting components for a dotnet command line running an application
85
//
86
// Parameters:
87
// argc
88
// Number of argv arguments
89
// argv
90
// Command-line arguments for running an application (as if through the dotnet executable).
91
// Only command-line arguments which are accepted by runtime installation are supported, SDK/CLI commands are not supported.
92
// For example 'app.dll app_argument_1 app_argument_2`.
93
// parameters
94
// Optional. Additional parameters for initialization
95
// host_context_handle
96
// On success, this will be populated with an opaque value representing the initialized host context
97
//
98
// Return value:
99
// Success - Hosting components were successfully initialized
100
// HostInvalidState - Hosting components are already initialized
101
//
102
// This function parses the specified command-line arguments to determine the application to run. It will
103
// then find the corresponding .runtimeconfig.json and .deps.json with which to resolve frameworks and
104
// dependencies and prepare everything needed to load the runtime.
105
//
106
// This function only supports arguments for running an application. It does not support SDK commands.
107
//
108
// This function does not load the runtime.
109
//
110
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_initialize_for_dotnet_command_line_fn)(
111
int argc,
112
const char_t **argv,
113
const struct hostfxr_initialize_parameters *parameters,
114
/*out*/ hostfxr_handle *host_context_handle);
115
116
//
117
// Initializes the hosting components using a .runtimeconfig.json file
118
//
119
// Parameters:
120
// runtime_config_path
121
// Path to the .runtimeconfig.json file
122
// parameters
123
// Optional. Additional parameters for initialization
124
// host_context_handle
125
// On success, this will be populated with an opaque value representing the initialized host context
126
//
127
// Return value:
128
// Success - Hosting components were successfully initialized
129
// Success_HostAlreadyInitialized - Config is compatible with already initialized hosting components
130
// Success_DifferentRuntimeProperties - Config has runtime properties that differ from already initialized hosting components
131
// CoreHostIncompatibleConfig - Config is incompatible with already initialized hosting components
132
//
133
// This function will process the .runtimeconfig.json to resolve frameworks and prepare everything needed
134
// to load the runtime. It will only process the .deps.json from frameworks (not any app/component that
135
// may be next to the .runtimeconfig.json).
136
//
137
// This function does not load the runtime.
138
//
139
// If called when the runtime has already been loaded, this function will check if the specified runtime
140
// config is compatible with the existing runtime.
141
//
142
// Both Success_HostAlreadyInitialized and Success_DifferentRuntimeProperties codes are considered successful
143
// initializations. In the case of Success_DifferentRuntimeProperties, it is left to the consumer to verify that
144
// the difference in properties is acceptable.
145
//
146
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_initialize_for_runtime_config_fn)(
147
const char_t *runtime_config_path,
148
const struct hostfxr_initialize_parameters *parameters,
149
/*out*/ hostfxr_handle *host_context_handle);
150
151
//
152
// Gets the runtime property value for an initialized host context
153
//
154
// Parameters:
155
// host_context_handle
156
// Handle to the initialized host context
157
// name
158
// Runtime property name
159
// value
160
// Out parameter. Pointer to a buffer with the property value.
161
//
162
// Return value:
163
// The error code result.
164
//
165
// The buffer pointed to by value is owned by the host context. The lifetime of the buffer is only
166
// guaranteed until any of the below occur:
167
// - a 'run' method is called for the host context
168
// - properties are changed via hostfxr_set_runtime_property_value
169
// - the host context is closed via 'hostfxr_close'
170
//
171
// If host_context_handle is nullptr and an active host context exists, this function will get the
172
// property value for the active host context.
173
//
174
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_get_runtime_property_value_fn)(
175
const hostfxr_handle host_context_handle,
176
const char_t *name,
177
/*out*/ const char_t **value);
178
179
//
180
// Sets the value of a runtime property for an initialized host context
181
//
182
// Parameters:
183
// host_context_handle
184
// Handle to the initialized host context
185
// name
186
// Runtime property name
187
// value
188
// Value to set
189
//
190
// Return value:
191
// The error code result.
192
//
193
// Setting properties is only supported for the first host context, before the runtime has been loaded.
194
//
195
// If the property already exists in the host context, it will be overwritten. If value is nullptr, the
196
// property will be removed.
197
//
198
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_set_runtime_property_value_fn)(
199
const hostfxr_handle host_context_handle,
200
const char_t *name,
201
const char_t *value);
202
203
//
204
// Gets all the runtime properties for an initialized host context
205
//
206
// Parameters:
207
// host_context_handle
208
// Handle to the initialized host context
209
// count
210
// [in] Size of the keys and values buffers
211
// [out] Number of properties returned (size of keys/values buffers used). If the input value is too
212
// small or keys/values is nullptr, this is populated with the number of available properties
213
// keys
214
// Array of pointers to buffers with runtime property keys
215
// values
216
// Array of pointers to buffers with runtime property values
217
//
218
// Return value:
219
// The error code result.
220
//
221
// The buffers pointed to by keys and values are owned by the host context. The lifetime of the buffers is only
222
// guaranteed until any of the below occur:
223
// - a 'run' method is called for the host context
224
// - properties are changed via hostfxr_set_runtime_property_value
225
// - the host context is closed via 'hostfxr_close'
226
//
227
// If host_context_handle is nullptr and an active host context exists, this function will get the
228
// properties for the active host context.
229
//
230
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_get_runtime_properties_fn)(
231
const hostfxr_handle host_context_handle,
232
/*inout*/ size_t * count,
233
/*out*/ const char_t **keys,
234
/*out*/ const char_t **values);
235
236
//
237
// Load CoreCLR and run the application for an initialized host context
238
//
239
// Parameters:
240
// host_context_handle
241
// Handle to the initialized host context
242
//
243
// Return value:
244
// If the app was successfully run, the exit code of the application. Otherwise, the error code result.
245
//
246
// The host_context_handle must have been initialized using hostfxr_initialize_for_dotnet_command_line.
247
//
248
// This function will not return until the managed application exits.
249
//
250
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_run_app_fn)(const hostfxr_handle host_context_handle);
251
252
//
253
// Gets a typed delegate from the currently loaded CoreCLR or from a newly created one.
254
//
255
// Parameters:
256
// host_context_handle
257
// Handle to the initialized host context
258
// type
259
// Type of runtime delegate requested
260
// delegate
261
// An out parameter that will be assigned the delegate.
262
//
263
// Return value:
264
// The error code result.
265
//
266
// If the host_context_handle was initialized using hostfxr_initialize_for_runtime_config,
267
// then all delegate types are supported.
268
// If the host_context_handle was initialized using hostfxr_initialize_for_dotnet_command_line,
269
// then only the following delegate types are currently supported:
270
// hdt_load_assembly_and_get_function_pointer
271
// hdt_get_function_pointer
272
//
273
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_get_runtime_delegate_fn)(
274
const hostfxr_handle host_context_handle,
275
enum hostfxr_delegate_type type,
276
/*out*/ void **delegate);
277
278
//
279
// Closes an initialized host context
280
//
281
// Parameters:
282
// host_context_handle
283
// Handle to the initialized host context
284
//
285
// Return value:
286
// The error code result.
287
//
288
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_close_fn)(const hostfxr_handle host_context_handle);
289
290
struct hostfxr_dotnet_environment_sdk_info
291
{
292
size_t size;
293
const char_t* version;
294
const char_t* path;
295
};
296
297
typedef void(HOSTFXR_CALLTYPE* hostfxr_get_dotnet_environment_info_result_fn)(
298
const struct hostfxr_dotnet_environment_info* info,
299
void* result_context);
300
301
struct hostfxr_dotnet_environment_framework_info
302
{
303
size_t size;
304
const char_t* name;
305
const char_t* version;
306
const char_t* path;
307
};
308
309
struct hostfxr_dotnet_environment_info
310
{
311
size_t size;
312
313
const char_t* hostfxr_version;
314
const char_t* hostfxr_commit_hash;
315
316
size_t sdk_count;
317
const struct hostfxr_dotnet_environment_sdk_info* sdks;
318
319
size_t framework_count;
320
const struct hostfxr_dotnet_environment_framework_info* frameworks;
321
};
322
323
#endif //__HOSTFXR_H__
324
325