bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / apache2 / include / apr_portable.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 /* This header file is where you should put ANY platform specific information.
18  * This should be the only header file that programs need to include that 
19  * actually has platform dependant code which refers to the .
20  */
21 #ifndef APR_PORTABLE_H
22 #define APR_PORTABLE_H
23 /**
24  * @file apr_portable.h
25  * @brief APR Portability Routines
26  */
27
28 #include "apr.h"
29 #include "apr_pools.h"
30 #include "apr_thread_proc.h"
31 #include "apr_file_io.h"
32 #include "apr_network_io.h"
33 #include "apr_errno.h"
34 #include "apr_global_mutex.h"
35 #include "apr_proc_mutex.h"
36 #include "apr_time.h"
37 #include "apr_dso.h"
38 #include "apr_shm.h"
39
40 #if APR_HAVE_DIRENT_H
41 #include <dirent.h>
42 #endif
43 #if APR_HAVE_FCNTL_H
44 #include <fcntl.h>
45 #endif
46 #if APR_HAVE_PTHREAD_H
47 #include <pthread.h>
48 #endif
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif /* __cplusplus */
53
54 /**
55  * @defgroup apr_portabile Portability Routines
56  * @ingroup APR 
57  * @{
58  */
59
60 #ifdef WIN32
61 /* The primitives for Windows types */
62 typedef HANDLE                apr_os_file_t;
63 typedef HANDLE                apr_os_dir_t;
64 typedef SOCKET                apr_os_sock_t;
65 typedef HANDLE                apr_os_proc_mutex_t;
66 typedef HANDLE                apr_os_thread_t;
67 typedef HANDLE                apr_os_proc_t;
68 typedef DWORD                 apr_os_threadkey_t; 
69 typedef FILETIME              apr_os_imp_time_t;
70 typedef SYSTEMTIME            apr_os_exp_time_t;
71 typedef HANDLE                apr_os_dso_handle_t;
72 typedef HANDLE                apr_os_shm_t;
73
74 #elif defined(OS2)
75 typedef HFILE                 apr_os_file_t;
76 typedef HDIR                  apr_os_dir_t;
77 typedef int                   apr_os_sock_t;
78 typedef HMTX                  apr_os_proc_mutex_t;
79 typedef TID                   apr_os_thread_t;
80 typedef PID                   apr_os_proc_t;
81 typedef PULONG                apr_os_threadkey_t; 
82 typedef struct timeval        apr_os_imp_time_t;
83 typedef struct tm             apr_os_exp_time_t;
84 typedef HMODULE               apr_os_dso_handle_t;
85 typedef void*                 apr_os_shm_t;
86
87 #elif defined(__BEOS__)
88 #include <kernel/OS.h>
89 #include <kernel/image.h>
90
91 struct apr_os_proc_mutex_t {
92         sem_id sem;
93         int32  ben;
94 };
95
96 typedef int                   apr_os_file_t;
97 typedef DIR                   apr_os_dir_t;
98 typedef int                   apr_os_sock_t;
99 typedef struct apr_os_proc_mutex_t  apr_os_proc_mutex_t;
100 typedef thread_id             apr_os_thread_t;
101 typedef thread_id             apr_os_proc_t;
102 typedef int                   apr_os_threadkey_t;
103 typedef struct timeval        apr_os_imp_time_t;
104 typedef struct tm             apr_os_exp_time_t;
105 typedef image_id              apr_os_dso_handle_t;
106 typedef void*                 apr_os_shm_t;
107
108 #elif defined(NETWARE)
109 typedef int                   apr_os_file_t;
110 typedef DIR                   apr_os_dir_t;
111 typedef int                   apr_os_sock_t;
112 typedef NXMutex_t             apr_os_proc_mutex_t;
113 typedef NXThreadId_t          apr_os_thread_t;
114 typedef long                  apr_os_proc_t;
115 typedef NXKey_t               apr_os_threadkey_t; 
116 typedef struct timeval        apr_os_imp_time_t;
117 typedef struct tm             apr_os_exp_time_t;
118 typedef void *                apr_os_dso_handle_t;
119 typedef void*                 apr_os_shm_t;
120
121 #else
122 /* Any other OS should go above this one.  This is the lowest common
123  * denominator typedefs for  all UNIX-like systems.  :)
124  */
125
126 /** Basic OS process mutex structure. */
127 struct apr_os_proc_mutex_t {
128 #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
129     int crossproc;
130 #endif
131 #if APR_HAS_PROC_PTHREAD_SERIALIZE
132     pthread_mutex_t *pthread_interproc;
133 #endif
134 #if APR_HAS_THREADS
135     /* If no threads, no need for thread locks */
136 #if APR_USE_PTHREAD_SERIALIZE
137     pthread_mutex_t *intraproc;
138 #endif
139 #endif
140 };
141
142 typedef int                   apr_os_file_t;        /**< native file */
143 typedef DIR                   apr_os_dir_t;         /**< native dir */
144 typedef int                   apr_os_sock_t;        /**< native dir */
145 typedef struct apr_os_proc_mutex_t  apr_os_proc_mutex_t; /**< native proces
146                                                           *   mutex
147                                                           */
148 #if APR_HAS_THREADS && APR_HAVE_PTHREAD_H 
149 typedef pthread_t             apr_os_thread_t;      /**< native thread */
150 typedef pthread_key_t         apr_os_threadkey_t;   /**< native thread address
151                                                      *   space */
152 #endif
153 typedef pid_t                 apr_os_proc_t;        /**< native pid */
154 typedef struct timeval        apr_os_imp_time_t;    /**< native timeval */
155 typedef struct tm             apr_os_exp_time_t;    /**< native tm */
156 /** @var apr_os_dso_handle_t
157  * native dso types
158  */
159 #if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
160 #include <dl.h>
161 typedef shl_t                 apr_os_dso_handle_t;
162 #elif defined(DARWIN)
163 #include <mach-o/dyld.h>
164 typedef NSModule              apr_os_dso_handle_t;
165 #else
166 typedef void *                apr_os_dso_handle_t;
167 #endif
168 typedef void*                 apr_os_shm_t;         /**< native SHM */
169
170 #endif
171
172 /**
173  * @typedef apr_os_sock_info_t
174  * @brief alias for local OS socket
175  */
176 /**
177  * everything APR needs to know about an active socket to construct
178  * an APR socket from it; currently, this is platform-independent
179  */
180 struct apr_os_sock_info_t {
181     apr_os_sock_t *os_sock; /**< always required */
182     struct sockaddr *local; /**< NULL if not yet bound */
183     struct sockaddr *remote; /**< NULL if not connected */
184     int family;             /**< always required (APR_INET, APR_INET6, etc.) */
185     int type;               /**< always required (SOCK_STREAM, SOCK_DGRAM, etc.) */
186 #ifdef APR_ENABLE_FOR_1_0   /**< enable with APR 1.0 */
187     int protocol;           /**< 0 or actual protocol (APR_PROTO_SCTP, APR_PROTO_TCP, etc.) */
188 #endif
189 };
190
191 typedef struct apr_os_sock_info_t apr_os_sock_info_t;
192
193 #if APR_PROC_MUTEX_IS_GLOBAL || defined(DOXYGEN)
194 /** Opaque global mutex type */
195 #define apr_os_global_mutex_t apr_os_proc_mutex_t
196 /** @return apr_os_global_mutex */
197 #define apr_os_global_mutex_get apr_os_proc_mutex_get
198 #else
199     /** Thread and process mutex for those platforms where process mutexes
200      *  are not held in threads.
201      */
202     struct apr_os_global_mutex_t {
203         apr_pool_t *pool;
204         apr_proc_mutex_t *proc_mutex;
205 #if APR_HAS_THREADS
206         apr_thread_mutex_t *thread_mutex;
207 #endif /* APR_HAS_THREADS */
208     };
209     typedef struct apr_os_global_mutex_t apr_os_global_mutex_t;
210
211 APR_DECLARE(apr_status_t) apr_os_global_mutex_get(apr_os_global_mutex_t *ospmutex, 
212                                                 apr_global_mutex_t *pmutex);
213 #endif
214
215
216 /**
217  * convert the file from apr type to os specific type.
218  * @param thefile The os specific file we are converting to
219  * @param file The apr file to convert.
220  * @remark On Unix, it is only possible to get a file descriptor from 
221  *         an apr file type.
222  */
223 APR_DECLARE(apr_status_t) apr_os_file_get(apr_os_file_t *thefile,
224                                           apr_file_t *file);
225
226 /**
227  * convert the dir from apr type to os specific type.
228  * @param thedir The os specific dir we are converting to
229  * @param dir The apr dir to convert.
230  */   
231 APR_DECLARE(apr_status_t) apr_os_dir_get(apr_os_dir_t **thedir, 
232                                          apr_dir_t *dir);
233
234 /**
235  * Convert the socket from an apr type to an OS specific socket
236  * @param thesock The socket to convert.
237  * @param sock The os specifc equivelant of the apr socket..
238  */
239 APR_DECLARE(apr_status_t) apr_os_sock_get(apr_os_sock_t *thesock,
240                                           apr_socket_t *sock);
241
242 /**
243  * Convert the proc mutex from os specific type to apr type
244  * @param ospmutex The os specific proc mutex we are converting to.
245  * @param pmutex The apr proc mutex to convert.
246  */
247 APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex, 
248                                                 apr_proc_mutex_t *pmutex);
249
250 /**
251  * Get the exploded time in the platforms native format.
252  * @param ostime the native time format
253  * @param aprtime the time to convert
254  */
255 APR_DECLARE(apr_status_t) apr_os_exp_time_get(apr_os_exp_time_t **ostime,
256                                  apr_time_exp_t *aprtime);
257
258 /**
259  * Get the imploded time in the platforms native format.
260  * @param ostime  the native time format
261  * @param aprtime the time to convert
262  */
263 APR_DECLARE(apr_status_t) apr_os_imp_time_get(apr_os_imp_time_t **ostime, 
264                                               apr_time_t *aprtime);
265
266 /**
267  * convert the shm from apr type to os specific type.
268  * @param osshm The os specific shm representation
269  * @param shm The apr shm to convert.
270  */   
271 APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,
272                                          apr_shm_t *shm);
273
274 #if APR_HAS_THREADS || defined(DOXYGEN)
275 /** 
276  * @defgroup apr_os_thread Thread portability Routines
277  * @{ 
278  */
279 /**
280  * convert the thread to os specific type from apr type.
281  * @param thethd The apr thread to convert
282  * @param thd The os specific thread we are converting to
283  */
284 APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd, 
285                                             apr_thread_t *thd);
286
287 /**
288  * convert the thread private memory key to os specific type from an apr type.
289  * @param thekey The apr handle we are converting from.
290  * @param key The os specific handle we are converting to.
291  */
292 APR_DECLARE(apr_status_t) apr_os_threadkey_get(apr_os_threadkey_t *thekey,
293                                                apr_threadkey_t *key);
294
295 /**
296  * convert the thread from os specific type to apr type.
297  * @param thd The apr thread we are converting to.
298  * @param thethd The os specific thread to convert
299  * @param cont The pool to use if it is needed.
300  */
301 APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd,
302                                             apr_os_thread_t *thethd,
303                                             apr_pool_t *cont);
304
305 /**
306  * convert the thread private memory key from os specific type to apr type.
307  * @param key The apr handle we are converting to.
308  * @param thekey The os specific handle to convert
309  * @param cont The pool to use if it is needed.
310  */
311 APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
312                                                apr_os_threadkey_t *thekey,
313                                                apr_pool_t *cont);
314 /**
315  * Get the thread ID
316  */
317 APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void);
318
319 /**
320  * Compare two thread id's
321  * @param tid1 1st Thread ID to compare
322  * @param tid2 2nd Thread ID to compare
323  */ 
324 APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1, 
325                                      apr_os_thread_t tid2);
326
327 /** @} */
328 #endif /* APR_HAS_THREADS */
329
330 /**
331  * convert the file from os specific type to apr type.
332  * @param file The apr file we are converting to.
333  * @param thefile The os specific file to convert
334  * @param flags The flags that were used to open this file.
335  * @param cont The pool to use if it is needed.
336  * @remark On Unix, it is only possible to put a file descriptor into
337  *         an apr file type.
338  */
339 APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file,
340                                           apr_os_file_t *thefile,
341                                           apr_int32_t flags, apr_pool_t *cont); 
342
343 /**
344  * convert the file from os specific type to apr type.
345  * @param file The apr file we are converting to.
346  * @param thefile The os specific pipe to convert
347  * @param cont The pool to use if it is needed.
348  * @remark On Unix, it is only possible to put a file descriptor into
349  *         an apr file type.
350  */
351 APR_DECLARE(apr_status_t) apr_os_pipe_put(apr_file_t **file,
352                                           apr_os_file_t *thefile,
353                                           apr_pool_t *cont);
354
355 /**
356  * convert the file from os specific type to apr type.
357  * @param file The apr file we are converting to.
358  * @param thefile The os specific pipe to convert
359  * @param register_cleanup A cleanup will be registered on the apr_file_t
360  *   to issue apr_file_close().
361  * @param cont The pool to use if it is needed.
362  * @remark On Unix, it is only possible to put a file descriptor into
363  *         an apr file type.
364  */
365 APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file,
366                                              apr_os_file_t *thefile,
367                                              int register_cleanup,
368                                              apr_pool_t *cont);
369
370 /**
371  * convert the dir from os specific type to apr type.
372  * @param dir The apr dir we are converting to.
373  * @param thedir The os specific dir to convert
374  * @param cont The pool to use when creating to apr directory.
375  */
376 APR_DECLARE(apr_status_t) apr_os_dir_put(apr_dir_t **dir,
377                                          apr_os_dir_t *thedir,
378                                          apr_pool_t *cont); 
379
380 /**
381  * Convert a socket from the os specific type to the apr type
382  * @param sock The pool to use.
383  * @param thesock The socket to convert to.
384  * @param cont The socket we are converting to an apr type.
385  * @remark If it is a true socket, it is best to call apr_os_sock_make()
386  *         and provide APR with more information about the socket.
387  */
388 APR_DECLARE(apr_status_t) apr_os_sock_put(apr_socket_t **sock, 
389                                           apr_os_sock_t *thesock, 
390                                           apr_pool_t *cont);
391
392 /**
393  * Create a socket from an existing descriptor and local and remote
394  * socket addresses.
395  * @param apr_sock The new socket that has been set up
396  * @param os_sock_info The os representation of the socket handle and
397  *        other characteristics of the socket
398  * @param cont The pool to use
399  * @remark If you only know the descriptor/handle or if it isn't really
400  *         a true socket, use apr_os_sock_put() instead.
401  */
402 APR_DECLARE(apr_status_t) apr_os_sock_make(apr_socket_t **apr_sock,
403                                            apr_os_sock_info_t *os_sock_info,
404                                            apr_pool_t *cont);
405
406 /**
407  * Convert the proc mutex from os specific type to apr type
408  * @param pmutex The apr proc mutex we are converting to.
409  * @param ospmutex The os specific proc mutex to convert.
410  * @param cont The pool to use if it is needed.
411  */
412 APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
413                                                 apr_os_proc_mutex_t *ospmutex,
414                                                 apr_pool_t *cont); 
415
416 /**
417  * Put the imploded time in the APR format.
418  * @param aprtime the APR time format
419  * @param ostime the time to convert
420  * @param cont the pool to use if necessary
421  */
422 APR_DECLARE(apr_status_t) apr_os_imp_time_put(apr_time_t *aprtime,
423                                               apr_os_imp_time_t **ostime,
424                                               apr_pool_t *cont); 
425
426 /**
427  * Put the exploded time in the APR format.
428  * @param aprtime the APR time format
429  * @param ostime the time to convert
430  * @param cont the pool to use if necessary
431  */
432 APR_DECLARE(apr_status_t) apr_os_exp_time_put(apr_time_exp_t *aprtime,
433                                               apr_os_exp_time_t **ostime,
434                                               apr_pool_t *cont); 
435
436 /**
437  * convert the shared memory from os specific type to apr type.
438  * @param shm The apr shm representation of osshm
439  * @param osshm The os specific shm identity
440  * @param cont The pool to use if it is needed.
441  * @remark On fork()ed architectures, this is typically nothing more than
442  * the memory block mapped.  On non-fork architectures, this is typically
443  * some internal handle to pass the mapping from process to process.
444  */
445 APR_DECLARE(apr_status_t) apr_os_shm_put(apr_shm_t **shm,
446                                          apr_os_shm_t *osshm,
447                                          apr_pool_t *cont); 
448
449
450 #if APR_HAS_DSO || defined(DOXYGEN)
451 /** 
452  * @defgroup apr_os_dso DSO (Dynamic Loading) Portabiliity Routines
453  * @{
454  */
455 /**
456  * convert the dso handle from os specific to apr
457  * @param dso The apr handle we are converting to
458  * @param thedso the os specific handle to convert
459  * @param pool the pool to use if it is needed
460  */
461 APR_DECLARE(apr_status_t) apr_os_dso_handle_put(apr_dso_handle_t **dso,
462                                                 apr_os_dso_handle_t thedso,
463                                                 apr_pool_t *pool);
464
465 /**
466  * convert the apr dso handle into an os specific one
467  * @param aprdso The apr dso handle to convert
468  * @param dso The os specific dso to return
469  */
470 APR_DECLARE(apr_status_t) apr_os_dso_handle_get(apr_os_dso_handle_t *dso,
471                                                 apr_dso_handle_t *aprdso);
472
473 #if APR_HAS_OS_UUID
474 /**
475  * Private: apr-util's apr_uuid module when supported by the platform
476  */
477 APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data);
478 #endif
479
480 /** @} */
481 #endif /* APR_HAS_DSO */
482
483
484 /**
485  * Get the name of the system default characer set.
486  * @param pool the pool to allocate the name from, if needed
487  */
488 APR_DECLARE(const char*) apr_os_default_encoding(apr_pool_t *pool);
489
490
491 /**
492  * Get the name of the current locale character set.
493  * @param pool the pool to allocate the name from, if needed
494  * @remark Defers to apr_os_default_encoding if the current locale's
495  * data can't be retreved on this system.
496  */
497 APR_DECLARE(const char*) apr_os_locale_encoding(apr_pool_t *pool);
498
499 /** @} */
500
501 #ifdef __cplusplus
502 }
503 #endif
504
505 #endif  /* ! APR_PORTABLE_H */