Apache HTTPD
apr_arch_misc.h
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#ifndef MISC_H
18#define MISC_H
19
20#include "apr.h"
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"
30
31#if APR_HAVE_STDIO_H
32#include <stdio.h>
33#endif
34#if APR_HAVE_SIGNAL_H
35#include <signal.h>
36#endif
37#if APR_HAVE_PTHREAD_H
38#include <pthread.h>
39#endif
40#if APR_HAVE_STDLIB_H
41#include <stdlib.h>
42#endif
43#if APR_HAVE_STRING_H
44#include <string.h>
45#endif
46#ifndef _WIN32_WCE
47#include <tlhelp32.h>
48#endif
49
50#if defined(HAVE_IF_INDEXTONAME) && defined(_MSC_VER)
51#include <Iphlpapi.h>
52#endif
53
58 void (*maintenance) (int, void *, int);
59 void *data;
61};
62
63#define WSAHighByte 2
64#define WSALowByte 0
65
66/* start.c and apr_app.c helpers and communication within misc.c
67 *
68 * They are not for public consumption, although apr_app_init_complete
69 * must be an exported symbol to avoid reinitialization.
70 */
72
73int apr_wastrtoastr(char const * const * *retarr,
74 wchar_t const * const *arr, int args);
75
76/* Platform specific designation of run time os version.
77 * Gaps allow for specific service pack levels that
78 * export new kernel or winsock functions or behavior.
79 */
80typedef enum {
89
90 APR_WIN_UNICODE = 20, /* Prior versions support only narrow chars */
91
92 APR_WIN_CE_3 = 23, /* CE is an odd beast, not supporting */
93 /* some pre-NT features, such as the */
94 APR_WIN_NT = 30, /* narrow charset APIs (fooA fns), while */
95 APR_WIN_NT_3_5 = 35, /* not supporting some NT-family features. */
97
104
117 APR_WIN_10 = 120
119
121
123
124/* The APR_HAS_ANSI_FS symbol is PRIVATE, and internal to APR.
125 * APR only supports char data for filenames. Like most applications,
126 * characters >127 are essentially undefined. APR_HAS_UNICODE_FS lets
127 * the application know that utf-8 is the encoding method of APR, and
128 * only incidently hints that we have Wide OS calls.
129 *
130 * APR_HAS_ANSI_FS is simply an OS flag to tell us all calls must be
131 * the unicode eqivilant.
132 */
133
134#if defined(_WIN32_WCE) || defined(WINNT)
135#define APR_HAS_ANSI_FS 0
136#else
137#define APR_HAS_ANSI_FS 1
138#endif
139
140/* IF_WIN_OS_IS_UNICODE / ELSE_WIN_OS_IS_ANSI help us keep the code trivial
141 * where have runtime tests for unicode-ness, that aren't needed in any
142 * build which supports only WINNT or WCE.
143 */
144#if APR_HAS_ANSI_FS && APR_HAS_UNICODE_FS
145#define IF_WIN_OS_IS_UNICODE if (apr_os_level >= APR_WIN_UNICODE)
146#define ELSE_WIN_OS_IS_ANSI else
147#else /* APR_HAS_UNICODE_FS */
148#define IF_WIN_OS_IS_UNICODE
149#define ELSE_WIN_OS_IS_ANSI
150#endif /* WINNT */
151
152#if defined(_MSC_VER) && !defined(_WIN32_WCE)
153#include "crtdbg.h"
154
155static APR_INLINE void* apr_malloc_dbg(size_t size, const char* filename,
156 int linenumber)
157{
159}
160
161static APR_INLINE void* apr_realloc_dbg(void* userData, size_t newSize,
162 const char* filename, int linenumber)
163{
165}
166
167#else
168
169static APR_INLINE void* apr_malloc_dbg(size_t size, const char* filename,
170 int linenumber)
171{
172 return malloc(size);
173}
174
175static APR_INLINE void* apr_realloc_dbg(void* userData, size_t newSize,
176 const char* filename, int linenumber)
177{
178 return realloc(userData, newSize);
179}
180
181#endif /* ! _MSC_VER */
182
183typedef enum {
184 DLL_WINBASEAPI = 0, /* kernel32 From WinBase.h */
185 DLL_WINADVAPI = 1, /* advapi32 From WinBase.h */
186 DLL_WINSOCKAPI = 2, /* mswsock From WinSock.h */
187 DLL_WINSOCK2API = 3, /* ws2_32 From WinSock2.h */
188 DLL_SHSTDAPI = 4, /* shell32 From ShellAPI.h */
189 DLL_NTDLL = 5, /* ntdll From our real kernel */
190 DLL_IPHLPAPI = 6, /* Iphlpapi From Iphlpapi.h */
191 DLL_defined = 7 /* must define as last idx_ + 1 */
193
195
196/* The apr_load_dll_func call WILL return 0 set error to
197 * ERROR_INVALID_FUNCTION if the function cannot be loaded
198 */
199#define APR_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
200 typedef rettype (calltype *apr_winapi_fpt_##fn) args; \
201 static volatile apr_winapi_fpt_##fn apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) (ULONG_PTR) (-1); \
202 static APR_INLINE int apr_winapi_ld_##fn(void) \
203 { \
204 apr_winapi_fpt_##fn cached_func = apr_winapi_pfn_##fn; \
205 if (cached_func == (apr_winapi_fpt_##fn) (ULONG_PTR) (-1)) { \
206 cached_func = (apr_winapi_fpt_##fn) apr_load_dll_func(lib, #fn, ord); \
207 /* Pointer-sized writes are atomic on Windows. */ \
208 apr_winapi_pfn_##fn = cached_func; \
209 } \
210 if (cached_func) return 1; else return 0; }; \
211 static APR_INLINE rettype apr_winapi_##fn args \
212 { if (apr_winapi_ld_##fn()) \
213 return (*(apr_winapi_pfn_##fn)) names; \
214 else { SetLastError(ERROR_INVALID_FUNCTION); return 0;} }; \
215
216#define APR_HAVE_LATE_DLL_FUNC(fn) apr_winapi_ld_##fn()
217
218/* Provide late bound declarations of every API function missing from
219 * one or more supported releases of the Win32 API
220 *
221 * lib is the enumerated token from apr_dlltoken_e, and must correspond
222 * to the string table entry in start.c used by the apr_load_dll_func().
223 * Token names (attempt to) follow Windows.h declarations prefixed by DLL_
224 * in order to facilitate comparison. Use the exact declaration syntax
225 * and names from Windows.h to prevent ambigutity and bugs.
226 *
227 * rettype and calltype follow the original declaration in Windows.h
228 * fn is the true function name - beware Ansi/Unicode #defined macros
229 * ord is the ordinal within the library, use 0 if it varies between versions
230 * args is the parameter list following the original declaration, in parens
231 * names is the parameter list sans data types, enclosed in parens
232 *
233 * #undef/re#define the Ansi/Unicode generic name to abate confusion
234 * In the case of non-text functions, simply #define the original name
235 */
236
237#if !defined(_WIN32_WCE) && !defined(WINNT)
238/* This group is available to all versions of WINNT 4.0 SP6 and later */
239
240#ifdef GetFileAttributesExA
241#undef GetFileAttributesExA
242#endif
248#define GetFileAttributesExA apr_winapi_GetFileAttributesExA
249#undef GetFileAttributesEx
250#define GetFileAttributesEx apr_winapi_GetFileAttributesExA
251
252#ifdef GetFileAttributesExW
253#undef GetFileAttributesExW
254#endif
260#define GetFileAttributesExW apr_winapi_GetFileAttributesExW
261
263 IN HANDLE hFile),
264 (hFile));
265#define CancelIo apr_winapi_CancelIo
266
270#define TryEnterCriticalSection apr_winapi_TryEnterCriticalSection
271
273 void),
274 ());
275#define SwitchToThread apr_winapi_SwitchToThread
276
278 IN PACL pacl,
282#define GetEffectiveRightsFromAclW apr_winapi_GetEffectiveRightsFromAclW
283
290 OUT PACL *ppDacl,
291 OUT PACL *ppSacl,
295#define GetNamedSecurityInfoW apr_winapi_GetNamedSecurityInfoW
296
303 OUT PACL *ppDacl,
304 OUT PACL *ppSacl,
308#define GetNamedSecurityInfoA apr_winapi_GetNamedSecurityInfoA
309#undef GetNamedSecurityInfo
310#define GetNamedSecurityInfo apr_winapi_GetNamedSecurityInfoA
311
318 OUT PACL *ppDacl,
319 OUT PACL *ppSacl,
323#define GetSecurityInfo apr_winapi_GetSecurityInfo
324
327 int *pNumArgs),
329#define CommandLineToArgvW apr_winapi_CommandLineToArgvW
330
331#endif /* !defined(_WIN32_WCE) && !defined(WINNT) */
332
333#if !defined(_WIN32_WCE)
334/* This group is NOT available to all versions of WinNT,
335 * these we must always look up
336 */
337
338#ifdef GetCompressedFileSizeA
339#undef GetCompressedFileSizeA
340#endif
345#define GetCompressedFileSizeA apr_winapi_GetCompressedFileSizeA
346#undef GetCompressedFileSize
347#define GetCompressedFileSize apr_winapi_GetCompressedFileSizeA
348
349#ifdef GetCompressedFileSizeW
350#undef GetCompressedFileSizeW
351#endif
356#define GetCompressedFileSizeW apr_winapi_GetCompressedFileSizeW
357
358
360 ULONG *pMaxRes, /* Minimum NS Resolution */
361 ULONG *pMinRes, /* Maximum NS Resolution */
362 ULONG *pCurRes), /* Current NS Resolution */
364#define QueryTimerResolution apr_winapi_NtQueryTimerResolution
365
367 ULONG ReqRes, /* Requested NS Clock Resolution */
368 BOOL Acquire, /* Aquire (1) or Release (0) our interest */
369 ULONG *pNewRes), /* The NS Clock Resolution granted */
371#define SetTimerResolution apr_winapi_NtSetTimerResolution
372
381
383 HANDLE hProcess, /* Obvious */
384 INT info, /* Use 0 for PBI documented above */
385 PVOID pPI, /* The PIB buffer */
386 ULONG LenPI, /* Use sizeof(PBI) */
387 ULONG *pSizePI), /* returns pPI buffer used (may pass NULL) */
389#define QueryInformationProcess apr_winapi_NtQueryInformationProcess
390
392 HANDLE hObject, /* Obvious */
393 INT info, /* Use 0 for PBI documented above */
394 PVOID pOI, /* The PIB buffer */
395 ULONG LenOI, /* Use sizeof(PBI) */
396 ULONG *pSizeOI), /* returns pPI buffer used (may pass NULL) */
398#define QueryObject apr_winapi_NtQueryObject
399
400typedef struct IOSB {
401 union {
404 };
405 apr_uintptr_t Information; /* Varies by op, consumed buffer size for FSI below */
407
415
417 HANDLE hObject, /* Obvious */
418 PVOID pIOSB, /* Point to the IOSB buffer for detailed return results */
419 PVOID pFI, /* The buffer, using FIB above */
420 ULONG LenFI, /* Use sizeof(FI) */
421 ULONG info), /* Use 5 for FSI documented above*/
423#define ZwQueryInformationFile apr_winapi_ZwQueryInformationFile
424
425#ifdef CreateToolhelp32Snapshot
426#undef CreateToolhelp32Snapshot
427#endif
429 DWORD dwFlags,
431 (dwFlags, th32ProcessID));
432#define CreateToolhelp32Snapshot apr_winapi_CreateToolhelp32Snapshot
433
434#ifdef Process32FirstW
435#undef Process32FirstW
436#endif
441#define Process32FirstW apr_winapi_Process32FirstW
442
443#ifdef Process32NextW
444#undef Process32NextW
445#endif
450#define Process32NextW apr_winapi_Process32NextW
451
452#if !defined(POLLERR)
453/* Event flag definitions for WSAPoll(). */
454#define POLLRDNORM 0x0100
455#define POLLRDBAND 0x0200
456#define POLLIN (POLLRDNORM | POLLRDBAND)
457#define POLLPRI 0x0400
458
459#define POLLWRNORM 0x0010
460#define POLLOUT (POLLWRNORM)
461#define POLLWRBAND 0x0020
462
463#define POLLERR 0x0001
464#define POLLHUP 0x0002
465#define POLLNVAL 0x0004
466
473
474#endif /* !defined(POLLERR) */
475#ifdef WSAPoll
476#undef WSAPoll
477#endif
480 IN ULONG fds,
481 IN INT timeout),
483#define WSAPoll apr_winapi_WSAPoll
484#define HAVE_POLL 1
485
486#ifdef SetDllDirectoryW
487#undef SetDllDirectoryW
488#endif
492#define SetDllDirectoryW apr_winapi_SetDllDirectoryW
493
494#if HAVE_IF_NAMETOINDEX
495#ifdef if_nametoindex
496#undef if_nametoindex
497#endif
500 (InterfaceName));
501#define if_nametoindex apr_winapi_if_nametoindex
502#endif
503
504#if HAVE_IF_INDEXTONAME
505#ifdef if_indextoname
506#undef if_indextoname
507#endif
512#define if_indextoname apr_winapi_if_indextoname
513#endif
514
515#endif /* !defined(_WIN32_WCE) */
516
517#endif /* ! MISC_H */
518
#define FAR
APR Error Codes.
APR File I/O Handling.
APR Miscellaneous library routines.
APR Command Arguments (getopt)
APR memory allocation.
APR Portability Routines.
APR Thread and Process Library.
apr_pool_t const char apr_dbd_t ** handle
Definition apr_dbd.h:142
#define BOOL
Definition ssl_private.h:81
apr_size_t size
int apr_status_t
Definition apr_errno.h:44
int apr_os_file_t
apr_size_t const char * filename
Definition apr_shm.h:72
const apr_array_header_t * arr
Definition apr_tables.h:187
const char const char *const * args
#define SHORT
#define LONG
LONGLONG EndOfFile
BOOL Directory
ULONG NumberOfLinks
BOOL DeletePending
LONGLONG AllocationSize
apr_uintptr_t Information
UINT Status
PVOID reserved
PVOID PebBaseAddress
LONG BasePriority
LONG ExitStatus
apr_uintptr_t UniqueProcessId
apr_uintptr_t AffinityMask
apr_uintptr_t InheritedFromUniqueProcessId
void(* maintenance)(int, void *, int)
apr_os_file_t write_fd
struct apr_other_child_rec_t * next
SHORT revents
SOCKET fd
SHORT events
INT PVOID ULONG LenPI
#define GetNamedSecurityInfoW
DWORD th32ProcessID
IN PTRUSTEE_W pTrustee
IN ULONG IN INT timeout
INT PVOID ULONG LenOI
IN SE_OBJECT_TYPE IN SECURITY_INFORMATION OUT PSID OUT PSID OUT PACL OUT PACL OUT PSECURITY_DESCRIPTOR * ppSecurityDescriptor
struct pollfd * PWSAPOLLFD
#define APR_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names)
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray
typedef HANDLE(WINAPI *apr_winapi_fpt_CreateToolhelp32Snapshot)(DWORD dwFlags
#define GetFileAttributesExA
LPPROCESSENTRY32W lppe
struct pollfd * LPWSAPOLLFD
#define GetSecurityInfo
#define WSAPoll
apr_dlltoken_e
@ DLL_NTDLL
@ DLL_WINADVAPI
@ DLL_WINSOCK2API
@ DLL_WINSOCKAPI
@ DLL_SHSTDAPI
@ DLL_defined
@ DLL_IPHLPAPI
@ DLL_WINBASEAPI
IN PTRUSTEE_W OUT PACCESS_MASK pAccessRights
PVOID PVOID ULONG LenFI
struct IOSB * PIOSB
INT PVOID pOI
struct FSI * PFSI
APR_DECLARE_DATA apr_oslevel_e apr_os_level
Definition misc.c:24
struct pollfd WSAPOLLFD
IN SE_OBJECT_TYPE IN SECURITY_INFORMATION OUT PSID OUT PSID OUT PACL OUT PACL * ppSacl
#define GetCompressedFileSizeA
apr_oslevel_e
@ APR_WIN_ME
@ APR_WIN_NT_4_SP4
@ APR_WIN_95
@ APR_WIN_NT
@ 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_UNICODE
@ APR_WIN_UNK
@ APR_WIN_XP_SP1
@ APR_WIN_2000
@ APR_WIN_NT_4_SP6
@ APR_WIN_UNSUP
@ APR_WIN_95_B
@ APR_WIN_XP
@ APR_WIN_NT_3_51
@ APR_WIN_XP_SP2
#define CreateToolhelp32Snapshot
#define GetFileAttributesExW
#define ZwQueryInformationFile
INT PVOID ULONG ULONG * pSizePI
IN SE_OBJECT_TYPE IN SECURITY_INFORMATION OUT PSID OUT PSID OUT PACL * ppDacl
OUT LPDWORD lpFileSizeHigh
#define GetNamedSecurityInfoA
IN GET_FILEEX_INFO_LEVELS OUT LPVOID lpFileInformation
IN SE_OBJECT_TYPE ObjectType
IN GET_FILEEX_INFO_LEVELS fInfoLevelId
static APR_INLINE void * apr_realloc_dbg(void *userData, size_t newSize, const char *filename, int linenumber)
IN SE_OBJECT_TYPE IN SECURITY_INFORMATION OUT PSID * ppsidOwner
struct PBI * PPBI
#define CancelIo
static APR_INLINE void * apr_malloc_dbg(size_t size, const char *filename, int linenumber)
PVOID PVOID pFI
#define CommandLineToArgvW
#define Process32NextW
INT PVOID ULONG ULONG * pSizeOI
FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char *fnName, int ordinal)
Definition misc.c:179
#define TryEnterCriticalSection
apr_status_t apr_get_oslevel(apr_oslevel_e *)
Definition misc.c:26
typedef DWORD(WINAPI *apr_winapi_fpt_GetCompressedFileSizeA)(IN LPCSTR lpFileName
#define Process32FirstW
#define SwitchToThread
INT info
BOOL ULONG * pNewRes
IN ULONG fds
int APR_DECLARE_DATA apr_app_init_complete
Definition start.c:31
int apr_wastrtoastr(char const *const **retarr, wchar_t const *const *arr, int args)
Definition internal.c:40
ULONG ULONG * pCurRes
BOOL Acquire
#define GetCompressedFileSizeW
IN SE_OBJECT_TYPE IN SECURITY_INFORMATION SecurityInfo
PVOID pIOSB
IN SE_OBJECT_TYPE IN SECURITY_INFORMATION OUT PSID OUT PSID * ppsidGroup
INT PVOID pPI
#define GetEffectiveRightsFromAclW
#define SetDllDirectoryW
ULONG * pMinRes