summaryrefslogtreecommitdiff
path: root/lib/mempool.c
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>2000-05-08 22:33:38 +0000
committerMartin Mares <mj@ucw.cz>2000-05-08 22:33:38 +0000
commitc976342828d5de3d16b59d623f4f7fb03f52acc9 (patch)
tree4c36b20465c2d7d65e248c14e718e778a5efef60 /lib/mempool.c
parent0521e4f68490d5ef5cc6ba6b2b4e4edf7cf6aa1a (diff)
Implemented debugging function rlookup() which you can call from gdb
to see what resource does the address given as a parameter belong to.
Diffstat (limited to 'lib/mempool.c')
-rw-r--r--lib/mempool.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/lib/mempool.c b/lib/mempool.c
index c9c1dd63..f21b3059 100644
--- a/lib/mempool.c
+++ b/lib/mempool.c
@@ -14,6 +14,7 @@
struct lp_chunk {
struct lp_chunk *next;
+ unsigned int size;
byte data[0];
};
@@ -25,14 +26,16 @@ struct linpool {
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
@@ -70,6 +73,7 @@ lp_alloc(linpool *m, unsigned size)
m->total_large += size;
c->next = m->first_large;
m->first_large = c->next;
+ c->size = size;
}
else
{
@@ -87,6 +91,7 @@ lp_alloc(linpool *m, unsigned size)
*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;
@@ -134,7 +139,7 @@ lp_flush(linpool *m)
m->total_large = 0;
}
-void
+static void
lp_free(resource *r)
{
linpool *m = (linpool *) r;
@@ -152,7 +157,7 @@ lp_free(resource *r)
}
}
-void
+static void
lp_dump(resource *r)
{
linpool *m = (linpool *) r;
@@ -171,3 +176,18 @@ lp_dump(resource *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;
+}