Skip to content

Commit

Permalink
Win32 build: upgrade to _WIN32_WINNT 0x600 (WinXP and above)
Browse files Browse the repository at this point in the history
This should enable us to use Windows dbghelp functions to get stack
traces on exceptions, including demangled names.

This required replacing our custom "struct pollfd" with
EMU_STRUCT_POLLFD everywhere, to fix the conflict with newer versions of
winsock2.h.
  • Loading branch information
qris committed Mar 27, 2017
1 parent 7bedbd8 commit 62dcc38
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
3 changes: 2 additions & 1 deletion lib/common/WaitForEvent.cpp
Expand Up @@ -141,7 +141,8 @@ void *WaitForEvent::Wait()
if(mpPollInfo == 0)
{
// Yes...
mpPollInfo = (struct pollfd *)::malloc((sizeof(struct pollfd) * mItems.size()) + 4);
mpPollInfo = (EMU_STRUCT_POLLFD *)::malloc(
(sizeof(EMU_STRUCT_POLLFD) * mItems.size()) + 4);
if(mpPollInfo == 0)
{
throw std::bad_alloc();
Expand Down
2 changes: 1 addition & 1 deletion lib/common/WaitForEvent.h
Expand Up @@ -141,7 +141,7 @@ class WaitForEvent
#else
int mTimeout;
std::vector<ItemInfo> mItems;
struct pollfd *mpPollInfo;
EMU_STRUCT_POLLFD *mpPollInfo;
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion lib/server/SocketListen.h
Expand Up @@ -231,7 +231,7 @@ class SocketListen
}

// poll this socket
struct pollfd p;
EMU_STRUCT_POLLFD p;
p.fd = mSocketHandle;
p.events = POLLIN;
p.revents = 0;
Expand Down
4 changes: 2 additions & 2 deletions lib/server/SocketStream.cpp
Expand Up @@ -228,7 +228,7 @@ int SocketStream::Read(void *pBuffer, int NBytes, int Timeout)

if(Timeout != IOStream::TimeOutInfinite)
{
struct pollfd p;
EMU_STRUCT_POLLFD p;
p.fd = mSocketHandle;
p.events = POLLIN;
p.revents = 0;
Expand Down Expand Up @@ -295,7 +295,7 @@ int SocketStream::Read(void *pBuffer, int NBytes, int Timeout)
bool SocketStream::Poll(short Events, int Timeout)
{
// Wait for data to send.
struct pollfd p;
EMU_STRUCT_POLLFD p;
p.fd = GetSocketHandle();
p.events = Events;
p.revents = 0;
Expand Down
8 changes: 4 additions & 4 deletions lib/win32/emu.cpp
Expand Up @@ -1234,7 +1234,7 @@ int closedir(DIR *dp)
// Created: 25th October 2004
//
// --------------------------------------------------------------------------
int poll (struct pollfd *ufds, unsigned long nfds, int timeout)
int poll(EMU_STRUCT_POLLFD *ufds, unsigned long nfds, int timeout)
{
try
{
Expand All @@ -1259,7 +1259,7 @@ int poll (struct pollfd *ufds, unsigned long nfds, int timeout)

for (unsigned long i = 0; i < nfds; i++)
{
struct pollfd* ufd = &(ufds[i]);
EMU_STRUCT_POLLFD* ufd = &(ufds[i]);

if (ufd->events & POLLIN)
{
Expand All @@ -1285,7 +1285,7 @@ int poll (struct pollfd *ufds, unsigned long nfds, int timeout)
{
// int errval = WSAGetLastError();

struct pollfd* pufd = ufds;
EMU_STRUCT_POLLFD* pufd = ufds;
for (unsigned long i = 0; i < nfds; i++)
{
pufd->revents = POLLERR;
Expand All @@ -1297,7 +1297,7 @@ int poll (struct pollfd *ufds, unsigned long nfds, int timeout)
{
for (unsigned long i = 0; i < nfds; i++)
{
struct pollfd *ufd = &(ufds[i]);
EMU_STRUCT_POLLFD *ufd = &(ufds[i]);

if (FD_ISSET(ufd->fd, &readfd))
{
Expand Down
6 changes: 4 additions & 2 deletions lib/win32/emu.h
Expand Up @@ -10,13 +10,15 @@

#ifdef WIN32
#define EMU_STRUCT_STAT struct emu_stat
#define EMU_STRUCT_POLLFD struct emu_pollfd
#define EMU_STAT emu_stat
#define EMU_FSTAT emu_fstat
#define EMU_LSTAT emu_stat
#define EMU_LINK emu_link
#define EMU_UNLINK emu_unlink
#else
#define EMU_STRUCT_STAT struct stat
#define EMU_STRUCT_POLLFD struct pollfd
#define EMU_STAT ::stat
#define EMU_FSTAT ::fstat
#define EMU_LSTAT ::lstat
Expand Down Expand Up @@ -320,7 +322,7 @@ extern "C" inline unsigned int sleep(unsigned int secs)
#define SHUT_RD SD_RECEIVE
#define SHUT_WR SD_SEND

struct pollfd
EMU_STRUCT_POLLFD
{
SOCKET fd;
short int events;
Expand Down Expand Up @@ -397,7 +399,7 @@ int emu_rename (const char* pOldName, const char* pNewName);

int statfs(const char * name, struct statfs * s);

int poll(struct pollfd *ufds, unsigned long nfds, int timeout);
int poll(EMU_STRUCT_POLLFD *ufds, unsigned long nfds, int timeout);

struct iovec {
void *iov_base; /* Starting address */
Expand Down
10 changes: 3 additions & 7 deletions lib/win32/emu_winver.h
Expand Up @@ -11,10 +11,6 @@

// We need WINVER at least 0x0500 to use GetFileSizeEx on Cygwin/MinGW,
// and 0x0501 for FindFirstFile(W) for opendir/readdir.
//
// WIN32_WINNT versions 0x0600 (Vista) and higher enable WSAPoll() in
// winsock2.h, whose struct pollfd conflicts with ours below, so for
// now we just set it lower than that, to Windows XP (0x0501).

#ifdef WINVER
# if WINVER != 0x0501
Expand All @@ -26,12 +22,12 @@
#define WINVER 0x0501

#ifdef _WIN32_WINNT
# if _WIN32_WINNT != 0x0501
# if _WIN32_WINNT != 0x0600
// provoke a redefinition warning to track down the offender
# define _WIN32_WINNT 0x0501
# define _WIN32_WINNT 0x0600
# error Must include emu.h before setting _WIN32_WINNT
# endif
#endif
#define _WIN32_WINNT 0x0501
#define _WIN32_WINNT 0x0600

#endif // _EMU_WINVER_H

0 comments on commit 62dcc38

Please sign in to comment.