2
0

fspr_pools.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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. #ifndef APR_POOLS_H
  17. #define APR_POOLS_H
  18. /**
  19. * @file fspr_pools.h
  20. * @brief APR memory allocation
  21. *
  22. * Resource allocation routines...
  23. *
  24. * designed so that we don't have to keep track of EVERYTHING so that
  25. * it can be explicitly freed later (a fundamentally unsound strategy ---
  26. * particularly in the presence of die()).
  27. *
  28. * Instead, we maintain pools, and allocate items (both memory and I/O
  29. * handlers) from the pools --- currently there are two, one for per
  30. * transaction info, and one for config info. When a transaction is over,
  31. * we can delete everything in the per-transaction fspr_pool_t without fear,
  32. * and without thinking too hard about it either.
  33. */
  34. #include "fspr.h"
  35. #include "fspr_errno.h"
  36. #include "fspr_general.h" /* for APR_STRINGIFY */
  37. #define APR_WANT_MEMFUNC /**< for no good reason? */
  38. #include "fspr_want.h"
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /**
  43. * @defgroup fspr_pools Memory Pool Functions
  44. * @ingroup APR
  45. * @{
  46. */
  47. /** The fundamental pool type */
  48. typedef struct fspr_pool_t fspr_pool_t;
  49. /**
  50. * Declaration helper macro to construct fspr_foo_pool_get()s.
  51. *
  52. * This standardized macro is used by opaque (APR) data types to return
  53. * the fspr_pool_t that is associated with the data type.
  54. *
  55. * APR_POOL_DECLARE_ACCESSOR() is used in a header file to declare the
  56. * accessor function. A typical usage and result would be:
  57. * <pre>
  58. * APR_POOL_DECLARE_ACCESSOR(file);
  59. * becomes:
  60. * APR_DECLARE(fspr_pool_t *) fspr_file_pool_get(fspr_file_t *ob);
  61. * </pre>
  62. * @remark Doxygen unwraps this macro (via doxygen.conf) to provide
  63. * actual help for each specific occurance of fspr_foo_pool_get.
  64. * @remark the linkage is specified for APR. It would be possible to expand
  65. * the macros to support other linkages.
  66. */
  67. #define APR_POOL_DECLARE_ACCESSOR(type) \
  68. APR_DECLARE(fspr_pool_t *) fspr_##type##_pool_get \
  69. (const fspr_##type##_t *the##type)
  70. /**
  71. * Implementation helper macro to provide fspr_foo_pool_get()s.
  72. *
  73. * In the implementation, the APR_POOL_IMPLEMENT_ACCESSOR() is used to
  74. * actually define the function. It assumes the field is named "pool".
  75. */
  76. #define APR_POOL_IMPLEMENT_ACCESSOR(type) \
  77. APR_DECLARE(fspr_pool_t *) fspr_##type##_pool_get \
  78. (const fspr_##type##_t *the##type) \
  79. { return the##type->pool; }
  80. /**
  81. * Pool debug levels
  82. *
  83. * <pre>
  84. * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  85. * ---------------------------------
  86. * | | | | | | | | x | General debug code enabled (useful in
  87. * combination with --with-efence).
  88. *
  89. * | | | | | | | x | | Verbose output on stderr (report
  90. * CREATE, CLEAR, DESTROY).
  91. *
  92. * | | | | x | | | | | Verbose output on stderr (report
  93. * PALLOC, PCALLOC).
  94. *
  95. * | | | | | | x | | | Lifetime checking. On each use of a
  96. * pool, check its lifetime. If the pool
  97. * is out of scope, abort().
  98. * In combination with the verbose flag
  99. * above, it will output LIFE in such an
  100. * event prior to aborting.
  101. *
  102. * | | | | | x | | | | Pool owner checking. On each use of a
  103. * pool, check if the current thread is the
  104. * pools owner. If not, abort(). In
  105. * combination with the verbose flag above,
  106. * it will output OWNER in such an event
  107. * prior to aborting. Use the debug
  108. * function fspr_pool_owner_set() to switch
  109. * a pools ownership.
  110. *
  111. * When no debug level was specified, assume general debug mode.
  112. * If level 0 was specified, debugging is switched off
  113. * </pre>
  114. */
  115. #if defined(APR_POOL_DEBUG)
  116. /* If APR_POOL_DEBUG is blank, we get 1; if it is a number, we get -1. */
  117. #if (APR_POOL_DEBUG - APR_POOL_DEBUG -1 == 1)
  118. #undef APR_POOL_DEBUG
  119. #define APR_POOL_DEBUG 1
  120. #endif
  121. #else
  122. #define APR_POOL_DEBUG 0
  123. #endif
  124. /** the place in the code where the particular function was called */
  125. #define APR_POOL__FILE_LINE__ __FILE__ ":" APR_STRINGIFY(__LINE__)
  126. /** A function that is called when allocation fails. */
  127. typedef int (*fspr_abortfunc_t)(int retcode);
  128. /*
  129. * APR memory structure manipulators (pools, tables, and arrays).
  130. */
  131. /*
  132. * Initialization
  133. */
  134. /**
  135. * Setup all of the internal structures required to use pools
  136. * @remark Programs do NOT need to call this directly. APR will call this
  137. * automatically from fspr_initialize.
  138. * @internal
  139. */
  140. APR_DECLARE(fspr_status_t) fspr_pool_initialize(void);
  141. /**
  142. * Tear down all of the internal structures required to use pools
  143. * @remark Programs do NOT need to call this directly. APR will call this
  144. * automatically from fspr_terminate.
  145. * @internal
  146. */
  147. APR_DECLARE(void) fspr_pool_terminate(void);
  148. /*
  149. * Pool creation/destruction
  150. */
  151. #include "fspr_allocator.h"
  152. /**
  153. * Create a new pool.
  154. * @param newpool The pool we have just created.
  155. * @param parent The parent pool. If this is NULL, the new pool is a root
  156. * pool. If it is non-NULL, the new pool will inherit all
  157. * of its parent pool's attributes, except the fspr_pool_t will
  158. * be a sub-pool.
  159. * @param abort_fn A function to use if the pool cannot allocate more memory.
  160. * @param allocator The allocator to use with the new pool. If NULL the
  161. * allocator of the parent pool will be used.
  162. */
  163. APR_DECLARE(fspr_status_t) fspr_pool_create_ex(fspr_pool_t **newpool,
  164. fspr_pool_t *parent,
  165. fspr_abortfunc_t abort_fn,
  166. fspr_allocator_t *allocator);
  167. /**
  168. * Debug version of fspr_pool_create_ex.
  169. * @param newpool @see fspr_pool_create.
  170. * @param parent @see fspr_pool_create.
  171. * @param abort_fn @see fspr_pool_create.
  172. * @param allocator @see fspr_pool_create.
  173. * @param file_line Where the function is called from.
  174. * This is usually APR_POOL__FILE_LINE__.
  175. * @remark Only available when APR_POOL_DEBUG is defined.
  176. * Call this directly if you have you fspr_pool_create_ex
  177. * calls in a wrapper function and wish to override
  178. * the file_line argument to reflect the caller of
  179. * your wrapper function. If you do not have
  180. * fspr_pool_create_ex in a wrapper, trust the macro
  181. * and don't call fspr_pool_create_ex_debug directly.
  182. */
  183. APR_DECLARE(fspr_status_t) fspr_pool_create_ex_debug(fspr_pool_t **newpool,
  184. fspr_pool_t *parent,
  185. fspr_abortfunc_t abort_fn,
  186. fspr_allocator_t *allocator,
  187. const char *file_line);
  188. #if APR_POOL_DEBUG
  189. #define fspr_pool_create_ex(newpool, parent, abort_fn, allocator) \
  190. fspr_pool_create_ex_debug(newpool, parent, abort_fn, allocator, \
  191. APR_POOL__FILE_LINE__)
  192. APR_DECLARE(int) fspr_pool_walk_tree_debug(fspr_pool_t *pool,
  193. int(*fn)(fspr_pool_t *pool, void *data),
  194. void *data);
  195. APR_DECLARE(void) fspr_pool_get_stats(fspr_pool_t *pool, unsigned int *alloc, unsigned int *total_alloc, unsigned int *clear);
  196. #endif
  197. /**
  198. * Create a new pool.
  199. * @param newpool The pool we have just created.
  200. * @param parent The parent pool. If this is NULL, the new pool is a root
  201. * pool. If it is non-NULL, the new pool will inherit all
  202. * of its parent pool's attributes, except the fspr_pool_t will
  203. * be a sub-pool.
  204. */
  205. #if defined(DOXYGEN)
  206. APR_DECLARE(fspr_status_t) fspr_pool_create(fspr_pool_t **newpool,
  207. fspr_pool_t *parent);
  208. #else
  209. #if APR_POOL_DEBUG
  210. #define fspr_pool_create(newpool, parent) \
  211. fspr_pool_create_ex_debug(newpool, parent, NULL, NULL, \
  212. APR_POOL__FILE_LINE__)
  213. #else
  214. #define fspr_pool_create(newpool, parent) \
  215. fspr_pool_create_ex(newpool, parent, NULL, NULL)
  216. #endif
  217. #endif
  218. /**
  219. * Find the pools allocator
  220. * @param pool The pool to get the allocator from.
  221. */
  222. APR_DECLARE(fspr_allocator_t *) fspr_pool_allocator_get(fspr_pool_t *pool);
  223. /**
  224. * Clear all memory in the pool and run all the cleanups. This also destroys all
  225. * subpools.
  226. * @param p The pool to clear
  227. * @remark This does not actually free the memory, it just allows the pool
  228. * to re-use this memory for the next allocation.
  229. * @see fspr_pool_destroy()
  230. */
  231. APR_DECLARE(void) fspr_pool_clear(fspr_pool_t *p);
  232. /**
  233. * Debug version of fspr_pool_clear.
  234. * @param p See: fspr_pool_clear.
  235. * @param file_line Where the function is called from.
  236. * This is usually APR_POOL__FILE_LINE__.
  237. * @remark Only available when APR_POOL_DEBUG is defined.
  238. * Call this directly if you have you fspr_pool_clear
  239. * calls in a wrapper function and wish to override
  240. * the file_line argument to reflect the caller of
  241. * your wrapper function. If you do not have
  242. * fspr_pool_clear in a wrapper, trust the macro
  243. * and don't call fspr_pool_destroy_clear directly.
  244. */
  245. APR_DECLARE(void) fspr_pool_clear_debug(fspr_pool_t *p,
  246. const char *file_line);
  247. #if APR_POOL_DEBUG
  248. #define fspr_pool_clear(p) \
  249. fspr_pool_clear_debug(p, APR_POOL__FILE_LINE__)
  250. #endif
  251. /**
  252. * Destroy the pool. This takes similar action as fspr_pool_clear() and then
  253. * frees all the memory.
  254. * @param p The pool to destroy
  255. * @remark This will actually free the memory
  256. */
  257. APR_DECLARE(void) fspr_pool_destroy(fspr_pool_t *p);
  258. /**
  259. * Debug version of fspr_pool_destroy.
  260. * @param p See: fspr_pool_destroy.
  261. * @param file_line Where the function is called from.
  262. * This is usually APR_POOL__FILE_LINE__.
  263. * @remark Only available when APR_POOL_DEBUG is defined.
  264. * Call this directly if you have you fspr_pool_destroy
  265. * calls in a wrapper function and wish to override
  266. * the file_line argument to reflect the caller of
  267. * your wrapper function. If you do not have
  268. * fspr_pool_destroy in a wrapper, trust the macro
  269. * and don't call fspr_pool_destroy_debug directly.
  270. */
  271. APR_DECLARE(void) fspr_pool_destroy_debug(fspr_pool_t *p,
  272. const char *file_line);
  273. #if APR_POOL_DEBUG
  274. #define fspr_pool_destroy(p) \
  275. fspr_pool_destroy_debug(p, APR_POOL__FILE_LINE__)
  276. #endif
  277. /*
  278. * Memory allocation
  279. */
  280. /**
  281. * Allocate a block of memory from a pool
  282. * @param p The pool to allocate from
  283. * @param size The amount of memory to allocate
  284. * @return The allocated memory
  285. */
  286. APR_DECLARE(void *) fspr_palloc(fspr_pool_t *p, fspr_size_t size);
  287. /**
  288. * Debug version of fspr_palloc
  289. * @param p See: fspr_palloc
  290. * @param size See: fspr_palloc
  291. * @param file_line Where the function is called from.
  292. * This is usually APR_POOL__FILE_LINE__.
  293. * @return See: fspr_palloc
  294. */
  295. APR_DECLARE(void *) fspr_palloc_debug(fspr_pool_t *p, fspr_size_t size,
  296. const char *file_line);
  297. #if APR_POOL_DEBUG
  298. #define fspr_palloc(p, size) \
  299. fspr_palloc_debug(p, size, APR_POOL__FILE_LINE__)
  300. #endif
  301. /**
  302. * Allocate a block of memory from a pool and set all of the memory to 0
  303. * @param p The pool to allocate from
  304. * @param size The amount of memory to allocate
  305. * @return The allocated memory
  306. */
  307. #if defined(DOXYGEN)
  308. APR_DECLARE(void *) fspr_pcalloc(fspr_pool_t *p, fspr_size_t size);
  309. #elif !APR_POOL_DEBUG
  310. #define fspr_pcalloc(p, size) memset(fspr_palloc(p, size), 0, size)
  311. #endif
  312. /**
  313. * Debug version of fspr_pcalloc
  314. * @param p See: fspr_pcalloc
  315. * @param size See: fspr_pcalloc
  316. * @param file_line Where the function is called from.
  317. * This is usually APR_POOL__FILE_LINE__.
  318. * @return See: fspr_pcalloc
  319. */
  320. APR_DECLARE(void *) fspr_pcalloc_debug(fspr_pool_t *p, fspr_size_t size,
  321. const char *file_line);
  322. #if APR_POOL_DEBUG
  323. #define fspr_pcalloc(p, size) \
  324. fspr_pcalloc_debug(p, size, APR_POOL__FILE_LINE__)
  325. #endif
  326. /*
  327. * Pool Properties
  328. */
  329. /**
  330. * Set the function to be called when an allocation failure occurs.
  331. * @remark If the program wants APR to exit on a memory allocation error,
  332. * then this function can be called to set the callback to use (for
  333. * performing cleanup and then exiting). If this function is not called,
  334. * then APR will return an error and expect the calling program to
  335. * deal with the error accordingly.
  336. */
  337. APR_DECLARE(void) fspr_pool_abort_set(fspr_abortfunc_t abortfunc,
  338. fspr_pool_t *pool);
  339. /**
  340. * Get the abort function associated with the specified pool.
  341. * @param pool The pool for retrieving the abort function.
  342. * @return The abort function for the given pool.
  343. */
  344. APR_DECLARE(fspr_abortfunc_t) fspr_pool_abort_get(fspr_pool_t *pool);
  345. /**
  346. * Get the parent pool of the specified pool.
  347. * @param pool The pool for retrieving the parent pool.
  348. * @return The parent of the given pool.
  349. */
  350. APR_DECLARE(fspr_pool_t *) fspr_pool_parent_get(fspr_pool_t *pool);
  351. /**
  352. * Determine if pool a is an ancestor of pool b.
  353. * @param a The pool to search
  354. * @param b The pool to search for
  355. * @return True if a is an ancestor of b, NULL is considered an ancestor
  356. * of all pools.
  357. * @remark if compiled with APR_POOL_DEBUG, this function will also
  358. * return true if A is a pool which has been guaranteed by the caller
  359. * (using fspr_pool_join) to have a lifetime at least as long as some
  360. * ancestor of pool B.
  361. */
  362. APR_DECLARE(int) fspr_pool_is_ancestor(fspr_pool_t *a, fspr_pool_t *b);
  363. /**
  364. * Tag a pool (give it a name)
  365. * @param pool The pool to tag
  366. * @param tag The tag
  367. */
  368. APR_DECLARE(const char *) fspr_pool_tag(fspr_pool_t *pool, const char *tag);
  369. #if APR_HAS_THREADS
  370. /**
  371. * Add a mutex to a pool to make it suitable to use from multiple threads.
  372. * @param pool The pool to add the mutex to
  373. * @param mutex The mutex
  374. * @remark The mutex does not protect the destroy operation just the low level allocs.
  375. */
  376. APR_DECLARE(void) fspr_pool_mutex_set(fspr_pool_t *pool,
  377. fspr_thread_mutex_t *mutex);
  378. #endif
  379. /*
  380. * User data management
  381. */
  382. /**
  383. * Set the data associated with the current pool
  384. * @param data The user data associated with the pool.
  385. * @param key The key to use for association
  386. * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
  387. * @param pool The current pool
  388. * @warning The data to be attached to the pool should have a life span
  389. * at least as long as the pool it is being attached to.
  390. *
  391. * Users of APR must take EXTREME care when choosing a key to
  392. * use for their data. It is possible to accidentally overwrite
  393. * data by choosing a key that another part of the program is using.
  394. * Therefore it is advised that steps are taken to ensure that unique
  395. * keys are used for all of the userdata objects in a particular pool
  396. * (the same key in two different pools or a pool and one of its
  397. * subpools is okay) at all times. Careful namespace prefixing of
  398. * key names is a typical way to help ensure this uniqueness.
  399. *
  400. */
  401. APR_DECLARE(fspr_status_t) fspr_pool_userdata_set(
  402. const void *data,
  403. const char *key,
  404. fspr_status_t (*cleanup)(void *),
  405. fspr_pool_t *pool);
  406. /**
  407. * Set the data associated with the current pool
  408. * @param data The user data associated with the pool.
  409. * @param key The key to use for association
  410. * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
  411. * @param pool The current pool
  412. * @note same as fspr_pool_userdata_set(), except that this version doesn't
  413. * make a copy of the key (this function is useful, for example, when
  414. * the key is a string literal)
  415. * @warning This should NOT be used if the key could change addresses by
  416. * any means between the fspr_pool_userdata_setn() call and a
  417. * subsequent fspr_pool_userdata_get() on that key, such as if a
  418. * static string is used as a userdata key in a DSO and the DSO could
  419. * be unloaded and reloaded between the _setn() and the _get(). You
  420. * MUST use fspr_pool_userdata_set() in such cases.
  421. * @warning More generally, the key and the data to be attached to the
  422. * pool should have a life span at least as long as the pool itself.
  423. *
  424. */
  425. APR_DECLARE(fspr_status_t) fspr_pool_userdata_setn(
  426. const void *data,
  427. const char *key,
  428. fspr_status_t (*cleanup)(void *),
  429. fspr_pool_t *pool);
  430. /**
  431. * Return the data associated with the current pool.
  432. * @param data The user data associated with the pool.
  433. * @param key The key for the data to retrieve
  434. * @param pool The current pool.
  435. */
  436. APR_DECLARE(fspr_status_t) fspr_pool_userdata_get(void **data, const char *key,
  437. fspr_pool_t *pool);
  438. /**
  439. * @defgroup PoolCleanup Pool Cleanup Functions
  440. *
  441. * Cleanups are performed in the reverse order they were registered. That is:
  442. * Last In, First Out. A cleanup function can safely allocate memory from
  443. * the pool that is being cleaned up. It can also safely register additional
  444. * cleanups which will be run LIFO, directly after the current cleanup
  445. * terminates. Cleanups have to take caution in calling functions that
  446. * create subpools. Subpools, created during cleanup will NOT automatically
  447. * be cleaned up. In other words, cleanups are to clean up after themselves.
  448. *
  449. * @{
  450. */
  451. /**
  452. * Register a function to be called when a pool is cleared or destroyed
  453. * @param p The pool register the cleanup with
  454. * @param data The data to pass to the cleanup function.
  455. * @param plain_cleanup The function to call when the pool is cleared
  456. * or destroyed
  457. * @param child_cleanup The function to call when a child process is about
  458. * to exec - this function is called in the child, obviously!
  459. */
  460. APR_DECLARE(void) fspr_pool_cleanup_register(
  461. fspr_pool_t *p,
  462. const void *data,
  463. fspr_status_t (*plain_cleanup)(void *),
  464. fspr_status_t (*child_cleanup)(void *));
  465. /**
  466. * Remove a previously registered cleanup function.
  467. *
  468. * The cleanup most recently registered with @a p having the same values of
  469. * @a data and @a cleanup will be removed.
  470. *
  471. * @param p The pool to remove the cleanup from
  472. * @param data The data of the registered cleanup
  473. * @param cleanup The function to remove from cleanup
  474. * @remarks For some strange reason only the plain_cleanup is handled by this
  475. * function
  476. */
  477. APR_DECLARE(void) fspr_pool_cleanup_kill(fspr_pool_t *p, const void *data,
  478. fspr_status_t (*cleanup)(void *));
  479. /**
  480. * Replace the child cleanup function of a previously registered cleanup.
  481. *
  482. * The cleanup most recently registered with @a p having the same values of
  483. * @a data and @a plain_cleanup will have the registered child cleanup
  484. * function replaced with @a child_cleanup.
  485. *
  486. * @param p The pool of the registered cleanup
  487. * @param data The data of the registered cleanup
  488. * @param plain_cleanup The plain cleanup function of the registered cleanup
  489. * @param child_cleanup The function to register as the child cleanup
  490. */
  491. APR_DECLARE(void) fspr_pool_child_cleanup_set(
  492. fspr_pool_t *p,
  493. const void *data,
  494. fspr_status_t (*plain_cleanup)(void *),
  495. fspr_status_t (*child_cleanup)(void *));
  496. /**
  497. * Run the specified cleanup function immediately and unregister it.
  498. *
  499. * The cleanup most recently registered with @a p having the same values of
  500. * @a data and @a cleanup will be removed and @a cleanup will be called
  501. * with @a data as the argument.
  502. *
  503. * @param p The pool to remove the cleanup from
  504. * @param data The data to remove from cleanup
  505. * @param cleanup The function to remove from cleanup
  506. */
  507. APR_DECLARE(fspr_status_t) fspr_pool_cleanup_run(
  508. fspr_pool_t *p,
  509. void *data,
  510. fspr_status_t (*cleanup)(void *));
  511. /**
  512. * An empty cleanup function.
  513. *
  514. * Passed to fspr_pool_cleanup_register() when no cleanup is required.
  515. *
  516. * @param data The data to cleanup, will not be used by this function.
  517. */
  518. APR_DECLARE_NONSTD(fspr_status_t) fspr_pool_cleanup_null(void *data);
  519. /**
  520. * Run all registered child cleanups, in preparation for an exec()
  521. * call in a forked child -- close files, etc., but *don't* flush I/O
  522. * buffers, *don't* wait for subprocesses, and *don't* free any
  523. * memory.
  524. */
  525. APR_DECLARE(void) fspr_pool_cleanup_for_exec(void);
  526. /** @} */
  527. /**
  528. * @defgroup PoolDebug Pool Debugging functions.
  529. *
  530. * pools have nested lifetimes -- sub_pools are destroyed when the
  531. * parent pool is cleared. We allow certain liberties with operations
  532. * on things such as tables (and on other structures in a more general
  533. * sense) where we allow the caller to insert values into a table which
  534. * were not allocated from the table's pool. The table's data will
  535. * remain valid as long as all the pools from which its values are
  536. * allocated remain valid.
  537. *
  538. * For example, if B is a sub pool of A, and you build a table T in
  539. * pool B, then it's safe to insert data allocated in A or B into T
  540. * (because B lives at most as long as A does, and T is destroyed when
  541. * B is cleared/destroyed). On the other hand, if S is a table in
  542. * pool A, it is safe to insert data allocated in A into S, but it
  543. * is *not safe* to insert data allocated from B into S... because
  544. * B can be cleared/destroyed before A is (which would leave dangling
  545. * pointers in T's data structures).
  546. *
  547. * In general we say that it is safe to insert data into a table T
  548. * if the data is allocated in any ancestor of T's pool. This is the
  549. * basis on which the APR_POOL_DEBUG code works -- it tests these ancestor
  550. * relationships for all data inserted into tables. APR_POOL_DEBUG also
  551. * provides tools (fspr_pool_find, and fspr_pool_is_ancestor) for other
  552. * folks to implement similar restrictions for their own data
  553. * structures.
  554. *
  555. * However, sometimes this ancestor requirement is inconvenient --
  556. * sometimes it's necessary to create a sub pool where the sub pool is
  557. * guaranteed to have the same lifetime as the parent pool. This is a
  558. * guarantee implemented by the *caller*, not by the pool code. That
  559. * is, the caller guarantees they won't destroy the sub pool
  560. * individually prior to destroying the parent pool.
  561. *
  562. * In this case the caller must call fspr_pool_join() to indicate this
  563. * guarantee to the APR_POOL_DEBUG code.
  564. *
  565. * These functions are only implemented when #APR_POOL_DEBUG is set.
  566. *
  567. * @{
  568. */
  569. #if APR_POOL_DEBUG || defined(DOXYGEN)
  570. /**
  571. * Guarantee that a subpool has the same lifetime as the parent.
  572. * @param p The parent pool
  573. * @param sub The subpool
  574. */
  575. APR_DECLARE(void) fspr_pool_join(fspr_pool_t *p, fspr_pool_t *sub);
  576. /**
  577. * Find a pool from something allocated in it.
  578. * @param mem The thing allocated in the pool
  579. * @return The pool it is allocated in
  580. */
  581. APR_DECLARE(fspr_pool_t *) fspr_pool_find(const void *mem);
  582. /**
  583. * Report the number of bytes currently in the pool
  584. * @param p The pool to inspect
  585. * @param recurse Recurse/include the subpools' sizes
  586. * @return The number of bytes
  587. */
  588. APR_DECLARE(fspr_size_t) fspr_pool_num_bytes(fspr_pool_t *p, int recurse);
  589. /**
  590. * Lock a pool
  591. * @param pool The pool to lock
  592. * @param flag The flag
  593. */
  594. APR_DECLARE(void) fspr_pool_lock(fspr_pool_t *pool, int flag);
  595. /* @} */
  596. #else /* APR_POOL_DEBUG or DOXYGEN */
  597. #ifdef fspr_pool_join
  598. #undef fspr_pool_join
  599. #endif
  600. #define fspr_pool_join(a,b)
  601. #ifdef fspr_pool_lock
  602. #undef fspr_pool_lock
  603. #endif
  604. #define fspr_pool_lock(pool, lock)
  605. #endif /* APR_POOL_DEBUG or DOXYGEN */
  606. /** @} */
  607. #ifdef __cplusplus
  608. }
  609. #endif
  610. #endif /* !APR_POOLS_H */