[njs] NXT_DEBUG_MEMORY macro.

Valentin Bartenev vbart at nginx.com
Thu Dec 8 16:30:32 UTC 2016


details:   http://hg.nginx.org/njs/rev/af66e460d7a0
branches:  
changeset: 278:af66e460d7a0
user:      Valentin Bartenev <vbart at nginx.com>
date:      Thu Dec 08 19:29:40 2016 +0300
description:
NXT_DEBUG_MEMORY macro.

It allows to turn off accumulation of small pool allocations into a big
preallocated chunk of memory.  This is useful for debugging memory access
with sanitizer, since such accumulation can cover buffer overruns from
being detected.

diffstat:

 nxt/nxt_mem_cache_pool.c |  14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diffs (69 lines):

diff -r 0315d62a78c2 -r af66e460d7a0 nxt/nxt_mem_cache_pool.c
--- a/nxt/nxt_mem_cache_pool.c	Thu Dec 08 17:15:54 2016 +0300
+++ b/nxt/nxt_mem_cache_pool.c	Thu Dec 08 19:29:40 2016 +0300
@@ -124,12 +124,14 @@ struct nxt_mem_cache_pool_s {
 
 
 static nxt_uint_t nxt_mem_cache_shift(nxt_uint_t n);
+#if !(NXT_DEBUG_MEMORY)
 static void *nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size);
 static nxt_uint_t nxt_mem_cache_alloc_chunk(u_char *map, nxt_uint_t size);
 static nxt_mem_cache_page_t *
     nxt_mem_cache_alloc_page(nxt_mem_cache_pool_t *pool);
 static nxt_mem_cache_block_t *
     nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool);
+#endif
 static void *nxt_mem_cache_alloc_large(nxt_mem_cache_pool_t *pool,
     size_t alignment, size_t size);
 static intptr_t nxt_mem_cache_rbtree_compare(nxt_rbtree_node_t *node1,
@@ -302,10 +304,14 @@ nxt_mem_cache_alloc(nxt_mem_cache_pool_t
         pool->proto->trace(pool->trace, "mem cache alloc: %zd", size);
     }
 
+#if !(NXT_DEBUG_MEMORY)
+
     if (size <= pool->page_size) {
         return nxt_mem_cache_alloc_small(pool, size);
     }
 
+#endif
+
     return nxt_mem_cache_alloc_large(pool, NXT_MAX_ALIGNMENT, size);
 }
 
@@ -337,6 +343,8 @@ nxt_mem_cache_align(nxt_mem_cache_pool_t
 
     if (nxt_fast_path((alignment - 1) & alignment) == 0) {
 
+#if !(NXT_DEBUG_MEMORY)
+
         if (size <= pool->page_size && alignment <= pool->page_alignment) {
             size = nxt_max(size, alignment);
 
@@ -345,6 +353,8 @@ nxt_mem_cache_align(nxt_mem_cache_pool_t
             }
         }
 
+#endif
+
         return nxt_mem_cache_alloc_large(pool, alignment, size);
     }
 
@@ -367,6 +377,8 @@ nxt_mem_cache_zalign(nxt_mem_cache_pool_
 }
 
 
+#if !(NXT_DEBUG_MEMORY)
+
 static void *
 nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size)
 {
@@ -549,6 +561,8 @@ nxt_mem_cache_alloc_cluster(nxt_mem_cach
     return cluster;
 }
 
+#endif
+
 
 static void *
 nxt_mem_cache_alloc_large(nxt_mem_cache_pool_t *pool, size_t alignment,


More information about the nginx-devel mailing list