fspr_portable.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. /* This header file is where you should put ANY platform specific information.
  17. * This should be the only header file that programs need to include that
  18. * actually has platform dependant code which refers to the .
  19. */
  20. #ifndef APR_PORTABLE_H
  21. #define APR_PORTABLE_H
  22. /**
  23. * @file fspr_portable.h
  24. * @brief APR Portability Routines
  25. */
  26. #include "fspr.h"
  27. #include "fspr_pools.h"
  28. #include "fspr_thread_proc.h"
  29. #include "fspr_file_io.h"
  30. #include "fspr_network_io.h"
  31. #include "fspr_errno.h"
  32. #include "fspr_global_mutex.h"
  33. #include "fspr_proc_mutex.h"
  34. #include "fspr_time.h"
  35. #include "fspr_dso.h"
  36. #include "fspr_shm.h"
  37. #if APR_HAVE_DIRENT_H
  38. #include <dirent.h>
  39. #endif
  40. #if APR_HAVE_FCNTL_H
  41. #include <fcntl.h>
  42. #endif
  43. #if APR_HAVE_PTHREAD_H
  44. #include <pthread.h>
  45. #endif
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif /* __cplusplus */
  49. /**
  50. * @defgroup fspr_portabile Portability Routines
  51. * @ingroup APR
  52. * @{
  53. */
  54. #ifdef WIN32
  55. /* The primitives for Windows types */
  56. typedef HANDLE fspr_os_file_t;
  57. typedef HANDLE fspr_os_dir_t;
  58. typedef SOCKET fspr_os_sock_t;
  59. typedef HANDLE fspr_os_proc_mutex_t;
  60. typedef HANDLE fspr_os_thread_t;
  61. typedef HANDLE fspr_os_proc_t;
  62. typedef DWORD fspr_os_threadkey_t;
  63. typedef FILETIME fspr_os_imp_time_t;
  64. typedef SYSTEMTIME fspr_os_exp_time_t;
  65. typedef HANDLE fspr_os_dso_handle_t;
  66. typedef HANDLE fspr_os_shm_t;
  67. #elif defined(OS2)
  68. typedef HFILE fspr_os_file_t;
  69. typedef HDIR fspr_os_dir_t;
  70. typedef int fspr_os_sock_t;
  71. typedef HMTX fspr_os_proc_mutex_t;
  72. typedef TID fspr_os_thread_t;
  73. typedef PID fspr_os_proc_t;
  74. typedef PULONG fspr_os_threadkey_t;
  75. typedef struct timeval fspr_os_imp_time_t;
  76. typedef struct tm fspr_os_exp_time_t;
  77. typedef HMODULE fspr_os_dso_handle_t;
  78. typedef void* fspr_os_shm_t;
  79. #elif defined(__BEOS__)
  80. #include <kernel/OS.h>
  81. #include <kernel/image.h>
  82. struct fspr_os_proc_mutex_t {
  83. sem_id sem;
  84. int32 ben;
  85. };
  86. typedef int fspr_os_file_t;
  87. typedef DIR fspr_os_dir_t;
  88. typedef int fspr_os_sock_t;
  89. typedef struct fspr_os_proc_mutex_t fspr_os_proc_mutex_t;
  90. typedef thread_id fspr_os_thread_t;
  91. typedef thread_id fspr_os_proc_t;
  92. typedef int fspr_os_threadkey_t;
  93. typedef struct timeval fspr_os_imp_time_t;
  94. typedef struct tm fspr_os_exp_time_t;
  95. typedef image_id fspr_os_dso_handle_t;
  96. typedef void* fspr_os_shm_t;
  97. #elif defined(NETWARE)
  98. typedef int fspr_os_file_t;
  99. typedef DIR fspr_os_dir_t;
  100. typedef int fspr_os_sock_t;
  101. typedef NXMutex_t fspr_os_proc_mutex_t;
  102. typedef NXThreadId_t fspr_os_thread_t;
  103. typedef long fspr_os_proc_t;
  104. typedef NXKey_t fspr_os_threadkey_t;
  105. typedef struct timeval fspr_os_imp_time_t;
  106. typedef struct tm fspr_os_exp_time_t;
  107. typedef void * fspr_os_dso_handle_t;
  108. typedef void* fspr_os_shm_t;
  109. #else
  110. /* Any other OS should go above this one. This is the lowest common
  111. * denominator typedefs for all UNIX-like systems. :)
  112. */
  113. /** Basic OS process mutex structure. */
  114. struct fspr_os_proc_mutex_t {
  115. #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
  116. /** Value used for SYS V Semaphore, FCNTL and FLOCK serialization */
  117. int crossproc;
  118. #endif
  119. #if APR_HAS_PROC_PTHREAD_SERIALIZE
  120. /** Value used for PTHREAD serialization */
  121. pthread_mutex_t *pthread_interproc;
  122. #endif
  123. #if APR_HAS_THREADS
  124. /* If no threads, no need for thread locks */
  125. #if APR_USE_PTHREAD_SERIALIZE
  126. /** This value is currently unused within APR and Apache */
  127. pthread_mutex_t *intraproc;
  128. #endif
  129. #endif
  130. };
  131. typedef int fspr_os_file_t; /**< native file */
  132. typedef DIR fspr_os_dir_t; /**< native dir */
  133. typedef int fspr_os_sock_t; /**< native dir */
  134. typedef struct fspr_os_proc_mutex_t fspr_os_proc_mutex_t; /**< native proces
  135. * mutex
  136. */
  137. #if APR_HAS_THREADS && APR_HAVE_PTHREAD_H
  138. typedef pthread_t fspr_os_thread_t; /**< native thread */
  139. typedef pthread_key_t fspr_os_threadkey_t; /**< native thread address
  140. * space */
  141. #endif
  142. typedef pid_t fspr_os_proc_t; /**< native pid */
  143. typedef struct timeval fspr_os_imp_time_t; /**< native timeval */
  144. typedef struct tm fspr_os_exp_time_t; /**< native tm */
  145. /** @var fspr_os_dso_handle_t
  146. * native dso types
  147. */
  148. #if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
  149. #include <dl.h>
  150. typedef shl_t fspr_os_dso_handle_t;
  151. #elif defined(DARWIN)
  152. #include <mach-o/dyld.h>
  153. typedef NSModule fspr_os_dso_handle_t;
  154. #else
  155. typedef void * fspr_os_dso_handle_t;
  156. #endif
  157. typedef void* fspr_os_shm_t; /**< native SHM */
  158. #endif
  159. /**
  160. * @typedef fspr_os_sock_info_t
  161. * @brief alias for local OS socket
  162. */
  163. /**
  164. * everything APR needs to know about an active socket to construct
  165. * an APR socket from it; currently, this is platform-independent
  166. */
  167. struct fspr_os_sock_info_t {
  168. fspr_os_sock_t *os_sock; /**< always required */
  169. struct sockaddr *local; /**< NULL if not yet bound */
  170. struct sockaddr *remote; /**< NULL if not connected */
  171. int family; /**< always required (APR_INET, APR_INET6, etc.) */
  172. int type; /**< always required (SOCK_STREAM, SOCK_DGRAM, etc.) */
  173. int protocol; /**< 0 or actual protocol (APR_PROTO_SCTP, APR_PROTO_TCP, etc.) */
  174. };
  175. typedef struct fspr_os_sock_info_t fspr_os_sock_info_t;
  176. #if APR_PROC_MUTEX_IS_GLOBAL || defined(DOXYGEN)
  177. /** Opaque global mutex type */
  178. #define fspr_os_global_mutex_t fspr_os_proc_mutex_t
  179. /** @return fspr_os_global_mutex */
  180. #define fspr_os_global_mutex_get fspr_os_proc_mutex_get
  181. #else
  182. /** Thread and process mutex for those platforms where process mutexes
  183. * are not held in threads.
  184. */
  185. struct fspr_os_global_mutex_t {
  186. fspr_pool_t *pool;
  187. fspr_proc_mutex_t *proc_mutex;
  188. #if APR_HAS_THREADS
  189. fspr_thread_mutex_t *thread_mutex;
  190. #endif /* APR_HAS_THREADS */
  191. };
  192. typedef struct fspr_os_global_mutex_t fspr_os_global_mutex_t;
  193. APR_DECLARE(fspr_status_t) fspr_os_global_mutex_get(fspr_os_global_mutex_t *ospmutex,
  194. fspr_global_mutex_t *pmutex);
  195. #endif
  196. /**
  197. * convert the file from apr type to os specific type.
  198. * @param thefile The os specific file we are converting to
  199. * @param file The apr file to convert.
  200. * @remark On Unix, it is only possible to get a file descriptor from
  201. * an apr file type.
  202. */
  203. APR_DECLARE(fspr_status_t) fspr_os_file_get(fspr_os_file_t *thefile,
  204. fspr_file_t *file);
  205. /**
  206. * convert the dir from apr type to os specific type.
  207. * @param thedir The os specific dir we are converting to
  208. * @param dir The apr dir to convert.
  209. */
  210. APR_DECLARE(fspr_status_t) fspr_os_dir_get(fspr_os_dir_t **thedir,
  211. fspr_dir_t *dir);
  212. /**
  213. * Convert the socket from an apr type to an OS specific socket
  214. * @param thesock The socket to convert.
  215. * @param sock The os specifc equivelant of the apr socket..
  216. */
  217. APR_DECLARE(fspr_status_t) fspr_os_sock_get(fspr_os_sock_t *thesock,
  218. fspr_socket_t *sock);
  219. /**
  220. * Convert the proc mutex from os specific type to apr type
  221. * @param ospmutex The os specific proc mutex we are converting to.
  222. * @param pmutex The apr proc mutex to convert.
  223. */
  224. APR_DECLARE(fspr_status_t) fspr_os_proc_mutex_get(fspr_os_proc_mutex_t *ospmutex,
  225. fspr_proc_mutex_t *pmutex);
  226. /**
  227. * Get the exploded time in the platforms native format.
  228. * @param ostime the native time format
  229. * @param aprtime the time to convert
  230. */
  231. APR_DECLARE(fspr_status_t) fspr_os_exp_time_get(fspr_os_exp_time_t **ostime,
  232. fspr_time_exp_t *aprtime);
  233. /**
  234. * Get the imploded time in the platforms native format.
  235. * @param ostime the native time format
  236. * @param aprtime the time to convert
  237. */
  238. APR_DECLARE(fspr_status_t) fspr_os_imp_time_get(fspr_os_imp_time_t **ostime,
  239. fspr_time_t *aprtime);
  240. /**
  241. * convert the shm from apr type to os specific type.
  242. * @param osshm The os specific shm representation
  243. * @param shm The apr shm to convert.
  244. */
  245. APR_DECLARE(fspr_status_t) fspr_os_shm_get(fspr_os_shm_t *osshm,
  246. fspr_shm_t *shm);
  247. #if APR_HAS_THREADS || defined(DOXYGEN)
  248. /**
  249. * @defgroup fspr_os_thread Thread portability Routines
  250. * @{
  251. */
  252. /**
  253. * convert the thread to os specific type from apr type.
  254. * @param thethd The apr thread to convert
  255. * @param thd The os specific thread we are converting to
  256. */
  257. APR_DECLARE(fspr_status_t) fspr_os_thread_get(fspr_os_thread_t **thethd,
  258. fspr_thread_t *thd);
  259. /**
  260. * convert the thread private memory key to os specific type from an apr type.
  261. * @param thekey The apr handle we are converting from.
  262. * @param key The os specific handle we are converting to.
  263. */
  264. APR_DECLARE(fspr_status_t) fspr_os_threadkey_get(fspr_os_threadkey_t *thekey,
  265. fspr_threadkey_t *key);
  266. /**
  267. * convert the thread from os specific type to apr type.
  268. * @param thd The apr thread we are converting to.
  269. * @param thethd The os specific thread to convert
  270. * @param cont The pool to use if it is needed.
  271. */
  272. APR_DECLARE(fspr_status_t) fspr_os_thread_put(fspr_thread_t **thd,
  273. fspr_os_thread_t *thethd,
  274. fspr_pool_t *cont);
  275. /**
  276. * convert the thread private memory key from os specific type to apr type.
  277. * @param key The apr handle we are converting to.
  278. * @param thekey The os specific handle to convert
  279. * @param cont The pool to use if it is needed.
  280. */
  281. APR_DECLARE(fspr_status_t) fspr_os_threadkey_put(fspr_threadkey_t **key,
  282. fspr_os_threadkey_t *thekey,
  283. fspr_pool_t *cont);
  284. /**
  285. * Get the thread ID
  286. */
  287. APR_DECLARE(fspr_os_thread_t) fspr_os_thread_current(void);
  288. /**
  289. * Compare two thread id's
  290. * @param tid1 1st Thread ID to compare
  291. * @param tid2 2nd Thread ID to compare
  292. */
  293. APR_DECLARE(int) fspr_os_thread_equal(fspr_os_thread_t tid1,
  294. fspr_os_thread_t tid2);
  295. /** @} */
  296. #endif /* APR_HAS_THREADS */
  297. /**
  298. * convert the file from os specific type to apr type.
  299. * @param file The apr file we are converting to.
  300. * @param thefile The os specific file to convert
  301. * @param flags The flags that were used to open this file.
  302. * @param cont The pool to use if it is needed.
  303. * @remark On Unix, it is only possible to put a file descriptor into
  304. * an apr file type.
  305. */
  306. APR_DECLARE(fspr_status_t) fspr_os_file_put(fspr_file_t **file,
  307. fspr_os_file_t *thefile,
  308. fspr_int32_t flags, fspr_pool_t *cont);
  309. /**
  310. * convert the file from os specific type to apr type.
  311. * @param file The apr file we are converting to.
  312. * @param thefile The os specific pipe to convert
  313. * @param cont The pool to use if it is needed.
  314. * @remark On Unix, it is only possible to put a file descriptor into
  315. * an apr file type.
  316. */
  317. APR_DECLARE(fspr_status_t) fspr_os_pipe_put(fspr_file_t **file,
  318. fspr_os_file_t *thefile,
  319. fspr_pool_t *cont);
  320. /**
  321. * convert the file from os specific type to apr type.
  322. * @param file The apr file we are converting to.
  323. * @param thefile The os specific pipe to convert
  324. * @param register_cleanup A cleanup will be registered on the fspr_file_t
  325. * to issue fspr_file_close().
  326. * @param cont The pool to use if it is needed.
  327. * @remark On Unix, it is only possible to put a file descriptor into
  328. * an apr file type.
  329. */
  330. APR_DECLARE(fspr_status_t) fspr_os_pipe_put_ex(fspr_file_t **file,
  331. fspr_os_file_t *thefile,
  332. int register_cleanup,
  333. fspr_pool_t *cont);
  334. /**
  335. * convert the dir from os specific type to apr type.
  336. * @param dir The apr dir we are converting to.
  337. * @param thedir The os specific dir to convert
  338. * @param cont The pool to use when creating to apr directory.
  339. */
  340. APR_DECLARE(fspr_status_t) fspr_os_dir_put(fspr_dir_t **dir,
  341. fspr_os_dir_t *thedir,
  342. fspr_pool_t *cont);
  343. /**
  344. * Convert a socket from the os specific type to the apr type
  345. * @param sock The pool to use.
  346. * @param thesock The socket to convert to.
  347. * @param cont The socket we are converting to an apr type.
  348. * @remark If it is a true socket, it is best to call fspr_os_sock_make()
  349. * and provide APR with more information about the socket.
  350. */
  351. APR_DECLARE(fspr_status_t) fspr_os_sock_put(fspr_socket_t **sock,
  352. fspr_os_sock_t *thesock,
  353. fspr_pool_t *cont);
  354. /**
  355. * Create a socket from an existing descriptor and local and remote
  356. * socket addresses.
  357. * @param fspr_sock The new socket that has been set up
  358. * @param os_sock_info The os representation of the socket handle and
  359. * other characteristics of the socket
  360. * @param cont The pool to use
  361. * @remark If you only know the descriptor/handle or if it isn't really
  362. * a true socket, use fspr_os_sock_put() instead.
  363. */
  364. APR_DECLARE(fspr_status_t) fspr_os_sock_make(fspr_socket_t **fspr_sock,
  365. fspr_os_sock_info_t *os_sock_info,
  366. fspr_pool_t *cont);
  367. /**
  368. * Convert the proc mutex from os specific type to apr type
  369. * @param pmutex The apr proc mutex we are converting to.
  370. * @param ospmutex The os specific proc mutex to convert.
  371. * @param cont The pool to use if it is needed.
  372. */
  373. APR_DECLARE(fspr_status_t) fspr_os_proc_mutex_put(fspr_proc_mutex_t **pmutex,
  374. fspr_os_proc_mutex_t *ospmutex,
  375. fspr_pool_t *cont);
  376. /**
  377. * Put the imploded time in the APR format.
  378. * @param aprtime the APR time format
  379. * @param ostime the time to convert
  380. * @param cont the pool to use if necessary
  381. */
  382. APR_DECLARE(fspr_status_t) fspr_os_imp_time_put(fspr_time_t *aprtime,
  383. fspr_os_imp_time_t **ostime,
  384. fspr_pool_t *cont);
  385. /**
  386. * Put the exploded time in the APR format.
  387. * @param aprtime the APR time format
  388. * @param ostime the time to convert
  389. * @param cont the pool to use if necessary
  390. */
  391. APR_DECLARE(fspr_status_t) fspr_os_exp_time_put(fspr_time_exp_t *aprtime,
  392. fspr_os_exp_time_t **ostime,
  393. fspr_pool_t *cont);
  394. /**
  395. * convert the shared memory from os specific type to apr type.
  396. * @param shm The apr shm representation of osshm
  397. * @param osshm The os specific shm identity
  398. * @param cont The pool to use if it is needed.
  399. * @remark On fork()ed architectures, this is typically nothing more than
  400. * the memory block mapped. On non-fork architectures, this is typically
  401. * some internal handle to pass the mapping from process to process.
  402. */
  403. APR_DECLARE(fspr_status_t) fspr_os_shm_put(fspr_shm_t **shm,
  404. fspr_os_shm_t *osshm,
  405. fspr_pool_t *cont);
  406. #if APR_HAS_DSO || defined(DOXYGEN)
  407. /**
  408. * @defgroup fspr_os_dso DSO (Dynamic Loading) Portabiliity Routines
  409. * @{
  410. */
  411. /**
  412. * convert the dso handle from os specific to apr
  413. * @param dso The apr handle we are converting to
  414. * @param thedso the os specific handle to convert
  415. * @param pool the pool to use if it is needed
  416. */
  417. APR_DECLARE(fspr_status_t) fspr_os_dso_handle_put(fspr_dso_handle_t **dso,
  418. fspr_os_dso_handle_t thedso,
  419. fspr_pool_t *pool);
  420. /**
  421. * convert the apr dso handle into an os specific one
  422. * @param aprdso The apr dso handle to convert
  423. * @param dso The os specific dso to return
  424. */
  425. APR_DECLARE(fspr_status_t) fspr_os_dso_handle_get(fspr_os_dso_handle_t *dso,
  426. fspr_dso_handle_t *aprdso);
  427. #if APR_HAS_OS_UUID
  428. /**
  429. * Private: apr-util's fspr_uuid module when supported by the platform
  430. */
  431. APR_DECLARE(fspr_status_t) fspr_os_uuid_get(unsigned char *uuid_data);
  432. #endif
  433. /** @} */
  434. #endif /* APR_HAS_DSO */
  435. /**
  436. * Get the name of the system default characer set.
  437. * @param pool the pool to allocate the name from, if needed
  438. */
  439. APR_DECLARE(const char*) fspr_os_default_encoding(fspr_pool_t *pool);
  440. /**
  441. * Get the name of the current locale character set.
  442. * @param pool the pool to allocate the name from, if needed
  443. * @remark Defers to fspr_os_default_encoding if the current locale's
  444. * data can't be retreved on this system.
  445. */
  446. APR_DECLARE(const char*) fspr_os_locale_encoding(fspr_pool_t *pool);
  447. /** @} */
  448. #ifdef __cplusplus
  449. }
  450. #endif
  451. #endif /* ! APR_PORTABLE_H */