Hi everyone,
For the past couple of days, I have been investigating the cause
of an interesting bug. What was happening was my application
was either crashing in WsControl, or losing its networking
after calls to WsControl. I thought this was rather odd,
so I started going through the CVS looking at what patch
was causing this. I found if I reverted a patch that made
importing ws2_32.dll from wsock32.dll work properly, there
would be no more crashes.
One of the bugs was related to mixing Windows and Linux
socket calls, which I fixed and submitted a patch for this
to Wine-Patches mailing list. However, despite this
patch, I was still getting wierd crashes, always after
entering WsControl.
Just for fun, I tried commenting out from WsControl all cross-dll
calls (ioctlsocket, socket, closesocket). Amazingly, no more
crashes! Add back a call only to socket() (really WSOCK32_socket),
mysterious crashes again. This problem is only happening if
I have a call to socket(), not closesocket() (I assume
ioctlsocket as well, but I didn't test that...)
My theory for this problem is as follows. In the standard Linux
headers there is a declaration for socket(). WINE's
declaration of WSOCK32_socket is different. (WINE's takes the
modifier WINAPI). When gcc is compiling wsock32.so, it is depending
on the declaration from linux's headers, so it places arguments
on the stack in the way it is defined there. Since ws2_32 is
expecting the arguments in a different way, the
stack gets corrupted either on function entry or exit.
To test this theory out, I made a quick hack. Basically, I make
sure not to call socket() as socket(). I export from ws2_32
another version of WSOCK32_socket, called WSCONTROL_HACK_socket;
I add an extern with the right signature in winsock2.h, and
I call it from WsControl with WSCONTROL_HACK_socket. I included
the hack as an attachment to this mail, you need my other fix
to WsControl recently sent to Wine-patches to apply it.
Interestingly enough, it works perfectly with my hack, so
it seems like my theory is correct.
My question to you guys is, how do I solve this problem
properly/cleanly? socket()'s declaration in the linux headers
is in a header that is needed, there doesn't appear to be a way
to "undeclare" a function signature in C (maybe I'm wrong on this?),
and simply making another declaration with the right signature
results in a type conflict error in compilation. What is a
non-hackish way of doing this?
Thanks in advance,
-James
--
James Hatheway
Software Designer - Macadamian Technologies, Inc.
[EMAIL PROTECTED] ~ http://www.macadamian.com
"Nothing is a problem once you debug the code."
wscontrol_socket_hack.diff