aboutsummaryrefslogtreecommitdiffstats
path: root/include/qdotnethostfxr.h
blob: dc57ce0a0b238ee518b664b20345bba5e5e6dcd9 (plain)
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
/***************************************************************************************************
 Copyright (C) 2023 The Qt Company Ltd.
 SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
***************************************************************************************************/

#pragma once

#ifdef __GNUC__
#   pragma GCC diagnostic push
#   pragma GCC diagnostic ignored "-Wconversion"
#endif
#include <QtGlobal>
#ifdef __GNUC__
#   pragma GCC diagnostic pop
#endif

#ifdef Q_OS_WINDOWS
#   define char_t char16_t
#   define STR(qstr) reinterpret_cast<const char_t*>(qstr.utf16())
#   define QSTR(str) QString::fromUtf16(str)
#else
#   define char_t char
#   define STR(qstr) reinterpret_cast<const char_t*>(qstr.toUtf8().constData())
#   define QSTR(str) QString(str)
#endif
#define FN_STR(t_fn) QString(#t_fn).chopped(3)
#define GET_FN(lib,t_fn) (t_fn)lib.resolve(FN_STR(t_fn).toLocal8Bit())


/*
    adapted from:
        https://github.com/dotnet/runtime/blob/main/src/native/corehost/error_codes.h
*/
enum StatusCode
{
    // Success
    Success = 0,
    Success_HostAlreadyInitialized = 0x00000001,
    Success_DifferentRuntimeProperties = 0x00000002,

    // Failure
    InvalidArgFailure = 0x80008081,
    CoreHostLibLoadFailure = 0x80008082,
    CoreHostLibMissingFailure = 0x80008083,
    CoreHostEntryPointFailure = 0x80008084,
    CoreHostCurHostFindFailure = 0x80008085,
    // unused = 0x80008086,
    CoreClrResolveFailure = 0x80008087,
    CoreClrBindFailure = 0x80008088,
    CoreClrInitFailure = 0x80008089,
    CoreClrExeFailure = 0x8000808a,
    ResolverInitFailure = 0x8000808b,
    ResolverResolveFailure = 0x8000808c,
    LibHostCurExeFindFailure = 0x8000808d,
    LibHostInitFailure = 0x8000808e,
    // unused = 0x8000808f,
    LibHostExecModeFailure = 0x80008090,
    LibHostSdkFindFailure = 0x80008091,
    LibHostInvalidArgs = 0x80008092,
    InvalidConfigFile = 0x80008093,
    AppArgNotRunnable = 0x80008094,
    AppHostExeNotBoundFailure = 0x80008095,
    FrameworkMissingFailure = 0x80008096,
    HostApiFailed = 0x80008097,
    HostApiBufferTooSmall = 0x80008098,
    LibHostUnknownCommand = 0x80008099,
    LibHostAppRootFindFailure = 0x8000809a,
    SdkResolverResolveFailure = 0x8000809b,
    FrameworkCompatFailure = 0x8000809c,
    FrameworkCompatRetry = 0x8000809d,
    AppHostExeNotBundle= 0x8000809e,
    BundleExtractionFailure = 0x8000809f,
    BundleExtractionIOError = 0x800080a0,
    LibHostDuplicateProperty = 0x800080a1,
    HostApiUnsupportedVersion = 0x800080a2,
    HostInvalidState = 0x800080a3,
    HostPropertyNotFound = 0x800080a4,
    CoreHostIncompatibleConfig = 0x800080a5,
    HostApiUnsupportedScenario = 0x800080a6,
    HostFeatureDisabled = 0x800080a7
};

#define HOSTFN_FAILED(status) ((static_cast<qint32>(static_cast<StatusCode>(status))) < 0)


/*
    adapted from:
        https://github.com/dotnet/runtime/blob/main/src/native/corehost/nethost/nethost.h
*/
#ifdef Q_OS_WINDOWS
#   define NETHOST_CALLTYPE __stdcall
#else
#   define NETHOST_CALLTYPE
#endif

struct get_hostfxr_parameters
{
    size_t size;
    const char_t *assembly_path;
    const char_t *dotnet_root;
};

using get_hostfxr_path_fn = quint32(NETHOST_CALLTYPE *)(
    char_t *buffer,
    size_t *buffer_size,
    const get_hostfxr_parameters *parameters);


/*
    adapted from:
        https://github.com/dotnet/runtime/blob/main/src/native/corehost/hostfxr.h
*/
#ifdef Q_OS_WINDOWS
#   define HOSTFXR_CALLTYPE __cdecl
#else
#   define HOSTFXR_CALLTYPE
#endif

using hostfxr_main_startupinfo_fn = int(HOSTFXR_CALLTYPE *)(
    const int argc,
    const char_t **argv,
    const char_t *host_path,
    const char_t *dotnet_root,
    const char_t *app_path);

enum hostfxr_delegate_type
{
    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
};

using hostfxr_error_writer_fn = void(HOSTFXR_CALLTYPE *)(const char_t *message);
//
using hostfxr_set_error_writer_fn = hostfxr_error_writer_fn(HOSTFXR_CALLTYPE *)(
    hostfxr_error_writer_fn error_writer);

using hostfxr_handle = void*;
struct hostfxr_initialize_parameters
{
    size_t size;
    const char_t *host_path;
    const char_t *dotnet_root;
};

using hostfxr_initialize_for_dotnet_command_line_fn = int(HOSTFXR_CALLTYPE *)(
    int argc,
    const char_t *argv[],
    const hostfxr_initialize_parameters *parameters,
    /*out*/ hostfxr_handle *host_context_handle
);

using hostfxr_initialize_for_runtime_config_fn = quint32(HOSTFXR_CALLTYPE *)(
    const char_t *runtime_config_path,
    const hostfxr_initialize_parameters *parameters,
    /*out*/ hostfxr_handle *host_context_handle);

using hostfxr_get_runtime_property_value_fn = quint32(HOSTFXR_CALLTYPE *)(
    hostfxr_handle host_context_handle,
    const char_t *name,
    /*out*/ const char_t **value);

using hostfxr_set_runtime_property_value_fn = quint32(HOSTFXR_CALLTYPE *)(
    hostfxr_handle host_context_handle,
    const char_t *name,
    const char_t *value);

using hostfxr_get_runtime_properties_fn = quint32(HOSTFXR_CALLTYPE *)(
    hostfxr_handle host_context_handle,
    /*inout*/ size_t *count,
    /*out*/ const char_t **keys,
    /*out*/ const char_t **values);

using hostfxr_run_app_fn = int (HOSTFXR_CALLTYPE *)(const hostfxr_handle host_context_handle);

using hostfxr_get_runtime_delegate_fn = quint32(HOSTFXR_CALLTYPE *)(
    hostfxr_handle host_context_handle,
    hostfxr_delegate_type type,
    /*out*/ void **delegate);

using hostfxr_close_fn = quint32(HOSTFXR_CALLTYPE *)(hostfxr_handle host_context_handle);

/*
    adapted from:
        https://github.com/dotnet/runtime/blob/main/src/native/corehost/coreclr_delegates.h
*/
#ifdef Q_OS_WINDOWS
#   define CORECLR_DELEGATE_CALLTYPE __stdcall
#else
#   define CORECLR_DELEGATE_CALLTYPE
#endif

using load_assembly_and_get_function_pointer_fn = quint32(CORECLR_DELEGATE_CALLTYPE *)(
    const char_t *assembly_path ,
    const char_t *type_name ,
    const char_t *method_name ,
    const char_t *delegate_type_name,
    nullptr_t reserved,
    /*out*/ void **delegate );

using get_function_pointer_fn = quint32(CORECLR_DELEGATE_CALLTYPE *)(
    const char_t *type_name,
    const char_t *method_name,
    const char_t *delegate_type_name,
    nullptr_t load_context,
    nullptr_t reserved,
    /*out*/ void **delegate);

using load_assembly_fn = int (CORECLR_DELEGATE_CALLTYPE *)(
    const char_t *assembly_path,
    nullptr_t load_context,
    nullptr_t reserved);

/*
    adapted from:
     https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.unmanagedtype
*/
enum class UnmanagedType
{
    Void = 0,
    ObjectRef = -1,
    Bool = 2,
    I1 = 3,
    U1 = 4,
    I2 = 5,
    U2 = 6,
    I4 = 7,
    U4 = 8,
    I8 = 9,
    U8 = 10,
    R4 = 11,
    R8 = 12,
    Currency = 15,
    BStr = 19,
    LPStr = 20,
    LPWStr = 21,
    LPTStr = 22,
    ByValTStr = 23,
    IUnknown = 25,
    IDispatch = 26,
    Struct = 27,
    Interface = 28,
    SafeArray = 29,
    ByValArray = 30,
    SysInt = 31,
    SysUInt = 32,
    VBByRefStr = 34,
    AnsiBStr = 35,
    TBStr = 36,
    VariantBool = 37,
    FunctionPtr = 38,
    AsAny = 40,
    LPArray = 42,
    LPStruct = 43,
    CustomMarshaler = 44,
    Error = 45,
    IInspectable = 46,
    HString = 47,
    LPUTF8Str = 48
};