[Mono-dev] [PATCH] Add mixed-mode assembly support on Windows

Kornél Pál kornelpal at gmail.com
Sat Apr 19 18:40:00 EDT 2008


Hi,

I finished implementing coree functions required for loading images without 
mono.exe.

The previously described issues remained however so I still need some help.

This contribution is licensed under MIT X11.

Also attached a minimalistic mscoree.dll implementation that I used for 
testing this patch. Note that Visual Studio has to be started with the 
original mscoree.dll and has to be temporarily replaced with this 
implementation while debugging.

Kornél

----- Original Message ----- 
From: "Kornél Pál" <kornelpal at gmail.com>
To: <mono-devel-list at lists.ximian.com>
Cc: "Miguel de Icaza" <Miguel at novell.com>
Sent: Friday, April 18, 2008 12:04 PM
Subject: [PATCH] Add mixed-mode assembly support on Windows


> Hi,
>
> I have attached my proposed patch.
>
> I need some help to finish mono_marshal_get_vtfixup_ftnptr. It should
> generate a wrapper method based on the method token.
> types:
> VTFIXUP_TYPE_FROM_UNMANAGED: unmanaged-to-managed wrapper (otherwise
> managed-to-managed)
> VTFIXUP_TYPE_CALL_MOST_DERIVED: callvirt (otherwise call)
> VTFIXUP_TYPE_RETAIN_APPDOMAIN: not important yet
>
> I would like to implement mono_marshal_get_vtfixup_ftnptr but I don't know
> where should I cache these methods and how can I obtain a marshaler
> wrapper
> without using delegates.
>
> Also note that I was unable to build the patch using gcc:
> /mono/mono/mono/metadata/domain.c:1172: undefined reference to
> `_MonoFixupCorEE at 4'
> /mono/mono/mono/metadata/domain.c:1217: undefined reference to
> `_MonoFixupExe at 4'
>
> And I have no idea why it builds with MSVC and not with gcc.
>
> _CorDllMain and _CorExeMain is not finished yet but is only required for
> Wine support so I didn't include them in the patch yet. They will call
> runtime initialization code. MonoFixupCorEE is intended to be called from
> Wine's mscoree.dll as well.
>
> Kornél
>
> ----- Original Message ----- 
> From: "Miguel de Icaza" <Miguel at novell.com>
> To: <kornelpal at gmail.com>
> Cc: <mono-devel-list at lists.ximian.com>
> Sent: Thursday, April 17, 2008 7:47 PM
> Subject: Re: [Mono-dev] Mono on wine redux
>
>
> Wow.
>
> Well, that was fast.   Congrats Kornel!
>
> -----Original Message-----
> From: Kornél Pál <kornelpal at gmail.com>
> Cc:  <mono-devel-list at lists.ximian.com>
> To: Miguel de Icaza <Miguel at novell.com>
>
> Sent: 4/17/2008 3:17:24 AM
> Subject: Re: [Mono-dev] Mono on wine redux
>
> Hi,
>
>> From: "Miguel de Icaza" <miguel at novell.com>
>>> But what percent of .net apps are pure?  If that fraction is small,
>>> as I suspect it is, then for Mono to really rock the world, it's going
>>> to have to tackle impure apps, too.  That is of course incredibly
>>> difficult,
>>> and would require considerable cooperation between the Mono and Wine
>>> projects.
>>
>> It is very hard to run into a mixed-mode assembly in the wild;   They do
>> happen, but they are rare.   I can only think of three projects that had
>> needed them in the history of Mono.
>
> I've done some work on this. And actually I managed to run mixed-mode
> assemblies.
>
> Note that it is only possible on Windows because native code is usually
> platform (arch and OS as well) dependent.
>
> I implemented support for loading image files using LoadLibrary so that
> the
> NT loader will take care of the image patching. I also had to patch the
> in-memory image of mscoree.dll so that export address table point to
> functions in mono.dll that is required for LoadLibrary support. This also
> will enable Wine (and Windows is someone is willing to replace or modify
> his
> on-disk mscoree.dll image) to execute managed images using CreateProcess
> without creating a mono.exe child process. This was the hardest part.
>
> IJW thunks (managed-to-native) are really P/Invoke methods with function
> RVA
> stored in method body RVA so it was very easy to implement, I only had to
> remove code preventing IJW from work.
>
> V-table fixups (native-to-managed) are not difficult either but requires
> it's own wrapper methods so my current implementation probably will need
> improvements.
>
> Note that this still will not make Mono able to use MSVCRT because that
> uses
> unmanaged API of .NET Framework that isn't implemented by Mono.
>
> I am stilll working on a cleaned-up patch but will send to the list soon.
>
> Kornél
>
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mixed_mode2.diff.txt
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080420/4fa80b28/attachment-0001.txt 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mscoree.c
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080420/4fa80b28/attachment-0001.c 


More information about the Mono-devel-list mailing list