summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2011-04-04 13:28:11 +0200
committerStefan Metzmacher <metze@samba.org>2011-04-08 09:28:10 +0200
commit6126c3506d493cd4836a7539586b74faea8ca0b3 (patch)
treeeff94fbdf7e43bdec846f1a04f6567460998fa6a
parent4895f55f0604a1851d45c24a8a584a10170d5917 (diff)
downloadsamba-6126c3506d493cd4836a7539586b74faea8ca0b3.tar.gz
samba-6126c3506d493cd4836a7539586b74faea8ca0b3.tar.bz2
samba-6126c3506d493cd4836a7539586b74faea8ca0b3.zip
talloc: add TC_INVALIDATE_SHRINK_CHUNK() marco
This invalidates the unused bytes if we shrink memory. metze Signed-off-By: Andrew Tridgell <tridge@samba.org>
-rw-r--r--lib/talloc/talloc.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index 522d60ff8f..3ec5d85eee 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -143,6 +143,32 @@ static struct {
TC_INVALIDATE_FULL_VALGRIND_CHUNK(_tc); \
} while (0)
+#define TC_INVALIDATE_SHRINK_FILL_CHUNK(_tc, _new_size) do { \
+ if (unlikely(talloc_fill.enabled)) { \
+ size_t _flen = (_tc)->size - (_new_size); \
+ char *_fptr = TC_PTR_FROM_CHUNK(_tc); \
+ _fptr += (_new_size); \
+ memset(_fptr, talloc_fill.fill_value, _flen); \
+ } \
+} while (0)
+
+#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_NOACCESS)
+/* Mark the unused bytes not accessable */
+#define TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) do { \
+ size_t _flen = (_tc)->size - (_new_size); \
+ char *_fptr = TC_PTR_FROM_CHUNK(_tc); \
+ _fptr += (_new_size); \
+ VALGRIND_MAKE_MEM_NOACCESS(_fptr, _flen); \
+} while (0)
+#else
+#define TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size) do { } while (0)
+#endif
+
+#define TC_INVALIDATE_SHRINK_CHUNK(_tc, _new_size) do { \
+ TC_INVALIDATE_SHRINK_FILL_CHUNK(_tc, _new_size); \
+ TC_INVALIDATE_SHRINK_VALGRIND_CHUNK(_tc, _new_size); \
+} while (0)
+
struct talloc_reference_handle {
struct talloc_reference_handle *next, *prev;
void *ptr;
@@ -1282,12 +1308,14 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons
if (size < tc->size) {
if (pool_tc) {
void *next_tc = TC_POOLMEM_NEXT_CHUNK(tc);
+ TC_INVALIDATE_SHRINK_CHUNK(tc, size);
tc->size = size;
if (next_tc == pool_tc->pool) {
pool_tc->pool = TC_POOLMEM_NEXT_CHUNK(tc);
}
return ptr;
} else if ((tc->size - size) < 1024) {
+ TC_INVALIDATE_SHRINK_CHUNK(tc, size);
/* do not shrink if we have less than 1k to gain */
tc->size = size;
return ptr;