1 from gdb import Type, Value, lookup_type
2 from . import KernelStruct
3 from ..utils import get_dnode_path
5 class MemRegion(KernelStruct):
6 def __init__(self, gdb_inferior: Value) -> None:
7 super().__init__(gdb_inferior, MemRegion)
8 self.__attr = self._kstruct["attr"]
11 def get_type() -> Type:
12 return lookup_type("struct mm_region").pointer()
14 def print_abstract(self, pp, *args):
15 self.print_detailed(pp, *args)
17 def print_simple(self, pp, *args):
18 self.print_detailed(pp, *args)
20 def print_detailed(self, pp, *args):
21 pp.print( "0x%x...0x%x [0x%x]"%(
22 self._kstruct['start'], self._kstruct['end'],
23 self._kstruct['end'] - self._kstruct['start']))
25 pp.printf("attributes: %s (0x%x)", ", ".join([self.get_vmr_kind(), self.get_protection()]), self.__attr)
27 file = self._kstruct["mfile"]
29 pp.print("anonymous region")
31 pp.print("file mapped:")
33 ppp.print("dnode: %s @0x%x"%(get_dnode_path(file["dnode"]), file))
34 ppp.print("range: 0x%x+0x%x"%(self._kstruct["foff"], self._kstruct["flen"]))
36 def get_protection(self):
38 if (self.__attr & (1 << 2)):
40 if (self.__attr & (1 << 3)):
42 if (self.__attr & (1 << 4)):
44 return ''.join(attr_str)
46 def get_vmr_kind(self):
48 #define REGION_TYPE_CODE (1 << 16)
49 #define REGION_TYPE_GENERAL (2 << 16)
50 #define REGION_TYPE_HEAP (3 << 16)
51 #define REGION_TYPE_STACK (4 << 16)
53 types = ["exec", "data", "heap", "stack"]
54 attr = ((self.__attr >> 16) & 0xf) - 1
55 if attr >= len(types):
56 return "unknown kind %d"%attr