1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
#include "apr_private.h"
18
#include "apr_arch_misc.h"
20
#include "apr_arch_file_io.h"
24
APR_DECLARE_DATA apr_oslevel_e apr_os_level = APR_WIN_UNK;
26
apr_status_t apr_get_oslevel(apr_oslevel_e *level)
28
if (apr_os_level == APR_WIN_UNK)
30
static OSVERSIONINFO oslev;
31
oslev.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
34
if (oslev.dwPlatformId == VER_PLATFORM_WIN32_NT)
36
static unsigned int servpack = 0;
38
if (pservpack = oslev.szCSDVersion) {
39
while (*pservpack && !apr_isdigit(*pservpack)) {
43
servpack = atoi(pservpack);
46
if (oslev.dwMajorVersion < 3) {
47
apr_os_level = APR_WIN_UNSUP;
49
else if (oslev.dwMajorVersion == 3) {
50
if (oslev.dwMajorVersion < 50) {
51
apr_os_level = APR_WIN_UNSUP;
53
else if (oslev.dwMajorVersion == 50) {
54
apr_os_level = APR_WIN_NT_3_5;
57
apr_os_level = APR_WIN_NT_3_51;
60
else if (oslev.dwMajorVersion == 4) {
62
apr_os_level = APR_WIN_NT_4;
63
else if (servpack <= 2)
64
apr_os_level = APR_WIN_NT_4_SP2;
65
else if (servpack <= 3)
66
apr_os_level = APR_WIN_NT_4_SP3;
67
else if (servpack <= 4)
68
apr_os_level = APR_WIN_NT_4_SP4;
69
else if (servpack <= 5)
70
apr_os_level = APR_WIN_NT_4_SP5;
72
apr_os_level = APR_WIN_NT_4_SP6;
74
else if (oslev.dwMajorVersion == 5) {
75
if (oslev.dwMinorVersion == 0) {
77
apr_os_level = APR_WIN_2000;
78
else if (servpack == 1)
79
apr_os_level = APR_WIN_2000_SP1;
81
apr_os_level = APR_WIN_2000_SP2;
83
else if (oslev.dwMinorVersion == 2) {
84
apr_os_level = APR_WIN_2003;
88
apr_os_level = APR_WIN_XP;
89
else if (servpack == 1)
90
apr_os_level = APR_WIN_XP_SP1;
92
apr_os_level = APR_WIN_XP_SP2;
96
apr_os_level = APR_WIN_XP;
100
else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
102
if (prevision = oslev.szCSDVersion) {
103
while (*prevision && !apr_isupper(*prevision)) {
109
if (oslev.dwMinorVersion < 10) {
110
if (*prevision < 'C')
111
apr_os_level = APR_WIN_95;
113
apr_os_level = APR_WIN_95_OSR2;
115
else if (oslev.dwMinorVersion < 90) {
116
if (*prevision < 'A')
117
apr_os_level = APR_WIN_98;
119
apr_os_level = APR_WIN_98_SE;
122
apr_os_level = APR_WIN_ME;
127
else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_CE)
129
if (oslev.dwMajorVersion < 3) {
130
apr_os_level = APR_WIN_UNSUP;
133
apr_os_level = APR_WIN_CE_3;
138
apr_os_level = APR_WIN_UNSUP;
142
*level = apr_os_level;
144
if (apr_os_level < APR_WIN_UNSUP) {
152
/* This is the helper code to resolve late bound entry points
153
* missing from one or more releases of the Win32 API
156
static const char* const lateDllName[DLL_defined] = {
157
"kernel32", "advapi32", "mswsock", "ws2_32", "shell32", "ntdll.dll" };
158
static HMODULE lateDllHandle[DLL_defined] = {
159
NULL, NULL, NULL, NULL, NULL, NULL };
161
FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char* fnName, int ordinal)
163
if (!lateDllHandle[fnLib]) {
164
lateDllHandle[fnLib] = LoadLibrary(lateDllName[fnLib]);
165
if (!lateDllHandle[fnLib])
169
return GetProcAddress(lateDllHandle[fnLib], (char *) ordinal);
171
return GetProcAddress(lateDllHandle[fnLib], fnName);
174
/* Declared in include/arch/win32/apr_dbg_win32_handles.h
176
APR_DECLARE_NONSTD(HANDLE) apr_dbg_log(char* fn, HANDLE ha, char* fl, int ln,
177
int nh, /* HANDLE hv, char *dsc */...)
179
static DWORD tlsid = 0xFFFFFFFF;
180
static HANDLE fh = NULL;
182
static CRITICAL_SECTION cs;
187
seq = (InterlockedIncrement)(&ctr);
189
if (tlsid == 0xFFFFFFFF) {
190
tlsid = (TlsAlloc)();
193
sbuf = (TlsGetValue)(tlsid);
195
sbuf = (malloc)(1024);
196
(TlsSetValue)(tlsid, sbuf);
199
(GetModuleFileName)(NULL, sbuf, 250);
200
sprintf(strchr(sbuf, '\0'), ".%d",
201
(GetCurrentProcessId)());
202
fh = (CreateFile)(sbuf, GENERIC_WRITE, 0, NULL,
203
CREATE_ALWAYS, 0, NULL);
204
(InitializeCriticalSection)(&cs);
209
(sprintf)(sbuf, "%08x %08x %08x %s() %s:%d\n",
210
(DWORD)ha, seq, GetCurrentThreadId(), fn, fl, ln);
211
(EnterCriticalSection)(&cs);
212
(WriteFile)(fh, sbuf, (DWORD)strlen(sbuf), &wrote, NULL);
213
(LeaveCriticalSection)(&cs);
218
(EnterCriticalSection)(&cs);
220
HANDLE *hv = va_arg(a, HANDLE*);
221
char *dsc = va_arg(a, char*);
222
if (strcmp(dsc, "Signaled") == 0) {
223
if ((DWORD)ha >= STATUS_WAIT_0
224
&& (DWORD)ha < STATUS_ABANDONED_WAIT_0) {
227
else if ((DWORD)ha >= STATUS_ABANDONED_WAIT_0
228
&& (DWORD)ha < STATUS_USER_APC) {
229
hv += (DWORD)ha - STATUS_ABANDONED_WAIT_0;
232
else if ((DWORD)ha == WAIT_TIMEOUT) {
236
(sprintf)(sbuf, "%08x %08x %08x %s(%s) %s:%d\n",
237
(DWORD*)*hv, seq, GetCurrentThreadId(),
239
(WriteFile)(fh, sbuf, (DWORD)strlen(sbuf), &wrote, NULL);
241
(LeaveCriticalSection)(&cs);