Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
54 struct apr_other_child_rec_t {
55  apr_pool_t *p;
58  void (*maintenance) (int, void *, int);
59  void *data;
60 };
61 
62 #define WSAHighByte 2
63 #define WSALowByte 0
64 
65 /* start.c and apr_app.c helpers and communication within misc.c
66  *
67  * They are not for public consumption, although apr_app_init_complete
68  * must be an exported symbol to avoid reinitialization.
69  */
71 
72 int apr_wastrtoastr(char const * const * *retarr,
73  wchar_t const * const *arr, int args);
74 
75 /* Platform specific designation of run time os version.
76  * Gaps allow for specific service pack levels that
77  * export new kernel or winsock functions or behavior.
78  */
79 typedef enum {
82  APR_WIN_95 = 10,
85  APR_WIN_98 = 14,
87  APR_WIN_ME = 18,
88 
89  APR_WIN_UNICODE = 20, /* Prior versions support only narrow chars */
90 
91  APR_WIN_CE_3 = 23, /* CE is an odd beast, not supporting */
92  /* some pre-NT features, such as the */
93  APR_WIN_NT = 30, /* narrow charset APIs (fooA fns), while */
94  APR_WIN_NT_3_5 = 35, /* not supporting some NT-family features. */
96 
103 
112  APR_WIN_7 = 90,
113  APR_WIN_8 = 100
114 } apr_oslevel_e;
115 
117 
119 
120 /* The APR_HAS_ANSI_FS symbol is PRIVATE, and internal to APR.
121  * APR only supports char data for filenames. Like most applications,
122  * characters >127 are essentially undefined. APR_HAS_UNICODE_FS lets
123  * the application know that utf-8 is the encoding method of APR, and
124  * only incidently hints that we have Wide OS calls.
125  *
126  * APR_HAS_ANSI_FS is simply an OS flag to tell us all calls must be
127  * the unicode eqivilant.
128  */
129 
130 #define APR_HAS_ANSI_FS 0
131 
132 /* IF_WIN_OS_IS_UNICODE / ELSE_WIN_OS_IS_ANSI help us keep the code trivial
133  * where have runtime tests for unicode-ness, that aren't needed in any
134  * build which supports only WINNT or WCE.
135  */
136 #if APR_HAS_ANSI_FS && APR_HAS_UNICODE_FS
137 #define IF_WIN_OS_IS_UNICODE if (apr_os_level >= APR_WIN_UNICODE)
138 #define ELSE_WIN_OS_IS_ANSI else
139 #else /* APR_HAS_UNICODE_FS */
140 #define IF_WIN_OS_IS_UNICODE
141 #define ELSE_WIN_OS_IS_ANSI
142 #endif /* APR_HAS_ANSI_FS && APR_HAS_UNICODE_FS */
143 
144 #if defined(_MSC_VER) && !defined(_WIN32_WCE)
145 #include "crtdbg.h"
146 
147 static APR_INLINE void* apr_malloc_dbg(size_t size, const char* filename,
148  int linenumber)
149 {
150  return _malloc_dbg(size, _CRT_BLOCK, filename, linenumber);
151 }
152 
153 static APR_INLINE void* apr_realloc_dbg(void* userData, size_t newSize,
154  const char* filename, int linenumber)
155 {
156  return _realloc_dbg(userData, newSize, _CRT_BLOCK, filename, linenumber);
157 }
158 
159 #else
160 
161 static APR_INLINE void* apr_malloc_dbg(size_t size, const char* filename,
162  int linenumber)
163 {
164  return malloc(size);
165 }
166 
167 static APR_INLINE void* apr_realloc_dbg(void* userData, size_t newSize,
168  const char* filename, int linenumber)
169 {
170  return realloc(userData, newSize);
171 }
172 
173 #endif /* ! _MSC_VER */
174 
175 typedef enum {
176  DLL_WINBASEAPI = 0, /* kernel32 From WinBase.h */
177  DLL_WINADVAPI = 1, /* advapi32 From WinBase.h */
178  DLL_WINSOCKAPI = 2, /* mswsock From WinSock.h */
179  DLL_WINSOCK2API = 3, /* ws2_32 From WinSock2.h */
180  DLL_SHSTDAPI = 4, /* shell32 From ShellAPI.h */
181  DLL_NTDLL = 5, /* ntdll From our real kernel */
182  DLL_IPHLPAPI = 6, /* Iphlpapi From Iphlpapi.h */
183  DLL_defined = 7 /* must define as last idx_ + 1 */
185 
186 FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char *fnName, int ordinal);
187 
188 /* The apr_load_dll_func call WILL return 0 set error to
189  * ERROR_INVALID_FUNCTION if the function cannot be loaded
190  */
191 #define APR_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
192  typedef rettype (calltype *apr_winapi_fpt_##fn) args; \
193  static apr_winapi_fpt_##fn apr_winapi_pfn_##fn = NULL; \
194  static int apr_winapi_chk_##fn = 0; \
195  static APR_INLINE int apr_winapi_ld_##fn(void) \
196  { if (apr_winapi_pfn_##fn) return 1; \
197  if (apr_winapi_chk_##fn ++) return 0; \
198  if (!apr_winapi_pfn_##fn) \
199  apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) \
200  apr_load_dll_func(lib, #fn, ord); \
201  if (apr_winapi_pfn_##fn) return 1; else return 0; }; \
202  static APR_INLINE rettype apr_winapi_##fn args \
203  { if (apr_winapi_ld_##fn()) \
204  return (*(apr_winapi_pfn_##fn)) names; \
205  else { SetLastError(ERROR_INVALID_FUNCTION); return 0;} }; \
206 
207 #define APR_HAVE_LATE_DLL_FUNC(fn) apr_winapi_ld_##fn()
208 
209 /* Provide late bound declarations of every API function missing from
210  * one or more supported releases of the Win32 API
211  *
212  * lib is the enumerated token from apr_dlltoken_e, and must correspond
213  * to the string table entry in start.c used by the apr_load_dll_func().
214  * Token names (attempt to) follow Windows.h declarations prefixed by DLL_
215  * in order to facilitate comparison. Use the exact declaration syntax
216  * and names from Windows.h to prevent ambigutity and bugs.
217  *
218  * rettype and calltype follow the original declaration in Windows.h
219  * fn is the true function name - beware Ansi/Unicode #defined macros
220  * ord is the ordinal within the library, use 0 if it varies between versions
221  * args is the parameter list following the original declaration, in parens
222  * names is the parameter list sans data types, enclosed in parens
223  *
224  * #undef/re#define the Ansi/Unicode generic name to abate confusion
225  * In the case of non-text functions, simply #define the original name
226  */
227 
228 #if !defined(_WIN32_WCE)
229 /* This group is NOT available to all versions of WinNT,
230  * these we must always look up
231  */
232 
233 #ifdef GetCompressedFileSizeA
234 #undef GetCompressedFileSizeA
235 #endif
237  IN LPCSTR lpFileName,
238  OUT LPDWORD lpFileSizeHigh),
239  (lpFileName, lpFileSizeHigh));
240 #define GetCompressedFileSizeA apr_winapi_GetCompressedFileSizeA
241 #undef GetCompressedFileSize
242 #define GetCompressedFileSize apr_winapi_GetCompressedFileSizeA
243 
244 #ifdef GetCompressedFileSizeW
245 #undef GetCompressedFileSizeW
246 #endif
248  IN LPCWSTR lpFileName,
249  OUT LPDWORD lpFileSizeHigh),
250  (lpFileName, lpFileSizeHigh));
251 #define GetCompressedFileSizeW apr_winapi_GetCompressedFileSizeW
252 
253 
254 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, LONG, WINAPI, NtQueryTimerResolution, 0, (
255  ULONG *pMaxRes, /* Minimum NS Resolution */
256  ULONG *pMinRes, /* Maximum NS Resolution */
257  ULONG *pCurRes), /* Current NS Resolution */
258  (pMaxRes, pMinRes, pCurRes));
259 #define QueryTimerResolution apr_winapi_NtQueryTimerResolution
260 
261 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, LONG, WINAPI, NtSetTimerResolution, 0, (
262  ULONG ReqRes, /* Requested NS Clock Resolution */
263  BOOL Acquire, /* Aquire (1) or Release (0) our interest */
264  ULONG *pNewRes), /* The NS Clock Resolution granted */
265  (ReqRes, Acquire, pNewRes));
266 #define SetTimerResolution apr_winapi_NtSetTimerResolution
267 
268 typedef struct PBI {
275 } PBI, *PPBI;
276 
277 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, LONG, WINAPI, NtQueryInformationProcess, 0, (
278  HANDLE hProcess, /* Obvious */
279  INT info, /* Use 0 for PBI documented above */
280  PVOID pPI, /* The PIB buffer */
281  ULONG LenPI, /* Use sizeof(PBI) */
282  ULONG *pSizePI), /* returns pPI buffer used (may pass NULL) */
283  (hProcess, info, pPI, LenPI, pSizePI));
284 #define QueryInformationProcess apr_winapi_NtQueryInformationProcess
285 
286 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, LONG, WINAPI, NtQueryObject, 0, (
287  HANDLE hObject, /* Obvious */
288  INT info, /* Use 0 for PBI documented above */
289  PVOID pOI, /* The PIB buffer */
290  ULONG LenOI, /* Use sizeof(PBI) */
291  ULONG *pSizeOI), /* returns pPI buffer used (may pass NULL) */
292  (hObject, info, pOI, LenOI, pSizeOI));
293 #define QueryObject apr_winapi_NtQueryObject
294 
295 typedef struct IOSB {
296  union {
297  UINT Status;
298  PVOID reserved;
299  };
300  apr_uintptr_t Information; /* Varies by op, consumed buffer size for FSI below */
301 } IOSB, *PIOSB;
302 
303 typedef struct FSI {
304  LONGLONG AllocationSize;
305  LONGLONG EndOfFile;
309 } FSI, *PFSI;
310 
312  HANDLE hObject, /* Obvious */
313  PVOID pIOSB, /* Point to the IOSB buffer for detailed return results */
314  PVOID pFI, /* The buffer, using FIB above */
315  ULONG LenFI, /* Use sizeof(FI) */
316  ULONG info), /* Use 5 for FSI documented above*/
317  (hObject, pIOSB, pFI, LenFI, info));
318 #define ZwQueryInformationFile apr_winapi_ZwQueryInformationFile
319 
320 #ifdef CreateToolhelp32Snapshot
321 #undef CreateToolhelp32Snapshot
322 #endif
324  DWORD dwFlags,
325  DWORD th32ProcessID),
326  (dwFlags, th32ProcessID));
327 #define CreateToolhelp32Snapshot apr_winapi_CreateToolhelp32Snapshot
328 
329 #ifdef Process32FirstW
330 #undef Process32FirstW
331 #endif
333  HANDLE hSnapshot,
334  LPPROCESSENTRY32W lppe),
335  (hSnapshot, lppe));
336 #define Process32FirstW apr_winapi_Process32FirstW
337 
338 #ifdef Process32NextW
339 #undef Process32NextW
340 #endif
342  HANDLE hSnapshot,
343  LPPROCESSENTRY32W lppe),
344  (hSnapshot, lppe));
345 #define Process32NextW apr_winapi_Process32NextW
346 
347 #if !defined(POLLERR)
348 /* Event flag definitions for WSAPoll(). */
349 #define POLLRDNORM 0x0100
350 #define POLLRDBAND 0x0200
351 #define POLLIN (POLLRDNORM | POLLRDBAND)
352 #define POLLPRI 0x0400
353 
354 #define POLLWRNORM 0x0010
355 #define POLLOUT (POLLWRNORM)
356 #define POLLWRBAND 0x0020
357 
358 #define POLLERR 0x0001
359 #define POLLHUP 0x0002
360 #define POLLNVAL 0x0004
361 
362 typedef struct pollfd {
363  SOCKET fd;
364  SHORT events;
365  SHORT revents;
366 
368 
369 #endif /* !defined(POLLERR) */
370 #ifdef WSAPoll
371 #undef WSAPoll
372 #endif
374  IN OUT LPWSAPOLLFD fdArray,
375  IN ULONG fds,
376  IN INT timeout),
377  (fdArray, fds, timeout));
378 #define WSAPoll apr_winapi_WSAPoll
379 #define HAVE_POLL 1
380 
381 #ifdef SetDllDirectoryW
382 #undef SetDllDirectoryW
383 #endif
385  IN LPCWSTR lpPathName),
386  (lpPathName));
387 #define SetDllDirectoryW apr_winapi_SetDllDirectoryW
388 
389 #ifdef if_nametoindex
390 #undef if_nametoindex
391 #endif
392 APR_DECLARE_LATE_DLL_FUNC(DLL_IPHLPAPI, NET_IFINDEX, WINAPI, if_nametoindex, 0, (
393  IN PCSTR InterfaceName),
394  (InterfaceName));
395 #define if_nametoindex apr_winapi_if_nametoindex
396 
397 #ifdef if_indextoname
398 #undef if_indextoname
399 #endif
400 APR_DECLARE_LATE_DLL_FUNC(DLL_IPHLPAPI, PCHAR, NETIOAPI_API_, if_indextoname, 0, (
401  NET_IFINDEX InterfaceIndex,
402  PCHAR InterfaceName),
403  (InterfaceIndex, InterfaceName));
404 #define if_indextoname apr_winapi_if_indextoname
405 
406 #endif /* !defined(_WIN32_WCE) */
407 
408 #endif /* ! MISC_H */
#define WSAPoll
Definition: apr_arch_misc.h:378
Definition: apr_arch_misc.h:52
LONG BasePriority
Definition: apr_arch_misc.h:272
Definition: apr_arch_misc.h:109
Definition: apr_arch_misc.h:112
#define BOOL
Definition: macros.h:25
Definition: apr_arch_misc.h:93
#define if_indextoname
Definition: apr_arch_misc.h:404
#define CreateToolhelp32Snapshot
Definition: apr_arch_misc.h:327
Definition: apr_arch_misc.h:181
ULONG NumberOfLinks
Definition: apr_arch_misc.h:306
Definition: apr_arch_misc.h:99
Definition: apr_arch_misc.h:183
apr_pool_t * p
Definition: apr_arch_misc.h:53
LONG ExitStatus
Definition: apr_arch_misc.h:269
#define Process32NextW
Definition: apr_arch_misc.h:345
LONGLONG AllocationSize
Definition: apr_arch_misc.h:304
APR Command Arguments (getopt)
Definition: apr_arch_misc.h:295
Definition: apr_arch_misc.h:87
struct IOSB IOSB
Definition: apr_arch_misc.h:94
SHORT events
Definition: apr_arch_misc.h:364
#define GetCompressedFileSizeW
Definition: apr_arch_misc.h:251
apr_uintptr_t UniqueProcessId
Definition: apr_arch_misc.h:273
Definition: apr_arch_misc.h:85
SHORT revents
Definition: apr_arch_misc.h:365
struct PBI PBI
Definition: apr_arch_misc.h:97
Definition: apr_arch_misc.h:268
Definition: apr_thread_proc.h:144
void(* maintenance)(int, void *, int)
Definition: apr_arch_misc.h:56
#define SetDllDirectoryW
Definition: apr_arch_misc.h:387
struct pollfd * PWSAPOLLFD
APR File I/O Handling.
Definition: apr_arch_misc.h:108
Definition: apr_arch_misc.h:179
Definition: apr_arch_misc.h:102
APR Miscellaneous library routines.
struct FSI FSI
Definition: apr_arch_misc.h:82
apr_proc_t * proc
Definition: apr_arch_misc.h:55
dav_buffer apr_size_t size
Definition: mod_dav.h:457
#define APR_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names)
Definition: apr_arch_misc.h:191
apr_uintptr_t Information
Definition: apr_arch_misc.h:300
UINT Status
Definition: apr_arch_misc.h:297
struct FSI * PFSI
Definition: apr_arch_misc.h:105
Definition: apr_arch_misc.h:177
Definition: apr_arch_misc.h:182
Definition: apr_arch_misc.h:107
APR memory allocation.
Definition: apr_arch_misc.h:80
Definition: apr_arch_misc.h:98
Definition: apr_arch_misc.h:84
LONGLONG EndOfFile
Definition: apr_arch_misc.h:305
int
Definition: mod_proxy.h:632
FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char *fnName, int ordinal)
#define ZwQueryInformationFile
Definition: apr_arch_misc.h:318
struct apr_other_child_rec_t * next
Definition: apr_arch_misc.h:54
Definition: apr_arch_misc.h:100
#define Process32FirstW
Definition: apr_arch_misc.h:336
Definition: apr_arch_misc.h:86
PVOID reserved
Definition: apr_arch_misc.h:298
APR Error Codes.
Definition: apr_arch_misc.h:176
apr_oslevel_e
Definition: apr_arch_misc.h:79
Definition: apr_arch_misc.h:180
int APR_DECLARE_DATA apr_app_init_complete
Definition: apr_arch_misc.h:178
Definition: apr_arch_misc.h:104
void * data
Definition: apr_arch_misc.h:57
#define APR_DECLARE_DATA
Definition: macros.h:17
APR Platform Definitions.
Definition: apr_arch_misc.h:106
Definition: apr_arch_misc.h:362
struct PBI * PPBI
#define if_nametoindex
Definition: apr_arch_misc.h:395
BOOL DeletePending
Definition: apr_arch_misc.h:307
PVOID PebBaseAddress
Definition: apr_arch_misc.h:270
int apr_wastrtoastr(char const *const **retarr, wchar_t const *const *arr, int args)
Definition: apr_arch_misc.h:113
Definition: apr_arch_misc.h:83
apr_status_t apr_get_oslevel(apr_oslevel_e *)
const dav_liveprop_group const dav_liveprop_spec ** info
Definition: mod_dav.h:966
#define APR_INLINE
Definition: apr.h:65
Definition: apr_arch_misc.h:110
Definition: apr_arch_misc.h:95
APR_DECLARE_DATA apr_oslevel_e apr_os_level
apr_uint64_t apr_uintptr_t
Definition: apr.h:382
APR Thread and Process Library.
BOOL Directory
Definition: apr_arch_misc.h:308
SOCKET fd
Definition: apr_arch_misc.h:363
struct pollfd * LPWSAPOLLFD
Definition: apr_arch_misc.h:303
#define GetCompressedFileSizeA
Definition: apr_arch_misc.h:240
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
apr_uintptr_t AffinityMask
Definition: apr_arch_misc.h:271
typedef void(APR_THREAD_FUNC *PFN_HSE_IO_COMPLETION)(EXTENSION_CONTROL_BLOCK *ecb
Definition: apr_arch_misc.h:111
int apr_status_t
Definition: apr_errno.h:44
Definition: apr_arch_misc.h:91
Definition: apr_arch_misc.h:89
struct pollfd WSAPOLLFD
apr_dlltoken_e
Definition: apr_arch_misc.h:175
struct IOSB * PIOSB
#define malloc(x)
Definition: apr_private.h:170
Definition: apr_arch_misc.h:101
Definition: apr_arch_misc.h:81
apr_uintptr_t InheritedFromUniqueProcessId
Definition: apr_arch_misc.h:274
APR Portability Routines.