0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-03 07:31:54 +00:00

Allocation from linpools and slabs requires the appropriate lock to be taken

This commit is contained in:
Maria Matejka 2023-04-28 23:48:03 +02:00
parent 010c26c296
commit 9f25dd79b8
4 changed files with 10 additions and 7 deletions

View 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;

View 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

View 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);

View 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);