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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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 dependent code which refers to the .
21 #ifndef APR_PORTABLE_H
22 #define APR_PORTABLE_H
24 * @file apr_portable.h
25 * @brief APR Portability Routines
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"
46 #if APR_HAVE_PTHREAD_H
52 #endif /* __cplusplus */
55 * @defgroup apr_portabile Portability Routines
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;
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;
87 #elif defined(__BEOS__)
88 #include <kernel/OS.h>
89 #include <kernel/image.h>
91 struct apr_os_proc_mutex_t {
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;
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;
122 /* Any other OS should go above this one. This is the lowest common
123 * denominator typedefs for all UNIX-like systems. :)
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 /** Value used for SYS V Semaphore, FCNTL and FLOCK serialization */
132 #if APR_HAS_PROC_PTHREAD_SERIALIZE
133 /** Value used for PTHREAD serialization */
134 pthread_mutex_t *pthread_interproc;
137 /* If no threads, no need for thread locks */
138 #if APR_USE_PTHREAD_SERIALIZE
139 /** This value is currently unused within APR and Apache */
140 pthread_mutex_t *intraproc;
145 typedef int apr_os_file_t; /**< native file */
146 typedef DIR apr_os_dir_t; /**< native dir */
147 typedef int apr_os_sock_t; /**< native dir */
148 typedef struct apr_os_proc_mutex_t apr_os_proc_mutex_t; /**< native process
151 #if APR_HAS_THREADS && APR_HAVE_PTHREAD_H
152 typedef pthread_t apr_os_thread_t; /**< native thread */
153 typedef pthread_key_t apr_os_threadkey_t; /**< native thread address
156 typedef pid_t apr_os_proc_t; /**< native pid */
157 typedef struct timeval apr_os_imp_time_t; /**< native timeval */
158 typedef struct tm apr_os_exp_time_t; /**< native tm */
159 /** @var apr_os_dso_handle_t
162 #if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
164 typedef shl_t apr_os_dso_handle_t;
165 #elif defined(DARWIN)
166 #include <mach-o/dyld.h>
167 typedef NSModule apr_os_dso_handle_t;
169 typedef void * apr_os_dso_handle_t;
171 typedef void* apr_os_shm_t; /**< native SHM */
176 * @typedef apr_os_sock_info_t
177 * @brief alias for local OS socket
180 * everything APR needs to know about an active socket to construct
181 * an APR socket from it; currently, this is platform-independent
183 struct apr_os_sock_info_t {
184 apr_os_sock_t *os_sock; /**< always required */
185 struct sockaddr *local; /**< NULL if not yet bound */
186 struct sockaddr *remote; /**< NULL if not connected */
187 int family; /**< always required (APR_INET, APR_INET6, etc.) */
188 int type; /**< always required (SOCK_STREAM, SOCK_DGRAM, etc.) */
189 int protocol; /**< 0 or actual protocol (APR_PROTO_SCTP, APR_PROTO_TCP, etc.) */
192 typedef struct apr_os_sock_info_t apr_os_sock_info_t;
194 #if APR_PROC_MUTEX_IS_GLOBAL || defined(DOXYGEN)
195 /** Opaque global mutex type */
196 #define apr_os_global_mutex_t apr_os_proc_mutex_t
197 /** @return apr_os_global_mutex */
198 #define apr_os_global_mutex_get apr_os_proc_mutex_get
200 /** Thread and process mutex for those platforms where process mutexes
201 * are not held in threads.
203 struct apr_os_global_mutex_t {
205 apr_proc_mutex_t *proc_mutex;
207 apr_thread_mutex_t *thread_mutex;
208 #endif /* APR_HAS_THREADS */
210 typedef struct apr_os_global_mutex_t apr_os_global_mutex_t;
212 APR_DECLARE(apr_status_t) apr_os_global_mutex_get(apr_os_global_mutex_t *ospmutex,
213 apr_global_mutex_t *pmutex);
218 * convert the file from apr type to os specific type.
219 * @param thefile The os specific file we are converting to
220 * @param file The apr file to convert.
221 * @remark On Unix, it is only possible to get a file descriptor from
224 APR_DECLARE(apr_status_t) apr_os_file_get(apr_os_file_t *thefile,
228 * convert the dir from apr type to os specific type.
229 * @param thedir The os specific dir we are converting to
230 * @param dir The apr dir to convert.
232 APR_DECLARE(apr_status_t) apr_os_dir_get(apr_os_dir_t **thedir,
236 * Convert the socket from an apr type to an OS specific socket
237 * @param thesock The socket to convert.
238 * @param sock The os specific equivalent of the apr socket..
240 APR_DECLARE(apr_status_t) apr_os_sock_get(apr_os_sock_t *thesock,
244 * Convert the proc mutex from os specific type to apr type
245 * @param ospmutex The os specific proc mutex we are converting to.
246 * @param pmutex The apr proc mutex to convert.
248 APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
249 apr_proc_mutex_t *pmutex);
252 * Get the exploded time in the platforms native format.
253 * @param ostime the native time format
254 * @param aprtime the time to convert
256 APR_DECLARE(apr_status_t) apr_os_exp_time_get(apr_os_exp_time_t **ostime,
257 apr_time_exp_t *aprtime);
260 * Get the imploded time in the platforms native format.
261 * @param ostime the native time format
262 * @param aprtime the time to convert
264 APR_DECLARE(apr_status_t) apr_os_imp_time_get(apr_os_imp_time_t **ostime,
265 apr_time_t *aprtime);
268 * convert the shm from apr type to os specific type.
269 * @param osshm The os specific shm representation
270 * @param shm The apr shm to convert.
272 APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,
275 #if APR_HAS_THREADS || defined(DOXYGEN)
277 * @defgroup apr_os_thread Thread portability Routines
281 * convert the thread to os specific type from apr type.
282 * @param thethd The apr thread to convert
283 * @param thd The os specific thread we are converting to
285 APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd,
289 * convert the thread private memory key to os specific type from an apr type.
290 * @param thekey The apr handle we are converting from.
291 * @param key The os specific handle we are converting to.
293 APR_DECLARE(apr_status_t) apr_os_threadkey_get(apr_os_threadkey_t *thekey,
294 apr_threadkey_t *key);
297 * convert the thread from os specific type to apr type.
298 * @param thd The apr thread we are converting to.
299 * @param thethd The os specific thread to convert
300 * @param cont The pool to use if it is needed.
302 APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd,
303 apr_os_thread_t *thethd,
307 * convert the thread private memory key from os specific type to apr type.
308 * @param key The apr handle we are converting to.
309 * @param thekey The os specific handle to convert
310 * @param cont The pool to use if it is needed.
312 APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
313 apr_os_threadkey_t *thekey,
318 APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void);
321 * Compare two thread id's
322 * @param tid1 1st Thread ID to compare
323 * @param tid2 2nd Thread ID to compare
324 * @return non-zero if the two threads are equal, zero otherwise
326 APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1,
327 apr_os_thread_t tid2);
330 #endif /* APR_HAS_THREADS */
333 * convert the file from os specific type to apr type.
334 * @param file The apr file we are converting to.
335 * @param thefile The os specific file to convert
336 * @param flags The flags that were used to open this file.
337 * @param cont The pool to use if it is needed.
338 * @remark On Unix, it is only possible to put a file descriptor into
341 APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file,
342 apr_os_file_t *thefile,
343 apr_int32_t flags, apr_pool_t *cont);
346 * convert the file from os specific type to apr type.
347 * @param file The apr file we are converting to.
348 * @param thefile The os specific pipe to convert
349 * @param cont The pool to use if it is needed.
350 * @remark On Unix, it is only possible to put a file descriptor into
353 APR_DECLARE(apr_status_t) apr_os_pipe_put(apr_file_t **file,
354 apr_os_file_t *thefile,
358 * convert the file from os specific type to apr type.
359 * @param file The apr file we are converting to.
360 * @param thefile The os specific pipe to convert
361 * @param register_cleanup A cleanup will be registered on the apr_file_t
362 * to issue apr_file_close().
363 * @param cont The pool to use if it is needed.
364 * @remark On Unix, it is only possible to put a file descriptor into
367 APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file,
368 apr_os_file_t *thefile,
369 int register_cleanup,
373 * convert the dir from os specific type to apr type.
374 * @param dir The apr dir we are converting to.
375 * @param thedir The os specific dir to convert
376 * @param cont The pool to use when creating to apr directory.
378 APR_DECLARE(apr_status_t) apr_os_dir_put(apr_dir_t **dir,
379 apr_os_dir_t *thedir,
383 * Convert a socket from the os specific type to the apr type
384 * @param sock The pool to use.
385 * @param thesock The socket to convert to.
386 * @param cont The socket we are converting to an apr type.
387 * @remark If it is a true socket, it is best to call apr_os_sock_make()
388 * and provide APR with more information about the socket.
390 APR_DECLARE(apr_status_t) apr_os_sock_put(apr_socket_t **sock,
391 apr_os_sock_t *thesock,
395 * Create a socket from an existing descriptor and local and remote
397 * @param apr_sock The new socket that has been set up
398 * @param os_sock_info The os representation of the socket handle and
399 * other characteristics of the socket
400 * @param cont The pool to use
401 * @remark If you only know the descriptor/handle or if it isn't really
402 * a true socket, use apr_os_sock_put() instead.
404 APR_DECLARE(apr_status_t) apr_os_sock_make(apr_socket_t **apr_sock,
405 apr_os_sock_info_t *os_sock_info,
409 * Convert the proc mutex from os specific type to apr type
410 * @param pmutex The apr proc mutex we are converting to.
411 * @param ospmutex The os specific proc mutex to convert.
412 * @param cont The pool to use if it is needed.
414 APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
415 apr_os_proc_mutex_t *ospmutex,
419 * Put the imploded time in the APR format.
420 * @param aprtime the APR time format
421 * @param ostime the time to convert
422 * @param cont the pool to use if necessary
424 APR_DECLARE(apr_status_t) apr_os_imp_time_put(apr_time_t *aprtime,
425 apr_os_imp_time_t **ostime,
429 * Put the exploded time in the APR format.
430 * @param aprtime the APR time format
431 * @param ostime the time to convert
432 * @param cont the pool to use if necessary
434 APR_DECLARE(apr_status_t) apr_os_exp_time_put(apr_time_exp_t *aprtime,
435 apr_os_exp_time_t **ostime,
439 * convert the shared memory from os specific type to apr type.
440 * @param shm The apr shm representation of osshm
441 * @param osshm The os specific shm identity
442 * @param cont The pool to use if it is needed.
443 * @remark On fork()ed architectures, this is typically nothing more than
444 * the memory block mapped. On non-fork architectures, this is typically
445 * some internal handle to pass the mapping from process to process.
447 APR_DECLARE(apr_status_t) apr_os_shm_put(apr_shm_t **shm,
452 #if APR_HAS_DSO || defined(DOXYGEN)
454 * @defgroup apr_os_dso DSO (Dynamic Loading) Portability Routines
458 * convert the dso handle from os specific to apr
459 * @param dso The apr handle we are converting to
460 * @param thedso the os specific handle to convert
461 * @param pool the pool to use if it is needed
463 APR_DECLARE(apr_status_t) apr_os_dso_handle_put(apr_dso_handle_t **dso,
464 apr_os_dso_handle_t thedso,
468 * convert the apr dso handle into an os specific one
469 * @param aprdso The apr dso handle to convert
470 * @param dso The os specific dso to return
472 APR_DECLARE(apr_status_t) apr_os_dso_handle_get(apr_os_dso_handle_t *dso,
473 apr_dso_handle_t *aprdso);
476 #endif /* APR_HAS_DSO */
481 * Private: apr-util's apr_uuid module when supported by the platform
483 APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data);
488 * Get the name of the system default character set.
489 * @param pool the pool to allocate the name from, if needed
491 APR_DECLARE(const char*) apr_os_default_encoding(apr_pool_t *pool);
495 * Get the name of the current locale character set.
496 * @param pool the pool to allocate the name from, if needed
497 * @remark Defers to apr_os_default_encoding if the current locale's
498 * data can't be retrieved on this system.
500 APR_DECLARE(const char*) apr_os_locale_encoding(apr_pool_t *pool);
508 #endif /* ! APR_PORTABLE_H */