either directly to the console or are printed to console in case of
a system crash.
+config XMEM_POOL_POISON
+ bool "Poison free xenpool blocks"
+ default DEBUG
+ ---help---
+ Poison free blocks with 0xAA bytes and verify them when a block is
+ allocated in order to spot use-after-free issues.
+
endif # DEBUG || EXPERT
endmenu
}
#endif
+/**
+ * memchr_inv - Find an unmatching character in an area of memory.
+ * @s: The memory area
+ * @c: The byte that is expected
+ * @n: The size of the area.
+ *
+ * returns the address of the first occurrence of a character other than @c,
+ * or %NULL if the whole buffer contains just @c.
+ */
+void *memchr_inv(const void *s, int c, size_t n)
+{
+ const unsigned char *p = s;
+
+ while (n--)
+ if ((unsigned char)c != *p++)
+ return (void *)(p - 1);
+
+ return NULL;
+}
+
/*
* Local variables:
* mode: C
b->ptr.free_ptr = (struct free_ptr) {NULL, NULL};
}
+#define POISON_BYTE 0xAA
+
/**
* Removes block(b) from free list with indexes (fl, sl)
*/
}
}
b->ptr.free_ptr = (struct free_ptr) {NULL, NULL};
+
+#ifdef CONFIG_XMEM_POOL_POISON
+ if ( (b->size & BLOCK_SIZE_MASK) > MIN_BLOCK_SIZE )
+ ASSERT(!memchr_inv(b->ptr.buffer + MIN_BLOCK_SIZE, POISON_BYTE,
+ (b->size & BLOCK_SIZE_MASK) - MIN_BLOCK_SIZE));
+#endif /* CONFIG_XMEM_POOL_POISON */
}
/**
*/
static inline void INSERT_BLOCK(struct bhdr *b, struct xmem_pool *p, int fl, int sl)
{
+#ifdef CONFIG_XMEM_POOL_POISON
+ if ( (b->size & BLOCK_SIZE_MASK) > MIN_BLOCK_SIZE )
+ memset(b->ptr.buffer + MIN_BLOCK_SIZE, POISON_BYTE,
+ (b->size & BLOCK_SIZE_MASK) - MIN_BLOCK_SIZE);
+#endif /* CONFIG_XMEM_POOL_POISON */
+
b->ptr.free_ptr = (struct free_ptr) {NULL, p->matrix[fl][sl]};
if ( p->matrix[fl][sl] )
p->matrix[fl][sl]->ptr.free_ptr.prev = b;
#define memchr(s, c, n) __builtin_memchr(s, c, n)
#endif
+void *memchr_inv(const void *, int, size_t);
+
#define is_char_array(x) __builtin_types_compatible_p(typeof(x), char[])
/* safe_xxx always NUL-terminates and returns !=0 if result is truncated. */