to see what resource does the address given as a parameter belong to.
struct lp_chunk {
struct lp_chunk *next;
+ unsigned int size;
byte data[0];
};
unsigned chunk_size, threshold, total, total_large;
};
-void lp_free(resource *);
-void lp_dump(resource *);
+static void lp_free(resource *);
+static void lp_dump(resource *);
+static resource *lp_lookup(resource *, unsigned long);
static struct resclass lp_class = {
"LinPool",
sizeof(struct linpool),
lp_free,
- lp_dump
+ lp_dump,
+ lp_lookup
};
linpool
m->total_large += size;
c->next = m->first_large;
m->first_large = c->next;
+ c->size = size;
}
else
{
*m->plast = c;
m->plast = &c->next;
c->next = NULL;
+ c->size = m->chunk_size;
}
m->ptr = c->data + size;
m->end = c->data + m->chunk_size;
m->total_large = 0;
}
-void
+static void
lp_free(resource *r)
{
linpool *m = (linpool *) r;
}
}
-void
+static void
lp_dump(resource *r)
{
linpool *m = (linpool *) r;
m->total,
m->total_large);
}
+
+static resource *
+lp_lookup(resource *r, unsigned long a)
+{
+ linpool *m = (linpool *) r;
+ struct lp_chunk *c;
+
+ for(c=m->first; c; c=c->next)
+ if ((unsigned long) c->data <= a && (unsigned long) c->data + c->size > a)
+ return r;
+ for(c=m->first_large; c; c=c->next)
+ if ((unsigned long) c->data <= a && (unsigned long) c->data + c->size > a)
+ return r;
+ return NULL;
+}
static void pool_dump(resource *);
static void pool_free(resource *);
+static resource *pool_lookup(resource *, unsigned long);
static struct resclass pool_class = {
"Pool",
sizeof(pool),
pool_free,
- pool_dump
+ pool_dump,
+ pool_lookup
};
pool root_pool;
indent -= 3;
}
+static resource *
+pool_lookup(resource *P, unsigned long a)
+{
+ pool *p = (pool *) P;
+ resource *r, *q;
+
+ WALK_LIST(r, p->inside)
+ if (r->class->lookup && (q = r->class->lookup(r, a)))
+ return q;
+ return NULL;
+}
+
void
rfree(void *res)
{
return r;
}
+void
+rlookup(unsigned long a)
+{
+ resource *r;
+
+ debug("Looking up %08lx\n", a);
+ if (r = pool_lookup(&root_pool.r, a))
+ rdump(r);
+ else
+ debug("Not found.\n");
+}
+
void
resource_init(void)
{
debug("(size=%d)\n", m->size);
}
+static resource *
+mbl_lookup(resource *r, unsigned long a)
+{
+ struct mblock *m = (struct mblock *) r;
+
+ if ((unsigned long) m->data <= a && (unsigned long) m->data + m->size > a)
+ return r;
+ return NULL;
+}
+
static struct resclass mb_class = {
"Memory",
0,
mbl_free,
mbl_debug,
+ mbl_lookup
};
void *
unsigned size; /* Standard size of single resource */
void (*free)(resource *); /* Freeing function */
void (*dump)(resource *); /* Dump to debug output */
+ resource *(*lookup)(resource *, unsigned long); /* Look up address (only for debugging) */
};
/* Generic resource manipulation */
pool *rp_new(pool *, char *); /* Create new pool */
void rfree(void *); /* Free single resource */
void rdump(void *); /* Dump to debug output */
+void rlookup(unsigned long); /* Look up address (only for debugging) */
void *ralloc(pool *, struct resclass *);
static void slab_free(resource *r);
static void slab_dump(resource *r);
+static resource *slab_lookup(resource *r, unsigned long addr);
#ifdef FAKE_SLAB
"Slab",
sizeof(struct slab),
slab_free,
- slab_dump
+ slab_dump,
+ slab_lookup
};
struct sl_head {
debug("(%de+%dp+%df blocks per %d objs per %d bytes)\n", ec, pc, fc, s->objs_per_slab, s->obj_size);
}
+static resource *
+slab_lookup(resource *r, unsigned long a)
+{
+ slab *s = (slab *) r;
+ struct sl_head *h;
+
+ WALK_LIST(h, s->partial_heads)
+ if ((unsigned long) h < a && (unsigned long) h + SLAB_SIZE < a)
+ return r;
+ WALK_LIST(h, s->full_heads)
+ if ((unsigned long) h < a && (unsigned long) h + SLAB_SIZE < a)
+ return r;
+ return NULL;
+}
+
#endif