[MPlayer-dev-eng] [PATCH] fix for crt8 init dll

Reimar Döffinger Reimar.Doeffinger at gmx.de
Tue Feb 2 22:53:57 CET 2010


On Tue, Feb 02, 2010 at 10:35:02PM +0100, Gianluigi Tiesi wrote:
> On Tue, Feb 02, 2010 at 08:16:36PM +0100, Reimar D?ffinger wrote:
> > On Tue, Feb 02, 2010 at 12:16:30AM +0100, Gianluigi Tiesi wrote:
> > > msvcrt static linked dll and newer are making a check for "mixed crt" (posix)
> > > executables, this implies a GetModuleHandle on the main exe
> > > and a check for a section named .mixcrt
> > > 
> > > The attached patch fixes it by providing a minimal struct
> > > needed to the crt init function, and fakes the section
> > > .mixcrt so the crt avoid using Encode/Decode Pointers
> > 
> > Could you also explain why you want that? :-)
> > Is there some broken codec that ends up using the static
> > linked MSVCRT for half the encode/decode and our stubs
> > for the other half or something like that (how would that
> > happen?)?
> 
> the crt8 (and above) will execute that code if compiled statically
> so every codec compiled with statically linked crt will crash,
> using .mixcrt will avoid some encodepointer/decodepointer call
> but it's not mandatory, a section and section count 1 (or even 0)
> is enough

Ah, that makes sense and I'd say is okay then, though I suggest simplifying
it to the minimum (at least improving the comment is a must though).
Possible suggestion (please test and modify to your liking):

> /* Fake executable header, statically linked msvcrt8 expects
>    GetModuleHandle(NULL) to return a pointer to IMAGE_DOS_HEADER
>    etc. (it looks for a ".mixcrt" section to decide whether to use
>    EncodePointer/DecodePointer or not)
>  */
>static const struct {
>    IMAGE_DOS_HEADER doshdr;
>    IMAGE_NT_HEADERS nthdr;
>} mp_exe = {
>    .doshdr.e_lfanew = sizeof(IMAGE_DOS_HEADER),
>    .nthdr.FileHeader.NumberOfSections = 0,
>}

(I don't think the packed attribute should be necessary).
I you much prefer to keep the ".mixcrt" part, keep it, I only
slightly prefer the smaller code size of my suggestion.

> > >      if(!name)
> > > -#ifdef QTX
> > > -	result=1;
> > > -#else
> > > -	result=0;
> > > -#endif
> > > +	result=(HMODULE)&mp_exe.doshdr;
> 
> I think some code will asks for GetModuleHandle(NULL) != 0
> the mp_exe struct should be ok

Yes, I agree, I am just suspicious if something expects == 0,
but forget about this now, you convinced me :-).



More information about the MPlayer-dev-eng mailing list