BUG/MINOR: pools/threads: don't ignore DEBUG_UAF on double-word CAS capable archs
Since commit cf975d4 ("MINOR: pools/threads: Implement lockless memory
pools."), we support lockless pools. However the parts dedicated to
detecting use-after-free are not present in this part, making DEBUG_UAF
useless in this situation.
The present patch sets a new define CONFIG_HAP_LOCKLESS_POOLS when such
a compatible architecture is detected, and when pool debugging is not
requested, then makes use of this everywhere in pools and buffers
functions. This way enabling DEBUG_UAF will automatically disable the
lockless version.
No backport is needed as this is purely 1.9-dev.
diff --git a/src/memory.c b/src/memory.c
index 929a04a..2d1a5e7 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -93,13 +93,13 @@
LIST_ADDQ(start, &pool->list);
}
pool->users++;
-#ifndef HA_HAVE_CAS_DW
+#ifndef CONFIG_HAP_LOCKLESS_POOLS
HA_SPIN_INIT(&pool->lock);
#endif
return pool;
}
-#ifdef HA_HAVE_CAS_DW
+#ifdef CONFIG_HAP_LOCKLESS_POOLS
/* Allocates new entries for pool <pool> until there are at least <avail> + 1
* available, then returns the last one for immediate use, so that at least
* <avail> are left available in the pool upon return. NULL is returned if the
@@ -221,7 +221,7 @@
HA_ATOMIC_STORE(&recurse, 0);
}
-#else
+#else /* CONFIG_HAP_LOCKLESS_POOLS */
/* Allocates new entries for pool <pool> until there are at least <avail> + 1
* available, then returns the last one for immediate use, so that at least
@@ -352,7 +352,7 @@
pool->users--;
if (!pool->users) {
LIST_DEL(&pool->list);
-#ifndef HA_HAVE_CAS_DW
+#ifndef CONFIG_HAP_LOCKLESS_POOLS
HA_SPIN_DESTROY(&pool->lock);
#endif
free(pool);
@@ -371,7 +371,7 @@
allocated = used = nbpools = 0;
chunk_printf(&trash, "Dumping pools usage. Use SIGQUIT to flush them.\n");
list_for_each_entry(entry, &pools, list) {
-#ifndef HA_HAVE_CAS_DW
+#ifndef CONFIG_HAP_LOCKLESS_POOLS
HA_SPIN_LOCK(POOL_LOCK, &entry->lock);
#endif
chunk_appendf(&trash, " - Pool %s (%d bytes) : %d allocated (%u bytes), %d used, %d failures, %d users%s\n",
@@ -382,7 +382,7 @@
allocated += entry->allocated * entry->size;
used += entry->used * entry->size;
nbpools++;
-#ifndef HA_HAVE_CAS_DW
+#ifndef CONFIG_HAP_LOCKLESS_POOLS
HA_SPIN_UNLOCK(POOL_LOCK, &entry->lock);
#endif
}