-
/*
- * $Id: win32.cc,v 1.4 2001/11/17 11:09:25 hno Exp $
- *
- * * * * * * * * Legal stuff * * * * * * *
- *
- * (C) 2001 Guido Serassio <serassio@libero.it>,
- * inspired by previous work by Romeo Anghelache & Eric Stern.
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+/* Inspired by previous work by Romeo Anghelache & Eric Stern. */
+
#include "squid.h"
-/* This code compiles only CygWin & Windows NT Port */
-#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)
-#include <windows.h>
+#if _SQUID_WINDOWS_
+
+#include "fde.h"
+#include "win32.h"
+
+#include <csignal>
+#if HAVE_WIN32_PSAPI
+#include <psapi.h>
+#endif
+#if HAVE_MSWSOCK_H
+#include <mswsock.h>
+#endif
+
+SQUIDCEXTERN LPCRITICAL_SECTION dbg_mutex;
+void WIN32_ExceptionHandlerCleanup(void);
+static LPTOP_LEVEL_EXCEPTION_FILTER Win32_Old_ExceptionHandler = NULL;
-static unsigned int GetOSVersion();
+int
+Win32__WSAFDIsSet(int fd, fd_set FAR * set)
+{
+ fde *F = &fd_table[fd];
+ SOCKET s = F->win32.handle;
-/* ====================================================================== */
-/* LOCAL FUNCTIONS */
-/* ====================================================================== */
+ return __WSAFDIsSet(s, set);
+}
-static unsigned int
-GetOSVersion()
+LONG CALLBACK WIN32_ExceptionHandler(EXCEPTION_POINTERS* ep)
{
- OSVERSIONINFO osvi;
-
- safe_free(WIN32_OS_string);
- memset(&osvi, '\0', sizeof(OSVERSIONINFO));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx((OSVERSIONINFO *) & osvi);
- switch (osvi.dwPlatformId) {
- case VER_PLATFORM_WIN32_NT:
- if (osvi.dwMajorVersion <= 4) {
- WIN32_OS_string = xstrdup("Windows NT");
- return _WIN_OS_WINNT;
- }
- if ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 0)) {
- WIN32_OS_string = xstrdup("Windows 2000");
- return _WIN_OS_WIN2K;
- }
- if ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 1)) {
- WIN32_OS_string = xstrdup("Windows XP");
- return _WIN_OS_WINXP;
- }
- break;
- case VER_PLATFORM_WIN32_WINDOWS:
- if ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 0)) {
- WIN32_OS_string = xstrdup("Windows 95");
- return _WIN_OS_WIN95;
- }
- if ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 10)) {
- WIN32_OS_string = xstrdup("Windows 98");
- return _WIN_OS_WIN98;
- }
- if ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 90)) {
- WIN32_OS_string = xstrdup("Windows Me");
- return _WIN_OS_WINME;
- }
- break;
- case VER_PLATFORM_WIN32s:
- WIN32_OS_string = xstrdup("Windows 3.1 with WIN32S");
- return _WIN_OS_WIN32S;
- break;
+ EXCEPTION_RECORD* er;
+
+ er = ep->ExceptionRecord;
+
+ switch (er->ExceptionCode) {
+
+ case EXCEPTION_ACCESS_VIOLATION:
+ raise(SIGSEGV);
+ break;
+
+ case EXCEPTION_DATATYPE_MISALIGNMENT:
+
+ case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
+
+ case EXCEPTION_IN_PAGE_ERROR:
+ raise(SIGBUS);
+ break;
+
default:
- break;
+ break;
}
- WIN32_OS_string = xstrdup("Unknown Windows system");
- return _WIN_OS_UNKNOWN;
-}
-/* ====================================================================== */
-/* PUBLIC FUNCTIONS */
-/* ====================================================================== */
+ return EXCEPTION_CONTINUE_SEARCH;
+}
-void
-WIN32_Exit()
+void WIN32_ExceptionHandlerInit()
{
- _exit(0);
+#if !defined(_DEBUG)
+
+ if (Win32_Old_ExceptionHandler == NULL)
+ Win32_Old_ExceptionHandler = SetUnhandledExceptionFilter(WIN32_ExceptionHandler);
+
+#endif
}
-int
-WIN32_Subsystem_Init()
+void WIN32_ExceptionHandlerCleanup()
{
- WIN32_OS_version = GetOSVersion();
- if ((WIN32_OS_version == _WIN_OS_UNKNOWN) || (WIN32_OS_version == _WIN_OS_WIN32S))
- return 1;
- if (atexit(WIN32_Exit) != 0)
- return 1;
- return 0;
+ if (Win32_Old_ExceptionHandler != NULL)
+ SetUnhandledExceptionFilter(Win32_Old_ExceptionHandler);
}
-#endif
+
+#endif /* SQUID_WINDOWS_ */
+