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