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.
21 #include "apr_portable.h"
22 #include "apr_private.h"
23 #include "apr_general.h"
24 #include "apr_pools.h"
25 #include "apr_getopt.h"
26 #include "apr_thread_proc.h"
27 #include "apr_file_io.h"
28 #include "apr_errno.h"
29 #include "apr_getopt.h"
37 #if APR_HAVE_PTHREAD_H
41 /* ### create APR_HAVE_* macros for these? */
49 struct apr_other_child_rec_t {
51 struct apr_other_child_rec_t *next;
53 void (*maintenance) (int, void *, int);
55 apr_os_file_t write_fd;
61 /* start.c and apr_app.c helpers and communication within misc.c
63 * They are not for public consumption, although apr_app_init_complete
64 * must be an exported symbol to avoid reinitialization.
66 extern int APR_DECLARE_DATA apr_app_init_complete;
68 int apr_wastrtoastr(char const * const * *retarr,
69 wchar_t const * const *arr, int args);
71 /* Platform specific designation of run time os version.
72 * Gaps allow for specific service pack levels that
73 * export new kernel or winsock functions or behavior.
85 APR_WIN_UNICODE = 20, /* Prior versions support only narrow chars */
87 APR_WIN_CE_3 = 23, /* CE is an odd beast, not supporting */
88 /* some pre-NT features, such as the */
89 APR_WIN_NT = 30, /* narrow charset APIs (fooA fns), while */
90 APR_WIN_NT_3_5 = 35, /* not supporting some NT-family features. */
94 APR_WIN_NT_4_SP2 = 42,
95 APR_WIN_NT_4_SP3 = 43,
96 APR_WIN_NT_4_SP4 = 44,
97 APR_WIN_NT_4_SP5 = 45,
98 APR_WIN_NT_4_SP6 = 46,
101 APR_WIN_2000_SP1 = 51,
102 APR_WIN_2000_SP2 = 52,
106 extern APR_DECLARE_DATA apr_oslevel_e apr_os_level;
108 apr_status_t apr_get_oslevel(apr_oslevel_e *);
110 /* The APR_HAS_ANSI_FS symbol is PRIVATE, and internal to APR.
111 * APR only supports char data for filenames. Like most applications,
112 * characters >127 are essentially undefined. APR_HAS_UNICODE_FS lets
113 * the application know that utf-8 is the encoding method of APR, and
114 * only incidently hints that we have Wide OS calls.
116 * APR_HAS_ANSI_FS is simply an OS flag to tell us all calls must be
117 * the unicode eqivilant.
120 #if defined(_WIN32_WCE) || defined(WINNT)
121 #define APR_HAS_ANSI_FS 0
123 #define APR_HAS_ANSI_FS 1
126 /* IF_WIN_OS_IS_UNICODE / ELSE_WIN_OS_IS_ANSI help us keep the code trivial
127 * where have runtime tests for unicode-ness, that aren't needed in any
128 * build which supports only WINNT or WCE.
130 #if APR_HAS_ANSI_FS && APR_HAS_UNICODE_FS
131 #define IF_WIN_OS_IS_UNICODE if (apr_os_level >= APR_WIN_UNICODE)
132 #define ELSE_WIN_OS_IS_ANSI else
133 #else /* APR_HAS_UNICODE_FS */
134 #define IF_WIN_OS_IS_UNICODE
135 #define ELSE_WIN_OS_IS_ANSI
139 DLL_WINBASEAPI = 0, // kernel32 From WinBase.h
140 DLL_WINADVAPI = 1, // advapi32 From WinBase.h
141 DLL_WINSOCKAPI = 2, // mswsock From WinSock.h
142 DLL_WINSOCK2API = 3, // ws2_32 From WinSock2.h
143 DLL_SHSTDAPI = 4, // shell32 From ShellAPI.h
144 DLL_NTDLL = 5, // shell32 From our real kernel
145 DLL_defined = 6 // must define as last idx_ + 1
148 FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char *fnName, int ordinal);
150 /* The apr_load_dll_func call WILL fault if the function cannot be loaded */
152 #define APR_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
153 typedef rettype (calltype *apr_winapi_fpt_##fn) args; \
154 static apr_winapi_fpt_##fn apr_winapi_pfn_##fn = NULL; \
155 __inline rettype apr_winapi_##fn args \
156 { if (!apr_winapi_pfn_##fn) \
157 apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) \
158 apr_load_dll_func(lib, #fn, ord); \
159 return (*(apr_winapi_pfn_##fn)) names; }; \
161 /* Provide late bound declarations of every API function missing from
162 * one or more supported releases of the Win32 API
164 * lib is the enumerated token from apr_dlltoken_e, and must correspond
165 * to the string table entry in start.c used by the apr_load_dll_func().
166 * Token names (attempt to) follow Windows.h declarations prefixed by DLL_
167 * in order to facilitate comparison. Use the exact declaration syntax
168 * and names from Windows.h to prevent ambigutity and bugs.
170 * rettype and calltype follow the original declaration in Windows.h
171 * fn is the true function name - beware Ansi/Unicode #defined macros
172 * ord is the ordinal within the library, use 0 if it varies between versions
173 * args is the parameter list following the original declaration, in parens
174 * names is the parameter list sans data types, enclosed in parens
176 * #undef/re#define the Ansi/Unicode generic name to abate confusion
177 * In the case of non-text functions, simply #define the original name
180 #if !defined(_WIN32_WCE) && !defined(WINNT)
182 #ifdef GetFileAttributesExA
183 #undef GetFileAttributesExA
185 APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, GetFileAttributesExA, 0, (
186 IN LPCSTR lpFileName,
187 IN GET_FILEEX_INFO_LEVELS fInfoLevelId,
188 OUT LPVOID lpFileInformation),
189 (lpFileName, fInfoLevelId, lpFileInformation));
190 #define GetFileAttributesExA apr_winapi_GetFileAttributesExA
191 #undef GetFileAttributesEx
192 #define GetFileAttributesEx apr_winapi_GetFileAttributesExA
194 #ifdef GetFileAttributesExW
195 #undef GetFileAttributesExW
197 APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, GetFileAttributesExW, 0, (
198 IN LPCWSTR lpFileName,
199 IN GET_FILEEX_INFO_LEVELS fInfoLevelId,
200 OUT LPVOID lpFileInformation),
201 (lpFileName, fInfoLevelId, lpFileInformation));
202 #define GetFileAttributesExW apr_winapi_GetFileAttributesExW
204 APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, CancelIo, 0, (
207 #define CancelIo apr_winapi_CancelIo
209 APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, TryEnterCriticalSection, 0, (
210 LPCRITICAL_SECTION lpCriticalSection),
211 (lpCriticalSection));
212 #define TryEnterCriticalSection apr_winapi_TryEnterCriticalSection
214 APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, SwitchToThread, 0, (
217 #define SwitchToThread apr_winapi_SwitchToThread
219 APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetEffectiveRightsFromAclW, 0, (
221 IN PTRUSTEE_W pTrustee,
222 OUT PACCESS_MASK pAccessRights),
223 (pacl, pTrustee, pAccessRights));
224 #define GetEffectiveRightsFromAclW apr_winapi_GetEffectiveRightsFromAclW
226 APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetNamedSecurityInfoW, 0, (
227 IN LPWSTR pObjectName,
228 IN SE_OBJECT_TYPE ObjectType,
229 IN SECURITY_INFORMATION SecurityInfo,
230 OUT PSID *ppsidOwner,
231 OUT PSID *ppsidGroup,
234 OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor),
235 (pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup,
236 ppDacl, ppSacl, ppSecurityDescriptor));
237 #define GetNamedSecurityInfoW apr_winapi_GetNamedSecurityInfoW
239 APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetNamedSecurityInfoA, 0, (
240 IN LPSTR pObjectName,
241 IN SE_OBJECT_TYPE ObjectType,
242 IN SECURITY_INFORMATION SecurityInfo,
243 OUT PSID *ppsidOwner,
244 OUT PSID *ppsidGroup,
247 OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor),
248 (pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup,
249 ppDacl, ppSacl, ppSecurityDescriptor));
250 #define GetNamedSecurityInfoA apr_winapi_GetNamedSecurityInfoA
251 #undef GetNamedSecurityInfo
252 #define GetNamedSecurityInfo apr_winapi_GetNamedSecurityInfoA
254 APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetSecurityInfo, 0, (
256 IN SE_OBJECT_TYPE ObjectType,
257 IN SECURITY_INFORMATION SecurityInfo,
258 OUT PSID *ppsidOwner,
259 OUT PSID *ppsidGroup,
262 OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor),
263 (handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup,
264 ppDacl, ppSacl, ppSecurityDescriptor));
265 #define GetSecurityInfo apr_winapi_GetSecurityInfo
267 APR_DECLARE_LATE_DLL_FUNC(DLL_SHSTDAPI, LPWSTR *, WINAPI, CommandLineToArgvW, 0, (
270 (lpCmdLine, pNumArgs));
271 #define CommandLineToArgvW apr_winapi_CommandLineToArgvW
273 #endif /* !defined(_WIN32_WCE) && !defined(WINNT) */
275 #if !defined(_WIN32_WCE)
277 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryTimerResolution, 0, (
278 ULONG *pMaxRes, /* Minimum NS Resolution */
279 ULONG *pMinRes, /* Maximum NS Resolution */
280 ULONG *pCurRes), /* Current NS Resolution */
281 (pMaxRes, pMinRes, pCurRes));
282 #define QueryTimerResolution apr_winapi_NtQueryTimerResolution
284 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtSetTimerResolution, 0, (
285 ULONG ReqRes, /* Requested NS Clock Resolution */
286 BOOL Acquire, /* Aquire (1) or Release (0) our interest */
287 ULONG *pNewRes), /* The NS Clock Resolution granted */
288 (ReqRes, Acquire, pNewRes));
289 #define SetTimerResolution apr_winapi_NtSetTimerResolution
291 /* ### These are ULONG_PTR values, but that's int32 for all we care
292 * until the Win64 port is prepared.
296 PVOID PebBaseAddress;
299 ULONG UniqueProcessId;
300 ULONG InheritedFromUniqueProcessId;
303 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryInformationProcess, 0, (
304 HANDLE hProcess, /* Obvious */
305 INT info, /* Use 0 for PBI documented above */
306 PVOID pPI, /* The PIB buffer */
307 ULONG LenPI, /* Use sizeof(PBI) */
308 ULONG *pSizePI), /* returns pPI buffer used (may pass NULL) */
309 (hProcess, info, pPI, LenPI, pSizePI));
310 #define QueryInformationProcess apr_winapi_NtQueryInformationProcess
312 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryObject, 0, (
313 HANDLE hObject, /* Obvious */
314 INT info, /* Use 0 for PBI documented above */
315 PVOID pOI, /* The PIB buffer */
316 ULONG LenOI, /* Use sizeof(PBI) */
317 ULONG *pSizeOI), /* returns pPI buffer used (may pass NULL) */
318 (hObject, info, pOI, LenOI, pSizeOI));
319 #define QueryObject apr_winapi_NtQueryObject
321 #endif /* !defined(_WIN32_WCE) */
323 #endif /* ! MISC_H */