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.
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,
109
extern APR_DECLARE_DATA apr_oslevel_e apr_os_level;
111
apr_status_t apr_get_oslevel(apr_oslevel_e *);
113
/* The APR_HAS_ANSI_FS symbol is PRIVATE, and internal to APR.
114
* APR only supports char data for filenames. Like most applications,
115
* characters >127 are essentially undefined. APR_HAS_UNICODE_FS lets
116
* the application know that utf-8 is the encoding method of APR, and
117
* only incidently hints that we have Wide OS calls.
119
* APR_HAS_ANSI_FS is simply an OS flag to tell us all calls must be
120
* the unicode eqivilant.
123
#if defined(_WIN32_WCE) || defined(WINNT)
124
#define APR_HAS_ANSI_FS 0
126
#define APR_HAS_ANSI_FS 1
129
/* IF_WIN_OS_IS_UNICODE / ELSE_WIN_OS_IS_ANSI help us keep the code trivial
130
* where have runtime tests for unicode-ness, that aren't needed in any
131
* build which supports only WINNT or WCE.
133
#if APR_HAS_ANSI_FS && APR_HAS_UNICODE_FS
134
#define IF_WIN_OS_IS_UNICODE if (apr_os_level >= APR_WIN_UNICODE)
135
#define ELSE_WIN_OS_IS_ANSI else
136
#else /* APR_HAS_UNICODE_FS */
137
#define IF_WIN_OS_IS_UNICODE
138
#define ELSE_WIN_OS_IS_ANSI
142
DLL_WINBASEAPI = 0, // kernel32 From WinBase.h
143
DLL_WINADVAPI = 1, // advapi32 From WinBase.h
144
DLL_WINSOCKAPI = 2, // mswsock From WinSock.h
145
DLL_WINSOCK2API = 3, // ws2_32 From WinSock2.h
146
DLL_SHSTDAPI = 4, // shell32 From ShellAPI.h
147
DLL_NTDLL = 5, // shell32 From our real kernel
148
DLL_defined = 6 // must define as last idx_ + 1
151
FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char *fnName, int ordinal);
153
/* The apr_load_dll_func call WILL fault if the function cannot be loaded */
155
#define APR_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
156
typedef rettype (calltype *apr_winapi_fpt_##fn) args; \
157
static apr_winapi_fpt_##fn apr_winapi_pfn_##fn = NULL; \
158
__inline rettype apr_winapi_##fn args \
159
{ if (!apr_winapi_pfn_##fn) \
160
apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) \
161
apr_load_dll_func(lib, #fn, ord); \
162
return (*(apr_winapi_pfn_##fn)) names; }; \
164
/* Provide late bound declarations of every API function missing from
165
* one or more supported releases of the Win32 API
167
* lib is the enumerated token from apr_dlltoken_e, and must correspond
168
* to the string table entry in start.c used by the apr_load_dll_func().
169
* Token names (attempt to) follow Windows.h declarations prefixed by DLL_
170
* in order to facilitate comparison. Use the exact declaration syntax
171
* and names from Windows.h to prevent ambigutity and bugs.
173
* rettype and calltype follow the original declaration in Windows.h
174
* fn is the true function name - beware Ansi/Unicode #defined macros
175
* ord is the ordinal within the library, use 0 if it varies between versions
176
* args is the parameter list following the original declaration, in parens
177
* names is the parameter list sans data types, enclosed in parens
179
* #undef/re#define the Ansi/Unicode generic name to abate confusion
180
* In the case of non-text functions, simply #define the original name
183
#if !defined(_WIN32_WCE) && !defined(WINNT)
185
#ifdef GetFileAttributesExA
186
#undef GetFileAttributesExA
188
APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, GetFileAttributesExA, 0, (
189
IN LPCSTR lpFileName,
190
IN GET_FILEEX_INFO_LEVELS fInfoLevelId,
191
OUT LPVOID lpFileInformation),
192
(lpFileName, fInfoLevelId, lpFileInformation));
193
#define GetFileAttributesExA apr_winapi_GetFileAttributesExA
194
#undef GetFileAttributesEx
195
#define GetFileAttributesEx apr_winapi_GetFileAttributesExA
197
#ifdef GetFileAttributesExW
198
#undef GetFileAttributesExW
200
APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, GetFileAttributesExW, 0, (
201
IN LPCWSTR lpFileName,
202
IN GET_FILEEX_INFO_LEVELS fInfoLevelId,
203
OUT LPVOID lpFileInformation),
204
(lpFileName, fInfoLevelId, lpFileInformation));
205
#define GetFileAttributesExW apr_winapi_GetFileAttributesExW
207
APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, CancelIo, 0, (
210
#define CancelIo apr_winapi_CancelIo
212
APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, TryEnterCriticalSection, 0, (
213
LPCRITICAL_SECTION lpCriticalSection),
214
(lpCriticalSection));
215
#define TryEnterCriticalSection apr_winapi_TryEnterCriticalSection
217
APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, SwitchToThread, 0, (
220
#define SwitchToThread apr_winapi_SwitchToThread
222
APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetEffectiveRightsFromAclW, 0, (
224
IN PTRUSTEE_W pTrustee,
225
OUT PACCESS_MASK pAccessRights),
226
(pacl, pTrustee, pAccessRights));
227
#define GetEffectiveRightsFromAclW apr_winapi_GetEffectiveRightsFromAclW
229
APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetNamedSecurityInfoW, 0, (
230
IN LPWSTR pObjectName,
231
IN SE_OBJECT_TYPE ObjectType,
232
IN SECURITY_INFORMATION SecurityInfo,
233
OUT PSID *ppsidOwner,
234
OUT PSID *ppsidGroup,
237
OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor),
238
(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup,
239
ppDacl, ppSacl, ppSecurityDescriptor));
240
#define GetNamedSecurityInfoW apr_winapi_GetNamedSecurityInfoW
242
APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetNamedSecurityInfoA, 0, (
243
IN LPSTR pObjectName,
244
IN SE_OBJECT_TYPE ObjectType,
245
IN SECURITY_INFORMATION SecurityInfo,
246
OUT PSID *ppsidOwner,
247
OUT PSID *ppsidGroup,
250
OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor),
251
(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup,
252
ppDacl, ppSacl, ppSecurityDescriptor));
253
#define GetNamedSecurityInfoA apr_winapi_GetNamedSecurityInfoA
254
#undef GetNamedSecurityInfo
255
#define GetNamedSecurityInfo apr_winapi_GetNamedSecurityInfoA
257
APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetSecurityInfo, 0, (
259
IN SE_OBJECT_TYPE ObjectType,
260
IN SECURITY_INFORMATION SecurityInfo,
261
OUT PSID *ppsidOwner,
262
OUT PSID *ppsidGroup,
265
OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor),
266
(handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup,
267
ppDacl, ppSacl, ppSecurityDescriptor));
268
#define GetSecurityInfo apr_winapi_GetSecurityInfo
270
APR_DECLARE_LATE_DLL_FUNC(DLL_SHSTDAPI, LPWSTR *, WINAPI, CommandLineToArgvW, 0, (
273
(lpCmdLine, pNumArgs));
274
#define CommandLineToArgvW apr_winapi_CommandLineToArgvW
276
#endif /* !defined(_WIN32_WCE) && !defined(WINNT) */
278
#if !defined(_WIN32_WCE)
280
APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryTimerResolution, 0, (
281
ULONG *pMaxRes, /* Minimum NS Resolution */
282
ULONG *pMinRes, /* Maximum NS Resolution */
283
ULONG *pCurRes), /* Current NS Resolution */
284
(pMaxRes, pMinRes, pCurRes));
285
#define QueryTimerResolution apr_winapi_NtQueryTimerResolution
287
APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtSetTimerResolution, 0, (
288
ULONG ReqRes, /* Requested NS Clock Resolution */
289
BOOL Acquire, /* Aquire (1) or Release (0) our interest */
290
ULONG *pNewRes), /* The NS Clock Resolution granted */
291
(ReqRes, Acquire, pNewRes));
292
#define SetTimerResolution apr_winapi_NtSetTimerResolution
294
/* ### These are ULONG_PTR values, but that's int32 for all we care
295
* until the Win64 port is prepared.
299
PVOID PebBaseAddress;
302
ULONG UniqueProcessId;
303
ULONG InheritedFromUniqueProcessId;
306
APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryInformationProcess, 0, (
307
HANDLE hProcess, /* Obvious */
308
INT info, /* Use 0 for PBI documented above */
309
PVOID pPI, /* The PIB buffer */
310
ULONG LenPI, /* Use sizeof(PBI) */
311
ULONG *pSizePI), /* returns pPI buffer used (may pass NULL) */
312
(hProcess, info, pPI, LenPI, pSizePI));
313
#define QueryInformationProcess apr_winapi_NtQueryInformationProcess
315
APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryObject, 0, (
316
HANDLE hObject, /* Obvious */
317
INT info, /* Use 0 for PBI documented above */
318
PVOID pOI, /* The PIB buffer */
319
ULONG LenOI, /* Use sizeof(PBI) */
320
ULONG *pSizeOI), /* returns pPI buffer used (may pass NULL) */
321
(hObject, info, pOI, LenOI, pSizeOI));
322
#define QueryObject apr_winapi_NtQueryObject
324
#endif /* !defined(_WIN32_WCE) */
326
#endif /* ! MISC_H */