Skip to content

Commit 084949b

Browse files
authored
Merge branch 'master' into update-mingw-16
2 parents 2044bce + 84bb09a commit 084949b

File tree

5 files changed

+119
-92
lines changed

5 files changed

+119
-92
lines changed

compat/mswindows.cc

+1-79
Original file line numberDiff line numberDiff line change
@@ -183,83 +183,6 @@ getgrnam(char *unused) {
183183
return &grp;
184184
}
185185

186-
struct errorentry {
187-
unsigned long WIN32_code;
188-
int POSIX_errno;
189-
};
190-
191-
static struct errorentry errortable[] = {
192-
{ERROR_INVALID_FUNCTION, EINVAL},
193-
{ERROR_FILE_NOT_FOUND, ENOENT},
194-
{ERROR_PATH_NOT_FOUND, ENOENT},
195-
{ERROR_TOO_MANY_OPEN_FILES, EMFILE},
196-
{ERROR_ACCESS_DENIED, EACCES},
197-
{ERROR_INVALID_HANDLE, EBADF},
198-
{ERROR_ARENA_TRASHED, ENOMEM},
199-
{ERROR_NOT_ENOUGH_MEMORY, ENOMEM},
200-
{ERROR_INVALID_BLOCK, ENOMEM},
201-
{ERROR_BAD_ENVIRONMENT, E2BIG},
202-
{ERROR_BAD_FORMAT, ENOEXEC},
203-
{ERROR_INVALID_ACCESS, EINVAL},
204-
{ERROR_INVALID_DATA, EINVAL},
205-
{ERROR_INVALID_DRIVE, ENOENT},
206-
{ERROR_CURRENT_DIRECTORY, EACCES},
207-
{ERROR_NOT_SAME_DEVICE, EXDEV},
208-
{ERROR_NO_MORE_FILES, ENOENT},
209-
{ERROR_LOCK_VIOLATION, EACCES},
210-
{ERROR_BAD_NETPATH, ENOENT},
211-
{ERROR_NETWORK_ACCESS_DENIED, EACCES},
212-
{ERROR_BAD_NET_NAME, ENOENT},
213-
{ERROR_FILE_EXISTS, EEXIST},
214-
{ERROR_CANNOT_MAKE, EACCES},
215-
{ERROR_FAIL_I24, EACCES},
216-
{ERROR_INVALID_PARAMETER, EINVAL},
217-
{ERROR_NO_PROC_SLOTS, EAGAIN},
218-
{ERROR_DRIVE_LOCKED, EACCES},
219-
{ERROR_BROKEN_PIPE, EPIPE},
220-
{ERROR_DISK_FULL, ENOSPC},
221-
{ERROR_INVALID_TARGET_HANDLE, EBADF},
222-
{ERROR_INVALID_HANDLE, EINVAL},
223-
{ERROR_WAIT_NO_CHILDREN, ECHILD},
224-
{ERROR_CHILD_NOT_COMPLETE, ECHILD},
225-
{ERROR_DIRECT_ACCESS_HANDLE, EBADF},
226-
{ERROR_NEGATIVE_SEEK, EINVAL},
227-
{ERROR_SEEK_ON_DEVICE, EACCES},
228-
{ERROR_DIR_NOT_EMPTY, ENOTEMPTY},
229-
{ERROR_NOT_LOCKED, EACCES},
230-
{ERROR_BAD_PATHNAME, ENOENT},
231-
{ERROR_MAX_THRDS_REACHED, EAGAIN},
232-
{ERROR_LOCK_FAILED, EACCES},
233-
{ERROR_ALREADY_EXISTS, EEXIST},
234-
{ERROR_FILENAME_EXCED_RANGE, ENOENT},
235-
{ERROR_NESTING_NOT_ALLOWED, EAGAIN},
236-
{ERROR_NOT_ENOUGH_QUOTA, ENOMEM}
237-
};
238-
239-
#define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG
240-
#define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN
241-
242-
#define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
243-
#define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
244-
245-
void
246-
WIN32_maperror(unsigned long WIN32_oserrno)
247-
{
248-
_doserrno = WIN32_oserrno;
249-
for (size_t i = 0; i < (sizeof(errortable) / sizeof(struct errorentry)); ++i) {
250-
if (WIN32_oserrno == errortable[i].WIN32_code) {
251-
errno = errortable[i].POSIX_errno;
252-
return;
253-
}
254-
}
255-
if (WIN32_oserrno >= MIN_EACCES_RANGE && WIN32_oserrno <= MAX_EACCES_RANGE)
256-
errno = EACCES;
257-
else if (WIN32_oserrno >= MIN_EXEC_ERROR && WIN32_oserrno <= MAX_EXEC_ERROR)
258-
errno = ENOEXEC;
259-
else
260-
errno = EINVAL;
261-
}
262-
263186
/* syslog emulation layer derived from git */
264187
static HANDLE ms_eventlog;
265188

@@ -322,5 +245,4 @@ syslog(int priority, const char *fmt, ...)
322245
}
323246

324247
/* note: this is all MSWindows-specific code; all of it should be conditional */
325-
#endif /* _SQUID_WINDOWS_ */
326-
248+
#endif /* _SQUID_WINDOWS_ && !_SQUID_CYGWIN_*/

compat/os/mswindows.h

-3
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,6 @@ void openlog(const char *ident, int logopt, int facility);
893893
void syslog(int priority, const char *fmt, ...);
894894
#endif
895895

896-
/* prototypes */
897-
void WIN32_maperror(unsigned long WIN32_oserrno);
898-
899896
#endif /* _SQUID_WINDOWS_ */
900897
#endif /* SQUID_COMPAT_OS_MSWINDOWS_H */
901898

compat/win32_maperror.cc

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3+
*
4+
* Squid software is distributed under GPLv2+ license and includes
5+
* contributions from numerous individuals and organizations.
6+
* Please see the COPYING and CONTRIBUTORS files for details.
7+
*/
8+
9+
#include "squid.h"
10+
#include "compat/win32_maperror.h"
11+
12+
#if (_SQUID_WINDOWS_ || _SQUID_MINGW_) && !_SQUID_CYGWIN_
13+
14+
#if HAVE_WINDOWS_H
15+
#include <windows.h>
16+
#endif
17+
#include <cstdlib>
18+
#include <unordered_map>
19+
20+
void
21+
WIN32_maperror(unsigned long WIN32_oserrno)
22+
{
23+
static const auto errormap = new std::unordered_map<unsigned long, int> {
24+
{ERROR_INVALID_FUNCTION, EINVAL},
25+
{ERROR_FILE_NOT_FOUND, ENOENT},
26+
{ERROR_PATH_NOT_FOUND, ENOENT},
27+
{ERROR_TOO_MANY_OPEN_FILES, EMFILE},
28+
{ERROR_ACCESS_DENIED, EACCES},
29+
{ERROR_INVALID_HANDLE, EBADF},
30+
{ERROR_ARENA_TRASHED, ENOMEM},
31+
{ERROR_NOT_ENOUGH_MEMORY, ENOMEM},
32+
{ERROR_INVALID_BLOCK, ENOMEM},
33+
{ERROR_BAD_ENVIRONMENT, E2BIG},
34+
{ERROR_BAD_FORMAT, ENOEXEC},
35+
{ERROR_INVALID_ACCESS, EINVAL},
36+
{ERROR_INVALID_DATA, EINVAL},
37+
{ERROR_INVALID_DRIVE, ENOENT},
38+
{ERROR_CURRENT_DIRECTORY, EACCES},
39+
{ERROR_NOT_SAME_DEVICE, EXDEV},
40+
{ERROR_NO_MORE_FILES, ENOENT},
41+
{ERROR_LOCK_VIOLATION, EACCES},
42+
{ERROR_BAD_NETPATH, ENOENT},
43+
{ERROR_NETWORK_ACCESS_DENIED, EACCES},
44+
{ERROR_BAD_NET_NAME, ENOENT},
45+
{ERROR_FILE_EXISTS, EEXIST},
46+
{ERROR_CANNOT_MAKE, EACCES},
47+
{ERROR_FAIL_I24, EACCES},
48+
{ERROR_INVALID_PARAMETER, EINVAL},
49+
{ERROR_NO_PROC_SLOTS, EAGAIN},
50+
{ERROR_DRIVE_LOCKED, EACCES},
51+
{ERROR_BROKEN_PIPE, EPIPE},
52+
{ERROR_DISK_FULL, ENOSPC},
53+
{ERROR_INVALID_TARGET_HANDLE, EBADF},
54+
{ERROR_INVALID_HANDLE, EINVAL},
55+
{ERROR_WAIT_NO_CHILDREN, ECHILD},
56+
{ERROR_CHILD_NOT_COMPLETE, ECHILD},
57+
{ERROR_DIRECT_ACCESS_HANDLE, EBADF},
58+
{ERROR_NEGATIVE_SEEK, EINVAL},
59+
{ERROR_SEEK_ON_DEVICE, EACCES},
60+
{ERROR_DIR_NOT_EMPTY, ENOTEMPTY},
61+
{ERROR_NOT_LOCKED, EACCES},
62+
{ERROR_BAD_PATHNAME, ENOENT},
63+
{ERROR_MAX_THRDS_REACHED, EAGAIN},
64+
{ERROR_LOCK_FAILED, EACCES},
65+
{ERROR_ALREADY_EXISTS, EEXIST},
66+
{ERROR_FILENAME_EXCED_RANGE, ENOENT},
67+
{ERROR_NESTING_NOT_ALLOWED, EAGAIN},
68+
{ERROR_NOT_ENOUGH_QUOTA, ENOMEM}
69+
};
70+
_set_doserrno(WIN32_oserrno);
71+
const auto it = errormap->find(WIN32_oserrno);
72+
if (it != errormap->end()) {
73+
errno = it->second;
74+
return;
75+
}
76+
const auto min_exec_error = ERROR_INVALID_STARTING_CODESEG;
77+
const auto max_exec_error = ERROR_INFLOOP_IN_RELOC_CHAIN;
78+
const auto min_eaccess_range = ERROR_WRITE_PROTECT;
79+
const auto max_eaccess_range = ERROR_SHARING_BUFFER_EXCEEDED;
80+
81+
if (min_eaccess_range <= WIN32_oserrno && WIN32_oserrno <= max_eaccess_range)
82+
errno = EACCES;
83+
else if (min_exec_error <= WIN32_oserrno && WIN32_oserrno <= max_exec_error)
84+
errno = ENOEXEC;
85+
else
86+
errno = EINVAL;
87+
}
88+
89+
#endif /* (_SQUID_WINDOWS_ || _SQUID_MINGW_) && !_SQUID_CYGWIN_ */

compat/win32_maperror.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3+
*
4+
* Squid software is distributed under GPLv2+ license and includes
5+
* contributions from numerous individuals and organizations.
6+
* Please see the COPYING and CONTRIBUTORS files for details.
7+
*/
8+
9+
#ifndef SQUID_COMPAT_WIN32_MAPERROR_H
10+
#define SQUID_COMPAT_WIN32_MAPERROR_H
11+
12+
#if (_SQUID_WINDOWS_ || _SQUID_MINGW_) && !_SQUID_CYGWIN_
13+
14+
/// maps a Windows system error code to a POSIX errno value
15+
/// sets errno and _doserrno as side effects
16+
void WIN32_maperror(unsigned long WIN32_oserrno);
17+
18+
#endif /* (_SQUID_WINDOWS_ || _SQUID_MINGW_) && !_SQUID_CYGWIN_ */
19+
20+
#endif /* SQUID_COMPAT_WIN32_MAPERROR_H */

src/DiskIO/DiskThreads/aiops_win32.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
/* DEBUG: section 43 Windows AIOPS */
1010

1111
#include "squid.h"
12+
#include "compat/win32_maperror.h"
1213
#include "DiskIO/DiskThreads/CommIO.h"
1314
#include "DiskThreads.h"
1415
#include "fd.h"
16+
#include "mem/Allocator.h"
1517
#include "mem/Pool.h"
1618
#include "SquidConfig.h"
1719
#include "Store.h"
@@ -108,7 +110,7 @@ static Mem::Allocator *squidaio_small_bufs = nullptr; /* 4K */
108110
static Mem::Allocator *squidaio_tiny_bufs = nullptr; /* 2K */
109111
static Mem::Allocator *squidaio_micro_bufs = nullptr; /* 128K */
110112

111-
static int request_queue_len = 0;
113+
static size_t request_queue_len = 0;
112114
static Mem::Allocator *squidaio_request_pool = nullptr;
113115
static Mem::Allocator *squidaio_thread_pool = nullptr;
114116
static squidaio_request_queue_t request_queue;
@@ -200,7 +202,6 @@ squidaio_xstrfree(char *str)
200202
void
201203
squidaio_init(void)
202204
{
203-
int i;
204205
squidaio_thread_t *threadp;
205206

206207
if (squidaio_initialised)
@@ -275,7 +276,7 @@ squidaio_init(void)
275276

276277
assert(NUMTHREADS > 0);
277278

278-
for (i = 0; i < NUMTHREADS; ++i) {
279+
for (size_t i = 0; i < NUMTHREADS; ++i) {
279280
threadp = (squidaio_thread_t *)squidaio_thread_pool->alloc();
280281
threadp->status = _THREAD_STARTING;
281282
threadp->current_req = nullptr;
@@ -319,7 +320,6 @@ void
319320
squidaio_shutdown(void)
320321
{
321322
squidaio_thread_t *threadp;
322-
int i;
323323
HANDLE * hthreads;
324324

325325
if (!squidaio_initialised)
@@ -334,7 +334,7 @@ squidaio_shutdown(void)
334334

335335
threadp = threads;
336336

337-
for (i = 0; i < NUMTHREADS; ++i) {
337+
for (size_t i = 0; i < NUMTHREADS; ++i) {
338338
threadp->exit = 1;
339339
hthreads[i] = threadp->thread;
340340
threadp = threadp->next;
@@ -348,7 +348,7 @@ squidaio_shutdown(void)
348348

349349
WaitForMultipleObjects(NUMTHREADS, hthreads, TRUE, 2000);
350350

351-
for (i = 0; i < NUMTHREADS; ++i) {
351+
for (size_t i = 0; i < NUMTHREADS; ++i) {
352352
CloseHandle(hthreads[i]);
353353
}
354354

@@ -589,7 +589,7 @@ squidaio_queue_request(squidaio_request_t * request)
589589
/* Warn if out of threads */
590590
if (request_queue_len > MAGIC1) {
591591
static int last_warn = 0;
592-
static int queue_high, queue_low;
592+
static size_t queue_high, queue_low;
593593

594594
if (high_start == 0) {
595595
high_start = (int)squid_curtime;
@@ -1099,7 +1099,6 @@ void
10991099
squidaio_stats(StoreEntry * sentry)
11001100
{
11011101
squidaio_thread_t *threadp;
1102-
int i;
11031102

11041103
if (!squidaio_initialised)
11051104
return;
@@ -1110,8 +1109,8 @@ squidaio_stats(StoreEntry * sentry)
11101109

11111110
threadp = threads;
11121111

1113-
for (i = 0; i < NUMTHREADS; ++i) {
1114-
storeAppendPrintf(sentry, "%i\t0x%lx\t%ld\n", i + 1, threadp->dwThreadId, threadp->requests);
1112+
for (size_t i = 0; i < NUMTHREADS; ++i) {
1113+
storeAppendPrintf(sentry, "%zu\t0x%lx\t%ld\n", i + 1, threadp->dwThreadId, threadp->requests);
11151114
threadp = threadp->next;
11161115
}
11171116
}

0 commit comments

Comments
 (0)