Gav sparked me to go look and see how I could pull argc/argv
out during the constructor phase of library load,
and I believe I have found a method that should work,
at least for elf/glibc implementations.

Specifically, according to the glibc source code, if
a function named '_init' exists (by convention, but
not requirement, in the .init section), then ld.so will
invoke that function at dl-init time.

The good news is that _init is passed argc, argv, and environp.

Thus, we have a method that shouldn't be too kludgy; simply
define an _init function in libwine.so, and initialize the
library with the args.

However, it is a little trickier than that.  First, if we
supply our own '_init' function, there is a raft of glibc
initialization that is not done (notably the invokation of
the ctors list to run the constructors).  [If anyone wants
to know more details, I just wasted two days of my life
learning all there is to know about .init and _init and glibc <g>].

Thus, we could put _init into libwine.so, but then we would
need to call the constructor functions ourselves
(or pull those functions out to be invoked by a central
function, and call that function during _init).

Alternately, we could simply put '_init' into libwinelib.so 
(as I had in my earlier patch), and then it all works (I tried it),
because libwinelib.so has no constructors.

The one thing I can't clearly assess is whether this method
is portable to all of the platforms we care about.

One advantage to Alexandre's method (let Wine run, do
a LoadLibrary(), GetProcAddress("WinMain"), start the app),
is that it is more portable.

At any rate, if I get some time, I will reformulate my patch
to use this method.

I'd also appreciate any further thoughts/comments/
reports of obvious problems I've overlooked.

Jer

Reply via email to