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
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;
84 apr_os_level = APR_WIN_XP;
88 apr_os_level = APR_WIN_XP;
92 else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
94 if (prevision = oslev.szCSDVersion) {
95 while (*prevision && !apr_isupper(*prevision)) {
101 if (oslev.dwMinorVersion < 10) {
102 if (*prevision < 'C')
103 apr_os_level = APR_WIN_95;
105 apr_os_level = APR_WIN_95_OSR2;
107 else if (oslev.dwMinorVersion < 90) {
108 if (*prevision < 'A')
109 apr_os_level = APR_WIN_98;
111 apr_os_level = APR_WIN_98_SE;
114 apr_os_level = APR_WIN_ME;
119 else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_CE)
121 if (oslev.dwMajorVersion < 3) {
122 apr_os_level = APR_WIN_UNSUP;
125 apr_os_level = APR_WIN_CE_3;
130 apr_os_level = APR_WIN_UNSUP;
134 *level = apr_os_level;
136 if (apr_os_level < APR_WIN_UNSUP) {
144 /* This is the helper code to resolve late bound entry points
145 * missing from one or more releases of the Win32 API
148 static const char* const lateDllName[DLL_defined] = {
149 "kernel32", "advapi32", "mswsock", "ws2_32", "shell32", "ntdll.dll" };
150 static HMODULE lateDllHandle[DLL_defined] = {
151 NULL, NULL, NULL, NULL, NULL, NULL };
153 FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char* fnName, int ordinal)
155 if (!lateDllHandle[fnLib]) {
156 lateDllHandle[fnLib] = LoadLibrary(lateDllName[fnLib]);
157 if (!lateDllHandle[fnLib])
161 return GetProcAddress(lateDllHandle[fnLib], (char *) ordinal);
163 return GetProcAddress(lateDllHandle[fnLib], fnName);
166 /* Declared in include/arch/win32/apr_dbg_win32_handles.h
168 APR_DECLARE_NONSTD(HANDLE) apr_dbg_log(char* fn, HANDLE ha, char* fl, int ln,
169 int nh, /* HANDLE hv, char *dsc */...)
171 static DWORD tlsid = 0xFFFFFFFF;
172 static HANDLE fh = NULL;
174 static CRITICAL_SECTION cs;
179 seq = (InterlockedIncrement)(&ctr);
181 if (tlsid == 0xFFFFFFFF) {
182 tlsid = (TlsAlloc)();
185 sbuf = (TlsGetValue)(tlsid);
187 sbuf = (malloc)(1024);
188 (TlsSetValue)(tlsid, sbuf);
191 (GetModuleFileName)(NULL, sbuf, 250);
192 sprintf(strchr(sbuf, '\0'), ".%d",
193 (GetCurrentProcessId)());
194 fh = (CreateFile)(sbuf, GENERIC_WRITE, 0, NULL,
195 CREATE_ALWAYS, 0, NULL);
196 (InitializeCriticalSection)(&cs);
201 (sprintf)(sbuf, "%08x %08x %08x %s() %s:%d\n",
202 (DWORD)ha, seq, GetCurrentThreadId(), fn, fl, ln);
203 (EnterCriticalSection)(&cs);
204 (WriteFile)(fh, sbuf, strlen(sbuf), &wrote, NULL);
205 (LeaveCriticalSection)(&cs);
210 (EnterCriticalSection)(&cs);
212 HANDLE *hv = va_arg(a, HANDLE*);
213 char *dsc = va_arg(a, char*);
214 if (strcmp(dsc, "Signaled") == 0) {
215 if ((DWORD)ha >= STATUS_WAIT_0
216 && (DWORD)ha < STATUS_ABANDONED_WAIT_0) {
219 else if ((DWORD)ha >= STATUS_ABANDONED_WAIT_0
220 && (DWORD)ha < STATUS_USER_APC) {
221 hv += (DWORD)ha - STATUS_ABANDONED_WAIT_0;
224 else if ((DWORD)ha == WAIT_TIMEOUT) {
228 (sprintf)(sbuf, "%08x %08x %08x %s(%s) %s:%d\n",
229 (DWORD*)*hv, seq, GetCurrentThreadId(),
231 (WriteFile)(fh, sbuf, strlen(sbuf), &wrote, NULL);
233 (LeaveCriticalSection)(&cs);