-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmm-drgn-helpers.py
54 lines (47 loc) · 1.68 KB
/
mm-drgn-helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from drgn import FaultError
def bio_for_each_bvec(prog, bio):
for idx in range(0, bio.bi_vcnt):
yield bio.bi_io_vec[idx]
def find_slab(name):
for s in list_for_each_entry("struct kmem_cache", prog['slab_caches'].address_of_(), 'list'):
if s.name.string_().decode("utf-8") == name:
return s
def dump_slabs():
for s in list_for_each_entry("struct kmem_cache", prog['slab_caches'].address_of_(), "list"):
print("{} {}".format(s.name.string_().decode("utf-8"), hex(s.value_())))
def _slub_page_objects(prog, slab, page, obj_type):
addr = page_to_virt(page).value_()
addr += slab.red_left_pad
ret = []
end = addr + slab.size * page.objects
while addr < end:
ret.append(Object(prog, obj_type, address=addr))
addr += slab.size
return ret
def slab_page_objects(prog, slab, page, obj_type):
try:
return _slub_page_objects(prog, slab, page, obj_type)
except AttributeError:
pass
ret = []
offset = 0
if prog.type('struct kmem_cache').has_member('obj_offset'):
offset = slab.obj_offset
for i in range(0, slab.num):
addr = page.s_mem.value_() + i * slab.size + offset
ret.append(Object(prog, obj_type, address=addr))
return ret
def for_each_slab_page(prog):
PGSlab = 1 << prog.constant('PG_slab')
for p in for_each_page(prog):
try:
if p.flags.value_() & PGSlab:
yield p
except FaultError:
pass
def dump_slab_objects(prog, slab, obj_type):
ret = []
for p in for_each_slab_page(prog):
if p.slab_cache == slab:
ret.extend(slab_page_objects(prog, slab, p, obj_type))
return ret