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