171 строка
4.0 KiB
Objective-C
171 строка
4.0 KiB
Objective-C
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
/*
|
|
* Authors: Rolf Bjarne Kvinge
|
|
*
|
|
* Copyright (C) 2021 Microsoft Corp.
|
|
*
|
|
*/
|
|
|
|
#if defined (CORECLR_RUNTIME)
|
|
|
|
#include "product.h"
|
|
#include "xamarin/xamarin.h"
|
|
#include "xamarin/coreclr-bridge.h"
|
|
|
|
#include "coreclrhost.h"
|
|
|
|
unsigned int coreclr_domainId = 0;
|
|
void *coreclr_handle = NULL;
|
|
|
|
void
|
|
xamarin_bridge_setup ()
|
|
{
|
|
}
|
|
|
|
void
|
|
xamarin_bridge_initialize ()
|
|
{
|
|
}
|
|
|
|
bool
|
|
xamarin_bridge_vm_initialize (int propertyCount, const char **propertyKeys, const char **propertyValues)
|
|
{
|
|
int rv;
|
|
|
|
const char *executablePath = [[[[NSBundle mainBundle] executableURL] path] UTF8String];
|
|
rv = coreclr_initialize (
|
|
executablePath,
|
|
xamarin_executable_name,
|
|
propertyCount,
|
|
propertyKeys,
|
|
propertyValues,
|
|
&coreclr_handle,
|
|
&coreclr_domainId
|
|
);
|
|
|
|
LOG_CORECLR (stderr, "xamarin_vm_initialize (%i, %p, %p): rv: %i domainId: %i handle: %p\n", propertyCount, propertyKeys, propertyValues, rv, coreclr_domainId, coreclr_handle);
|
|
|
|
return rv == 0;
|
|
}
|
|
|
|
void
|
|
xamarin_handle_bridge_exception (GCHandle gchandle, const char *method)
|
|
{
|
|
if (gchandle == INVALID_GCHANDLE)
|
|
return;
|
|
|
|
if (method == NULL)
|
|
method = "<unknown method";
|
|
|
|
fprintf (stderr, "%s threw an exception: %p\n", method, gchandle);
|
|
xamarin_assertion_message ("%s threw an exception: %p", method, gchandle);
|
|
}
|
|
|
|
typedef void (*xamarin_runtime_initialize_decl)(struct InitializationOptions* options);
|
|
void
|
|
xamarin_bridge_call_runtime_initialize (struct InitializationOptions* options, GCHandle* exception_gchandle)
|
|
{
|
|
void *del = NULL;
|
|
int rv = coreclr_create_delegate (coreclr_handle, coreclr_domainId, PRODUCT ", Version=0.0.0.0", "ObjCRuntime.Runtime", "Initialize", &del);
|
|
if (rv != 0)
|
|
xamarin_assertion_message ("xamarin_bridge_call_runtime_initialize: failed to create delegate: %i\n", rv);
|
|
|
|
xamarin_runtime_initialize_decl runtime_initialize = (xamarin_runtime_initialize_decl) del;
|
|
runtime_initialize (options);
|
|
}
|
|
|
|
void
|
|
xamarin_bridge_register_product_assembly (GCHandle* exception_gchandle)
|
|
{
|
|
MonoAssembly *assembly;
|
|
assembly = xamarin_open_and_register (PRODUCT_DUAL_ASSEMBLY, exception_gchandle);
|
|
xamarin_mono_object_release (&assembly);
|
|
}
|
|
|
|
MonoClass *
|
|
xamarin_get_nsnumber_class ()
|
|
{
|
|
xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__);
|
|
}
|
|
|
|
MonoClass *
|
|
xamarin_get_nsvalue_class ()
|
|
{
|
|
xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__);
|
|
}
|
|
|
|
MonoClass *
|
|
xamarin_get_inativeobject_class ()
|
|
{
|
|
xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__);
|
|
}
|
|
|
|
MonoClass *
|
|
xamarin_get_nsobject_class ()
|
|
{
|
|
xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__);
|
|
}
|
|
|
|
MonoClass *
|
|
xamarin_get_nsstring_class ()
|
|
{
|
|
xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__);
|
|
}
|
|
|
|
MonoClass *
|
|
xamarin_get_runtime_class ()
|
|
{
|
|
xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__);
|
|
}
|
|
|
|
void
|
|
xamarin_mono_object_retain (MonoObject *mobj)
|
|
{
|
|
atomic_fetch_add (&mobj->reference_count, 1);
|
|
}
|
|
|
|
void
|
|
xamarin_mono_object_release (MonoObject **mobj_ref)
|
|
{
|
|
MonoObject *mobj = *mobj_ref;
|
|
|
|
if (mobj == NULL)
|
|
return;
|
|
|
|
int rc = atomic_fetch_sub (&mobj->reference_count, 1) - 1;
|
|
if (rc == 0) {
|
|
if (mobj->gchandle != INVALID_GCHANDLE) {
|
|
xamarin_gchandle_free (mobj->gchandle);
|
|
mobj->gchandle = INVALID_GCHANDLE;
|
|
}
|
|
|
|
xamarin_free (mobj); // allocated using Marshal.AllocHGlobal.
|
|
}
|
|
|
|
*mobj_ref = NULL;
|
|
}
|
|
|
|
/* Implementation of the Mono Embedding API */
|
|
|
|
// returns a retained MonoAssembly *
|
|
MonoAssembly *
|
|
mono_assembly_open (const char * filename, MonoImageOpenStatus * status)
|
|
{
|
|
assert (status == NULL);
|
|
|
|
MonoAssembly *rv = xamarin_find_assembly (filename);
|
|
|
|
LOG_CORECLR (stderr, "mono_assembly_open (%s, %p) => MonoObject=%p GCHandle=%p\n", filename, status, rv, rv->gchandle);
|
|
|
|
return rv;
|
|
}
|
|
|
|
MonoDomain *
|
|
mono_domain_get (void)
|
|
{
|
|
// This is not needed for CoreCLR.
|
|
return NULL;
|
|
}
|
|
|
|
#endif // CORECLR_RUNTIME
|