未验证 提交 de32c446 编写于 作者: N Nathan Ricci 提交者: GitHub

[MONO] Move marshal-ilgen into a component (#71203)

* Move marshal-ilgen into a component.
上级 fa75057c
......@@ -206,6 +206,13 @@
<PlatformManifestFileEntry Include="libmono-component-debugger-stub-static.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-debugger-static.lib" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-debugger-stub-static.lib" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen.dll" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen.so" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen.dylib" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-static.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-stub-static.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-static.lib" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-component-marshal-ilgen-stub-static.lib" IsNative="true" />
<!-- Mono WASM-specific files -->
<PlatformManifestFileEntry Include="libmono-ee-interp.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-icall-table.a" IsNative="true" />
......
......@@ -6,7 +6,7 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
</PropertyGroup>
<PropertyGroup>
<RuntimeComponents Condition="'$(TargetsAppleMobile)' == 'true' or '$(TargetOS)' == 'Android'">diagnostics_tracing</RuntimeComponents>
<RuntimeComponents Condition="'$(TargetsAppleMobile)' == 'true' or '$(TargetOS)' == 'Android'">diagnostics_tracing;marshal-ilgen</RuntimeComponents>
</PropertyGroup>
<!-- Windows only files -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
......
......@@ -733,7 +733,8 @@
<MonoAOTCMakeArgs Include="-DENABLE_ICALL_SYMBOL_MAP=1" />
<MonoAOTCMakeArgs Include="-DDISABLE_SHARED_LIBS=1" />
<MonoAOTCMakeArgs Include="-DDISABLE_LIBS=1" />
<MonoAOTCMakeArgs Include="-DDISABLE_COMPONENTS=1" />
<!-- Link in only the components neeeded for AOT compilation -->
<MonoAOTCMakeArgs Include="-DAOT_COMPONENTS=1 -DSTATIC_COMPONENTS=1;" />
<MonoAOTCMakeArgs Condition="'$(MonoAotOffsetsFile)' != ''" Include="-DAOT_OFFSETS_FILE=&quot;$(MonoAotOffsetsFile)&quot;" />
<MonoAOTCMakeArgs Condition="'$(MonoAOTEnableLLVM)' == 'true'" Include="-DLLVM_PREFIX=$(MonoAOTLLVMDir.TrimEnd('\/'))" />
<MonoAOTCMakeArgs Include="$(_MonoAOTCFLAGSOption)" />
......
......@@ -6,9 +6,12 @@ set(MONO_EVENTPIPE_GEN_INCLUDE_PATH "${CMAKE_CURRENT_BINARY_DIR}/eventpipe")
set(MONO_HOT_RELOAD_COMPONENT_NAME "hot_reload")
set(MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME "diagnostics_tracing")
set(MONO_DEBUGGER_COMPONENT_NAME "debugger")
set(MONO_MARSHAL_ILGEN_COMPONENT_NAME "marshal-ilgen")
# a list of every component.
set(components "")
# a list of components needed by the AOT compiler
set(components_for_aot "")
# the sources for each individiable component define a new
# component_name-sources list for each component, and a
......@@ -78,17 +81,53 @@ set(${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-dependencies
${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-gen-sources
)
# marshal-ilgen
list(APPEND components
${MONO_MARSHAL_ILGEN_COMPONENT_NAME}
)
list(APPEND components_for_aot
${MONO_MARSHAL_ILGEN_COMPONENT_NAME}
)
set(${MONO_MARSHAL_ILGEN_COMPONENT_NAME}-sources
${MONO_COMPONENT_PATH}/marshal-ilgen.c
${MONO_COMPONENT_PATH}/marshal-ilgen.h
${MONO_COMPONENT_PATH}/marshal-ilgen-noilgen.c
${MONO_COMPONENT_PATH}/marshal-ilgen-noilgen.h
)
# For every component not build into the AOT compiler, build the stub instead
set(stubs_for_aot "")
foreach (component IN LISTS components)
if (NOT (component IN_LIST components_for_aot))
list(APPEND stubs_for_aot "${component}")
endif()
endforeach()
set(${MONO_MARSHAL_ILGEN_COMPONENT_NAME}-stub-sources
${MONO_COMPONENT_PATH}/marshal-ilgen-stub.c
)
if (AOT_COMPONENTS)
set(components_to_build ${components_for_aot})
set(stubs_to_build ${stubs_for_aot})
else()
set(components_to_build ${components})
set(stubs_to_build ${components})
endif()
# from here down, all the components are treated in the same way
#define a library for each component and component stub
function(define_component_libs)
# NOTE: keep library naming pattern in sync with RuntimeComponentManifest.targets
if (NOT DISABLE_LIBS)
foreach(component IN LISTS components)
if (AOT_COMPONENTS OR NOT DISABLE_LIBS )
foreach(component IN LISTS components_to_build)
add_library("mono-component-${component}-static" STATIC $<TARGET_OBJECTS:${component}-objects>)
install(TARGETS "mono-component-${component}-static" LIBRARY)
endforeach()
foreach(component IN LISTS components)
foreach(component IN LISTS stubs_to_build)
add_library("mono-component-${component}-stub-static" STATIC $<TARGET_OBJECTS:${component}-stub-objects>)
install(TARGETS "mono-component-${component}-stub-static" LIBRARY)
endforeach()
......@@ -102,7 +141,7 @@ target_sources(component_base INTERFACE
)
target_link_libraries(component_base INTERFACE monoapi)
if(DISABLE_COMPONENTS OR DISABLE_LIBS)
if(NOT AOT_COMPONENTS AND (DISABLE_COMPONENTS OR DISABLE_LIBS))
set(DISABLE_COMPONENT_OBJECTS 1)
endif()
......@@ -122,7 +161,7 @@ endforeach()
if(NOT DISABLE_COMPONENTS AND NOT STATIC_COMPONENTS)
# define a shared library for each component
foreach(component IN LISTS components)
foreach(component IN LISTS components_to_build)
# NOTE: keep library naming pattern in sync with RuntimeComponentManifest.targets
if(HOST_WIN32)
add_library("mono-component-${component}" SHARED "${${component}-sources}")
......@@ -154,14 +193,14 @@ if(NOT DISABLE_COMPONENTS AND NOT STATIC_COMPONENTS)
#define a library for each component and component stub
define_component_libs()
elseif(NOT DISABLE_COMPONENTS AND STATIC_COMPONENTS)
elseif(AOT_COMPONENTS OR (NOT DISABLE_COMPONENTS AND STATIC_COMPONENTS))
#define a library for each component and component stub
define_component_libs()
# define a list of mono-components objects for mini if building a shared libmono with static-linked components
set(mono-components-objects "")
foreach(component IN LISTS components)
foreach(component IN LISTS components_to_build)
list(APPEND mono-components-objects $<TARGET_OBJECTS:${component}-objects>)
endforeach()
......
#include "mono/component/marshal-ilgen.h"
#include "mono/component/marshal-ilgen-noilgen.h"
#ifndef ENABLE_ILGEN
static int
emit_marshal_array_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
MonoType *object_type = mono_get_object_type ();
switch (action) {
case MARSHAL_ACTION_CONV_IN:
*conv_arg_type = object_type;
break;
case MARSHAL_ACTION_MANAGED_CONV_IN:
*conv_arg_type = int_type;
break;
}
return conv_arg;
}
static int
emit_marshal_ptr_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
return conv_arg;
}
#endif
#if !defined(ENABLE_ILGEN) || defined(DISABLE_NONBLITTABLE)
static int
emit_marshal_vtype_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
return conv_arg;
}
static int
emit_marshal_string_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
switch (action) {
case MARSHAL_ACTION_CONV_IN:
*conv_arg_type = int_type;
break;
case MARSHAL_ACTION_MANAGED_CONV_IN:
*conv_arg_type = int_type;
break;
}
return conv_arg;
}
static int
emit_marshal_safehandle_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN)
*conv_arg_type = int_type;
return conv_arg;
}
static int
emit_marshal_handleref_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN)
*conv_arg_type = int_type;
return conv_arg;
}
static int
emit_marshal_object_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN)
*conv_arg_type = int_type;
return conv_arg;
}
static int
emit_marshal_variant_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
g_assert_not_reached ();
}
static int
emit_marshal_asany_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
return conv_arg;
}
static int
emit_marshal_boolean_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
switch (action) {
case MARSHAL_ACTION_CONV_IN:
if (m_type_is_byref (t))
*conv_arg_type = int_type;
else
*conv_arg_type = mono_marshal_boolean_conv_in_get_local_type (spec, NULL);
break;
case MARSHAL_ACTION_MANAGED_CONV_IN: {
MonoClass* conv_arg_class = mono_marshal_boolean_managed_conv_in_get_conv_arg_class (spec, NULL);
if (m_type_is_byref (t))
*conv_arg_type = m_class_get_this_arg (conv_arg_class);
else
*conv_arg_type = m_class_get_byval_arg (conv_arg_class);
break;
}
}
return conv_arg;
}
static int
emit_marshal_char_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
return conv_arg;
}
static int
emit_marshal_custom_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN && t->type == MONO_TYPE_VALUETYPE)
*conv_arg_type = int_type;
return conv_arg;
}
#endif
#ifndef ENABLE_ILGEN
void
mono_marshal_noilgen_init_heavyweight (void)
{
MonoMarshalILgenCallbacks ilgen_cb;
ilgen_cb.version = MONO_MARSHAL_CALLBACKS_VERSION;
ilgen_cb.emit_marshal_array = emit_marshal_array_noilgen;
ilgen_cb.emit_marshal_vtype = emit_marshal_vtype_noilgen;
ilgen_cb.emit_marshal_string = emit_marshal_string_noilgen;
ilgen_cb.emit_marshal_safehandle = emit_marshal_safehandle_noilgen;
ilgen_cb.emit_marshal_handleref = emit_marshal_handleref_noilgen;
ilgen_cb.emit_marshal_object = emit_marshal_object_noilgen;
ilgen_cb.emit_marshal_variant = emit_marshal_variant_noilgen;
ilgen_cb.emit_marshal_asany = emit_marshal_asany_noilgen;
ilgen_cb.emit_marshal_boolean = emit_marshal_boolean_noilgen;
ilgen_cb.emit_marshal_custom = emit_marshal_custom_noilgen;
ilgen_cb.emit_marshal_ptr = emit_marshal_ptr_noilgen;
ilgen_cb.emit_marshal_char = emit_marshal_char_noilgen;
mono_install_marshal_callbacks_ilgen(&ilgen_cb);
}
#endif
\ No newline at end of file
/**
* \file
* Copyright 2022 Microsoft
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
#ifndef __MARSHAL_ILGEN_NOILGEN_H__
#define __MARSHAL_ILGEN_NOILGEN_H__
void mono_marshal_noilgen_init_heavyweight (void);
#endif // __MARSHAL_ILGEN_NOILGEN_H__
\ No newline at end of file
#include <mono/component/component.h>
#include <mono/component/marshal-ilgen.h>
#include <mono/metadata/marshal.h>
static bool
marshal_ilgen_available (void)
{
return false;
}
static int
stub_emit_marshal_ilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action, MonoMarshalLightweightCallbacks* lightweigth_cb)
{
return 0;
}
static void
mono_component_marshal_ilgen_stub_init(void)
{
}
static void
stub_mono_marshal_ilgen_install_callbacks_mono (IlgenCallbacksToMono *callbacks)
{
}
static MonoComponentMarshalILgen component_func_table = {
{ MONO_COMPONENT_ITF_VERSION, &marshal_ilgen_available },
mono_component_marshal_ilgen_stub_init,
stub_emit_marshal_ilgen,
stub_mono_marshal_ilgen_install_callbacks_mono
};
MonoComponentMarshalILgen*
mono_component_marshal_ilgen_init (void)
{
return &component_func_table;
}
/**
* \file
* Copyright 2022 Microsoft
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
#ifndef __MARSHAL_ILGEN_H__
#define __MARSHAL_ILGEN_H__
#include "metadata/marshal-lightweight.h"
#include "metadata/marshal.h"
#include "mono/component/component.h"
typedef struct MonoComponentMarshalILgen {
MonoComponent component;
void (*ilgen_init) (void);
int (*emit_marshal_ilgen) (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action, MonoMarshalLightweightCallbacks* lightweigth_cb);
void (*install_callbacks_mono) (IlgenCallbacksToMono *callbacks);
} MonoComponentMarshalILgen;
typedef struct {
int version;
......@@ -19,24 +34,23 @@ typedef struct {
int (*emit_marshal_custom) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
int (*emit_marshal_asany) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
int (*emit_marshal_handleref) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
} MonoMarshalIlgenCallbacks;
} MonoMarshalILgenCallbacks;
void
mono_install_marshal_callbacks_ilgen (MonoMarshalIlgenCallbacks *cb);
MONO_COMPONENT_EXPORT_ENTRYPOINT
MonoComponentMarshalILgen* mono_component_marshal_ilgen_init (void);
void
mono_install_marshal_callbacks_ilgen (MonoMarshalILgenCallbacks *cb);
MONO_API void
mono_marshal_ilgen_init (void);
void
mono_marshal_noilgen_init_heavyweight (void);
void
mono_marshal_noilgen_init_lightweight (void);
int
mono_emit_marshal_ilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action, MonoMarshalLightweightCallbacks* lightweigth_cb);
void
mono_marshal_ilgen_install_callbacks_mono (IlgenCallbacksToMono *callbacks);
#endif // __MARSHAL_ILGEN_H__
\ No newline at end of file
......@@ -16,8 +16,6 @@ set(ilgen_base_sources
method-builder-ilgen.c
method-builder-ilgen.h
method-builder-ilgen-internals.h
marshal-ilgen.c
marshal-ilgen.h
marshal-lightweight.c
marshal-lightweight.h
marshal-shared.c
......@@ -97,6 +95,7 @@ set(metadata_common_sources
marshal.h
marshal-internals.h
marshal-noilgen.c
marshal-noilgen.h
mempool.c
mempool.h
mempool-internals.h
......
......@@ -43,6 +43,9 @@ typedef struct _MonoComponentEntry {
#define DEBUGGER_LIBRARY_NAME "debugger"
#define DEBUGGER_COMPONENT_NAME DEBUGGER_LIBRARY_NAME
#define MARSHAL_ILGEN_LIBRARY_NAME "marshal-ilgen"
#define MARSHAL_ILGEN_COMPONENT_NAME "marshal_ilgen"
MonoComponentHotReload *mono_component_hot_reload_private_ptr = NULL;
MonoComponentDebugger *mono_component_debugger_private_ptr = NULL;
......@@ -50,6 +53,8 @@ MonoComponentDebugger *mono_component_debugger_private_ptr = NULL;
MonoComponentEventPipe *mono_component_event_pipe_private_ptr = NULL;
MonoComponentDiagnosticsServer *mono_component_diagnostics_server_private_ptr = NULL;
MonoComponentMarshalILgen* mono_component_marshal_ilgen_private_ptr = NULL;
// DiagnosticsServer/EventPipe components currently hosted by diagnostics_tracing library.
#define DIAGNOSTICS_TRACING_LIBRARY_NAME "diagnostics_tracing"
#define EVENT_PIPE_COMPONENT_NAME "event_pipe"
......@@ -61,6 +66,7 @@ MonoComponentEntry components[] = {
{ HOT_RELOAD_LIBRARY_NAME, HOT_RELOAD_COMPONENT_NAME, COMPONENT_INIT_FUNC (hot_reload), (MonoComponent**)&mono_component_hot_reload_private_ptr, NULL },
{ DIAGNOSTICS_TRACING_LIBRARY_NAME, EVENT_PIPE_COMPONENT_NAME, COMPONENT_INIT_FUNC (event_pipe), (MonoComponent**)&mono_component_event_pipe_private_ptr, NULL },
{ DIAGNOSTICS_TRACING_LIBRARY_NAME, DIAGNOSTICS_SERVER_COMPONENT_NAME, COMPONENT_INIT_FUNC (diagnostics_server), (MonoComponent**)&mono_component_diagnostics_server_private_ptr, NULL },
{ MARSHAL_ILGEN_LIBRARY_NAME, MARSHAL_ILGEN_COMPONENT_NAME, COMPONENT_INIT_FUNC (marshal_ilgen), (MonoComponent**)&mono_component_marshal_ilgen_private_ptr, NULL }
};
#ifndef STATIC_COMPONENTS
......
......@@ -8,6 +8,7 @@
#include <mono/component/component.h>
#include <mono/component/hot_reload.h>
#include <mono/component/event_pipe.h>
#include <mono/component/marshal-ilgen.h>
#include <mono/component/diagnostics_server.h>
#include <mono/component/debugger.h>
......@@ -24,6 +25,7 @@ extern MonoComponentHotReload *mono_component_hot_reload_private_ptr;
extern MonoComponentEventPipe *mono_component_event_pipe_private_ptr;
extern MonoComponentDiagnosticsServer *mono_component_diagnostics_server_private_ptr;
extern MonoComponentDebugger *mono_component_debugger_private_ptr;
extern MonoComponentMarshalILgen *mono_component_marshal_ilgen_private_ptr;
/* Declare each component's getter function here */
static inline
......@@ -54,4 +56,11 @@ mono_component_debugger (void)
return mono_component_debugger_private_ptr;
}
#endif/*_MONO_METADATA_COMPONENTS_H*/
static inline
MonoComponentMarshalILgen*
mono_component_marshal_ilgen (void)
{
return mono_component_marshal_ilgen_private_ptr;
}
#endif/*_MONO_METADATA_COMPONENTS_H*/
\ No newline at end of file
......@@ -8,14 +8,13 @@
#include <alloca.h>
#endif
#include "metadata/method-builder-ilgen.h"
#include "metadata/method-builder-ilgen-internals.h"
#include "mono/metadata/method-builder-ilgen.h"
#include "mono/metadata/method-builder-ilgen-internals.h"
#include <mono/metadata/object.h>
#include <mono/metadata/loader.h>
#include "cil-coff.h"
#include "metadata/marshal.h"
#include "metadata/marshal-internals.h"
#include "metadata/marshal-ilgen.h"
#include "metadata/marshal-lightweight.h"
#include "metadata/marshal-shared.h"
#include "metadata/tabledefs.h"
......@@ -24,6 +23,7 @@
#include "mono/metadata/abi-details.h"
#include "mono/metadata/class-abi-details.h"
#include "mono/metadata/class-init.h"
#include "mono/metadata/components.h"
#include "mono/metadata/debug-helpers.h"
#include "mono/metadata/threads.h"
#include "mono/metadata/monitor.h"
......
......@@ -5,6 +5,7 @@
*/
#ifndef __MONO_MARSHAL_LIGHTWEIGHT_H__
#define __MONO_MARSHAL_LIGHTWEIGHT_H__
#include <mono/utils/mono-publib.h>
MONO_API void
mono_marshal_lightweight_init (void);
......
#include "config.h"
#include <mono/metadata/attrdefs.h>
#include "metadata/marshal-internals.h"
#include "metadata/marshal.h"
#include "metadata/marshal-ilgen.h"
#include <mono/metadata/marshal-internals.h>
#include <mono/metadata/marshal.h>
#include <mono/metadata/marshal-noilgen.h>
#include "utils/mono-compiler.h"
#ifndef ENABLE_ILGEN
static int
emit_marshal_array_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
MonoType *object_type = mono_get_object_type ();
switch (action) {
case MARSHAL_ACTION_CONV_IN:
*conv_arg_type = object_type;
break;
case MARSHAL_ACTION_MANAGED_CONV_IN:
*conv_arg_type = int_type;
break;
}
return conv_arg;
}
static int
emit_marshal_ptr_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
return conv_arg;
}
static int
emit_marshal_scalar_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
......@@ -43,136 +18,6 @@ emit_marshal_scalar_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
}
#endif
#if !defined(ENABLE_ILGEN) || defined(DISABLE_NONBLITTABLE)
static int
emit_marshal_boolean_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
switch (action) {
case MARSHAL_ACTION_CONV_IN:
if (m_type_is_byref (t))
*conv_arg_type = int_type;
else
*conv_arg_type = mono_marshal_boolean_conv_in_get_local_type (spec, NULL);
break;
case MARSHAL_ACTION_MANAGED_CONV_IN: {
MonoClass* conv_arg_class = mono_marshal_boolean_managed_conv_in_get_conv_arg_class (spec, NULL);
if (m_type_is_byref (t))
*conv_arg_type = m_class_get_this_arg (conv_arg_class);
else
*conv_arg_type = m_class_get_byval_arg (conv_arg_class);
break;
}
}
return conv_arg;
}
static int
emit_marshal_char_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
return conv_arg;
}
static int
emit_marshal_custom_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN && t->type == MONO_TYPE_VALUETYPE)
*conv_arg_type = int_type;
return conv_arg;
}
static int
emit_marshal_asany_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
return conv_arg;
}
static int
emit_marshal_vtype_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
return conv_arg;
}
static int
emit_marshal_string_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
switch (action) {
case MARSHAL_ACTION_CONV_IN:
*conv_arg_type = int_type;
break;
case MARSHAL_ACTION_MANAGED_CONV_IN:
*conv_arg_type = int_type;
break;
}
return conv_arg;
}
static int
emit_marshal_safehandle_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN)
*conv_arg_type = int_type;
return conv_arg;
}
static int
emit_marshal_handleref_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec, int conv_arg,
MonoType **conv_arg_type, MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN)
*conv_arg_type = int_type;
return conv_arg;
}
static int
emit_marshal_object_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
MonoType *int_type = mono_get_int_type ();
if (action == MARSHAL_ACTION_CONV_IN)
*conv_arg_type = int_type;
return conv_arg;
}
static int
emit_marshal_variant_noilgen (EmitMarshalContext *m, int argnum, MonoType *t,
MonoMarshalSpec *spec,
int conv_arg, MonoType **conv_arg_type,
MarshalAction action)
{
g_assert_not_reached ();
}
#endif
#ifndef ENABLE_ILGEN
static void
emit_managed_wrapper_noilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, MonoGCHandle target_handle, MonoError *error)
......@@ -406,38 +251,13 @@ mono_marshal_noilgen_init_lightweight (void)
}
void
mono_marshal_noilgen_init_heavyweight (void)
{
MonoMarshalIlgenCallbacks ilgen_cb;
ilgen_cb.version = MONO_MARSHAL_CALLBACKS_VERSION;
ilgen_cb.emit_marshal_array = emit_marshal_array_noilgen;
ilgen_cb.emit_marshal_vtype = emit_marshal_vtype_noilgen;
ilgen_cb.emit_marshal_string = emit_marshal_string_noilgen;
ilgen_cb.emit_marshal_safehandle = emit_marshal_safehandle_noilgen;
ilgen_cb.emit_marshal_handleref = emit_marshal_handleref_noilgen;
ilgen_cb.emit_marshal_object = emit_marshal_object_noilgen;
ilgen_cb.emit_marshal_variant = emit_marshal_variant_noilgen;
ilgen_cb.emit_marshal_asany = emit_marshal_asany_noilgen;
ilgen_cb.emit_marshal_boolean = emit_marshal_boolean_noilgen;
ilgen_cb.emit_marshal_custom = emit_marshal_custom_noilgen;
ilgen_cb.emit_marshal_ptr = emit_marshal_ptr_noilgen;
ilgen_cb.emit_marshal_char = emit_marshal_char_noilgen;
mono_install_marshal_callbacks_ilgen(&ilgen_cb);
}
#else
void
mono_marshal_noilgen_init_lightweight (void)
{
}
void
mono_marshal_noilgen_init_heavyweight (void)
{
}
#endif
#ifdef DISABLE_NONBLITTABLE
......
/**
* \file
* Copyright 2022 Microsoft
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
#ifndef __MARSHAL_NOILGEN_H__
#define __MARSHAL_NOILGEN_H__
void
mono_marshal_noilgen_init_lightweight (void);
void
mono_marshal_noilgen_init_heavyweight (void);
#endif // __MARSHAL_NOILGEN_H__
\ No newline at end of file
......@@ -32,7 +32,7 @@ MONO_PRAGMA_WARNING_POP()
#include "cil-coff.h"
#include "metadata/marshal.h"
#include "metadata/marshal-internals.h"
#include "metadata/marshal-ilgen.h"
#include "metadata/marshal-shared.h"
#include "metadata/marshal-lightweight.h"
#include "metadata/method-builder.h"
#include "metadata/method-builder-internals.h"
......@@ -41,8 +41,10 @@ MONO_PRAGMA_WARNING_POP()
#include <mono/metadata/appdomain.h>
#include "mono/metadata/abi-details.h"
#include "mono/metadata/class-abi-details.h"
#include "mono/metadata/components.h"
#include "mono/metadata/debug-helpers.h"
#include "mono/metadata/threads.h"
#include "mono/metadata/marshal-noilgen.h"
#include "mono/metadata/monitor.h"
#include "mono/metadata/class-init.h"
#include "mono/metadata/class-internals.h"
......@@ -127,6 +129,66 @@ static GENERATE_TRY_GET_CLASS_WITH_CACHE (unmanaged_callconv_attribute, "System.
static gboolean type_is_blittable (MonoType *type);
static IlgenCallbacksToMono ilgenCallbacksToMono = {
&mono_get_object_type,
&mono_marshal_get_ptr_to_string_conv,
&mono_class_is_subclass_of_internal,
&mono_class_native_size,
&mono_class_try_get_handleref_class,
&mono_class_try_get_safehandle_class,
&mono_class_try_get_stringbuilder_class,
&mono_defaults,
&mono_marshal_boolean_conv_in_get_local_type,
&mono_marshal_boolean_managed_conv_in_get_conv_arg_class,
&mono_marshal_get_ptr_to_stringbuilder_conv,
&mono_marshal_get_string_encoding,
&mono_marshal_get_string_to_ptr_conv,
&mono_marshal_get_stringbuilder_to_ptr_conv,
&mono_marshal_load_type_info,
&mono_marshal_shared_conv_to_icall,
&mono_marshal_shared_emit_marshal_custom_get_instance,
&mono_marshal_shared_emit_struct_conv,
&mono_marshal_shared_emit_struct_conv_full,
&mono_marshal_shared_get_method_nofail,
&mono_marshal_shared_get_sh_dangerous_add_ref,
&mono_marshal_shared_get_sh_dangerous_release,
&mono_marshal_shared_init_safe_handle,
&mono_marshal_shared_is_in,
&mono_marshal_shared_is_out,
&mono_marshal_shared_mb_emit_exception_marshal_directive,
&mono_mb_add_local,
&mono_mb_emit_add_to_local,
&mono_mb_emit_auto_layout_exception,
&mono_mb_emit_branch,
&mono_mb_emit_branch_label,
&mono_mb_emit_byte,
&mono_mb_emit_exception,
&mono_mb_emit_exception_full,
&mono_mb_emit_icall_id,
&mono_mb_emit_icon,
&mono_mb_emit_ldarg,
&mono_mb_emit_ldarg_addr,
&mono_mb_emit_ldflda,
&mono_mb_emit_ldloc,
&mono_mb_emit_ldloc_addr,
&mono_mb_emit_managed_call,
&mono_mb_emit_op,
&mono_mb_emit_stloc,
&mono_mb_get_label,
&mono_mb_patch_branch,
&mono_pinvoke_is_unicode,
&mono_reflection_type_from_name_checked,
&mono_memory_barrier,
&mono_marshal_need_free,
&mono_get_int_type
};
IlgenCallbacksToMono*
mono_marshal_get_mono_callbacks_for_ilgen (void)
{
return &ilgenCallbacksToMono;
}
static MonoImage*
get_method_image (MonoMethod *method)
{
......@@ -3160,8 +3222,9 @@ mono_emit_marshal (EmitMarshalContext *m, int argnum, MonoType *t,
if (!m->runtime_marshalling_enabled)
return mono_emit_disabled_marshal (m, argnum, t, spec, conv_arg, conv_arg_type, action);
return mono_emit_marshal_ilgen(m, argnum, t, spec, conv_arg, conv_arg_type, action, get_marshal_cb());
}
mono_component_marshal_ilgen()->install_callbacks_mono(mono_marshal_get_mono_callbacks_for_ilgen());
return mono_component_marshal_ilgen()->emit_marshal_ilgen(m, argnum, t, spec, conv_arg, conv_arg_type, action, get_marshal_cb());
}
static void
mono_marshal_set_callconv_for_type(MonoType *type, MonoMethodSignature *csig, gboolean *skip_gc_trans /*out*/)
......@@ -6260,7 +6323,6 @@ get_marshal_cb (void)
mono_marshal_noilgen_init_lightweight ();
#endif
}
return &marshal_lightweight_cb;
}
......
......@@ -348,6 +348,60 @@ typedef struct {
int (*emit_marshal_scalar) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
} MonoMarshalLightweightCallbacks;
typedef struct {
MonoType* (*get_object_type) (void);
MonoMarshalConv (*get_ptr_to_string_conv) (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec, gboolean *need_free);
gboolean (*is_subclass_of_internal) (MonoClass *klass, MonoClass *klassc, gboolean check_interfaces);
gint32 (*class_native_size) (MonoClass *klass, guint32 *align);
MonoClass* (*class_try_get_handleref_class) (void);
MonoClass* (*try_get_safehandle_class) (void);
MonoClass* (*try_get_stringbuilder_class) (void);
MonoDefaults* mono_defaults;
MonoType* (*boolean_conv_in_get_local_type) (MonoMarshalSpec *spec, guint8 *ldc_op /*out*/);
MonoClass* (*boolean_managed_conv_in_get_conv_arg_class) (MonoMarshalSpec *spec, guint8 *ldop/*out*/);
MonoMarshalConv (*get_ptr_to_stringbuilder_conv) (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec, gboolean *need_free);
MonoMarshalNative (*get_string_encoding) (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
MonoMarshalConv (*get_string_to_ptr_conv) (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
MonoMarshalConv (*get_stringbuilder_to_ptr_conv) (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
MonoMarshalType* (*load_type_info) (MonoClass* klass);
MonoJitICallId (*conv_to_icall) (MonoMarshalConv conv, int *ind_store_type);
void (*emit_marshal_custom_get_instance) (MonoMethodBuilder *mb, MonoClass *klass, MonoMarshalSpec *spec);
void (*emit_struct_conv) (MonoMethodBuilder *mb, MonoClass *klass, gboolean to_object);
void (*emit_struct_conv_full) (MonoMethodBuilder *mb, MonoClass *klass, gboolean to_object, int offset_of_first_child_field, MonoMarshalNative string_encoding);
MonoMethod* (*get_method_nofail) (MonoClass *klass, const char *method_name, int num_params, int flags);
MonoMethod** (*get_sh_dangerous_add_ref) (void);
MonoMethod** (*get_sh_dangerous_release) (void);
void (*init_safe_handle) (void);
gboolean (*is_in) (const MonoType *t);
gboolean (*is_out) (const MonoType *t);
void (*mb_emit_exception_marshal_directive) (MonoMethodBuilder *mb, char *msg);
int (*mb_add_local) (MonoMethodBuilder *mb, MonoType *type);
void (*mb_emit_add_to_local) (MonoMethodBuilder *mb, guint16 local, gint32 incr);
void (*mb_emit_auto_layout_exception) (MonoMethodBuilder *mb, MonoClass *klass);
guint32 (*mb_emit_branch) (MonoMethodBuilder *mb, guint8 op);
void (*mb_emit_branch_label) (MonoMethodBuilder *mb, guint8 op, guint32 label);
void (*mb_emit_byte) (MonoMethodBuilder *mb, guint8 op);
void (*mb_emit_exception) (MonoMethodBuilder *mb, const char *exc_name, const char *msg);
void (*mb_emit_exception_full) (MonoMethodBuilder *mb, const char *exc_nspace, const char *exc_name, const char *msg);
void (*mb_emit_icall_id) (MonoMethodBuilder *mb, MonoJitICallId jit_icall_id);
void (*mb_emit_icon) (MonoMethodBuilder *mb, gint32 value);
void (*mb_emit_ldarg) (MonoMethodBuilder *mb, guint argnum);
void (*mb_emit_ldarg_addr) (MonoMethodBuilder *mb, guint argnum);
void (*mb_emit_ldflda) (MonoMethodBuilder *mb, gint32 offset);
void (*mb_emit_ldloc) (MonoMethodBuilder *mb, guint num);
void (*mb_emit_ldloc_addr) (MonoMethodBuilder *mb, guint argnum);
void (*mb_emit_managed_call) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *opt_sig);
void (*mb_emit_op) (MonoMethodBuilder *mb, guint8 op, gpointer data);
void (*mb_emit_stloc) (MonoMethodBuilder *mb, guint num);
int (*mb_get_label) (MonoMethodBuilder *mb);
void (*mb_patch_branch) (MonoMethodBuilder *mb, guint32 pos);
gboolean (*pinvoke_is_unicode) (MonoMethodPInvoke *piinfo);
MonoType* (*reflection_type_from_name_checked) (char *name, MonoAssemblyLoadContext *alc, MonoImage *image, MonoError *error);
void (*memory_barrier) (void);
gboolean (*need_free) (MonoType *t, MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
MonoType* (*get_int_type) (void);
} IlgenCallbacksToMono;
/*type of the function pointer of methods returned by mono_marshal_get_runtime_invoke*/
typedef MonoObject *(*RuntimeInvokeFunction) (MonoObject *this_obj, void **params, MonoObject **exc, void* compiled_method);
......@@ -702,4 +756,7 @@ mono_mb_create_and_cache_full (GHashTable *cache, gpointer key,
MonoMethodBuilder *mb, MonoMethodSignature *sig,
int max_stack, WrapperInfo *info, gboolean *out_found);
IlgenCallbacksToMono*
mono_marshal_get_mono_callbacks_for_ilgen (void);
#endif /* __MONO_MARSHAL_H__ */
......@@ -349,7 +349,7 @@ add_library(monosgen-static STATIC $<TARGET_OBJECTS:monosgen-objects>;$<TARGET_O
target_link_libraries (monosgen-static PRIVATE monoapi)
set_target_properties(monosgen-static PROPERTIES OUTPUT_NAME ${MONO_LIB_NAME})
if(DISABLE_COMPONENTS)
if(DISABLE_COMPONENTS OR AOT_COMPONENTS)
# add component fallback stubs into static mono library when components have been disabled.
target_sources(monosgen-static PRIVATE "${mono-components-stub-objects}")
endif()
......
......@@ -119,8 +119,13 @@
</ItemGroup>
</Target>
<Target Name="_AndroidGenerateAppBundle" DependsOnTargets="_AndroidGenerateRuntimeConfig">
<PropertyGroup>
<RuntimeComponents Condition="'$(RuntimeComponents)' == ''" >marshal-ilgen</RuntimeComponents>
</PropertyGroup>
<AndroidAppBuilderTask
RuntimeIdentifier="$(RuntimeIdentifier)"
ProjectName="$(AssemblyName)"
......
......@@ -109,9 +109,15 @@
</ItemGroup>
</Target>
<Target Name="_AppleGenerateAppBundle" DependsOnTargets="_AppleGenerateRuntimeConfig">
<!-- Run App bundler, it uses AOT libs (if needed), link all native bits, compile simple UI (written in ObjC)
and produce an app bundle (with xcode project) -->
<PropertyGroup>
<RuntimeComponents Condition="'$(RuntimeComponents)' == ''">marshal-ilgen</RuntimeComponents>
</PropertyGroup>
<AppleAppBuilderTask
TargetOS="$(TargetOS)"
Arch="$(TargetArchitecture)"
......
......@@ -67,6 +67,10 @@
<Output TaskParameter="CompiledAssemblies" ItemName="BundleAssemblies" />
</MonoAOTCompiler>
<PropertyGroup>
<RuntimeComponents Condition="'$(RuntimeComponents)' == ''">marshal-ilgen</RuntimeComponents>
</PropertyGroup>
<AppleAppBuilderTask
TargetOS="$(TargetOS)"
Arch="$(TargetArchitecture)"
......
......@@ -18,5 +18,6 @@
<!-- FIXME: This will exclude the diagnostics component if tracing is not on and threads are not on. Which means that if you turn on threading, you will get diagnostics. Is this what we want? -->
<_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-static.a" Condition="'$(FeatureWasmPerfTracing)' != 'true' and $(FeatureWasmThreads) != 'true'"/>
<_MonoRuntimeComponentDontLink Include="libmono-component-hot_reload-stub-static.a" />
<_MonoRuntimeComponentDontLink Include="libmono-component-marshal-ilgen-stub-static.a" />
</ItemGroup>
</Project>
......@@ -31,6 +31,9 @@
<ItemGroup Condition="'$(Configuration)' == 'Debug' and '@(_MonoComponent->Count())' == 0">
<_MonoComponent Include="hot_reload;debugger" />
</ItemGroup>
<ItemGroup>
<_MonoComponent Include="marshal-ilgen" />
</ItemGroup>
<Import Project="$(MSBuildThisFileDirectory)EmSdkRepo.Defaults.props" Condition="'$(WasmUseEMSDK_PATH)' == 'true'" />
......
......@@ -19,6 +19,7 @@ target_link_libraries(dotnet
${MONO_ARTIFACTS_DIR}/libmono-component-hot_reload-static.a
${MONO_ARTIFACTS_DIR}/libmono-component-debugger-static.a
${MONO_ARTIFACTS_DIR}/libmono-component-diagnostics_tracing-stub-static.a
${MONO_ARTIFACTS_DIR}/libmono-component-marshal-ilgen-static.a
${MONO_ARTIFACTS_DIR}/libmono-ee-interp.a
${MONO_ARTIFACTS_DIR}/libmonosgen-2.0.a
${MONO_ARTIFACTS_DIR}/libmono-ilgen.a
......
......@@ -185,7 +185,7 @@
<AppDir>$(BuildDir)\apk</AppDir>
<FinalApkPath>$(XUnitTestBinBase)$(CategoryWithSlash)\$(Category).apk</FinalApkPath>
<StripDebugSymbols>False</StripDebugSymbols>
<RuntimeComponents>diagnostics_tracing</RuntimeComponents>
<RuntimeComponents>diagnostics_tracing;marshal-ilgen</RuntimeComponents>
<DiagnosticPorts>127.0.0.1:9000,nosuspend,listen</DiagnosticPorts>
<StripDebugSymbols Condition="'$(Configuration)' == 'Release'">True</StripDebugSymbols>
<MicrosoftNetCoreAppRuntimePackDir>$(ArtifactsBinDir)microsoft.netcore.app.runtime.android-$(TargetArchitecture)\$(Configuration)\runtimes\android-$(TargetArchitecture)\</MicrosoftNetCoreAppRuntimePackDir>
......@@ -272,7 +272,7 @@
<XUnitWrapperDll>$(CMDDIR_GrandParent)/$(CategoryWithSlash)/$(XUnitWrapperFileName)</XUnitWrapperDll>
<BuildDir>$(IntermediateOutputPath)\iOSApps\$(Category)</BuildDir>
<FinalPath>$(XUnitTestBinBase)$(CategoryWithSlash)\$(Category).app</FinalPath>
<RuntimeComponents>diagnostics_tracing</RuntimeComponents>
<RuntimeComponents>diagnostics_tracing;marshal-ilgen</RuntimeComponents>
</PropertyGroup>
<PropertyGroup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册