Apache HTTPD
misc.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "apr_private.h"
18#include "apr_arch_misc.h"
19#include "apr_arch_file_io.h"
20#include "assert.h"
21#include "apr_lib.h"
22#include "tchar.h"
23
25
27{
29 {
31 oslev.dwOSVersionInfoSize = sizeof(oslev);
33 return apr_get_os_error();
34 }
35
36 if (oslev.dwPlatformId == VER_PLATFORM_WIN32_NT)
37 {
38 unsigned int servpack = oslev.wServicePackMajor;
39
40 if (oslev.dwMajorVersion < 3) {
42 }
43 else if (oslev.dwMajorVersion == 3) {
44 if (oslev.dwMajorVersion < 50) {
46 }
47 else if (oslev.dwMajorVersion == 50) {
49 }
50 else {
52 }
53 }
54 else if (oslev.dwMajorVersion == 4) {
55 if (servpack < 2)
57 else if (servpack <= 2)
59 else if (servpack <= 3)
61 else if (servpack <= 4)
63 else if (servpack <= 5)
65 else
67 }
68 else if (oslev.dwMajorVersion == 5) {
69 if (oslev.dwMinorVersion == 0) {
70 if (servpack == 0)
72 else if (servpack == 1)
74 else
76 }
77 else if (oslev.dwMinorVersion == 2) {
79 }
80 else {
81 if (servpack < 1)
83 else if (servpack == 1)
85 else
87 }
88 }
89 else if (oslev.dwMajorVersion == 6) {
90 if (oslev.dwMinorVersion == 0)
92 else if (oslev.dwMinorVersion == 1) {
93 if (servpack < 1)
95 else
97 }
98 else if (oslev.dwMinorVersion == 2)
100 else
102 }
103 else {
105 }
106 }
107#ifndef WINNT
108 else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
110 if (prevision = oslev.szCSDVersion) {
111 while (*prevision && !apr_isupper(*prevision)) {
112 prevision++;
113 }
114 }
115 else prevision = _T("");
116
117 if (oslev.dwMinorVersion < 10) {
118 if (*prevision < _T('C'))
120 else
122 }
123 else if (oslev.dwMinorVersion < 90) {
124 if (*prevision < _T('A'))
126 else
128 }
129 else {
131 }
132 }
133#endif
134#ifdef _WIN32_WCE
135 else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_CE)
136 {
137 if (oslev.dwMajorVersion < 3) {
139 }
140 else {
142 }
143 }
144#endif
145 else {
147 }
148 }
149
150 *level = apr_os_level;
151
153 return APR_EGENERAL;
154 }
155
156 return APR_SUCCESS;
157}
158
159
160/* This is the helper code to resolve late bound entry points
161 * missing from one or more releases of the Win32 API
162 */
163
168
170 {"kernel32", INVALID_HANDLE_VALUE},
171 {"advapi32", INVALID_HANDLE_VALUE},
172 {"mswsock", INVALID_HANDLE_VALUE},
173 {"ws2_32", INVALID_HANDLE_VALUE},
174 {"shell32", INVALID_HANDLE_VALUE},
175 {"ntdll.dll", INVALID_HANDLE_VALUE},
176 {"Iphplapi", INVALID_HANDLE_VALUE}
177};
178
180{
183
184 /* Pointer sized reads are atomic on Windows. */
187 HMODULE dll_handle = NULL;
188
189 dll_handle = LoadLibrary(dll->dll_name);
190
192 dll_handle,
195 cached_dll_handle = dll_handle;
196 }
197 else if (dll_handle) {
198 /* Other thread won the race: release our library handle. */
199 FreeLibrary(dll_handle);
200 }
201 }
202
203 if (!cached_dll_handle) {
204 return NULL;
205 }
206
207#if defined(_WIN32_WCE)
208 if (ordinal)
210 (const char *) (apr_ssize_t)ordinal);
211 else
213#else
214 if (ordinal)
216 (const char *) (apr_ssize_t)ordinal);
217 else
219#endif
220}
221
222/* Declared in include/arch/win32/apr_dbg_win32_handles.h
223 */
225 int nh, /* HANDLE hv, char *dsc */...)
226{
227 static DWORD tlsid = 0xFFFFFFFF;
228 static HANDLE fh = NULL;
229 static long ctr = 0;
230 static CRITICAL_SECTION cs;
231 long seq;
232 DWORD wrote;
233 char *sbuf;
234
236
237 if (tlsid == 0xFFFFFFFF) {
238 tlsid = (TlsAlloc)();
239 }
240
242 if (!fh || !sbuf) {
243 sbuf = (malloc)(1024);
245 sbuf[1023] = '\0';
246 if (!fh) {
248 sprintf(strchr(sbuf, '\0'), ".%u",
249 (unsigned int)(GetCurrentProcessId)());
251 CREATE_ALWAYS, 0, NULL);
253 }
254 }
255
256 if (!nh) {
257 (sprintf)(sbuf, "%p %08x %08x %s() %s:%d\n",
258 ha, (unsigned int)seq, (unsigned int)GetCurrentThreadId(),
259 fn, fl, ln);
261 (WriteFile)(fh, sbuf, (DWORD)strlen(sbuf), &wrote, NULL);
263 }
264 else {
265 va_list a;
266 va_start(a,nh);
268 do {
269 HANDLE *hv = va_arg(a, HANDLE*);
270 char *dsc = va_arg(a, char*);
271 if (strcmp(dsc, "Signaled") == 0) {
274 hv += (apr_ssize_t)ha;
275 }
279 dsc = "Abandoned";
280 }
281 else if ((apr_ssize_t)ha == WAIT_TIMEOUT) {
282 dsc = "Timed Out";
283 }
284 }
285 (sprintf)(sbuf, "%p %08x %08x %s(%s) %s:%d\n",
286 *hv, (unsigned int)seq,
287 (unsigned int)GetCurrentThreadId(),
288 fn, dsc, fl, ln);
289 (WriteFile)(fh, sbuf, (DWORD)strlen(sbuf), &wrote, NULL);
290 } while (--nh);
292 va_end(a);
293 }
294 return ha;
295}
HANDLE char int ln
HANDLE char int int nh
#define CreateFileA(nm, d1, d2, sd, d3, d4, h)
HANDLE ha
HANDLE char * fl
APR general purpose library routines.
#define APR_EGENERAL
Definition apr_errno.h:313
apr_bucket apr_bucket_brigade * a
apr_size_t size
#define apr_isupper(c)
Definition apr_lib.h:227
#define APR_SUCCESS
Definition apr_errno.h:225
#define apr_get_os_error()
Definition apr_errno.h:1217
int apr_status_t
Definition apr_errno.h:44
APR_DECLARE_NONSTD(void) apr_terminate(void)
Definition start.c:173
APR_DECLARE_DATA apr_oslevel_e apr_os_level
Definition misc.c:24
FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char *fnName, int ordinal)
Definition misc.c:179
static win32_late_dll_t late_dll[DLL_defined]
Definition misc.c:169
apr_status_t apr_get_oslevel(apr_oslevel_e *level)
Definition misc.c:26
return NULL
Definition mod_so.c:359
volatile HMODULE dll_handle
Definition misc.c:166
const char * dll_name
Definition misc.c:165
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray
typedef HANDLE(WINAPI *apr_winapi_fpt_CreateToolhelp32Snapshot)(DWORD dwFlags
apr_dlltoken_e
@ DLL_defined
apr_oslevel_e
@ APR_WIN_ME
@ APR_WIN_NT_4_SP4
@ APR_WIN_95
@ APR_WIN_8
@ APR_WIN_VISTA
@ APR_WIN_2000_SP2
@ APR_WIN_95_OSR2
@ APR_WIN_8_1
@ APR_WIN_NT_4_SP5
@ APR_WIN_98
@ APR_WIN_NT_4
@ APR_WIN_CE_3
@ APR_WIN_NT_3_5
@ APR_WIN_10
@ APR_WIN_7_SP1
@ APR_WIN_NT_4_SP2
@ APR_WIN_NT_4_SP3
@ APR_WIN_2003
@ APR_WIN_98_SE
@ APR_WIN_2000_SP1
@ APR_WIN_7
@ APR_WIN_UNK
@ APR_WIN_XP_SP1
@ APR_WIN_2000
@ APR_WIN_NT_4_SP6
@ APR_WIN_UNSUP
@ APR_WIN_XP
@ APR_WIN_NT_3_51
@ APR_WIN_XP_SP2
typedef DWORD(WINAPI *apr_winapi_fpt_GetCompressedFileSizeA)(IN LPCSTR lpFileName