/*
- * $Id: win32.cc,v 1.26 2007/12/14 23:11:48 amosjeffries Exp $
- *
- * Windows support
- * AUTHOR: Guido Serassio <serassio@squid-cache.org>
- * inspired by previous work by Romeo Anghelache & Eric Stern.
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * 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-2023 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"
-#include "squid_windows.h"
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
+
+#include "fde.h"
+#include "win32.h"
+
+#include <csignal>
#if HAVE_WIN32_PSAPI
#include <psapi.h>
#endif
-#ifndef _MSWSOCK_
+#if HAVE_MSWSOCK_H
#include <mswsock.h>
#endif
-#include <fde.h>
SQUIDCEXTERN LPCRITICAL_SECTION dbg_mutex;
void WIN32_ExceptionHandlerCleanup(void);
static LPTOP_LEVEL_EXCEPTION_FILTER Win32_Old_ExceptionHandler = NULL;
-
-int WIN32_pipe(int handles[2])
-{
- int new_socket;
- fde *F = NULL;
-
- IPAddress localhost;
- IPAddress handle0;
- IPAddress handle1;
- struct addrinfo *AI = NULL;
-
- localhost.SetLocalhost;
-
-#if !IPV6_SPECIAL_LOCALHOST
- /* INET6: back-compatible: localhost pipes default to IPv4 unless set otherwise.
- * it is blocked by untested helpers on many admins configs
- * if this proves to be wrong it can die easily.
- */
- localhost.SetIPv4();
-#endif
-
- handles[0] = handles[1] = -1;
-
- statCounter.syscalls.sock.sockets++;
-
- handle0 = localhost;
- handle0.SetPort(0);
- handle0.GetAddrInfo(AI);
-
- if ((new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol)) < 0)
- return -1;
-
- if (bind(new_socket, AI->ai_addr, AI->ai_addrlen) < 0 ||
- listen(new_socket, 1) < 0 || getsockname(new_socket, AI->ai_addr, &(AI->ai_addrlen) ) < 0 ||
- (handles[1] = socket(AI->ai_family, AI->ai_socktype, 0)) < 0) {
- closesocket(new_socket);
- return -1;
- }
-
- handle0 = *AI; // retrieve the new details returned by connect()
-
- handle1.SetPort(handle1.GetPort());
- handle1.GetAddrInfo(AI);
-
- if (connect(handles[1], AI->ai_addr, AI->ai_addrlen) < 0 ||
- (handles[0] = accept(new_socket, AI->ai_addr, &(AI->ai_addrlen)) ) < 0) {
- closesocket(handles[1]);
- handles[1] = -1;
- closesocket(new_socket);
- return -1;
- }
-
- closesocket(new_socket);
-
- F = &fd_table[handles[0]];
- F->local_addr = handle0;
-
- F = &fd_table[handles[1]];
- F->local_addr = localhost;
- handle1.NtoA(F->ipaddr, MAX_IPSTRLEN);
- F->remote_port = handle1.GetPort();
-
- return 0;
-}
-
-int WIN32_getrusage(int who, struct rusage *usage)
-{
-#if HAVE_WIN32_PSAPI
-
- if ((WIN32_OS_version == _WIN_OS_WINNT) || (WIN32_OS_version == _WIN_OS_WIN2K)
- || (WIN32_OS_version == _WIN_OS_WINXP) || (WIN32_OS_version == _WIN_OS_WINNET))
- {
- /* On Windows NT/2000 call PSAPI.DLL for process Memory */
- /* informations -- Guido Serassio */
- HANDLE hProcess;
- PROCESS_MEMORY_COUNTERS pmc;
- hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
- PROCESS_VM_READ,
- FALSE, GetCurrentProcessId());
- {
- /* Microsoft CRT doesn't have getrusage function, */
- /* so we get process CPU time information from PSAPI.DLL. */
- FILETIME ftCreate, ftExit, ftKernel, ftUser;
-
- if (GetProcessTimes(hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser)) {
- int64_t tUser64 = (*(int64_t *)&ftUser / 10);
- int64_t tKernel64 = (*(int64_t *)&ftKernel / 10);
- usage->ru_utime.tv_sec =(long)(tUser64 / 1000000);
- usage->ru_stime.tv_sec =(long)(tKernel64 / 1000000);
- usage->ru_utime.tv_usec =(long)(tUser64 % 1000000);
- usage->ru_stime.tv_usec =(long)(tKernel64 % 1000000);
- } else {
- CloseHandle( hProcess );
- return -1;
- }
- }
-
- if (GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc))) {
- usage->ru_maxrss=(DWORD)(pmc.WorkingSetSize / getpagesize());
- usage->ru_majflt=pmc.PageFaultCount;
- } else {
- CloseHandle( hProcess );
- return -1;
- }
-
- CloseHandle( hProcess );
- }
-
-#endif
- return 0;
-}
-
-
-int Win32__WSAFDIsSet(int fd, fd_set FAR * set
- )
+int
+Win32__WSAFDIsSet(int fd, fd_set FAR * set)
{
fde *F = &fd_table[fd];
SOCKET s = F->win32.handle;
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
case EXCEPTION_IN_PAGE_ERROR:
- death(SIGBUS);
+ raise(SIGBUS);
break;
default:
return EXCEPTION_CONTINUE_SEARCH;
}
-
void WIN32_ExceptionHandlerInit()
{
#if !defined(_DEBUG)
SetUnhandledExceptionFilter(Win32_Old_ExceptionHandler);
}
-#endif /* SQUID_MSWIN_ */
+#endif /* SQUID_WINDOWS_ */
+