Apache HTTPD
apr_pools.c
Go to the documentation of this file.
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#include "apr.h"
18#include "apr_private.h"
19
20#include "apr_atomic.h"
21#include "apr_portable.h" /* for get_os_proc */
22#include "apr_strings.h"
23#include "apr_general.h"
24#include "apr_pools.h"
25#include "apr_allocator.h"
26#include "apr_lib.h"
27#include "apr_thread_mutex.h"
28#include "apr_hash.h"
29#include "apr_time.h"
30#include "apr_support.h"
31#define APR_WANT_MEMFUNC
32#include "apr_want.h"
33#include "apr_env.h"
34
35#if APR_HAVE_STDLIB_H
36#include <stdlib.h> /* for malloc, free and abort */
37#endif
38
39#if APR_HAVE_UNISTD_H
40#include <unistd.h> /* for getpid and sysconf */
41#endif
42
43#if APR_ALLOCATOR_GUARD_PAGES && !APR_ALLOCATOR_USES_MMAP
44#define APR_ALLOCATOR_USES_MMAP 1
45#endif
46
47#if APR_ALLOCATOR_USES_MMAP
48#include <sys/mman.h>
49#endif
50
51#if HAVE_VALGRIND
52#include <valgrind.h>
53#include <memcheck.h>
54
55#define REDZONE APR_ALIGN_DEFAULT(8)
57#define APR_IF_VALGRIND(x) \
58 do { if (apr_running_on_valgrind) { x; } } while (0)
59
60#else
61
62#define APR_IF_VALGRIND(x)
63
64#endif /* HAVE_VALGRIND */
65
66#define APR_VALGRIND_NOACCESS(addr_, size_) \
67 APR_IF_VALGRIND(VALGRIND_MAKE_MEM_NOACCESS(addr_, size_))
68#define APR_VALGRIND_UNDEFINED(addr_, size_) \
69 APR_IF_VALGRIND(VALGRIND_MAKE_MEM_UNDEFINED(addr_, size_))
70
71
72#if APR_POOL_CONCURRENCY_CHECK && !APR_HAS_THREADS
73#error pool-concurrency-check does not make sense without threads
74#endif
75
76/*
77 * Magic numbers
78 */
79
80/*
81 * XXX: This is not optimal when using --enable-allocator-uses-mmap on
82 * XXX: machines with large pagesize, but currently the sink is assumed
83 * XXX: to be index 0, so MIN_ALLOC must be at least two pages.
84 */
85#define MIN_ALLOC (2 * BOUNDARY_SIZE)
86#define MAX_INDEX 20
87
88#if APR_ALLOCATOR_USES_MMAP && defined(_SC_PAGESIZE)
89static unsigned int boundary_index;
90static unsigned int boundary_size;
91#define BOUNDARY_INDEX boundary_index
92#define BOUNDARY_SIZE boundary_size
93#else
94#define BOUNDARY_INDEX 12
95#define BOUNDARY_SIZE (1 << BOUNDARY_INDEX)
96#endif
97
98#if APR_ALLOCATOR_GUARD_PAGES
99#if defined(_SC_PAGESIZE)
100#define GUARDPAGE_SIZE boundary_size
101#else
102#error Cannot determine page size
103#endif /* _SC_PAGESIZE */
104#else
105#define GUARDPAGE_SIZE 0
106#endif /* APR_ALLOCATOR_GUARD_PAGES */
107
108/*
109 * Timing constants for killing subprocesses
110 * There is a total 3-second delay between sending a SIGINT
111 * and sending of the final SIGKILL.
112 * TIMEOUT_INTERVAL should be set to TIMEOUT_USECS / 64
113 * for the exponetial timeout alogrithm.
114 */
115#define TIMEOUT_USECS 3000000
116#define TIMEOUT_INTERVAL 46875
117
118/*
119 * Allocator
120 *
121 * @note The max_free_index and current_free_index fields are not really
122 * indices, but quantities of BOUNDARY_SIZE big memory blocks.
123 */
124
155
156#define SIZEOF_ALLOCATOR_T APR_ALIGN_DEFAULT(sizeof(apr_allocator_t))
157
158
159/*
160 * Allocator
161 */
162
163static APR_INLINE
165{
166#if APR_HAS_THREADS
167 if (allocator->mutex)
169#endif /* APR_HAS_THREADS */
170}
171
172static APR_INLINE
174{
175#if APR_HAS_THREADS
176 if (allocator->mutex)
178#endif /* APR_HAS_THREADS */
179}
180
197
199{
200 apr_size_t index;
201 apr_memnode_t *node, **ref;
202
203 for (index = 0; index < MAX_INDEX; index++) {
204 ref = &allocator->free[index];
205 while ((node = *ref) != NULL) {
206 *ref = node->next;
207#if APR_ALLOCATOR_USES_MMAP
208 munmap((char *)node - GUARDPAGE_SIZE,
209 2 * GUARDPAGE_SIZE + ((node->index+1) << BOUNDARY_INDEX));
210#else
211 free(node);
212#endif
213 }
214 }
215
216 free(allocator);
217}
218
219#if APR_HAS_THREADS
221 apr_thread_mutex_t *mutex)
222{
223 allocator->mutex = mutex;
224}
225
228{
229 return allocator->mutex;
230}
231#endif /* APR_HAS_THREADS */
232
235{
237}
238
243
246{
247 apr_size_t max_free_index;
249
251
252 max_free_index = APR_ALIGN(size, BOUNDARY_SIZE) >> BOUNDARY_INDEX;
253 allocator->current_free_index += max_free_index;
255 allocator->max_free_index = max_free_index;
256 if (allocator->current_free_index > max_free_index)
257 allocator->current_free_index = max_free_index;
258
260}
261
262static APR_INLINE
264{
266
267 /* Round up the block size to the next boundary, but always
268 * allocate at least a certain size (MIN_ALLOC).
269 */
271 if (size < in_size) {
272 return 0;
273 }
274 if (size < MIN_ALLOC) {
275 size = MIN_ALLOC;
276 }
277
278 return size;
279}
280
287
288static APR_INLINE
290{
291 apr_memnode_t *node, **ref;
292 apr_size_t max_index;
293 apr_size_t size, i, index;
294
295 /* Round up the block size to the next boundary, but always
296 * allocate at least a certain size (MIN_ALLOC).
297 */
299 if (!size) {
300 return NULL;
301 }
302
303 /* Find the index for this node size by
304 * dividing its size by the boundary size
305 */
306 index = (size >> BOUNDARY_INDEX) - 1;
307
308 if (index > APR_UINT32_MAX) {
309 return NULL;
310 }
311
312 /* First see if there are any nodes in the area we know
313 * our node will fit into.
314 */
315 if (index <= allocator->max_index) {
317
318 /* Walk the free list to see if there are
319 * any nodes on it of the requested size
320 *
321 * NOTE: an optimization would be to check
322 * allocator->free[index] first and if no
323 * node is present, directly use
324 * allocator->free[max_index]. This seems
325 * like overkill though and could cause
326 * memory waste.
327 */
328 max_index = allocator->max_index;
329 ref = &allocator->free[index];
330 i = index;
331 while (*ref == NULL && i < max_index) {
332 ref++;
333 i++;
334 }
335
336 if ((node = *ref) != NULL) {
337 /* If we have found a node and it doesn't have any
338 * nodes waiting in line behind it _and_ we are on
339 * the highest available index, find the new highest
340 * available index
341 */
342 if ((*ref = node->next) == NULL && i >= max_index) {
343 do {
344 ref--;
345 max_index--;
346 }
347 while (*ref == NULL && max_index);
348
349 allocator->max_index = max_index;
350 }
351
352 allocator->current_free_index += node->index + 1;
355
357
358 goto have_node;
359 }
360
362 }
363
364 /* If we found nothing, seek the sink (at index 0), if
365 * it is not empty.
366 */
367 else if (allocator->free[0]) {
369
370 /* Walk the free list to see if there are
371 * any nodes on it of the requested size
372 */
373 ref = &allocator->free[0];
374 while ((node = *ref) != NULL && index > node->index)
375 ref = &node->next;
376
377 if (node) {
378 *ref = node->next;
379
380 allocator->current_free_index += node->index + 1;
383
385
386 goto have_node;
387 }
388
390 }
391
392 /* If we haven't got a suitable node, malloc a new one
393 * and initialize it.
394 */
395#if APR_ALLOCATOR_GUARD_PAGES
396 if ((node = mmap(NULL, size + 2 * GUARDPAGE_SIZE, PROT_NONE,
397 MAP_PRIVATE|MAP_ANON, -1, 0)) == MAP_FAILED)
398#elif APR_ALLOCATOR_USES_MMAP
399 if ((node = mmap(NULL, size, PROT_READ|PROT_WRITE,
400 MAP_PRIVATE|MAP_ANON, -1, 0)) == MAP_FAILED)
401#else
402 if ((node = malloc(size)) == NULL)
403#endif
404 return NULL;
405
406#if APR_ALLOCATOR_GUARD_PAGES
407 node = (apr_memnode_t *)((char *)node + GUARDPAGE_SIZE);
408 if (mprotect(node, size, PROT_READ|PROT_WRITE) != 0) {
409 munmap((char *)node - GUARDPAGE_SIZE, size + 2 * GUARDPAGE_SIZE);
410 return NULL;
411 }
412#endif
413 node->index = (apr_uint32_t)index;
414 node->endp = (char *)node + size;
415
417 node->next = NULL;
418 node->first_avail = (char *)node + APR_MEMNODE_T_SIZE;
419
421
422 return node;
423}
424
425static APR_INLINE
427{
428 apr_memnode_t *next, *freelist = NULL;
429 apr_size_t index, max_index;
430 apr_size_t max_free_index, current_free_index;
431
433
434 max_index = allocator->max_index;
435 max_free_index = allocator->max_free_index;
436 current_free_index = allocator->current_free_index;
437
438 /* Walk the list of submitted nodes and free them one by one,
439 * shoving them in the right 'size' buckets as we go.
440 */
441 do {
442 next = node->next;
443 index = node->index;
444
446 (node->index+1) << BOUNDARY_INDEX);
447
448 if (max_free_index != APR_ALLOCATOR_MAX_FREE_UNLIMITED
449 && index + 1 > current_free_index) {
450 node->next = freelist;
451 freelist = node;
452 }
453 else if (index < MAX_INDEX) {
454 /* Add the node to the appropriate 'size' bucket. Adjust
455 * the max_index when appropriate.
456 */
457 if ((node->next = allocator->free[index]) == NULL
458 && index > max_index) {
459 max_index = index;
460 }
461 allocator->free[index] = node;
462 if (current_free_index >= index + 1)
463 current_free_index -= index + 1;
464 else
465 current_free_index = 0;
466 }
467 else {
468 /* This node is too large to keep in a specific size bucket,
469 * just add it to the sink (at index 0).
470 */
471 node->next = allocator->free[0];
472 allocator->free[0] = node;
473 if (current_free_index >= index + 1)
474 current_free_index -= index + 1;
475 else
476 current_free_index = 0;
477 }
478 } while ((node = next) != NULL);
479
480 allocator->max_index = max_index;
481 allocator->current_free_index = current_free_index;
482
484
485 while (freelist != NULL) {
486 node = freelist;
487 freelist = node->next;
488#if APR_ALLOCATOR_USES_MMAP
489 munmap((char *)node - GUARDPAGE_SIZE,
490 2 * GUARDPAGE_SIZE + ((node->index+1) << BOUNDARY_INDEX));
491#else
492 free(node);
493#endif
494 }
495}
496
502
504 apr_memnode_t *node)
505{
507}
508
509
510
511/*
512 * Debug level
513 */
514
515#define APR_POOL_DEBUG_GENERAL 0x01
516#define APR_POOL_DEBUG_VERBOSE 0x02
517#define APR_POOL_DEBUG_LIFETIME 0x04
518#define APR_POOL_DEBUG_OWNER 0x08
519#define APR_POOL_DEBUG_VERBOSE_ALLOC 0x10
520
521#define APR_POOL_DEBUG_VERBOSE_ALL (APR_POOL_DEBUG_VERBOSE \
522 | APR_POOL_DEBUG_VERBOSE_ALLOC)
523
524
525/*
526 * Structures
527 */
528
529typedef struct cleanup_t cleanup_t;
530
539
540
541#if APR_POOL_DEBUG
542
543typedef struct debug_node_t debug_node_t;
544
545struct debug_node_t {
546 debug_node_t *next;
547 apr_size_t index;
548 void *beginp[64];
549 void *endp[64];
550};
551
552#define SIZEOF_DEBUG_NODE_T APR_ALIGN_DEFAULT(sizeof(debug_node_t))
553
554#endif /* APR_POOL_DEBUG */
555
556/* The ref field in the apr_pool_t struct holds a
557 * pointer to the pointer referencing this pool.
558 * It is used for parent, child, sibling management.
559 * Look at apr_pool_create_ex() and apr_pool_destroy()
560 * to see how it is used.
561 */
573 const char *tag;
574
575#if !APR_POOL_DEBUG
577 apr_memnode_t *self; /* The node containing the pool itself */
579
580#else /* APR_POOL_DEBUG */
581 apr_pool_t *joined; /* the caller has guaranteed that this pool
582 * will survive as long as ->joined */
584 const char *file_line;
586 unsigned int stat_alloc;
587 unsigned int stat_total_alloc;
588 unsigned int stat_clear;
589#if APR_HAS_THREADS
590 apr_os_thread_t owner;
591 apr_thread_mutex_t *mutex;
592#endif /* APR_HAS_THREADS */
593#endif /* APR_POOL_DEBUG */
594#ifdef NETWARE
596#endif /* defined(NETWARE) */
598#if APR_POOL_CONCURRENCY_CHECK
599
600#define IDLE 0
601#define IN_USE 1
602#define DESTROYED 2
603 volatile apr_uint32_t in_use;
605#endif /* APR_POOL_CONCURRENCY_CHECK */
606};
607
608#define SIZEOF_POOL_T APR_ALIGN_DEFAULT(sizeof(apr_pool_t))
609
610
611/*
612 * Variables
613 */
614
617
618#if !APR_POOL_DEBUG
620#endif /* !APR_POOL_DEBUG */
621
622#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL)
623static apr_file_t *file_stderr = NULL;
625{
627 return APR_SUCCESS;
628}
629
630#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) */
631
632/*
633 * Local functions
634 */
635
636static void run_cleanups(cleanup_t **c);
637static void free_proc_chain(struct process_chain *procs);
638
639#if APR_POOL_DEBUG
640static void pool_destroy_debug(apr_pool_t *pool, const char *file_line);
641#endif
642
643#if !APR_POOL_DEBUG
644/*
645 * Initialization
646 */
647
649{
650 apr_status_t rv;
651
653 return APR_SUCCESS;
654
655#if HAVE_VALGRIND
657#endif
658
659#if APR_ALLOCATOR_USES_MMAP && defined(_SC_PAGESIZE)
661 boundary_index = 12;
662 while ( (1 << boundary_index) < boundary_size)
665#endif
666
669 return rv;
670 }
671
677 return rv;
678 }
679
680 apr_pool_tag(global_pool, "apr_global_pool");
681
682 /* This has to happen here because mutexes might be backed by
683 * atomics. It used to be snug and safe in apr_initialize().
684 *
685 * Warning: apr_atomic_init() must always be called, by any
686 * means possible, from apr_initialize().
687 */
688 if ((rv = apr_atomic_init(global_pool)) != APR_SUCCESS) {
689 return rv;
690 }
691
692#if APR_HAS_THREADS
693 {
694 apr_thread_mutex_t *mutex;
695
696 if ((rv = apr_thread_mutex_create(&mutex,
699 return rv;
700 }
701
703 }
704#endif /* APR_HAS_THREADS */
705
707
708 return APR_SUCCESS;
709}
710
712{
714 return;
715
717 return;
718
719 apr_pool_destroy(global_pool); /* This will also destroy the mutex */
721
723}
724
725
726/* Node list management helper macros; list_insert() inserts 'node'
727 * before 'point'. */
728#define list_insert(node, point) do { \
729 node->ref = point->ref; \
730 *node->ref = node; \
731 node->next = point; \
732 point->ref = &node->next; \
733} while (0)
734
735/* list_remove() removes 'node' from its list. */
736#define list_remove(node) do { \
737 *node->ref = node->next; \
738 node->next->ref = node->ref; \
739} while (0)
740
741/* Returns the amount of free space in the given node. */
742#define node_free_space(node_) ((apr_size_t)(node_->endp - node_->first_avail))
743
744/*
745 * Helpers to mark pool as in-use/free. Used for finding thread-unsafe
746 * concurrent accesses from different threads.
747 */
748#if APR_POOL_CONCURRENCY_CHECK
749
750static const char * const in_use_string[] = { "idle", "in use", "destroyed" };
751
753{
754 fprintf(stderr, "pool concurrency check: pool %p(%s), thread cur %lx "
755 "in use by %lx, state %s -> %s \n",
756 pool, pool->tag, (unsigned long)apr_os_thread_current(),
757 (unsigned long)pool->in_use_by,
759 abort();
760}
761
763{
765
766 old = apr_atomic_cas32(&pool->in_use, IN_USE, IDLE);
767
768 if (old != IDLE)
770
771 pool->in_use_by = apr_os_thread_current();
772}
773
775{
777
778 old = apr_atomic_cas32(&pool->in_use, IDLE, IN_USE);
779
780 if (old != IN_USE)
782}
783
785{
786 pool->in_use = IDLE;
787}
788
790{
792
793 old = apr_atomic_cas32(&pool->in_use, DESTROYED, IDLE);
794
795 if (old != IDLE)
797 pool->in_use_by = apr_os_thread_current();
798}
799#else
804#endif /* APR_POOL_CONCURRENCY_CHECK */
805
806/*
807 * Memory allocation
808 */
809
811{
812 apr_memnode_t *active, *node;
813 void *mem;
814 apr_size_t size, free_index;
815
818#if HAVE_VALGRIND
820 size += 2 * REDZONE;
821#endif
822 if (size < in_size) {
824 if (pool->abort_fn)
826
827 return NULL;
828 }
829 active = pool->active;
830
831 /* If the active node has enough bytes left, use it. */
832 if (size <= node_free_space(active)) {
833 mem = active->first_avail;
834 active->first_avail += size;
835 goto have_mem;
836 }
837
838 node = active->next;
839 if (size <= node_free_space(node)) {
840 list_remove(node);
841 }
842 else {
843 if ((node = allocator_alloc(pool->allocator, size)) == NULL) {
845 if (pool->abort_fn)
847
848 return NULL;
849 }
850 }
851
852 node->free_index = 0;
853
854 mem = node->first_avail;
855 node->first_avail += size;
856
857 list_insert(node, active);
858
859 pool->active = node;
860
861 free_index = (APR_ALIGN(active->endp - active->first_avail + 1,
863
864 active->free_index = (apr_uint32_t)free_index;
865 node = active->next;
866 if (free_index >= node->free_index)
867 goto have_mem;
868
869 do {
870 node = node->next;
871 }
872 while (free_index < node->free_index);
873
874 list_remove(active);
875 list_insert(active, node);
876
878#if HAVE_VALGRIND
881 return mem;
882 }
883 else {
884 mem = (char *)mem + REDZONE;
887 return mem;
888 }
889#else
891 return mem;
892#endif
893}
894
895/* Provide an implementation of apr_pcalloc for backward compatibility
896 * with code built before apr_pcalloc was a macro
897 */
898
899#ifdef apr_pcalloc
900#undef apr_pcalloc
901#endif
902
905{
906 void *mem;
907
908 if ((mem = apr_palloc(pool, size)) != NULL) {
909 memset(mem, 0, size);
910 }
911
912 return mem;
913}
914
915
916/*
917 * Pool creation/destruction
918 */
919
921{
922 apr_memnode_t *active;
923
924 /* Run pre destroy cleanups */
926
930
931 /* Destroy the subpools. The subpools will detach themselves from
932 * this pool thus this loop is safe and easy.
933 */
934 while (pool->child)
936
937 /* Run cleanups */
939
941 pool->cleanups = NULL;
943
944 /* Free subprocesses */
947
948 /* Clear the user data. */
950
951 /* Find the node attached to the pool structure, reset it, make
952 * it the active node and free the rest of the nodes.
953 */
954 active = pool->active = pool->self;
956
958
959 if (active->next == active) {
961 return;
962 }
963
964 *active->ref = NULL;
966 active->next = active;
967 active->ref = &active->next;
968
970}
971
973{
974 apr_memnode_t *active;
976
977 /* Run pre destroy cleanups */
979
983
984 /* Destroy the subpools. The subpools will detach themselve from
985 * this pool thus this loop is safe and easy.
986 */
987 while (pool->child)
989
990 /* Run cleanups */
993
994 /* Free subprocesses */
996
997 /* Remove the pool from the parents child list */
998 if (pool->parent) {
1000
1001 if ((*pool->ref = pool->sibling) != NULL)
1002 pool->sibling->ref = pool->ref;
1003
1005 }
1006
1007 /* Find the block attached to the pool structure. Save a copy of the
1008 * allocator pointer, because the pool struct soon will be no more.
1009 */
1011 active = pool->self;
1012 *active->ref = NULL;
1013
1014#if APR_HAS_THREADS
1016 /* Make sure to remove the lock, since it is highly likely to
1017 * be invalid now.
1018 */
1020 }
1021#endif /* APR_HAS_THREADS */
1022
1023 /* Free all the nodes in the pool (including the node holding the
1024 * pool struct), by giving them back to the allocator.
1025 */
1026 allocator_free(allocator, active);
1027
1028 /* If this pool happens to be the owner of the allocator, free
1029 * everything in the allocator (that includes the pool struct
1030 * and the allocator). Don't worry about destroying the optional mutex
1031 * in the allocator, it will have been destroyed by the cleanup function.
1032 */
1035 }
1037}
1038
1043{
1045 apr_memnode_t *node;
1046
1047 *newpool = NULL;
1048
1049 if (!parent)
1051
1052 /* parent will always be non-NULL here except the first time a
1053 * pool is created, in which case allocator is guaranteed to be
1054 * non-NULL. */
1055
1056 if (!abort_fn && parent)
1058
1059 if (allocator == NULL)
1061
1062 if ((node = allocator_alloc(allocator,
1064 if (abort_fn)
1066
1067 return APR_ENOMEM;
1068 }
1069
1070 node->next = node;
1071 node->ref = &node->next;
1072
1073#if HAVE_VALGRIND
1075 pool = (apr_pool_t *)node->first_avail;
1077 }
1078 else {
1079 pool = (apr_pool_t *)(node->first_avail + REDZONE);
1080 pool->self_first_avail = (char *)pool + SIZEOF_POOL_T + 2 * REDZONE;
1082 node->endp - pool->self_first_avail);
1084 }
1085#else
1086 pool = (apr_pool_t *)node->first_avail;
1088#endif
1090
1092 pool->active = pool->self = node;
1094 pool->child = NULL;
1095 pool->cleanups = NULL;
1099 pool->user_data = NULL;
1100 pool->tag = NULL;
1101
1102#ifdef NETWARE
1103 pool->owner_proc = (apr_os_proc_t)getnlmhandle();
1104#endif /* defined(NETWARE) */
1105
1106 if ((pool->parent = parent) != NULL) {
1108
1109 if ((pool->sibling = parent->child) != NULL)
1110 pool->sibling->ref = &pool->sibling;
1111
1112 parent->child = pool;
1113 pool->ref = &parent->child;
1114
1116 }
1117 else {
1118 pool->sibling = NULL;
1119 pool->ref = NULL;
1120 }
1121
1123
1124 *newpool = pool;
1125
1126 return APR_SUCCESS;
1127}
1128
1129/* Deprecated. Renamed to apr_pool_create_unmanaged_ex
1130 */
1134{
1136}
1137
1141{
1143 apr_memnode_t *node;
1145
1146 *newpool = NULL;
1147
1149 return APR_ENOPOOL;
1150 if ((pool_allocator = allocator) == NULL) {
1152 if (abort_fn)
1154
1155 return APR_ENOMEM;
1156 }
1159 }
1160 if ((node = allocator_alloc(pool_allocator,
1162 if (abort_fn)
1164
1165 return APR_ENOMEM;
1166 }
1167
1168 node->next = node;
1169 node->ref = &node->next;
1170
1171 pool = (apr_pool_t *)node->first_avail;
1172 node->first_avail = pool->self_first_avail = (char *)pool + SIZEOF_POOL_T;
1173
1175 pool->active = pool->self = node;
1177 pool->child = NULL;
1178 pool->cleanups = NULL;
1182 pool->user_data = NULL;
1183 pool->tag = NULL;
1184 pool->parent = NULL;
1185 pool->sibling = NULL;
1186 pool->ref = NULL;
1187
1188#ifdef NETWARE
1189 pool->owner_proc = (apr_os_proc_t)getnlmhandle();
1190#endif /* defined(NETWARE) */
1191 if (!allocator)
1192 pool_allocator->owner = pool;
1193
1195 *newpool = pool;
1196
1197 return APR_SUCCESS;
1198}
1199
1200/*
1201 * "Print" functions
1202 */
1203
1204/*
1205 * apr_psprintf is implemented by writing directly into the current
1206 * block of the pool, starting right at first_avail. If there's
1207 * insufficient room, then a new block is allocated and the earlier
1208 * output is copied over. The new block isn't linked into the pool
1209 * until all the output is done.
1210 *
1211 * Note that this is completely safe because nothing else can
1212 * allocate in this apr_pool_t while apr_psprintf is running. alarms are
1213 * blocked, and the only thing outside of apr_pools.c that's invoked
1214 * is apr_vformatter -- which was purposefully written to be
1215 * self-contained with no callouts.
1216 */
1217
1225
1226#define APR_PSPRINTF_MIN_STRINGSIZE 32
1227
1229{
1230 struct psprintf_data *ps = (struct psprintf_data *)vbuff;
1231 apr_memnode_t *node, *active;
1232 apr_size_t cur_len, size;
1233 char *strp;
1235 apr_size_t free_index;
1236
1237 pool = ps->pool;
1238 active = ps->node;
1239 strp = ps->vbuff.curpos;
1240 cur_len = strp - active->first_avail;
1241 size = cur_len << 1;
1242
1243 /* Make sure that we don't try to use a block that has less
1244 * than APR_PSPRINTF_MIN_STRINGSIZE bytes left in it. This
1245 * also catches the case where size == 0, which would result
1246 * in reusing a block that can't even hold the NUL byte.
1247 */
1250
1251 node = active->next;
1252 if (!ps->got_a_new_node && size <= node_free_space(node)) {
1253
1255 list_insert(node, active);
1256
1257 node->free_index = 0;
1258
1259 pool->active = node;
1260
1261 free_index = (APR_ALIGN(active->endp - active->first_avail + 1,
1263
1264 active->free_index = (apr_uint32_t)free_index;
1265 node = active->next;
1266 if (free_index < node->free_index) {
1267 do {
1268 node = node->next;
1269 }
1270 while (free_index < node->free_index);
1271
1272 list_remove(active);
1273 list_insert(active, node);
1274 }
1275
1276 node = pool->active;
1277 }
1278 else {
1280 return -1;
1281
1282 if (ps->got_a_new_node) {
1283 active->next = ps->free;
1284 ps->free = active;
1285 }
1286
1287 ps->got_a_new_node = 1;
1288 }
1289
1292 memcpy(node->first_avail, active->first_avail, cur_len);
1294 active->endp - active->first_avail);
1295
1296 ps->node = node;
1297 ps->vbuff.curpos = node->first_avail + cur_len;
1298 ps->vbuff.endpos = node->endp - 1; /* Save a byte for NUL terminator */
1299
1300 return 0;
1301}
1302
1303#if HAVE_VALGRIND
1304static int add_redzone(int (*flush_func)(apr_vformatter_buff_t *b),
1305 struct psprintf_data *ps)
1306{
1307 apr_size_t len = ps->vbuff.curpos - ps->node->first_avail + REDZONE;
1308
1309 while (ps->vbuff.curpos - ps->node->first_avail < len) {
1310 if (ps->vbuff.endpos - ps->node->first_avail >= len)
1311 ps->vbuff.curpos = ps->node->first_avail + len;
1312 else
1313 ps->vbuff.curpos = ps->vbuff.endpos;
1314
1315 /*
1316 * Prevent valgrind from complaining when psprintf_flush()
1317 * does a memcpy(). The VALGRIND_MEMPOOL_ALLOC() will reset
1318 * the redzone to NOACCESS.
1319 */
1320 if (ps->vbuff.curpos != ps->node->first_avail)
1321 VALGRIND_MAKE_MEM_DEFINED(ps->node->first_avail,
1322 ps->vbuff.curpos - ps->node->first_avail);
1323 if (ps->vbuff.curpos == ps->vbuff.endpos) {
1324 if (psprintf_flush(&ps->vbuff) == -1)
1325 return -1;
1326 }
1327 }
1328 return 0;
1329}
1330#endif
1331
1333{
1334 struct psprintf_data ps;
1335 char *strp;
1337 apr_memnode_t *active, *node;
1338 apr_size_t free_index;
1339
1341 ps.node = pool->active;
1342 ps.pool = pool;
1343 ps.vbuff.curpos = ps.node->first_avail;
1344
1345 /* Save a byte for the NUL terminator */
1346 ps.vbuff.endpos = ps.node->endp - 1;
1347 ps.got_a_new_node = 0;
1348 ps.free = NULL;
1349
1350 /* Make sure that the first node passed to apr_vformatter has at least
1351 * room to hold the NUL terminator.
1352 */
1353 if (ps.node->first_avail == ps.node->endp) {
1354 if (psprintf_flush(&ps.vbuff) == -1)
1355 goto error;
1356 }
1357#if HAVE_VALGRIND
1359 if (add_redzone(psprintf_flush, &ps) == -1)
1360 goto error;
1361 if (!ps.got_a_new_node) {
1362 /* psprintf_flush() has not been called, allow access to our node */
1363 VALGRIND_MAKE_MEM_UNDEFINED(ps.vbuff.curpos,
1364 ps.node->endp - ps.vbuff.curpos);
1365 }
1366 }
1367#endif /* HAVE_VALGRIND */
1368
1369 if (apr_vformatter(psprintf_flush, &ps.vbuff, fmt, ap) == -1)
1370 goto error;
1371
1372 *ps.vbuff.curpos++ = '\0';
1373
1374#if HAVE_VALGRIND
1376 strp = ps.node->first_avail;
1377 }
1378 else {
1379 if (add_redzone(psprintf_flush, &ps) == -1)
1380 goto error;
1381 if (ps.node->endp != ps.vbuff.curpos)
1382 APR_VALGRIND_NOACCESS(ps.vbuff.curpos,
1383 ps.node->endp - ps.vbuff.curpos);
1384 strp = ps.node->first_avail + REDZONE;
1385 size = ps.vbuff.curpos - strp;
1388 }
1389#else
1390 strp = ps.node->first_avail;
1391#endif
1392
1393 size = ps.vbuff.curpos - ps.node->first_avail;
1395 ps.node->first_avail += size;
1396
1397 if (ps.free)
1399
1400 /*
1401 * Link the node in if it's a new one
1402 */
1403 if (!ps.got_a_new_node) {
1405 return strp;
1406 }
1407
1408 active = pool->active;
1409 node = ps.node;
1410
1411 node->free_index = 0;
1412
1413 list_insert(node, active);
1414
1415 pool->active = node;
1416
1417 free_index = (APR_ALIGN(active->endp - active->first_avail + 1,
1419
1420 active->free_index = (apr_uint32_t)free_index;
1421 node = active->next;
1422
1423 if (free_index >= node->free_index) {
1425 return strp;
1426 }
1427
1428 do {
1429 node = node->next;
1430 }
1431 while (free_index < node->free_index);
1432
1433 list_remove(active);
1434 list_insert(active, node);
1435
1437 return strp;
1438
1439error:
1441 if (pool->abort_fn)
1443 if (ps.got_a_new_node) {
1444 ps.node->next = ps.free;
1446 }
1449 return NULL;
1450}
1451
1452
1453#else /* APR_POOL_DEBUG */
1454/*
1455 * Debug helper functions
1456 */
1457
1458static APR_INLINE
1460{
1461#if APR_HAS_THREADS
1463#endif /* APR_HAS_THREADS */
1464}
1465
1466static APR_INLINE
1468{
1469#if APR_HAS_THREADS
1471#endif /* APR_HAS_THREADS */
1472}
1473
1474#if APR_HAS_THREADS
1475static APR_INLINE
1477{
1478 if (pool->parent) {
1480 return pool->parent->mutex;
1481 }
1482 return NULL;
1483}
1484
1485static APR_INLINE
1487{
1488 if (mutex) {
1490 }
1491}
1492#endif /* APR_HAS_THREADS */
1493
1494/*
1495 * Walk the pool tree rooted at pool, depth first. When fn returns
1496 * anything other than 0, abort the traversal and return the value
1497 * returned by fn.
1498 */
1500 int (*fn)(apr_pool_t *pool, void *data),
1501 void *data)
1502{
1503 int rv;
1504 apr_pool_t *child;
1505
1506 rv = fn(pool, data);
1507 if (rv)
1508 return rv;
1509
1510 pool_lock(pool);
1511
1512 child = pool->child;
1513 while (child) {
1514 rv = apr_pool_walk_tree(child, fn, data);
1515 if (rv)
1516 break;
1517
1518 child = child->sibling;
1519 }
1520
1522
1523 return rv;
1524}
1525
1526#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL)
1527static void apr_pool_log_event(apr_pool_t *pool, const char *event,
1528 const char *file_line, int deref)
1529{
1530 if (file_stderr) {
1531 if (deref) {
1533 "POOL DEBUG: "
1534 "[%lu"
1536 "/%lu"
1537#endif /* APR_HAS_THREADS */
1538 "] "
1539 "%7s "
1540 "(%10lu/%10lu/%10lu) "
1541 "0x%pp \"%s\" "
1542 "<%s> "
1543 "0x%pp "
1544 "(%u/%u/%u) "
1545 "\n",
1546 (unsigned long)getpid(),
1548 (unsigned long)apr_os_thread_current(),
1549#endif /* APR_HAS_THREADS */
1550 event,
1551 (unsigned long)apr_pool_num_bytes(pool, 0),
1552 (unsigned long)apr_pool_num_bytes(pool, 1),
1553 (unsigned long)apr_pool_num_bytes(global_pool, 1),
1554 pool, pool->tag,
1555 file_line,
1556 pool->parent,
1557 pool->stat_alloc, pool->stat_total_alloc, pool->stat_clear);
1558 }
1559 else {
1561 "POOL DEBUG: "
1562 "[%lu"
1564 "/%lu"
1565#endif /* APR_HAS_THREADS */
1566 "] "
1567 "%7s "
1568 " "
1569 "0x%pp "
1570 "<%s> "
1571 "\n",
1572 (unsigned long)getpid(),
1574 (unsigned long)apr_os_thread_current(),
1575#endif /* APR_HAS_THREADS */
1576 event,
1577 pool,
1578 file_line);
1579 }
1580 }
1581}
1582#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) */
1583
1584#if (APR_POOL_DEBUG & APR_POOL_DEBUG_LIFETIME)
1585static int pool_is_child_of(apr_pool_t *parent, void *data)
1586{
1588
1589 return (pool == parent);
1590}
1591
1593{
1594 if (parent == NULL)
1595 return 0;
1596
1598}
1599#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_LIFETIME) */
1600
1602{
1603 /* Rule of thumb: use of the global pool is always
1604 * ok, since the only user is apr_pools.c. Unless
1605 * people have searched for the top level parent and
1606 * started to use that...
1607 */
1608 if (pool == global_pool || global_pool == NULL)
1609 return;
1610
1611 /* Lifetime
1612 * This basically checks to see if the pool being used is still
1613 * a relative to the global pool. If not it was previously
1614 * destroyed, in which case we abort().
1615 */
1616#if (APR_POOL_DEBUG & APR_POOL_DEBUG_LIFETIME)
1618#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL)
1619 apr_pool_log_event(pool, "LIFE",
1620 __FILE__ ":apr_pool_integrity check [lifetime]", 0);
1621#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) */
1622 abort();
1623 }
1624#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_LIFETIME) */
1625}
1626
1628{
1629#if (APR_POOL_DEBUG & APR_POOL_DEBUG_OWNER)
1630#if APR_HAS_THREADS
1632#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL)
1633 apr_pool_log_event(pool, "THREAD",
1634 __FILE__ ":apr_pool_integrity check [owner]", 0);
1635#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) */
1636 abort();
1637 }
1638#endif /* APR_HAS_THREADS */
1639#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_OWNER) */
1640}
1641
1643{
1646}
1647
1648/*
1649 * Initialization (debug)
1650 */
1651
1653{
1654 apr_status_t rv;
1655#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL)
1656 char *logpath;
1658#endif
1659
1661 return APR_SUCCESS;
1662
1663#if APR_ALLOCATOR_USES_MMAP && defined(_SC_PAGESIZE)
1665 boundary_index = 12;
1666 while ( (1 << boundary_index) < boundary_size)
1669#endif
1670
1671 /* Since the debug code works a bit differently then the
1672 * regular pools code, we ask for a lock here. The regular
1673 * pools code has got this lock embedded in the global
1674 * allocator, a concept unknown to debug mode.
1675 */
1677 NULL)) != APR_SUCCESS) {
1678 return rv;
1679 }
1680
1681 apr_pool_tag(global_pool, "APR global pool");
1682
1684
1685 /* This has to happen here because mutexes might be backed by
1686 * atomics. It used to be snug and safe in apr_initialize().
1687 */
1688 if ((rv = apr_atomic_init(global_pool)) != APR_SUCCESS) {
1689 return rv;
1690 }
1691
1692#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL)
1693 rv = apr_env_get(&logpath, "APR_POOL_DEBUG_LOG", global_pool);
1694
1695 /* Don't pass file_stderr directly to apr_file_open() here, since
1696 * apr_file_open() can call back to apr_pool_log_event() and that
1697 * may attempt to use then then non-NULL but partially set up file
1698 * object. */
1699 if (rv == APR_SUCCESS) {
1702 }
1703 else {
1705 }
1706
1707 /* debug_log is now a file handle. */
1709
1710 if (file_stderr) {
1712 "POOL DEBUG: [PID"
1714 "/TID"
1715#endif /* APR_HAS_THREADS */
1716 "] ACTION (SIZE /POOL SIZE /TOTAL SIZE) "
1717 "POOL \"TAG\" <__FILE__:__LINE__> PARENT (ALLOCS/TOTAL ALLOCS/CLEARS)\n");
1718
1719 apr_pool_log_event(global_pool, "GLOBAL", __FILE__ ":apr_pool_initialize", 0);
1720
1721 /* Add a cleanup handler that sets the debug log file handle
1722 * to NULL, otherwise we'll try to log the global pool
1723 * destruction event with predictably disastrous results. */
1727 }
1728#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) */
1729
1730 return APR_SUCCESS;
1731}
1732
1734{
1736 return;
1737
1739 return;
1740
1741 apr_pool_destroy(global_pool); /* This will also destroy the mutex */
1742 global_pool = NULL;
1743
1744#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL)
1745 file_stderr = NULL;
1746#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) */
1747}
1748
1749
1750/*
1751 * Memory allocation (debug)
1752 */
1753
1755{
1757 void *mem;
1758
1759 if ((mem = malloc(size)) == NULL) {
1760 if (pool->abort_fn)
1762
1763 return NULL;
1764 }
1765
1766 node = pool->nodes;
1767 if (node == NULL || node->index == 64) {
1768 if ((node = malloc(SIZEOF_DEBUG_NODE_T)) == NULL) {
1769 free(mem);
1770 if (pool->abort_fn)
1772
1773 return NULL;
1774 }
1775
1777
1778 node->next = pool->nodes;
1779 pool->nodes = node;
1780 node->index = 0;
1781 }
1782
1783 node->beginp[node->index] = mem;
1784 node->endp[node->index] = (char *)mem + size;
1785 node->index++;
1786
1787 pool->stat_alloc++;
1788 pool->stat_total_alloc++;
1789
1790 return mem;
1791}
1792
1794 const char *file_line)
1795{
1796 void *mem;
1797
1799
1800 mem = pool_alloc(pool, size);
1801
1802#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALLOC)
1803 apr_pool_log_event(pool, "PALLOC", file_line, 1);
1804#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALLOC) */
1805
1806 return mem;
1807}
1808
1810 const char *file_line)
1811{
1812 void *mem;
1813
1815
1816 mem = pool_alloc(pool, size);
1817 memset(mem, 0, size);
1818
1819#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALLOC)
1820 apr_pool_log_event(pool, "PCALLOC", file_line, 1);
1821#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALLOC) */
1822
1823 return mem;
1824}
1825
1826
1827/*
1828 * Pool creation/destruction (debug)
1829 */
1830
1831#define POOL_POISON_BYTE 'A'
1832
1833static void pool_clear_debug(apr_pool_t *pool, const char *file_line)
1834{
1836 apr_size_t index;
1837
1838 /* Run pre destroy cleanups */
1841
1842 /*
1843 * Now that we have given the pre cleanups the chance to kill of any
1844 * threads using the pool, the owner must be correct.
1845 */
1847
1848 /* Destroy the subpools. The subpools will detach themselves from
1849 * this pool thus this loop is safe and easy.
1850 */
1851 while (pool->child)
1853
1854 /* Run cleanups */
1857 pool->cleanups = NULL;
1858
1859 /* If new child pools showed up, this is a reason to raise a flag */
1860 if (pool->child)
1861 abort();
1862
1863 /* Free subprocesses */
1866
1867 /* Clear the user data. */
1868 pool->user_data = NULL;
1869
1870 /* Free the blocks, scribbling over them first to help highlight
1871 * use-after-free issues. */
1872 while ((node = pool->nodes) != NULL) {
1873 pool->nodes = node->next;
1874
1875 for (index = 0; index < node->index; index++) {
1876 memset(node->beginp[index], POOL_POISON_BYTE,
1877 (char *)node->endp[index] - (char *)node->beginp[index]);
1878 free(node->beginp[index]);
1879 }
1880
1882 free(node);
1883 }
1884
1885 pool->stat_alloc = 0;
1886 pool->stat_clear++;
1887
1888#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE)
1889 apr_pool_log_event(pool, "CLEARED", file_line, 1);
1890#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */
1891}
1892
1894 const char *file_line)
1895{
1896#if APR_HAS_THREADS
1897 apr_thread_mutex_t *mutex;
1898#endif
1899
1901
1902#if APR_HAS_THREADS
1903 /* Lock the parent mutex before clearing so that if we have our
1904 * own mutex it won't be accessed by apr_pool_walk_tree after
1905 * it has been destroyed.
1906 */
1907 mutex = parent_lock(pool);
1908#endif
1909
1910#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE)
1911 apr_pool_log_event(pool, "CLEAR", file_line, 1);
1912#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */
1913
1915
1916#if APR_HAS_THREADS
1917 /* If we had our own mutex, it will have been destroyed by
1918 * the registered cleanups. Recreate it.
1919 */
1920 if (mutex != pool->mutex) {
1921 /*
1922 * Prevent apr_palloc() in apr_thread_mutex_create() from trying to
1923 * use the destroyed mutex.
1924 */
1925 pool->mutex = NULL;
1926 (void)apr_thread_mutex_create(&pool->mutex,
1928 }
1929
1930 /* Unlock the mutex we obtained above */
1931 parent_unlock(mutex);
1932#endif /* APR_HAS_THREADS */
1933}
1934
1935static void pool_destroy_debug(apr_pool_t *pool, const char *file_line)
1936{
1938
1939 /* Remove the pool from the parent's child list */
1940 if (pool->parent != NULL
1941 && (*pool->ref = pool->sibling) != NULL) {
1942 pool->sibling->ref = pool->ref;
1943 }
1944
1945 /* Destroy the allocator if the pool owns it */
1946 if (pool->allocator != NULL
1949 }
1950
1951 /* Free the pool itself */
1952 free(pool);
1953}
1954
1956 const char *file_line)
1957{
1958#if APR_HAS_THREADS
1959 apr_thread_mutex_t *mutex;
1960#endif
1961
1963
1964 if (pool->joined) {
1965 /* Joined pools must not be explicitly destroyed; the caller
1966 * has broken the guarantee. */
1967#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL)
1968 apr_pool_log_event(pool, "LIFE",
1969 __FILE__ ":apr_pool_destroy abort on joined", 0);
1970#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) */
1971
1972 abort();
1973 }
1974
1975#if APR_HAS_THREADS
1976 /* Lock the parent mutex before destroying so that it's not accessed
1977 * concurrently by apr_pool_walk_tree.
1978 */
1979 mutex = parent_lock(pool);
1980#endif
1981
1982#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE)
1983 apr_pool_log_event(pool, "DESTROY", file_line, 1);
1984#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */
1985
1987
1988#if APR_HAS_THREADS
1989 /* Unlock the mutex we obtained above */
1990 parent_unlock(mutex);
1991#endif /* APR_HAS_THREADS */
1992}
1993
1998 const char *file_line)
1999{
2001
2002 *newpool = NULL;
2003
2004 if (!parent) {
2006 }
2007 else {
2009
2010 if (!allocator)
2012 }
2013
2014 if (!abort_fn && parent)
2016
2017 if ((pool = malloc(SIZEOF_POOL_T)) == NULL) {
2018 if (abort_fn)
2020
2021 return APR_ENOMEM;
2022 }
2023
2025
2028 pool->tag = file_line;
2029 pool->file_line = file_line;
2030
2031#if APR_HAS_THREADS
2032 pool->owner = apr_os_thread_current();
2033#endif /* APR_HAS_THREADS */
2034#ifdef NETWARE
2035 pool->owner_proc = (apr_os_proc_t)getnlmhandle();
2036#endif /* defined(NETWARE) */
2037
2038#if APR_HAS_THREADS
2039 if (parent == NULL || parent->allocator != allocator) {
2040 apr_status_t rv;
2041
2042 /* No matter what the creation flags say, always create
2043 * a lock. Without it integrity_check and apr_pool_num_bytes
2044 * blow up (because they traverse pools child lists that
2045 * possibly belong to another thread, in combination with
2046 * the pool having no lock). However, this might actually
2047 * hide problems like creating a child pool of a pool
2048 * belonging to another thread.
2049 */
2050 if ((rv = apr_thread_mutex_create(&pool->mutex,
2052 free(pool);
2053 return rv;
2054 }
2055 }
2056 else {
2057 pool->mutex = parent->mutex;
2058 }
2059#endif /* APR_HAS_THREADS */
2060
2061 if ((pool->parent = parent) != NULL) {
2063
2064 if ((pool->sibling = parent->child) != NULL)
2065 pool->sibling->ref = &pool->sibling;
2066
2067 parent->child = pool;
2068 pool->ref = &parent->child;
2069
2071 }
2072 else {
2073 pool->sibling = NULL;
2074 pool->ref = NULL;
2075 }
2076
2077#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE)
2078 apr_pool_log_event(pool, "CREATE", file_line, 1);
2079#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */
2080
2081 *newpool = pool;
2082
2083 return APR_SUCCESS;
2084}
2085
2089 const char *file_line)
2090{
2092 file_line);
2093}
2094
2098 const char *file_line)
2099{
2102
2103 *newpool = NULL;
2104
2105 if ((pool = malloc(SIZEOF_POOL_T)) == NULL) {
2106 if (abort_fn)
2108
2109 return APR_ENOMEM;
2110 }
2111
2113
2115 pool->tag = file_line;
2116 pool->file_line = file_line;
2117
2118#if APR_HAS_THREADS
2119 {
2120 apr_status_t rv;
2121
2122 /* No matter what the creation flags say, always create
2123 * a lock. Without it integrity_check and apr_pool_num_bytes
2124 * blow up (because they traverse pools child lists that
2125 * possibly belong to another thread, in combination with
2126 * the pool having no lock). However, this might actually
2127 * hide problems like creating a child pool of a pool
2128 * belonging to another thread.
2129 */
2130 if ((rv = apr_thread_mutex_create(&pool->mutex,
2132 free(pool);
2133 return rv;
2134 }
2135 }
2136#endif /* APR_HAS_THREADS */
2137
2138#if APR_HAS_THREADS
2139 pool->owner = apr_os_thread_current();
2140#endif /* APR_HAS_THREADS */
2141#ifdef NETWARE
2142 pool->owner_proc = (apr_os_proc_t)getnlmhandle();
2143#endif /* defined(NETWARE) */
2144
2145 if ((pool_allocator = allocator) == NULL) {
2146 apr_status_t rv;
2148 if (abort_fn)
2149 abort_fn(rv);
2150 return rv;
2151 }
2152 pool_allocator->owner = pool;
2153 }
2155
2156#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE)
2157 apr_pool_log_event(pool, "CREATEU", file_line, 1);
2158#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */
2159
2160 *newpool = pool;
2161
2162 return APR_SUCCESS;
2163}
2164
2165/*
2166 * "Print" functions (debug)
2167 */
2168
2169struct psprintf_data {
2171 char *mem;
2173};
2174
2175static int psprintf_flush(apr_vformatter_buff_t *vbuff)
2176{
2177 struct psprintf_data *ps = (struct psprintf_data *)vbuff;
2179
2180 size = ps->vbuff.curpos - ps->mem;
2181
2182 ps->size <<= 1;
2183 if ((ps->mem = realloc(ps->mem, ps->size)) == NULL)
2184 return -1;
2185
2186 ps->vbuff.curpos = ps->mem + size;
2187 ps->vbuff.endpos = ps->mem + ps->size - 1;
2188
2189 return 0;
2190}
2191
2192APR_DECLARE(char *) apr_pvsprintf(apr_pool_t *pool, const char *fmt, va_list ap)
2193{
2194 struct psprintf_data ps;
2196
2198
2199 ps.size = 64;
2200 ps.mem = malloc(ps.size);
2201 ps.vbuff.curpos = ps.mem;
2202
2203 /* Save a byte for the NUL terminator */
2204 ps.vbuff.endpos = ps.mem + ps.size - 1;
2205
2206 if (apr_vformatter(psprintf_flush, &ps.vbuff, fmt, ap) == -1) {
2207 if (pool->abort_fn)
2209
2210 return NULL;
2211 }
2212
2213 *ps.vbuff.curpos++ = '\0';
2214
2215 /*
2216 * Link the node in
2217 */
2218 node = pool->nodes;
2219 if (node == NULL || node->index == 64) {
2220 if ((node = malloc(SIZEOF_DEBUG_NODE_T)) == NULL) {
2221 if (pool->abort_fn)
2223
2224 return NULL;
2225 }
2226
2227 node->next = pool->nodes;
2228 pool->nodes = node;
2229 node->index = 0;
2230 }
2231
2232 node->beginp[node->index] = ps.mem;
2233 node->endp[node->index] = ps.mem + ps.size;
2234 node->index++;
2235
2236 return ps.mem;
2237}
2238
2239
2240/*
2241 * Debug functions
2242 */
2243
2245{
2246#if APR_POOL_DEBUG
2247 if (sub->parent != p) {
2248 abort();
2249 }
2250 sub->joined = p;
2251#endif
2252}
2253
2254static int pool_find(apr_pool_t *pool, void *data)
2255{
2256 void **pmem = (void **)data;
2258 apr_size_t index;
2259
2260 node = pool->nodes;
2261
2262 while (node) {
2263 for (index = 0; index < node->index; index++) {
2264 if (node->beginp[index] <= *pmem
2265 && node->endp[index] > *pmem) {
2266 *pmem = pool;
2267 return 1;
2268 }
2269 }
2270
2271 node = node->next;
2272 }
2273
2274 return 0;
2275}
2276
2278{
2279 void *pool = (void *)mem;
2280
2282 return pool;
2283
2284 return NULL;
2285}
2286
2287static int pool_num_bytes(apr_pool_t *pool, void *data)
2288{
2291 apr_size_t index;
2292
2293 node = pool->nodes;
2294
2295 while (node) {
2296 for (index = 0; index < node->index; index++) {
2297 *psize += (char *)node->endp[index] - (char *)node->beginp[index];
2298 }
2299
2300 node = node->next;
2301 }
2302
2303 return 0;
2304}
2305
2307{
2308 apr_size_t size = 0;
2309
2310 if (!recurse) {
2312
2313 return size;
2314 }
2315
2317
2318 return size;
2319}
2320
2322{
2323}
2324
2325#endif /* !APR_POOL_DEBUG */
2326
2327#ifdef NETWARE
2329{
2332
2333 while (pool) {
2334 if (pool->owner_proc == owner_proc) {
2337 }
2338 else {
2339 pool = pool->sibling;
2340 }
2341 }
2342 return;
2343}
2344#endif /* defined(NETWARE) */
2345
2346
2347/*
2348 * "Print" functions (common)
2349 */
2350
2352{
2353 va_list ap;
2354 char *res;
2355
2356 va_start(ap, fmt);
2357 res = apr_pvsprintf(p, fmt, ap);
2358 va_end(ap);
2359 return res;
2360}
2361
2362/*
2363 * Pool Properties
2364 */
2365
2368{
2370}
2371
2376
2378{
2379#ifdef NETWARE
2380 /* On NetWare, don't return the global_pool, return the application pool
2381 as the top most pool */
2382 if (pool->parent == global_pool)
2383 return pool;
2384 else
2385#endif
2386 return pool->parent;
2387}
2388
2393
2394/* return TRUE if a is an ancestor of b
2395 * NULL is considered an ancestor of all pools
2396 */
2398{
2399 if (a == NULL)
2400 return 1;
2401
2402#if APR_POOL_DEBUG
2403 /* Find the pool with the longest lifetime guaranteed by the
2404 * caller: */
2405 while (a->joined) {
2406 a = a->joined;
2407 }
2408#endif
2409
2410 while (b) {
2411 if (a == b)
2412 return 1;
2413
2414 b = b->parent;
2415 }
2416
2417 return 0;
2418}
2419
2420APR_DECLARE(void) apr_pool_tag(apr_pool_t *pool, const char *tag)
2421{
2422 pool->tag = tag;
2423}
2424
2425
2426/*
2427 * User data management
2428 */
2429
2430APR_DECLARE(apr_status_t) apr_pool_userdata_set(const void *data, const char *key,
2431 apr_status_t (*cleanup) (void *),
2433{
2434#if APR_POOL_DEBUG
2436#endif /* APR_POOL_DEBUG */
2437
2438 if (pool->user_data == NULL)
2440
2442 char *new_key = apr_pstrdup(pool, key);
2444 }
2445 else {
2447 }
2448
2449 if (cleanup)
2451
2452 return APR_SUCCESS;
2453}
2454
2456 const char *key,
2457 apr_status_t (*cleanup)(void *),
2459{
2460#if APR_POOL_DEBUG
2462#endif /* APR_POOL_DEBUG */
2463
2464 if (pool->user_data == NULL)
2466
2468
2469 if (cleanup)
2471
2472 return APR_SUCCESS;
2473}
2474
2477{
2478#if APR_POOL_DEBUG
2480#endif /* APR_POOL_DEBUG */
2481
2482 if (pool->user_data == NULL) {
2483 *data = NULL;
2484 }
2485 else {
2487 }
2488
2489 return APR_SUCCESS;
2490}
2491
2492
2493/*
2494 * Cleanup
2495 */
2496
2503
2507{
2508 cleanup_t *c = NULL;
2509
2510#if APR_POOL_DEBUG
2512#endif /* APR_POOL_DEBUG */
2513
2514 if (p != NULL) {
2515 if (p->free_cleanups) {
2516 /* reuse a cleanup structure */
2517 c = p->free_cleanups;
2518 p->free_cleanups = c->next;
2519 } else {
2520 c = apr_palloc(p, sizeof(cleanup_t));
2521 }
2522 c->data = data;
2523 c->plain_cleanup_fn = plain_cleanup_fn;
2524 c->child_cleanup_fn = child_cleanup_fn;
2525 c->next = p->cleanups;
2526 p->cleanups = c;
2527 }
2528
2529#if APR_POOL_DEBUG
2530 if (!c || !c->plain_cleanup_fn || !c->child_cleanup_fn) {
2531 abort();
2532 }
2533#endif /* APR_POOL_DEBUG */
2534}
2535
2538{
2539 cleanup_t *c = NULL;
2540
2541#if APR_POOL_DEBUG
2543#endif /* APR_POOL_DEBUG */
2544
2545 if (p != NULL) {
2546 if (p->free_cleanups) {
2547 /* reuse a cleanup structure */
2548 c = p->free_cleanups;
2549 p->free_cleanups = c->next;
2550 } else {
2551 c = apr_palloc(p, sizeof(cleanup_t));
2552 }
2553 c->data = data;
2554 c->plain_cleanup_fn = plain_cleanup_fn;
2555 c->next = p->pre_cleanups;
2556 p->pre_cleanups = c;
2557 }
2558
2559#if APR_POOL_DEBUG
2560 if (!c || !c->plain_cleanup_fn) {
2561 abort();
2562 }
2563#endif /* APR_POOL_DEBUG */
2564}
2565
2567 apr_status_t (*cleanup_fn)(void *))
2568{
2569 cleanup_t *c, **lastp;
2570
2571#if APR_POOL_DEBUG
2573#endif /* APR_POOL_DEBUG */
2574
2575 if (p == NULL)
2576 return;
2577
2578 c = p->cleanups;
2579 lastp = &p->cleanups;
2580 while (c) {
2581#if APR_POOL_DEBUG
2582 /* Some cheap loop detection to catch a corrupt list: */
2583 if (c == c->next
2584 || (c->next && c == c->next->next)
2585 || (c->next && c->next->next && c == c->next->next->next)) {
2586 abort();
2587 }
2588#endif
2589
2590 if (c->data == data && c->plain_cleanup_fn == cleanup_fn) {
2591 *lastp = c->next;
2592 /* move to freelist */
2593 c->next = p->free_cleanups;
2594 p->free_cleanups = c;
2595 break;
2596 }
2597
2598 lastp = &c->next;
2599 c = c->next;
2600 }
2601
2602 /* Remove any pre-cleanup as well */
2603 c = p->pre_cleanups;
2604 lastp = &p->pre_cleanups;
2605 while (c) {
2606#if APR_POOL_DEBUG
2607 /* Some cheap loop detection to catch a corrupt list: */
2608 if (c == c->next
2609 || (c->next && c == c->next->next)
2610 || (c->next && c->next->next && c == c->next->next->next)) {
2611 abort();
2612 }
2613#endif
2614
2615 if (c->data == data && c->plain_cleanup_fn == cleanup_fn) {
2616 *lastp = c->next;
2617 /* move to freelist */
2618 c->next = p->free_cleanups;
2619 p->free_cleanups = c;
2620 break;
2621 }
2622
2623 lastp = &c->next;
2624 c = c->next;
2625 }
2626
2627}
2628
2630 apr_status_t (*plain_cleanup_fn)(void *),
2631 apr_status_t (*child_cleanup_fn)(void *))
2632{
2633 cleanup_t *c;
2634
2635#if APR_POOL_DEBUG
2637#endif /* APR_POOL_DEBUG */
2638
2639 if (p == NULL)
2640 return;
2641
2642 c = p->cleanups;
2643 while (c) {
2644 if (c->data == data && c->plain_cleanup_fn == plain_cleanup_fn) {
2645 c->child_cleanup_fn = child_cleanup_fn;
2646 break;
2647 }
2648
2649 c = c->next;
2650 }
2651}
2652
2654 apr_status_t (*cleanup_fn)(void *))
2655{
2657 return (*cleanup_fn)(data);
2658}
2659
2661{
2662 cleanup_t *c = *cref;
2663
2664 while (c) {
2665 *cref = c->next;
2666 (*c->plain_cleanup_fn)((void *)c->data);
2667 c = *cref;
2668 }
2669}
2670
2671#if !defined(WIN32) && !defined(OS2)
2672
2674{
2675 cleanup_t *c = *cref;
2676
2677 while (c) {
2678 *cref = c->next;
2679 (*c->child_cleanup_fn)((void *)c->data);
2680 c = *cref;
2681 }
2682}
2683
2685{
2687
2688 for (p = p->child; p; p = p->sibling)
2690}
2691
2693{
2695}
2696
2697#else /* !defined(WIN32) && !defined(OS2) */
2698
2700{
2701 /*
2702 * Don't need to do anything on NT or OS/2, because
2703 * these platforms will spawn the new process - not
2704 * fork for exec. All handles that are not inheritable,
2705 * will be automajically closed. The only problem is
2706 * with file handles that are open, but there isn't
2707 * much that can be done about that (except if the
2708 * child decides to go out and close them, or the
2709 * developer quits opening them shared)
2710 */
2711 return;
2712}
2713
2714#endif /* !defined(WIN32) && !defined(OS2) */
2715
2717{
2718 /* do nothing cleanup routine */
2719 return APR_SUCCESS;
2720}
2721
2722/* Subprocesses don't use the generic cleanup interface because
2723 * we don't want multiple subprocesses to result in multiple
2724 * three-second pauses; the subprocesses have to be "freed" all
2725 * at once. If other resources are introduced with the same property,
2726 * we might want to fold support for that into the generic interface.
2727 * For now, it's a special case.
2728 */
2731{
2732 struct process_chain *pc = apr_palloc(pool, sizeof(struct process_chain));
2733
2734 pc->proc = proc;
2735 pc->kill_how = how;
2736 pc->next = pool->subprocesses;
2737 pool->subprocesses = pc;
2738}
2739
2741{
2742 /* Dispose of the subprocesses we've spawned off in the course of
2743 * whatever it was we're cleaning up now. This may involve killing
2744 * some of them off...
2745 */
2746 struct process_chain *pc;
2747 int need_timeout = 0;
2749
2750 if (!procs)
2751 return; /* No work. Whew! */
2752
2753 /* First, check to see if we need to do the SIGTERM, sleep, SIGKILL
2754 * dance with any of the processes we're cleaning up. If we've got
2755 * any kill-on-sight subprocesses, ditch them now as well, so they
2756 * don't waste any more cycles doing whatever it is that they shouldn't
2757 * be doing anymore.
2758 */
2759
2760#ifndef NEED_WAITPID
2761 /* Pick up all defunct processes */
2762 for (pc = procs; pc; pc = pc->next) {
2765 }
2766#endif /* !defined(NEED_WAITPID) */
2767
2768 for (pc = procs; pc; pc = pc->next) {
2769#ifndef WIN32
2770 if ((pc->kill_how == APR_KILL_AFTER_TIMEOUT)
2771 || (pc->kill_how == APR_KILL_ONLY_ONCE)) {
2772 /*
2773 * Subprocess may be dead already. Only need the timeout if not.
2774 * Note: apr_proc_kill on Windows is TerminateProcess(), which is
2775 * similar to a SIGKILL, so always give the process a timeout
2776 * under Windows before killing it.
2777 */
2778 if (apr_proc_kill(pc->proc, SIGTERM) == APR_SUCCESS)
2779 need_timeout = 1;
2780 }
2781 else if (pc->kill_how == APR_KILL_ALWAYS) {
2782#else /* WIN32 knows only one fast, clean method of killing processes today */
2783 if (pc->kill_how != APR_KILL_NEVER) {
2784 need_timeout = 1;
2785 pc->kill_how = APR_KILL_ALWAYS;
2786#endif
2787 apr_proc_kill(pc->proc, SIGKILL);
2788 }
2789 }
2790
2791 /* Sleep only if we have to. The sleep algorithm grows
2792 * by a factor of two on each iteration. TIMEOUT_INTERVAL
2793 * is equal to TIMEOUT_USECS / 64.
2794 */
2795 if (need_timeout) {
2798
2799 do {
2800 /* check the status of the subprocesses */
2801 need_timeout = 0;
2802 for (pc = procs; pc; pc = pc->next) {
2803 if (pc->kill_how == APR_KILL_AFTER_TIMEOUT) {
2804 if (apr_proc_wait(pc->proc, NULL, NULL, APR_NOWAIT)
2806 need_timeout = 1; /* subprocess is still active */
2807 else
2808 pc->kill_how = APR_KILL_NEVER; /* subprocess has exited */
2809 }
2810 }
2811 if (need_timeout) {
2813 break;
2814 }
2816 timeout_interval *= 2;
2817 }
2818 } while (need_timeout);
2819 }
2820
2821 /* OK, the scripts we just timed out for have had a chance to clean up
2822 * --- now, just get rid of them, and also clean up the system accounting
2823 * goop...
2824 */
2825 for (pc = procs; pc; pc = pc->next) {
2826 if (pc->kill_how == APR_KILL_AFTER_TIMEOUT)
2827 apr_proc_kill(pc->proc, SIGKILL);
2828 }
2829
2830 /* Now wait for all the signaled processes to die */
2831 for (pc = procs; pc; pc = pc->next) {
2832 if (pc->kill_how != APR_KILL_NEVER)
2833 (void)apr_proc_wait(pc->proc, NULL, NULL, APR_WAIT);
2834 }
2835}
2836
2837
2838/*
2839 * Pool creation/destruction stubs, for people who are running
2840 * mixed release/debug enviroments.
2841 */
2842
2843#if !APR_POOL_DEBUG
2845 const char *file_line)
2846{
2847 return apr_palloc(pool, size);
2848}
2849
2851 const char *file_line)
2852{
2853 return apr_pcalloc(pool, size);
2854}
2855
2857 const char *file_line)
2858{
2860}
2861
2863 const char *file_line)
2864{
2866}
2867
2872 const char *file_line)
2873{
2875}
2876
2880 const char *file_line)
2881{
2883}
2884
2888 const char *file_line)
2889{
2891}
2892
2893#else /* APR_POOL_DEBUG */
2894
2895#undef apr_palloc
2897
2899{
2900 return apr_palloc_debug(pool, size, "undefined");
2901}
2902
2903#undef apr_pcalloc
2905
2907{
2908 return apr_pcalloc_debug(pool, size, "undefined");
2909}
2910
2911#undef apr_pool_clear
2913
2915{
2916 apr_pool_clear_debug(pool, "undefined");
2917}
2918
2919#undef apr_pool_destroy
2921
2923{
2924 apr_pool_destroy_debug(pool, "undefined");
2925}
2926
2927#undef apr_pool_create_ex
2932
2937{
2940 "undefined");
2941}
2942
2943#undef apr_pool_create_core_ex
2947
2951{
2953 allocator, "undefined");
2954}
2955
2956#undef apr_pool_create_unmanaged_ex
2960
2964{
2966 allocator, "undefined");
2967}
2968
2969#endif /* APR_POOL_DEBUG */
const char apr_size_t len
Definition ap_regex.h:187
APR Internal Memory Allocation.
#define MAP_FAILED
APR Atomic Operations.
APR Environment functions.
APR Miscellaneous library routines.
APR Hash Tables.
APR general purpose library routines.
#define APR_IF_VALGRIND(x)
Definition apr_pools.c:62
#define TIMEOUT_INTERVAL
Definition apr_pools.c:116
#define APR_PSPRINTF_MIN_STRINGSIZE
Definition apr_pools.c:1226
static int psprintf_flush(apr_vformatter_buff_t *vbuff)
Definition apr_pools.c:1228
#define SIZEOF_ALLOCATOR_T
Definition apr_pools.c:156
static APR_INLINE void pool_concurrency_set_destroyed(apr_pool_t *pool)
Definition apr_pools.c:803
static APR_INLINE void allocator_unlock(apr_allocator_t *allocator)
Definition apr_pools.c:173
#define BOUNDARY_SIZE
Definition apr_pools.c:95
#define APR_VALGRIND_UNDEFINED(addr_, size_)
Definition apr_pools.c:68
#define list_insert(node, point)
Definition apr_pools.c:728
static void cleanup_pool_for_exec(apr_pool_t *p)
Definition apr_pools.c:2684
#define BOUNDARY_INDEX
Definition apr_pools.c:94
static APR_INLINE void allocator_free(apr_allocator_t *allocator, apr_memnode_t *node)
Definition apr_pools.c:426
static void run_child_cleanups(cleanup_t **cref)
Definition apr_pools.c:2673
static APR_INLINE void allocator_lock(apr_allocator_t *allocator)
Definition apr_pools.c:164
static APR_INLINE void pool_concurrency_set_idle(apr_pool_t *pool)
Definition apr_pools.c:802
static APR_INLINE apr_size_t allocator_align(apr_size_t in_size)
Definition apr_pools.c:263
static apr_allocator_t * global_allocator
Definition apr_pools.c:619
static APR_INLINE apr_memnode_t * allocator_alloc(apr_allocator_t *allocator, apr_size_t in_size)
Definition apr_pools.c:289
static void free_proc_chain(struct process_chain *procs)
Definition apr_pools.c:2740
static apr_pool_t * global_pool
Definition apr_pools.c:616
#define GUARDPAGE_SIZE
Definition apr_pools.c:105
#define APR_VALGRIND_NOACCESS(addr_, size_)
Definition apr_pools.c:66
#define list_remove(node)
Definition apr_pools.c:736
static apr_byte_t apr_pools_initialized
Definition apr_pools.c:615
#define MIN_ALLOC
Definition apr_pools.c:85
static void run_cleanups(cleanup_t **c)
Definition apr_pools.c:2660
#define MAX_INDEX
Definition apr_pools.c:86
#define SIZEOF_POOL_T
Definition apr_pools.c:608
static APR_INLINE void pool_concurrency_set_used(apr_pool_t *pool)
Definition apr_pools.c:801
#define TIMEOUT_USECS
Definition apr_pools.c:115
static APR_INLINE void pool_concurrency_init(apr_pool_t *pool)
Definition apr_pools.c:800
#define node_free_space(node_)
Definition apr_pools.c:742
APR memory allocation.
APR Portability Routines.
APR Strings library.
APR Support functions.
APR Thread Mutex Routines.
APR Time Library.
APR Standard Headers Support.
apr_status_t apr_atomic_init(apr_pool_t *p)
Definition atomic.c:21
apr_uint32_t apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t swap, apr_uint32_t cmp)
Definition atomic.c:78
int apr_os_thread_equal(apr_os_thread_t tid1, apr_os_thread_t tid2)
Definition thread.c:117
const char server_rec server_rec ** ps
#define APR_CHILD_NOTDONE
Definition apr_errno.h:448
#define APR_ENOMEM
Definition apr_errno.h:683
#define APR_ENOPOOL
Definition apr_errno.h:290
apr_bucket apr_bucket_brigade * a
apr_pool_t const char apr_dbd_t const char ** error
Definition apr_dbd.h:143
apr_pool_t apr_dbd_t apr_dbd_results_t ** res
Definition apr_dbd.h:287
const apr_xml_elem int apr_array_header_t int const char apr_size_t * psize
Definition apr_xml.h:289
#define apr_pool_join(a, b)
Definition apr_pools.h:800
#define apr_pool_lock(pool, lock)
Definition apr_pools.h:805
#define APR_ALLOCATOR_MAX_FREE_UNLIMITED
apr_size_t size
#define APR_MEMNODE_T_SIZE
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
const char * key
const char apr_int32_t flag
void * data
void const char apr_status_t(* cleanup)(void *))
#define APR_APPEND
Definition apr_file_io.h:96
#define APR_WRITE
Definition apr_file_io.h:94
#define APR_CREATE
Definition apr_file_io.h:95
#define APR_OS_DEFAULT
#define APR_ALIGN(size, boundary)
#define APR_ALIGN_DEFAULT(size)
#define APR_HASH_KEY_STRING
Definition apr_hash.h:47
apr_vformatter_buff_t const char * fmt
Definition apr_lib.h:175
apr_vformatter_buff_t * c
Definition apr_lib.h:175
apr_vformatter_buff_t const char va_list ap
Definition apr_lib.h:176
APR_DECLARE(void)
Definition apr_pools.c:198
APR_DECLARE_NONSTD(void) apr_terminate(void)
Definition start.c:173
apr_shutdown_how_e how
apr_pool_t * b
Definition apr_pools.h:529
int(* apr_abortfunc_t)(int retcode)
Definition apr_pools.h:148
apr_abortfunc_t apr_allocator_t * allocator
Definition apr_pools.h:208
apr_pool_t * parent
Definition apr_pools.h:197
apr_abortfunc_t apr_allocator_t const char * file_line
Definition apr_pools.h:267
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
apr_pool_t apr_abortfunc_t abort_fn
Definition apr_pools.h:198
pid_t apr_os_proc_t
void * mem
apr_proc_t * proc
apr_kill_conditions_e
@ APR_KILL_AFTER_TIMEOUT
@ APR_KILL_ONLY_ONCE
@ APR_KILL_NEVER
@ APR_KILL_ALWAYS
@ APR_NOWAIT
@ APR_WAIT
apr_int64_t apr_time_t
Definition apr_time.h:45
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
apr_os_thread_t apr_os_thread_current()
Definition thread.c:142
apr_memnode_t * free[20]
Definition apr_pools.c:153
apr_size_t max_index
Definition apr_pools.c:127
apr_size_t current_free_index
Definition apr_pools.c:138
apr_pool_t * owner
Definition apr_pools.c:142
apr_size_t max_free_index
Definition apr_pools.c:133
apr_memnode_t * next
apr_uint32_t index
apr_memnode_t ** ref
apr_uint32_t free_index
apr_allocator_t * allocator
Definition apr_pools.c:569
const char * tag
Definition apr_pools.c:573
apr_pool_t * parent
Definition apr_pools.c:563
apr_memnode_t * active
Definition apr_pools.c:576
cleanup_t * free_cleanups
Definition apr_pools.c:568
apr_hash_t * user_data
Definition apr_pools.c:572
apr_pool_t * child
Definition apr_pools.c:564
apr_abortfunc_t abort_fn
Definition apr_pools.c:571
cleanup_t * cleanups
Definition apr_pools.c:567
cleanup_t * pre_cleanups
Definition apr_pools.c:597
apr_memnode_t * self
Definition apr_pools.c:577
char * self_first_avail
Definition apr_pools.c:578
apr_pool_t * sibling
Definition apr_pools.c:565
apr_pool_t ** ref
Definition apr_pools.c:566
struct process_chain * subprocesses
Definition apr_pools.c:570
apr_status_t(* child_cleanup_fn)(void *data)
Definition apr_pools.c:2501
apr_status_t(* plain_cleanup_fn)(void *data)
Definition apr_pools.c:2500
struct cleanup_t * next
Definition apr_pools.c:2498
const void * data
Definition apr_pools.c:2499
apr_kill_conditions_e kill_how
Definition apr_pools.c:535
apr_proc_t * proc
Definition apr_pools.c:534
struct process_chain * next
Definition apr_pools.c:537
apr_memnode_t * node
Definition apr_pools.c:1220
apr_byte_t got_a_new_node
Definition apr_pools.c:1222
apr_memnode_t * free
Definition apr_pools.c:1223
apr_vformatter_buff_t vbuff
Definition apr_pools.c:1219
apr_pool_t * pool
Definition apr_pools.c:1221
server_rec * next
Definition httpd.h:1326