mirror of
https://github.com/squid-cache/squid.git
synced 2025-04-18 22:04:07 +03:00
MinGW: Fix aiops_win32.cc (#2030)
Fixed missing includes, type mismatches in some local variables, applied some AAA; extracted WIN32_maperror into own header and implementation files using NoMoreGlobals, and used modern c++ data types for it. This change also mirrors changes introduced in aiops.cc by commit 91d1cfb. These changes require further refinement (in both files). Examples of errors fixed: ``` aiops_win32.cc: In function 'void* squidaio_xmalloc(int)': aiops_win32.cc:161:17: error: invalid use of incomplete type 'class Mem::Allocator' aiops_win32.cc: In function 'void squidaio_init()': aiops_win32.cc:278:19: error: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long long unsigned int'} aiops_win32.cc: In function 'void squidaio_do_read(squidaio_request_t*)': aiops_win32.cc:782:9: error: 'WIN32_maperror' was not declared in this scope ```
This commit is contained in:
parent
c807ccfd49
commit
84bb09abbd
@ -73,6 +73,8 @@ libcompatsquid_la_SOURCES = \
|
||||
tempnam.h \
|
||||
types.h \
|
||||
valgrind.h \
|
||||
win32_maperror.cc \
|
||||
win32_maperror.h \
|
||||
xalloc.cc \
|
||||
xalloc.h \
|
||||
xis.h \
|
||||
|
@ -183,83 +183,6 @@ getgrnam(char *unused) {
|
||||
return &grp;
|
||||
}
|
||||
|
||||
struct errorentry {
|
||||
unsigned long WIN32_code;
|
||||
int POSIX_errno;
|
||||
};
|
||||
|
||||
static struct errorentry errortable[] = {
|
||||
{ERROR_INVALID_FUNCTION, EINVAL},
|
||||
{ERROR_FILE_NOT_FOUND, ENOENT},
|
||||
{ERROR_PATH_NOT_FOUND, ENOENT},
|
||||
{ERROR_TOO_MANY_OPEN_FILES, EMFILE},
|
||||
{ERROR_ACCESS_DENIED, EACCES},
|
||||
{ERROR_INVALID_HANDLE, EBADF},
|
||||
{ERROR_ARENA_TRASHED, ENOMEM},
|
||||
{ERROR_NOT_ENOUGH_MEMORY, ENOMEM},
|
||||
{ERROR_INVALID_BLOCK, ENOMEM},
|
||||
{ERROR_BAD_ENVIRONMENT, E2BIG},
|
||||
{ERROR_BAD_FORMAT, ENOEXEC},
|
||||
{ERROR_INVALID_ACCESS, EINVAL},
|
||||
{ERROR_INVALID_DATA, EINVAL},
|
||||
{ERROR_INVALID_DRIVE, ENOENT},
|
||||
{ERROR_CURRENT_DIRECTORY, EACCES},
|
||||
{ERROR_NOT_SAME_DEVICE, EXDEV},
|
||||
{ERROR_NO_MORE_FILES, ENOENT},
|
||||
{ERROR_LOCK_VIOLATION, EACCES},
|
||||
{ERROR_BAD_NETPATH, ENOENT},
|
||||
{ERROR_NETWORK_ACCESS_DENIED, EACCES},
|
||||
{ERROR_BAD_NET_NAME, ENOENT},
|
||||
{ERROR_FILE_EXISTS, EEXIST},
|
||||
{ERROR_CANNOT_MAKE, EACCES},
|
||||
{ERROR_FAIL_I24, EACCES},
|
||||
{ERROR_INVALID_PARAMETER, EINVAL},
|
||||
{ERROR_NO_PROC_SLOTS, EAGAIN},
|
||||
{ERROR_DRIVE_LOCKED, EACCES},
|
||||
{ERROR_BROKEN_PIPE, EPIPE},
|
||||
{ERROR_DISK_FULL, ENOSPC},
|
||||
{ERROR_INVALID_TARGET_HANDLE, EBADF},
|
||||
{ERROR_INVALID_HANDLE, EINVAL},
|
||||
{ERROR_WAIT_NO_CHILDREN, ECHILD},
|
||||
{ERROR_CHILD_NOT_COMPLETE, ECHILD},
|
||||
{ERROR_DIRECT_ACCESS_HANDLE, EBADF},
|
||||
{ERROR_NEGATIVE_SEEK, EINVAL},
|
||||
{ERROR_SEEK_ON_DEVICE, EACCES},
|
||||
{ERROR_DIR_NOT_EMPTY, ENOTEMPTY},
|
||||
{ERROR_NOT_LOCKED, EACCES},
|
||||
{ERROR_BAD_PATHNAME, ENOENT},
|
||||
{ERROR_MAX_THRDS_REACHED, EAGAIN},
|
||||
{ERROR_LOCK_FAILED, EACCES},
|
||||
{ERROR_ALREADY_EXISTS, EEXIST},
|
||||
{ERROR_FILENAME_EXCED_RANGE, ENOENT},
|
||||
{ERROR_NESTING_NOT_ALLOWED, EAGAIN},
|
||||
{ERROR_NOT_ENOUGH_QUOTA, ENOMEM}
|
||||
};
|
||||
|
||||
#define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG
|
||||
#define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN
|
||||
|
||||
#define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
|
||||
#define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
|
||||
|
||||
void
|
||||
WIN32_maperror(unsigned long WIN32_oserrno)
|
||||
{
|
||||
_doserrno = WIN32_oserrno;
|
||||
for (size_t i = 0; i < (sizeof(errortable) / sizeof(struct errorentry)); ++i) {
|
||||
if (WIN32_oserrno == errortable[i].WIN32_code) {
|
||||
errno = errortable[i].POSIX_errno;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (WIN32_oserrno >= MIN_EACCES_RANGE && WIN32_oserrno <= MAX_EACCES_RANGE)
|
||||
errno = EACCES;
|
||||
else if (WIN32_oserrno >= MIN_EXEC_ERROR && WIN32_oserrno <= MAX_EXEC_ERROR)
|
||||
errno = ENOEXEC;
|
||||
else
|
||||
errno = EINVAL;
|
||||
}
|
||||
|
||||
/* syslog emulation layer derived from git */
|
||||
static HANDLE ms_eventlog;
|
||||
|
||||
@ -322,5 +245,4 @@ syslog(int priority, const char *fmt, ...)
|
||||
}
|
||||
|
||||
/* note: this is all MSWindows-specific code; all of it should be conditional */
|
||||
#endif /* _SQUID_WINDOWS_ */
|
||||
|
||||
#endif /* _SQUID_WINDOWS_ && !_SQUID_CYGWIN_*/
|
||||
|
@ -906,9 +906,6 @@ void openlog(const char *ident, int logopt, int facility);
|
||||
void syslog(int priority, const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
/* prototypes */
|
||||
void WIN32_maperror(unsigned long WIN32_oserrno);
|
||||
|
||||
#endif /* _SQUID_WINDOWS_ */
|
||||
#endif /* SQUID_COMPAT_OS_MSWINDOWS_H */
|
||||
|
||||
|
89
compat/win32_maperror.cc
Normal file
89
compat/win32_maperror.cc
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "squid.h"
|
||||
#include "compat/win32_maperror.h"
|
||||
|
||||
#if (_SQUID_WINDOWS_ || _SQUID_MINGW_) && !_SQUID_CYGWIN_
|
||||
|
||||
#if HAVE_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <cstdlib>
|
||||
#include <unordered_map>
|
||||
|
||||
void
|
||||
WIN32_maperror(unsigned long WIN32_oserrno)
|
||||
{
|
||||
static const auto errormap = new std::unordered_map<unsigned long, int> {
|
||||
{ERROR_INVALID_FUNCTION, EINVAL},
|
||||
{ERROR_FILE_NOT_FOUND, ENOENT},
|
||||
{ERROR_PATH_NOT_FOUND, ENOENT},
|
||||
{ERROR_TOO_MANY_OPEN_FILES, EMFILE},
|
||||
{ERROR_ACCESS_DENIED, EACCES},
|
||||
{ERROR_INVALID_HANDLE, EBADF},
|
||||
{ERROR_ARENA_TRASHED, ENOMEM},
|
||||
{ERROR_NOT_ENOUGH_MEMORY, ENOMEM},
|
||||
{ERROR_INVALID_BLOCK, ENOMEM},
|
||||
{ERROR_BAD_ENVIRONMENT, E2BIG},
|
||||
{ERROR_BAD_FORMAT, ENOEXEC},
|
||||
{ERROR_INVALID_ACCESS, EINVAL},
|
||||
{ERROR_INVALID_DATA, EINVAL},
|
||||
{ERROR_INVALID_DRIVE, ENOENT},
|
||||
{ERROR_CURRENT_DIRECTORY, EACCES},
|
||||
{ERROR_NOT_SAME_DEVICE, EXDEV},
|
||||
{ERROR_NO_MORE_FILES, ENOENT},
|
||||
{ERROR_LOCK_VIOLATION, EACCES},
|
||||
{ERROR_BAD_NETPATH, ENOENT},
|
||||
{ERROR_NETWORK_ACCESS_DENIED, EACCES},
|
||||
{ERROR_BAD_NET_NAME, ENOENT},
|
||||
{ERROR_FILE_EXISTS, EEXIST},
|
||||
{ERROR_CANNOT_MAKE, EACCES},
|
||||
{ERROR_FAIL_I24, EACCES},
|
||||
{ERROR_INVALID_PARAMETER, EINVAL},
|
||||
{ERROR_NO_PROC_SLOTS, EAGAIN},
|
||||
{ERROR_DRIVE_LOCKED, EACCES},
|
||||
{ERROR_BROKEN_PIPE, EPIPE},
|
||||
{ERROR_DISK_FULL, ENOSPC},
|
||||
{ERROR_INVALID_TARGET_HANDLE, EBADF},
|
||||
{ERROR_INVALID_HANDLE, EINVAL},
|
||||
{ERROR_WAIT_NO_CHILDREN, ECHILD},
|
||||
{ERROR_CHILD_NOT_COMPLETE, ECHILD},
|
||||
{ERROR_DIRECT_ACCESS_HANDLE, EBADF},
|
||||
{ERROR_NEGATIVE_SEEK, EINVAL},
|
||||
{ERROR_SEEK_ON_DEVICE, EACCES},
|
||||
{ERROR_DIR_NOT_EMPTY, ENOTEMPTY},
|
||||
{ERROR_NOT_LOCKED, EACCES},
|
||||
{ERROR_BAD_PATHNAME, ENOENT},
|
||||
{ERROR_MAX_THRDS_REACHED, EAGAIN},
|
||||
{ERROR_LOCK_FAILED, EACCES},
|
||||
{ERROR_ALREADY_EXISTS, EEXIST},
|
||||
{ERROR_FILENAME_EXCED_RANGE, ENOENT},
|
||||
{ERROR_NESTING_NOT_ALLOWED, EAGAIN},
|
||||
{ERROR_NOT_ENOUGH_QUOTA, ENOMEM}
|
||||
};
|
||||
_set_doserrno(WIN32_oserrno);
|
||||
const auto it = errormap->find(WIN32_oserrno);
|
||||
if (it != errormap->end()) {
|
||||
errno = it->second;
|
||||
return;
|
||||
}
|
||||
const auto min_exec_error = ERROR_INVALID_STARTING_CODESEG;
|
||||
const auto max_exec_error = ERROR_INFLOOP_IN_RELOC_CHAIN;
|
||||
const auto min_eaccess_range = ERROR_WRITE_PROTECT;
|
||||
const auto max_eaccess_range = ERROR_SHARING_BUFFER_EXCEEDED;
|
||||
|
||||
if (min_eaccess_range <= WIN32_oserrno && WIN32_oserrno <= max_eaccess_range)
|
||||
errno = EACCES;
|
||||
else if (min_exec_error <= WIN32_oserrno && WIN32_oserrno <= max_exec_error)
|
||||
errno = ENOEXEC;
|
||||
else
|
||||
errno = EINVAL;
|
||||
}
|
||||
|
||||
#endif /* (_SQUID_WINDOWS_ || _SQUID_MINGW_) && !_SQUID_CYGWIN_ */
|
20
compat/win32_maperror.h
Normal file
20
compat/win32_maperror.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef SQUID_COMPAT_WIN32_MAPERROR_H
|
||||
#define SQUID_COMPAT_WIN32_MAPERROR_H
|
||||
|
||||
#if (_SQUID_WINDOWS_ || _SQUID_MINGW_) && !_SQUID_CYGWIN_
|
||||
|
||||
/// maps a Windows system error code to a POSIX errno value
|
||||
/// sets errno and _doserrno as side effects
|
||||
void WIN32_maperror(unsigned long WIN32_oserrno);
|
||||
|
||||
#endif /* (_SQUID_WINDOWS_ || _SQUID_MINGW_) && !_SQUID_CYGWIN_ */
|
||||
|
||||
#endif /* SQUID_COMPAT_WIN32_MAPERROR_H */
|
@ -9,9 +9,11 @@
|
||||
/* DEBUG: section 43 Windows AIOPS */
|
||||
|
||||
#include "squid.h"
|
||||
#include "compat/win32_maperror.h"
|
||||
#include "DiskIO/DiskThreads/CommIO.h"
|
||||
#include "DiskThreads.h"
|
||||
#include "fd.h"
|
||||
#include "mem/Allocator.h"
|
||||
#include "mem/Pool.h"
|
||||
#include "SquidConfig.h"
|
||||
#include "Store.h"
|
||||
@ -108,7 +110,7 @@ static Mem::Allocator *squidaio_small_bufs = nullptr; /* 4K */
|
||||
static Mem::Allocator *squidaio_tiny_bufs = nullptr; /* 2K */
|
||||
static Mem::Allocator *squidaio_micro_bufs = nullptr; /* 128K */
|
||||
|
||||
static int request_queue_len = 0;
|
||||
static size_t request_queue_len = 0;
|
||||
static Mem::Allocator *squidaio_request_pool = nullptr;
|
||||
static Mem::Allocator *squidaio_thread_pool = nullptr;
|
||||
static squidaio_request_queue_t request_queue;
|
||||
@ -200,7 +202,6 @@ squidaio_xstrfree(char *str)
|
||||
void
|
||||
squidaio_init(void)
|
||||
{
|
||||
int i;
|
||||
squidaio_thread_t *threadp;
|
||||
|
||||
if (squidaio_initialised)
|
||||
@ -275,7 +276,7 @@ squidaio_init(void)
|
||||
|
||||
assert(NUMTHREADS > 0);
|
||||
|
||||
for (i = 0; i < NUMTHREADS; ++i) {
|
||||
for (size_t i = 0; i < NUMTHREADS; ++i) {
|
||||
threadp = (squidaio_thread_t *)squidaio_thread_pool->alloc();
|
||||
threadp->status = _THREAD_STARTING;
|
||||
threadp->current_req = nullptr;
|
||||
@ -319,7 +320,6 @@ void
|
||||
squidaio_shutdown(void)
|
||||
{
|
||||
squidaio_thread_t *threadp;
|
||||
int i;
|
||||
HANDLE * hthreads;
|
||||
|
||||
if (!squidaio_initialised)
|
||||
@ -334,7 +334,7 @@ squidaio_shutdown(void)
|
||||
|
||||
threadp = threads;
|
||||
|
||||
for (i = 0; i < NUMTHREADS; ++i) {
|
||||
for (size_t i = 0; i < NUMTHREADS; ++i) {
|
||||
threadp->exit = 1;
|
||||
hthreads[i] = threadp->thread;
|
||||
threadp = threadp->next;
|
||||
@ -348,7 +348,7 @@ squidaio_shutdown(void)
|
||||
|
||||
WaitForMultipleObjects(NUMTHREADS, hthreads, TRUE, 2000);
|
||||
|
||||
for (i = 0; i < NUMTHREADS; ++i) {
|
||||
for (size_t i = 0; i < NUMTHREADS; ++i) {
|
||||
CloseHandle(hthreads[i]);
|
||||
}
|
||||
|
||||
@ -589,7 +589,7 @@ squidaio_queue_request(squidaio_request_t * request)
|
||||
/* Warn if out of threads */
|
||||
if (request_queue_len > MAGIC1) {
|
||||
static int last_warn = 0;
|
||||
static int queue_high, queue_low;
|
||||
static size_t queue_high, queue_low;
|
||||
|
||||
if (high_start == 0) {
|
||||
high_start = (int)squid_curtime;
|
||||
@ -1099,7 +1099,6 @@ void
|
||||
squidaio_stats(StoreEntry * sentry)
|
||||
{
|
||||
squidaio_thread_t *threadp;
|
||||
int i;
|
||||
|
||||
if (!squidaio_initialised)
|
||||
return;
|
||||
@ -1110,8 +1109,8 @@ squidaio_stats(StoreEntry * sentry)
|
||||
|
||||
threadp = threads;
|
||||
|
||||
for (i = 0; i < NUMTHREADS; ++i) {
|
||||
storeAppendPrintf(sentry, "%i\t0x%lx\t%ld\n", i + 1, threadp->dwThreadId, threadp->requests);
|
||||
for (size_t i = 0; i < NUMTHREADS; ++i) {
|
||||
storeAppendPrintf(sentry, "%zu\t0x%lx\t%ld\n", i + 1, threadp->dwThreadId, threadp->requests);
|
||||
threadp = threadp->next;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user