Skip to content

Commit

Permalink
Mono runtime: Add support for mixed-mode assemblies. Contributed unde…
Browse files Browse the repository at this point in the history
…r MIT/X11 license.

svn path=/trunk/mono/; revision=102052
  • Loading branch information
kornelpal committed Apr 28, 2008
1 parent 5c865e3 commit b06a638
Show file tree
Hide file tree
Showing 28 changed files with 1,036 additions and 83 deletions.
7 changes: 7 additions & 0 deletions libgc/ChangeLog
@@ -1,3 +1,10 @@
2008-04-28 Kornél Pál <kornelpal@gmail.com>

* include/gc.h: Add GC_DllMain.
* win32_threads.c: Rename DllMain to GC_DllMain.

Contributed under MIT/X11 license.

2008-04-15 Jonathan Chambers <joncham@gmail.com>
* include/private/gcconfig.h: Backport GC7 code to support Win64.
* win32_threads.c: Backport GC7 code to support Win64.
Expand Down
2 changes: 2 additions & 0 deletions libgc/include/gc.h
Expand Up @@ -922,6 +922,8 @@ extern void GC_thr_init(void); /* Needed for Solaris/X86 */
#if defined(GC_WIN32_THREADS) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
# include <windows.h>

BOOL WINAPI GC_DllMain(HINSTANCE inst, ULONG reason, LPVOID reserved);

/*
* All threads must be created using GC_CreateThread, so that they will be
* recorded in the thread table. For backwards compatibility, this is not
Expand Down
2 changes: 1 addition & 1 deletion libgc/win32_threads.c
Expand Up @@ -782,7 +782,7 @@ int GC_pthread_detach(pthread_t thread)
* Pontus Rydin suggests wrapping the thread start routine instead.
*/
#if defined(GC_DLL) || defined(GC_INSIDE_DLL)
BOOL WINAPI DllMain(HINSTANCE inst, ULONG reason, LPVOID reserved)
BOOL WINAPI GC_DllMain(HINSTANCE inst, ULONG reason, LPVOID reserved)
{
switch (reason) {
case DLL_PROCESS_ATTACH:
Expand Down
49 changes: 49 additions & 0 deletions mono/metadata/ChangeLog
@@ -1,3 +1,52 @@
2008-04-28 Kornél Pál <kornelpal@gmail.com>

* loader.c (mono_get_method_from_token, mono_method_signature): Add
support for METHOD_IMPL_ATTRIBUTE_NATIVE.
* domain.c (mono_init_internal): Load and fixup mscoree.dll on startup and
fixup main EXE images when using mono.exe for mixed-mode assembly support.
* domain-internals.h: Add MonoLoadFunc, mono_install_runtime_load and
mono_runtime_load.
* appdomain.c: Add mono_install_runtime_load, mono_runtime_load to support
runtime initialization from metadata.
* assembly.c: Remove obsolete ceGetModuleFileNameA.
(mono_set_rootdir): Use mono_get_module_file_name.
(mono_assembly_load_from_full): Call mono_image_fixup_vtable for module
handles.
* cil-coff.h: Add MonoVTableFixup. Update mono_cli_rva_image_map signature.
* metadata-internals.h: Add is_module_handle to _MonoImage on Windows.
* image.c (mono_cli_rva_image_map): Use MonoImage instead of
MonoCLIImageInfo. Add support for module handles.
(load_cli_header): Update mono_cli_rva_image_map signature.
(load_metadata_ptrs): Update mono_cli_rva_image_map signature.
(mono_image_strong_name_position): Use mono_cli_rva_image_map.
(mono_image_rva_map): Add support for module handles.
(mono_image_ensure_section_idx): Add support for module handles.
(mono_image_close): Add support for module handles.
(do_load_header): Add support for module handles.
(mono_image_open_from_module_handle): New function for internal use.
(mono_image_open_full): Load normal images using LoadLibrary on Windows.
(mono_image_load_module): Call mono_image_fixup_vtable for module handles.
(mono_image_load_file_for_image): Call mono_image_fixup_vtable for module
handles.
(mono_image_fixup_vtable): New function for mixed-mode assembly support.
* image.h: Add mono_image_fixup_vtable.
* coree.c: New file for mscoree.dll functions and mixed-mode assembly
support.
* coree.h: New file.
* marshal.c (mono_marshal_get_native_wrapper): Throw exception for
unsupported native code.
(mono_marshal_set_callconv_from_modopt): New function splitted from
mono_marshal_get_managed_wrapper.
(mono_marshal_get_managed_wrapper): Use
mono_marshal_set_callconv_from_modopt.
(mono_marshal_get_vtfixup_ftnptr): New function for mixed-mode assembly support.
* marshal.h: Add mono_marshal_get_vtfixup_ftnptr.
* gc.c (mono_gc_init): Don't wait for the finalizer thread on Windows because
that results in a deadlock when the runtime is loaded in _CorDllMain.
* Makefile.am: Add coree.c and coree.h.

Contributed under MIT/X11 license.

2008-04-28 Mark Probst <mark.probst@gmail.com>

* generic-sharing.c: Search for type arguments in array element
Expand Down
2 changes: 2 additions & 0 deletions mono/metadata/Makefile.am
Expand Up @@ -108,6 +108,8 @@ libmonoruntime_la_SOURCES = \
console-io.c \
console-io.h \
assembly.c \
coree.c \
coree.h \
domain.c \
domain-internals.h \
opcodes.c \
Expand Down
15 changes: 15 additions & 0 deletions mono/metadata/appdomain.c
Expand Up @@ -96,6 +96,21 @@ add_assemblies_to_domain (MonoDomain *domain, MonoAssembly *ass, GHashTable *has
static void
mono_domain_unload (MonoDomain *domain);

static MonoLoadFunc load_function = NULL;

void
mono_install_runtime_load (MonoLoadFunc func)
{
load_function = func;
}

MonoDomain*
mono_runtime_load (const char *filename, const char *runtime_version)
{
g_assert (load_function);
return load_function (filename, runtime_version);
}

/**
* mono_runtime_init:
* @domain: domain returned by mono_init ()
Expand Down
33 changes: 9 additions & 24 deletions mono/metadata/assembly.c
Expand Up @@ -31,6 +31,7 @@
#include <mono/utils/mono-digest.h>
#include <mono/utils/mono-logger.h>
#include <mono/metadata/reflection.h>
#include <mono/metadata/coree.h>

#ifndef PLATFORM_WIN32
#include <sys/types.h>
Expand Down Expand Up @@ -550,24 +551,6 @@ set_dirs (char *exe)

#endif /* PLATFORM_WIN32 */

#ifdef UNDER_CE
#undef GetModuleFileName
#define GetModuleFileName ceGetModuleFileNameA

DWORD ceGetModuleFileNameA(HMODULE hModule, char* lpFilename, DWORD nSize)
{
DWORD res = 0;
wchar_t* wbuff = (wchar_t*)LocalAlloc(LPTR, nSize*2);
res = GetModuleFileNameW(hModule, wbuff, nSize);
if (res) {
int len = wcslen(wbuff);
WideCharToMultiByte(CP_ACP, 0, wbuff, len, lpFilename, len, NULL, NULL);
}
LocalFree(wbuff);
return res;
}
#endif

/**
* mono_set_rootdir:
*
Expand All @@ -578,12 +561,10 @@ void
mono_set_rootdir (void)
{
#ifdef PLATFORM_WIN32
gunichar2 moddir [MAXPATHLEN];
gchar *bindir, *installdir, *root, *utf8name, *config;
gchar *bindir, *installdir, *root, *name, *config;

GetModuleFileNameW (NULL, moddir, MAXPATHLEN);
utf8name = g_utf16_to_utf8 (moddir, -1, NULL, NULL, NULL);
bindir = g_path_get_dirname (utf8name);
name = mono_get_module_file_name (mono_module_handle);
bindir = g_path_get_dirname (name);
installdir = g_path_get_dirname (bindir);
root = g_build_path (G_DIR_SEPARATOR_S, installdir, "lib", NULL);

Expand All @@ -594,7 +575,7 @@ mono_set_rootdir (void)
g_free (root);
g_free (installdir);
g_free (bindir);
g_free (utf8name);
g_free (name);
#else
char buf [4096];
int s;
Expand Down Expand Up @@ -1486,6 +1467,10 @@ mono_assembly_load_from_full (MonoImage *image, const char*fname,
loaded_assemblies = g_list_prepend (loaded_assemblies, ass);
if (mono_defaults.internals_visible_class)
mono_assembly_load_friends (ass);
#ifdef PLATFORM_WIN32
if (image->is_module_handle)
mono_image_fixup_vtable (image);
#endif
mono_assemblies_unlock ();

mono_assembly_invoke_load_hook (ass);
Expand Down
14 changes: 13 additions & 1 deletion mono/metadata/cil-coff.h
Expand Up @@ -246,6 +246,18 @@ typedef struct {
MonoPEDatadir datadir;
} MonoDotNetHeader64;

#define VTFIXUP_TYPE_32BIT 0x01
#define VTFIXUP_TYPE_64BIT 0x02
#define VTFIXUP_TYPE_FROM_UNMANAGED 0x04
#define VTFIXUP_TYPE_FROM_UNMANAGED_RETAIN_APPDOMAIN 0x08
#define VTFIXUP_TYPE_CALL_MOST_DERIVED 0x10

typedef struct {
guint32 rva;
guint16 count;
guint16 type;
} MonoVTableFixup;

typedef struct {
char st_name [8];
guint32 st_virtual_size;
Expand Down Expand Up @@ -311,6 +323,6 @@ typedef struct {
MonoCLIHeader cli_cli_header;
} MonoCLIImageInfo;

guint32 mono_cli_rva_image_map (MonoCLIImageInfo *iinfo, guint32 rva);
guint32 mono_cli_rva_image_map (MonoImage *image, guint32 rva);

#endif /* __MONO_CIL_COFF_H__ */

0 comments on commit b06a638

Please sign in to comment.