aboutsummaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2023-10-01 03:03:13 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-10-01 04:27:00 +0200
commit42bdb9e4fea494b85b394dd99d1686e812eb8a28 (patch)
treee4cbc60130c81c94043f603ef8a826d0a896e842 /kern
parent511536317e810a5d204530ed8513f645acf67d9c (diff)
downloadgnumach-42bdb9e4fea494b85b394dd99d1686e812eb8a28.tar.gz
gnumach-42bdb9e4fea494b85b394dd99d1686e812eb8a28.tar.bz2
gnumach-42bdb9e4fea494b85b394dd99d1686e812eb8a28.zip
ddb: Add whatis command
This is convenient when tracking buffer overflows
Diffstat (limited to 'kern')
-rw-r--r--kern/slab.c40
-rw-r--r--kern/slab.h1
2 files changed, 40 insertions, 1 deletions
diff --git a/kern/slab.c b/kern/slab.c
index 545c7019..3264ebba 100644
--- a/kern/slab.c
+++ b/kern/slab.c
@@ -1496,11 +1496,49 @@ void slab_info(void)
#if MACH_KDB
#include <ddb/db_output.h>
- void db_show_slab_info(void)
+void db_show_slab_info(void)
{
_slab_info(db_printf);
}
+void db_whatis_slab(vm_offset_t a)
+{
+ struct kmem_cache *cache;
+
+#ifndef SLAB_VERIFY
+ db_printf("enabling SLAB_VERIFY is recommended\n");
+#endif
+
+ simple_lock(&kmem_cache_list_lock);
+
+ list_for_each_entry(&kmem_cache_list, cache, node) {
+ if (a >= (vm_offset_t) cache
+ && a < (vm_offset_t) cache + sizeof(*cache))
+ db_printf("Cache %s\n", cache->name);
+
+ simple_lock(&cache->lock);
+
+ if (cache->flags & KMEM_CF_USE_TREE) {
+ struct rbtree_node *node;
+
+ node = rbtree_lookup_nearest(&cache->active_slabs, (void*) a,
+ kmem_slab_cmp_lookup, RBTREE_LEFT);
+ if (node) {
+ struct kmem_slab *slab;
+ slab = rbtree_entry(node, struct kmem_slab, tree_node);
+ if (a >= (vm_offset_t) slab->addr
+ && a < (vm_offset_t) slab->addr + cache->slab_size)
+ db_printf("In cache %s\n", cache->name);
+ }
+ }
+
+ simple_unlock(&cache->lock);
+ }
+
+ simple_unlock(&kmem_cache_list_lock);
+
+}
+
#endif /* MACH_KDB */
#if MACH_DEBUG
diff --git a/kern/slab.h b/kern/slab.h
index 1e916872..4d51755a 100644
--- a/kern/slab.h
+++ b/kern/slab.h
@@ -237,6 +237,7 @@ void slab_info(void);
#if MACH_KDB
void db_show_slab_info(void);
+void db_whatis_slab(vm_offset_t addr);
#endif /* MACH_KDB */
#endif /* _KERN_SLAB_H */