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