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

Reimar Döffinger Reimar.Doeffinger at gmx.de
Wed Feb 3 19:40:44 CET 2010


On Wed, Feb 03, 2010 at 03:51:17AM +0100, Gianluigi Tiesi wrote:
> On Tue, Feb 02, 2010 at 10:53:57PM +0100, Reimar D?ffinger wrote:
> > 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.
> 
> dunno about the packed, but session struct is needed by this:
> 
> pSection = IMAGE_FIRST_SECTION(pNTHeader)
> 
> it's a macro that point at least on the first section

Of course, keep anything that's necessary, and as said feel free to
keep the code if you think it's a good idea, but the comment
at least needs to explain the real reason (crash due to hacks
in static msvcrt, not due to pointer de-/encoding, which is
just an additional feature).



More information about the MPlayer-dev-eng mailing list