Till now it was limited to objects allocated from the OS which means
it had little use as soon as pools were enabled. Let's move it upper
in the layers so that any code can benefit from fault injection. In
addition this allows to pass a new flag POOL_F_NO_FAIL to disable it
if some callers prefer a no-failure approach.
/* possible flags for __pool_alloc() */
#define POOL_F_NO_POISON 0x00000001 // do not poison the area
#define POOL_F_MUST_ZERO 0x00000002 // zero the returned area
+#define POOL_F_NO_FAIL 0x00000004 // do not randomly fail
struct pool_cache_head {
{
void *p;
+#ifdef DEBUG_FAIL_ALLOC
+ if (!(flags & POOL_F_NO_FAIL) && mem_should_fail(pool))
+ return NULL;
+#endif
+
#ifdef CONFIG_HAP_POOLS
if (likely(p = pool_get_from_local_cache(pool)))
goto ret;
int limit = pool->limit;
void *ptr = NULL;
-#ifdef DEBUG_FAIL_ALLOC
- if (mem_should_fail(pool))
- return NULL;
-#endif
if (limit && allocated >= limit) {
activity[tid].pool_fail++;
return NULL;