@@ -147,31 +147,6 @@ static void InitializeStartupFlags(STARTUP_FLAGS* startupFlagsRef)
147
147
*startupFlagsRef = startupFlags;
148
148
}
149
149
150
- #if defined(TARGET_ANDROID)
151
- static void ConvertConfigPropertiesToUnicode (
152
- const host_configuration_properties* properties,
153
- LPCWSTR** propertyKeysWRef,
154
- LPCWSTR** propertyValuesWRef)
155
- {
156
- LPCWSTR* propertyKeysW = new (nothrow) LPCWSTR[properties->nitems ];
157
- ASSERTE_ALL_BUILDS (propertyKeysW != nullptr );
158
-
159
- LPCWSTR* propertyValuesW = new (nothrow) LPCWSTR[properties->nitems ];
160
- ASSERTE_ALL_BUILDS (propertyValuesW != nullptr );
161
-
162
- for (size_t propertyIndex = 0 ; propertyIndex < properties->nitems ; ++propertyIndex)
163
- {
164
- host_configuration_property const & prop = properties->data [propertyIndex];
165
- propertyKeysW[propertyIndex] = prop.name ;
166
- propertyValuesW[propertyIndex] = prop.value ;
167
- }
168
-
169
- *propertyKeysWRef = propertyKeysW;
170
- *propertyValuesWRef = propertyValuesW;
171
- }
172
-
173
- #else // TARGET_ANDROID
174
-
175
150
static void ConvertConfigPropertiesToUnicode (
176
151
const char ** propertyKeys,
177
152
const char ** propertyValues,
@@ -230,7 +205,6 @@ static void ConvertConfigPropertiesToUnicode(
230
205
*propertyKeysWRef = propertyKeysW;
231
206
*propertyValuesWRef = propertyValuesW;
232
207
}
233
- #endif // !TARGET_ANDROID
234
208
coreclr_error_writer_callback_fn g_errorWriter = nullptr ;
235
209
236
210
//
@@ -256,103 +230,6 @@ GetInfoForMethodDelegate getInfoForMethodDelegate = NULL;
256
230
extern " C" int coreclr_create_delegate (void *, unsigned int , const char *, const char *, const char *, void **);
257
231
#endif // FEATURE_GDBJIT
258
232
259
- #if defined(TARGET_ANDROID)
260
- extern " C"
261
- NOINLINE
262
- DLLEXPORT
263
- int android_coreclr_initialize (
264
- const char * appName,
265
- const char16_t * appDomainFriendlyName,
266
- host_runtime_contract* hostContract,
267
- const host_configuration_properties* properties,
268
- void **hostHandle,
269
- unsigned int * domainId)
270
- {
271
- HostingApiFrameHolder apiFrameHolder (_ReturnAddress ());
272
-
273
- if (properties == nullptr ) { [[unlikely]]
274
- LogErrorToLogcat (ANDROID_LOG_FATAL, " Initialization routine was not passed the required configuration properties pointer." );
275
- return HOST_E_INVALIDOPERATION;
276
- }
277
-
278
- if (properties->data == nullptr ) { [[unlikely]]
279
- LogErrorToLogcat (ANDROID_LOG_FATAL, " Initialization routine was not passed valid configuration properties data." );
280
- return HOST_E_INVALIDOPERATION;
281
- }
282
-
283
- if (hostContract == nullptr ) { [[unlikely]]
284
- LogErrorToLogcat (ANDROID_LOG_FATAL, " Initialization routine was not passed the required host contract pointer." );
285
- return HOST_E_INVALIDOPERATION;
286
- }
287
-
288
- if (hostContract->pinvoke_override == nullptr ) { [[unlikely]]
289
- LogErrorToLogcat (ANDROID_LOG_FATAL, " Host contract isn't initialized properly: missing p/invoke override handler." );
290
- return HOST_E_INVALIDOPERATION;
291
- }
292
-
293
- if (hostContract->android_bundle_probe == nullptr ) { [[unlikely]]
294
- LogErrorToLogcat (ANDROID_LOG_FATAL, " Host contract isn't initialized properly: missing bundle probe handler." );
295
- return HOST_E_INVALIDOPERATION;
296
- }
297
-
298
- LPCWSTR* propertyKeysW = nullptr ;
299
- LPCWSTR* propertyValuesW = nullptr ;
300
- ConvertConfigPropertiesToUnicode (properties, &propertyKeysW, &propertyValuesW);
301
-
302
- // Android doesn't have executables as such (at least as far as Android applications are concerned),
303
- // so we will use application name (package name) as the "executable path" here.
304
- DWORD error = PAL_InitializeCoreCLR (appName, g_coreclr_embedded);
305
- HRESULT hr = HRESULT_FROM_WIN32 (error);
306
-
307
- // If PAL initialization failed, then we should return right away and avoid
308
- // calling any other APIs because they can end up calling into the PAL layer again.
309
- if (FAILED (hr))
310
- {
311
- return hr;
312
- }
313
-
314
- HostInformation::SetContract (hostContract);
315
- PInvokeOverride::SetPInvokeOverride (hostContract->pinvoke_override , PInvokeOverride::Source::RuntimeConfiguration);
316
-
317
- ReleaseHolder<ICLRRuntimeHost4> host;
318
- hr = CorHost2::CreateObject (IID_ICLRRuntimeHost4, (void **)&host);
319
- IfFailRet (hr);
320
-
321
- static Bundle bundle (appName, hostContract->android_bundle_probe );
322
- Bundle::AppBundle = &bundle;
323
-
324
- // This will take ownership of propertyKeysWTemp and propertyValuesWTemp
325
- Configuration::InitializeConfigurationKnobs (static_cast <int >(properties->nitems ), propertyKeysW, propertyValuesW);
326
-
327
- STARTUP_FLAGS startupFlags;
328
- InitializeStartupFlags (&startupFlags);
329
-
330
- hr = host->SetStartupFlags (startupFlags);
331
- IfFailRet (hr);
332
-
333
- hr = host->Start ();
334
- IfFailRet (hr);
335
-
336
- hr = host->CreateAppDomainWithManager (
337
- appDomainFriendlyName,
338
- APPDOMAIN_SECURITY_DEFAULT,
339
- nullptr , // Name of the assembly that contains the AppDomainManager implementation
340
- nullptr , // The AppDomainManager implementation type name
341
- static_cast <int >(properties->nitems ),
342
- propertyKeysW,
343
- propertyValuesW,
344
- (DWORD *)domainId);
345
-
346
- if (SUCCEEDED (hr))
347
- {
348
- host.SuppressRelease ();
349
- *hostHandle = host;
350
- }
351
- return hr;
352
- }
353
-
354
- #endif // TARGET_ANDROID
355
-
356
233
//
357
234
// Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain
358
235
//
@@ -372,6 +249,9 @@ extern "C"
372
249
NOINLINE
373
250
DLLEXPORT
374
251
int coreclr_initialize (
252
+ #if defined(TARGET_ANDROID)
253
+ host_runtime_contract* contract,
254
+ #endif
375
255
const char * exePath,
376
256
const char * appDomainFriendlyName,
377
257
int propertyCount,
@@ -380,14 +260,13 @@ int coreclr_initialize(
380
260
void ** hostHandle,
381
261
unsigned int * domainId)
382
262
{
383
- #if !defined(TARGET_ANDROID)
384
263
HRESULT hr;
385
264
386
265
LPCWSTR* propertyKeysW;
387
266
LPCWSTR* propertyValuesW;
388
267
BundleProbeFn* bundleProbe = nullptr ;
389
268
PInvokeOverrideFn* pinvokeOverride = nullptr ;
390
- host_runtime_contract* hostContract = nullptr ;
269
+ host_runtime_contract* hostContract = contract ;
391
270
392
271
#ifdef TARGET_UNIX
393
272
HostingApiFrameHolder apiFrameHolder (_ReturnAddress ());
@@ -432,9 +311,10 @@ int coreclr_initialize(
432
311
433
312
ConstWStringHolder appDomainFriendlyNameW = StringToUnicode (appDomainFriendlyName);
434
313
435
- if (bundleProbe != nullptr )
314
+ ExternalAssemblyProbeFn* externalAssemblyProbe = contract != nullptr ? contract->external_assembly_probe : nullptr ;
315
+ if (bundleProbe != nullptr || externalAssemblyProbe != nullptr )
436
316
{
437
- static Bundle bundle (exePath, bundleProbe);
317
+ static Bundle bundle (exePath, bundleProbe, externalAssemblyProbe );
438
318
Bundle::AppBundle = &bundle;
439
319
}
440
320
@@ -485,9 +365,6 @@ int coreclr_initialize(
485
365
#endif
486
366
}
487
367
return hr;
488
- #else // TARGET_ANDROID
489
- return HOST_E_INVALIDOPERATION;
490
- #endif
491
368
}
492
369
493
370
//
0 commit comments