]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Allocation from linpools and slabs requires the appropriate lock to be taken
authorMaria Matejka <mq@ucw.cz>
Fri, 28 Apr 2023 21:48:03 +0000 (23:48 +0200)
committerMaria Matejka <mq@ucw.cz>
Wed, 3 May 2023 19:30:29 +0000 (21:30 +0200)
lib/mempool.c
lib/resource.c
lib/resource.h
lib/slab.c

index 56a4c3db561f1fb4c9650c0d40853f78a1e026f0..578750c12e292cc5652e81502700e77ec21c3a56 100644 (file)
@@ -86,6 +86,7 @@ linpool
 void *
 lp_alloc(linpool *m, uint size)
 {
+  ASSERT_DIE(DG_IS_LOCKED(resource_parent(&m->r)->domain));
   byte *a = (byte *) BIRD_ALIGN((unsigned long) m->ptr, CPU_STRUCT_ALIGN);
   byte *e = a + size;
 
@@ -145,6 +146,7 @@ lp_alloc(linpool *m, uint size)
 void *
 lp_allocu(linpool *m, uint size)
 {
+  ASSERT_DIE(DG_IS_LOCKED(resource_parent(&m->r)->domain));
   byte *a = m->ptr;
   byte *e = a + size;
 
@@ -183,6 +185,7 @@ lp_allocz(linpool *m, uint size)
 void
 lp_flush(linpool *m)
 {
+  ASSERT_DIE(DG_IS_LOCKED(resource_parent(&m->r)->domain));
   struct lp_chunk *c;
 
   /* Move ptr to the first chunk and free all other chunks */
@@ -216,6 +219,7 @@ lp_flush(linpool *m)
 void
 lp_save(linpool *m, lp_state *p)
 {
+  ASSERT_DIE(DG_IS_LOCKED(resource_parent(&m->r)->domain));
   p->current = m->current;
   p->large = m->first_large;
   p->total_large = m->total_large;
@@ -236,6 +240,7 @@ void
 lp_restore(linpool *m, lp_state *p)
 {
   struct lp_chunk *c;
+  ASSERT_DIE(DG_IS_LOCKED(resource_parent(&m->r)->domain));
 
   /* Move ptr to the saved pos and free all newer large chunks */
   m->current = c = p->current ?: m->first;
index e0aaac0a11c3325016f9ade6581e8f6090ef64b0..611db4d7e2bee760003ffe94507a840388ad14fb 100644 (file)
@@ -189,13 +189,6 @@ pool_lookup(resource *P, unsigned long a)
   return q;
 }
 
-static pool *
-resource_parent(resource *r)
-{
-  return SKIP_BACK(pool, inside, resource_enlisted(r));
-}
-
-
 /**
  * rmove - move a resource
  * @res: resource
index 810334c14264fca43c24aa6df25ffb12ba1448bc..06af4289925c535749cd38cf61309756a489d8dd 100644 (file)
@@ -76,6 +76,9 @@ void rp_free(pool *p);                                                        /* Free the whole pool */
 
 extern pool root_pool;
 
+static inline pool *resource_parent(resource *r)
+{ return SKIP_BACK(pool, inside, resource_enlisted(r)); }
+
 /* Normal memory blocks */
 
 void *mb_alloc(pool *, unsigned size);
index 23316e82805c2efb1b191db27ddc8b80786a5523..7d2c87e9e18b775a4eb177ea47679c0bce90ec04 100644 (file)
@@ -256,6 +256,7 @@ void *
 sl_alloc(slab *s)
 {
   struct sl_head *h;
+  ASSERT_DIE(DG_IS_LOCKED(resource_parent(&s->r)->domain));
 
 redo:
   if (!(h = s->partial_heads.first))
@@ -331,6 +332,7 @@ sl_free(void *oo)
 {
   struct sl_head *h = SL_GET_HEAD(oo);
   struct slab *s = h->slab;
+  ASSERT_DIE(DG_IS_LOCKED(resource_parent(&s->r)->domain));
 
 #ifdef POISON
   memset(oo, 0xdb, s->data_size);