-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathcoreclrhost.h
158 lines (141 loc) · 5.71 KB
/
coreclrhost.h
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// APIs for hosting CoreCLR
//
#ifndef __CORECLR_HOST_H__
#define __CORECLR_HOST_H__
#if defined(_WIN32) && defined(_M_IX86)
#define CORECLR_CALLING_CONVENTION __stdcall
#else
#define CORECLR_CALLING_CONVENTION
#endif
#include <stdint.h>
#ifdef __cplusplus
#define CORECLR_HOSTING_API_LINKAGE extern "C"
#else
#define CORECLR_HOSTING_API_LINKAGE
#endif
// For each hosting API, we define a function prototype and a function pointer
// The prototype is useful for implicit linking against the dynamic coreclr
// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
#define CORECLR_HOSTING_API(function, ...) \
CORECLR_HOSTING_API_LINKAGE int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \
typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__)
//
// Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain
//
// Parameters:
// exePath - Absolute path of the executable that invoked the ExecuteAssembly (the native host application)
// appDomainFriendlyName - Friendly name of the app domain that will be created to execute the assembly
// propertyCount - Number of properties (elements of the following two arguments)
// propertyKeys - Keys of properties of the app domain
// propertyValues - Values of properties of the app domain
// hostHandle - Output parameter, handle of the created host
// domainId - Output parameter, id of the created app domain
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_initialize,
const char* exePath,
const char* appDomainFriendlyName,
int propertyCount,
const char** propertyKeys,
const char** propertyValues,
void** hostHandle,
unsigned int* domainId);
//
// Type of the callback function that can be set by the coreclr_set_error_writer
//
typedef void (*coreclr_error_writer_callback_fn) (const char *message);
//
// Set callback for writing error logging
//
// Parameters:
// errorWriter - callback that will be called for each line of the error info
// - passing in NULL removes a callback that was previously set
//
// Returns:
// S_OK
//
CORECLR_HOSTING_API(coreclr_set_error_writer,
coreclr_error_writer_callback_fn errorWriter);
//
// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host.
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_shutdown,
void* hostHandle,
unsigned int domainId);
//
// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host.
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
// latchedExitCode - Latched exit code after domain unloaded
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_shutdown_2,
void* hostHandle,
unsigned int domainId,
int* latchedExitCode);
//
// Create a native callable function pointer for a managed method.
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
// entryPointAssemblyName - Name of the assembly which holds the custom entry point
// entryPointTypeName - Name of the type which holds the custom entry point
// entryPointMethodName - Name of the method which is the custom entry point
// delegate - Output parameter, the function stores a native callable function pointer to the delegate at the specified address
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_create_delegate,
void* hostHandle,
unsigned int domainId,
const char* entryPointAssemblyName,
const char* entryPointTypeName,
const char* entryPointMethodName,
void** delegate);
//
// Execute a managed assembly with given arguments
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
// argc - Number of arguments passed to the executed assembly
// argv - Array of arguments passed to the executed assembly
// managedAssemblyPath - Path of the managed assembly to execute (or NULL if using a custom entrypoint).
// exitCode - Exit code returned by the executed assembly
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_execute_assembly,
void* hostHandle,
unsigned int domainId,
int argc,
const char** argv,
const char* managedAssemblyPath,
unsigned int* exitCode);
#undef CORECLR_HOSTING_API
//
// Callback types used by the hosts
//
typedef bool(CORECLR_CALLING_CONVENTION ExternalAssemblyProbeFn)(const char* path, void** data_start, int64_t* size);
typedef bool(CORECLR_CALLING_CONVENTION BundleProbeFn)(const char* path, int64_t* offset, int64_t* size, int64_t* compressedSize);
typedef const void* (CORECLR_CALLING_CONVENTION PInvokeOverrideFn)(const char* libraryName, const char* entrypointName);
#endif // __CORECLR_HOST_H__