bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / include / arch / win32 / apr_arch_misc.h
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
41 /* ### create APR_HAVE_* macros for these? */
42 #if APR_HAVE_STDLIB_H
43 #include <stdlib.h>
44 #endif
45 #if APR_HAVE_STRING_H
46 #include <string.h>
47 #endif
48
49 struct apr_other_child_rec_t {
50     apr_pool_t *p;
51     struct apr_other_child_rec_t *next;
52     apr_proc_t *proc;
53     void (*maintenance) (int, void *, int);
54     void *data;
55     apr_os_file_t write_fd;
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  */
66 extern int APR_DECLARE_DATA apr_app_init_complete;
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 {
76         APR_WIN_UNK =       0,
77         APR_WIN_UNSUP =     1,
78         APR_WIN_95 =       10,
79         APR_WIN_95_B =     11,
80         APR_WIN_95_OSR2 =  12,
81         APR_WIN_98 =       14,
82         APR_WIN_98_SE =    16,
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.  */
91         APR_WIN_NT_3_51 =  36,
92
93         APR_WIN_NT_4 =     40,
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,
99
100         APR_WIN_2000 =     50,
101         APR_WIN_2000_SP1 = 51,
102         APR_WIN_2000_SP2 = 52,
103         APR_WIN_XP =       60
104 } apr_oslevel_e;
105
106 extern APR_DECLARE_DATA apr_oslevel_e apr_os_level;
107
108 apr_status_t apr_get_oslevel(apr_oslevel_e *);
109
110 /* The APR_HAS_ANSI_FS symbol is PRIVATE, and internal to APR.
111  * APR only supports char data for filenames.  Like most applications,
112  * characters >127 are essentially undefined.  APR_HAS_UNICODE_FS lets
113  * the application know that utf-8 is the encoding method of APR, and
114  * only incidently hints that we have Wide OS calls.
115  *
116  * APR_HAS_ANSI_FS is simply an OS flag to tell us all calls must be
117  * the unicode eqivilant.
118  */
119
120 #if defined(_WIN32_WCE) || defined(WINNT)
121 #define APR_HAS_ANSI_FS           0
122 #else
123 #define APR_HAS_ANSI_FS           1
124 #endif
125
126 /* IF_WIN_OS_IS_UNICODE / ELSE_WIN_OS_IS_ANSI help us keep the code trivial
127  * where have runtime tests for unicode-ness, that aren't needed in any
128  * build which supports only WINNT or WCE.
129  */
130 #if APR_HAS_ANSI_FS && APR_HAS_UNICODE_FS
131 #define IF_WIN_OS_IS_UNICODE if (apr_os_level >= APR_WIN_UNICODE)
132 #define ELSE_WIN_OS_IS_ANSI else
133 #else /* APR_HAS_UNICODE_FS */
134 #define IF_WIN_OS_IS_UNICODE
135 #define ELSE_WIN_OS_IS_ANSI
136 #endif /* WINNT */
137
138 typedef enum {
139     DLL_WINBASEAPI = 0,    // kernel32 From WinBase.h
140     DLL_WINADVAPI = 1,     // advapi32 From WinBase.h
141     DLL_WINSOCKAPI = 2,    // mswsock  From WinSock.h
142     DLL_WINSOCK2API = 3,   // ws2_32   From WinSock2.h
143     DLL_SHSTDAPI = 4,      // shell32  From ShellAPI.h
144     DLL_NTDLL = 5,         // shell32  From our real kernel
145     DLL_defined = 6        // must define as last idx_ + 1
146 } apr_dlltoken_e;
147
148 FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char *fnName, int ordinal);
149
150 /* The apr_load_dll_func call WILL fault if the function cannot be loaded */
151
152 #define APR_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
153     typedef rettype (calltype *apr_winapi_fpt_##fn) args; \
154     static apr_winapi_fpt_##fn apr_winapi_pfn_##fn = NULL; \
155     __inline rettype apr_winapi_##fn args \
156     {   if (!apr_winapi_pfn_##fn) \
157             apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) \
158                                       apr_load_dll_func(lib, #fn, ord); \
159         return (*(apr_winapi_pfn_##fn)) names; }; \
160
161 /* Provide late bound declarations of every API function missing from
162  * one or more supported releases of the Win32 API
163  *
164  * lib is the enumerated token from apr_dlltoken_e, and must correspond
165  * to the string table entry in start.c used by the apr_load_dll_func().
166  * Token names (attempt to) follow Windows.h declarations prefixed by DLL_
167  * in order to facilitate comparison.  Use the exact declaration syntax
168  * and names from Windows.h to prevent ambigutity and bugs.
169  *
170  * rettype and calltype follow the original declaration in Windows.h
171  * fn is the true function name - beware Ansi/Unicode #defined macros
172  * ord is the ordinal within the library, use 0 if it varies between versions
173  * args is the parameter list following the original declaration, in parens
174  * names is the parameter list sans data types, enclosed in parens
175  *
176  * #undef/re#define the Ansi/Unicode generic name to abate confusion
177  * In the case of non-text functions, simply #define the original name
178  */
179
180 #if !defined(_WIN32_WCE) && !defined(WINNT)
181
182 #ifdef GetFileAttributesExA
183 #undef GetFileAttributesExA
184 #endif
185 APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, GetFileAttributesExA, 0, (
186     IN LPCSTR lpFileName,
187     IN GET_FILEEX_INFO_LEVELS fInfoLevelId,
188     OUT LPVOID lpFileInformation),
189     (lpFileName, fInfoLevelId, lpFileInformation));
190 #define GetFileAttributesExA apr_winapi_GetFileAttributesExA
191 #undef GetFileAttributesEx
192 #define GetFileAttributesEx apr_winapi_GetFileAttributesExA
193
194 #ifdef GetFileAttributesExW
195 #undef GetFileAttributesExW
196 #endif
197 APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, GetFileAttributesExW, 0, (
198     IN LPCWSTR lpFileName,
199     IN GET_FILEEX_INFO_LEVELS fInfoLevelId,
200     OUT LPVOID lpFileInformation),
201     (lpFileName, fInfoLevelId, lpFileInformation));
202 #define GetFileAttributesExW apr_winapi_GetFileAttributesExW
203
204 APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, CancelIo, 0, (
205     IN HANDLE hFile),
206     (hFile));
207 #define CancelIo apr_winapi_CancelIo
208
209 APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, TryEnterCriticalSection, 0, (
210     LPCRITICAL_SECTION lpCriticalSection),
211     (lpCriticalSection));
212 #define TryEnterCriticalSection apr_winapi_TryEnterCriticalSection
213
214 APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, SwitchToThread, 0, (
215     void),
216     ());
217 #define SwitchToThread apr_winapi_SwitchToThread
218
219 APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetEffectiveRightsFromAclW, 0, (
220     IN PACL pacl,
221     IN PTRUSTEE_W pTrustee,
222     OUT PACCESS_MASK pAccessRights),
223     (pacl, pTrustee, pAccessRights));
224 #define GetEffectiveRightsFromAclW apr_winapi_GetEffectiveRightsFromAclW
225
226 APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetNamedSecurityInfoW, 0, (
227     IN LPWSTR pObjectName,
228     IN SE_OBJECT_TYPE ObjectType,
229     IN SECURITY_INFORMATION SecurityInfo,
230     OUT PSID *ppsidOwner,
231     OUT PSID *ppsidGroup,
232     OUT PACL *ppDacl,
233     OUT PACL *ppSacl,
234     OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor),
235     (pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, 
236          ppDacl, ppSacl, ppSecurityDescriptor));
237 #define GetNamedSecurityInfoW apr_winapi_GetNamedSecurityInfoW
238
239 APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetNamedSecurityInfoA, 0, (
240     IN LPSTR pObjectName,
241     IN SE_OBJECT_TYPE ObjectType,
242     IN SECURITY_INFORMATION SecurityInfo,
243     OUT PSID *ppsidOwner,
244     OUT PSID *ppsidGroup,
245     OUT PACL *ppDacl,
246     OUT PACL *ppSacl,
247     OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor),
248     (pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, 
249          ppDacl, ppSacl, ppSecurityDescriptor));
250 #define GetNamedSecurityInfoA apr_winapi_GetNamedSecurityInfoA
251 #undef GetNamedSecurityInfo
252 #define GetNamedSecurityInfo apr_winapi_GetNamedSecurityInfoA
253
254 APR_DECLARE_LATE_DLL_FUNC(DLL_WINADVAPI, BOOL, WINAPI, GetSecurityInfo, 0, (
255     IN HANDLE handle,
256     IN SE_OBJECT_TYPE ObjectType,
257     IN SECURITY_INFORMATION SecurityInfo,
258     OUT PSID *ppsidOwner,
259     OUT PSID *ppsidGroup,
260     OUT PACL *ppDacl,
261     OUT PACL *ppSacl,
262     OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor),
263     (handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, 
264          ppDacl, ppSacl, ppSecurityDescriptor));
265 #define GetSecurityInfo apr_winapi_GetSecurityInfo
266
267 APR_DECLARE_LATE_DLL_FUNC(DLL_SHSTDAPI, LPWSTR *, WINAPI, CommandLineToArgvW, 0, (
268     LPCWSTR lpCmdLine, 
269     int *pNumArgs),
270     (lpCmdLine, pNumArgs));
271 #define CommandLineToArgvW apr_winapi_CommandLineToArgvW
272
273 #endif /* !defined(_WIN32_WCE) && !defined(WINNT) */
274
275 #if !defined(_WIN32_WCE)
276
277 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryTimerResolution, 0, (
278     ULONG *pMaxRes,  /* Minimum NS Resolution */
279     ULONG *pMinRes,  /* Maximum NS Resolution */
280     ULONG *pCurRes), /* Current NS Resolution */
281     (pMaxRes, pMinRes, pCurRes));
282 #define QueryTimerResolution apr_winapi_NtQueryTimerResolution
283
284 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtSetTimerResolution, 0, (
285     ULONG ReqRes,    /* Requested NS Clock Resolution */
286     BOOL  Acquire,   /* Aquire (1) or Release (0) our interest */
287     ULONG *pNewRes), /* The NS Clock Resolution granted */
288     (ReqRes, Acquire, pNewRes));
289 #define SetTimerResolution apr_winapi_NtSetTimerResolution
290
291 /* ### These are ULONG_PTR values, but that's int32 for all we care
292  * until the Win64 port is prepared.
293  */
294 typedef struct PBI {
295     DWORD ExitStatus;
296     PVOID PebBaseAddress;
297     ULONG AffinityMask;
298     LONG  BasePriority;
299     ULONG UniqueProcessId;
300     ULONG InheritedFromUniqueProcessId;
301 } PBI, *PPBI;
302
303 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryInformationProcess, 0, (
304     HANDLE hProcess,  /* Obvious */
305     INT   info,       /* Use 0 for PBI documented above */
306     PVOID pPI,        /* The PIB buffer */
307     ULONG LenPI,      /* Use sizeof(PBI) */
308     ULONG *pSizePI),  /* returns pPI buffer used (may pass NULL) */
309     (hProcess, info, pPI, LenPI, pSizePI));
310 #define QueryInformationProcess apr_winapi_NtQueryInformationProcess
311
312 APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, DWORD, WINAPI, NtQueryObject, 0, (
313     HANDLE hObject,   /* Obvious */
314     INT   info,       /* Use 0 for PBI documented above */
315     PVOID pOI,        /* The PIB buffer */
316     ULONG LenOI,      /* Use sizeof(PBI) */
317     ULONG *pSizeOI),  /* returns pPI buffer used (may pass NULL) */
318     (hObject, info, pOI, LenOI, pSizeOI));
319 #define QueryObject apr_winapi_NtQueryObject
320
321 #endif /* !defined(_WIN32_WCE) */
322
323 #endif  /* ! MISC_H */
324