xref: /xnu-11417.140.69/tools/lldbmacros/kmemory/vm.py (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1*43a90889SApple OSS Distributionsfrom abc import (
2*43a90889SApple OSS Distributions    ABCMeta,
3*43a90889SApple OSS Distributions    abstractmethod,
4*43a90889SApple OSS Distributions    abstractproperty,
5*43a90889SApple OSS Distributions)
6*43a90889SApple OSS Distributionsimport argparse
7*43a90889SApple OSS Distributionsimport re
8*43a90889SApple OSS Distributionsimport struct
9*43a90889SApple OSS Distributionsfrom typing import (
10*43a90889SApple OSS Distributions    Optional,
11*43a90889SApple OSS Distributions)
12*43a90889SApple OSS Distributions
13*43a90889SApple OSS Distributionsfrom core import (
14*43a90889SApple OSS Distributions    SBValueFormatter,
15*43a90889SApple OSS Distributions    caching,
16*43a90889SApple OSS Distributions    gettype,
17*43a90889SApple OSS Distributions    lldbwrap,
18*43a90889SApple OSS Distributions    value,
19*43a90889SApple OSS Distributions    xnu_format,
20*43a90889SApple OSS Distributions)
21*43a90889SApple OSS Distributionsfrom core.standard import (
22*43a90889SApple OSS Distributions    ArgumentError,
23*43a90889SApple OSS Distributions)
24*43a90889SApple OSS Distributionsfrom core.kernelcore import (
25*43a90889SApple OSS Distributions    KernelTarget,
26*43a90889SApple OSS Distributions)
27*43a90889SApple OSS Distributionsfrom core.iterators import (
28*43a90889SApple OSS Distributions    RB_HEAD,
29*43a90889SApple OSS Distributions)
30*43a90889SApple OSS Distributions
31*43a90889SApple OSS Distributionsfrom .kmem   import MemoryRange
32*43a90889SApple OSS Distributionsfrom .btlog  import BTLog, BTLibrary
33*43a90889SApple OSS Distributionsfrom .whatis import *
34*43a90889SApple OSS Distributions
35*43a90889SApple OSS Distributions# FIXME: should not import this from xnu / utils
36*43a90889SApple OSS Distributionsfrom pmap import (
37*43a90889SApple OSS Distributions    PmapWalkARM64,
38*43a90889SApple OSS Distributions    PmapWalkX86_64,
39*43a90889SApple OSS Distributions    KVToPhysARM,
40*43a90889SApple OSS Distributions)
41*43a90889SApple OSS Distributionsfrom utils import (
42*43a90889SApple OSS Distributions    GetEnumName,
43*43a90889SApple OSS Distributions    print_hex_data,
44*43a90889SApple OSS Distributions)
45*43a90889SApple OSS Distributionsfrom xnu import (
46*43a90889SApple OSS Distributions    lldb_command,
47*43a90889SApple OSS Distributions)
48*43a90889SApple OSS Distributions
49*43a90889SApple OSS Distributions@SBValueFormatter.converter("vm_prot")
50*43a90889SApple OSS Distributionsdef vm_prot_converter(prot):
51*43a90889SApple OSS Distributions    PROT_STR = "-rw?x"
52*43a90889SApple OSS Distributions    return PROT_STR[prot & 1] + PROT_STR[prot & 2] + PROT_STR[prot & 4]
53*43a90889SApple OSS Distributions
54*43a90889SApple OSS Distributions
55*43a90889SApple OSS Distributionsclass Pmap(object, metaclass=ABCMeta):
56*43a90889SApple OSS Distributions    """ Helper class to manipulate a pmap_t"""
57*43a90889SApple OSS Distributions
58*43a90889SApple OSS Distributions    def __new__(cls, pmap: lldbwrap.SBValue, name: Optional[str]=None):
59*43a90889SApple OSS Distributions        target = pmap.GetTarget()
60*43a90889SApple OSS Distributions        arch   = target.triple[:target.triple.find('-')]
61*43a90889SApple OSS Distributions
62*43a90889SApple OSS Distributions        if cls is Pmap:
63*43a90889SApple OSS Distributions            if arch.startswith('arm64'):
64*43a90889SApple OSS Distributions                return _PmapARM64(pmap, name)
65*43a90889SApple OSS Distributions            elif arch.startswith('x86_64'):
66*43a90889SApple OSS Distributions                return _PmapX86(pmap, name)
67*43a90889SApple OSS Distributions            else:
68*43a90889SApple OSS Distributions                return None
69*43a90889SApple OSS Distributions
70*43a90889SApple OSS Distributions        return super(Pmap, cls).__new__(cls)
71*43a90889SApple OSS Distributions
72*43a90889SApple OSS Distributions    def __init__(self, pmap: lldbwrap.SBValue, name: Optional[str]=None):
73*43a90889SApple OSS Distributions        self.sbv       = pmap
74*43a90889SApple OSS Distributions        self.name      = name
75*43a90889SApple OSS Distributions        self.kern      = KernelTarget(pmap.GetTarget().GetDebugger())
76*43a90889SApple OSS Distributions        self.page_size = 4096
77*43a90889SApple OSS Distributions
78*43a90889SApple OSS Distributions        self._last_phytokv_paddr = None
79*43a90889SApple OSS Distributions        self._last_phytokv_result = None
80*43a90889SApple OSS Distributions
81*43a90889SApple OSS Distributions    def describe(self, verbose=False):
82*43a90889SApple OSS Distributions        fmt = (
83*43a90889SApple OSS Distributions            "Pmap Info\n"
84*43a90889SApple OSS Distributions            " pmap                 : {&v:#x} \n"
85*43a90889SApple OSS Distributions        )
86*43a90889SApple OSS Distributions
87*43a90889SApple OSS Distributions    @staticmethod
88*43a90889SApple OSS Distributions    @caching.cache_statically
89*43a90889SApple OSS Distributions    def kernel_pmap(target=None):
90*43a90889SApple OSS Distributions        """
91*43a90889SApple OSS Distributions        Returns an object for the kernel pmap
92*43a90889SApple OSS Distributions        """
93*43a90889SApple OSS Distributions
94*43a90889SApple OSS Distributions        pmap = target.FindFirstGlobalVariable('kernel_pmap').Dereference()
95*43a90889SApple OSS Distributions        return Pmap(pmap, 'kernel_pmap')
96*43a90889SApple OSS Distributions
97*43a90889SApple OSS Distributions    def phystokv(self, paddr: int) -> int:
98*43a90889SApple OSS Distributions        base = self.trunc_page(paddr)
99*43a90889SApple OSS Distributions
100*43a90889SApple OSS Distributions        if self._last_phytokv_paddr != base:
101*43a90889SApple OSS Distributions            self._last_phytokv_paddr = base
102*43a90889SApple OSS Distributions            self._last_phytokv_result = self.kern.PhysToKernelVirt(base)
103*43a90889SApple OSS Distributions
104*43a90889SApple OSS Distributions        return self._last_phytokv_result + self.page_offset(paddr)
105*43a90889SApple OSS Distributions
106*43a90889SApple OSS Distributions    def trunc_page(self, addr: int) -> int:
107*43a90889SApple OSS Distributions        return addr & -self.page_size
108*43a90889SApple OSS Distributions
109*43a90889SApple OSS Distributions    def round_page(self, addr: int) -> int:
110*43a90889SApple OSS Distributions        return (addr + self.page_size - 1) & -self.page_size
111*43a90889SApple OSS Distributions
112*43a90889SApple OSS Distributions    def page_offset(self, addr: int) -> int:
113*43a90889SApple OSS Distributions        return addr & (self.page_size - 1)
114*43a90889SApple OSS Distributions
115*43a90889SApple OSS Distributions    @abstractmethod
116*43a90889SApple OSS Distributions    def kvtophys(self, vaddr: int) -> int:
117*43a90889SApple OSS Distributions        """
118*43a90889SApple OSS Distributions        resolves a kernel virtual address into a physical address
119*43a90889SApple OSS Distributions        """
120*43a90889SApple OSS Distributions        pass
121*43a90889SApple OSS Distributions
122*43a90889SApple OSS Distributions    @abstractmethod
123*43a90889SApple OSS Distributions    def walk(self, vaddr: int, extra: Optional[dict] = None) -> Optional[int]:
124*43a90889SApple OSS Distributions        """
125*43a90889SApple OSS Distributions        resolves a virtual address to a physical address for this pmap
126*43a90889SApple OSS Distributions
127*43a90889SApple OSS Distributions        @param vaddr (int)
128*43a90889SApple OSS Distributions            The address to resolve
129*43a90889SApple OSS Distributions
130*43a90889SApple OSS Distributions        @param extra (dict)
131*43a90889SApple OSS Distributions            Extra pmap specific information about the mapping
132*43a90889SApple OSS Distributions        """
133*43a90889SApple OSS Distributions
134*43a90889SApple OSS Distributions        pass
135*43a90889SApple OSS Distributions
136*43a90889SApple OSS Distributions
137*43a90889SApple OSS Distributionsclass _PmapARM64(Pmap):
138*43a90889SApple OSS Distributions    """
139*43a90889SApple OSS Distributions    Specialization of Pmap for arm64
140*43a90889SApple OSS Distributions    """
141*43a90889SApple OSS Distributions
142*43a90889SApple OSS Distributions    def __init__(self, pmap: lldbwrap.SBValue, name: Optional[str]=None):
143*43a90889SApple OSS Distributions        super().__init__(pmap, name)
144*43a90889SApple OSS Distributions
145*43a90889SApple OSS Distributions        target = pmap.GetTarget()
146*43a90889SApple OSS Distributions        self.gVirtBase = target.FindFirstGlobalVariable('gVirtBase').xGetValueAsInteger()
147*43a90889SApple OSS Distributions        self.gPhysBase = target.FindFirstGlobalVariable('gPhysBase').xGetValueAsInteger()
148*43a90889SApple OSS Distributions
149*43a90889SApple OSS Distributions        try:
150*43a90889SApple OSS Distributions            self.pt_attr = pmap.chkGetChildMemberWithName('pmap_pt_attr')
151*43a90889SApple OSS Distributions        except:
152*43a90889SApple OSS Distributions            self.pt_attr = target.FindFirstGlobalVariable('native_pt_attr')
153*43a90889SApple OSS Distributions        self.page_size = self.pt_attr.xGetIntegerByName('pta_page_size')
154*43a90889SApple OSS Distributions
155*43a90889SApple OSS Distributions
156*43a90889SApple OSS Distributions        self._last_walk_vaddr = None
157*43a90889SApple OSS Distributions        self._last_walk_extra = None
158*43a90889SApple OSS Distributions        self._last_walk_result = None
159*43a90889SApple OSS Distributions
160*43a90889SApple OSS Distributions        self._last_kvtophys_vaddr = None
161*43a90889SApple OSS Distributions        self._last_kvtophys_result = None
162*43a90889SApple OSS Distributions
163*43a90889SApple OSS Distributions    def kvtophys(self, vaddr: int) -> int:
164*43a90889SApple OSS Distributions        base = self.trunc_page(vaddr)
165*43a90889SApple OSS Distributions
166*43a90889SApple OSS Distributions        if self._last_kvtophys_vaddr != base:
167*43a90889SApple OSS Distributions            self._last_walk_vaddr = base
168*43a90889SApple OSS Distributions            self._last_walk_result = KVToPhysARM(base)
169*43a90889SApple OSS Distributions
170*43a90889SApple OSS Distributions        return self._last_walk_result + self.page_offset(base)
171*43a90889SApple OSS Distributions
172*43a90889SApple OSS Distributions    def walk(self, vaddr: int, extra: Optional[dict] = None) -> Optional[int]:
173*43a90889SApple OSS Distributions        base = self.trunc_page(vaddr)
174*43a90889SApple OSS Distributions
175*43a90889SApple OSS Distributions        if self._last_walk_vaddr != base:
176*43a90889SApple OSS Distributions            self._last_walk_vaddr = base
177*43a90889SApple OSS Distributions            self._last_walk_extra = {}
178*43a90889SApple OSS Distributions
179*43a90889SApple OSS Distributions            tte = self.sbv.chkGetChildMemberWithName('tte')
180*43a90889SApple OSS Distributions            self._last_walk_result = PmapWalkARM64(
181*43a90889SApple OSS Distributions                value(self.pt_attr), value(tte), base,
182*43a90889SApple OSS Distributions                0, self._last_walk_extra
183*43a90889SApple OSS Distributions            )
184*43a90889SApple OSS Distributions
185*43a90889SApple OSS Distributions        if extra is not None:
186*43a90889SApple OSS Distributions            extra.update(self._last_walk_extra)
187*43a90889SApple OSS Distributions        if self._last_walk_result:
188*43a90889SApple OSS Distributions            return self._last_walk_result + self.page_offset(vaddr)
189*43a90889SApple OSS Distributions        return None
190*43a90889SApple OSS Distributions
191*43a90889SApple OSS Distributions
192*43a90889SApple OSS Distributions
193*43a90889SApple OSS Distributionsclass _PmapX86(Pmap):
194*43a90889SApple OSS Distributions    """
195*43a90889SApple OSS Distributions    Specialization of Pmap for Intel
196*43a90889SApple OSS Distributions    """
197*43a90889SApple OSS Distributions
198*43a90889SApple OSS Distributions    def __init__(self, pmap: lldbwrap.SBValue, name: Optional[str]=None):
199*43a90889SApple OSS Distributions        super().__init__(pmap, name)
200*43a90889SApple OSS Distributions
201*43a90889SApple OSS Distributions        target = pmap.GetTarget()
202*43a90889SApple OSS Distributions        self.physmap_base = target.FindFirstGlobalVariable('physmap_base').xGetValueAsInteger()
203*43a90889SApple OSS Distributions
204*43a90889SApple OSS Distributions    @property
205*43a90889SApple OSS Distributions    def page_size(self):
206*43a90889SApple OSS Distributions        return 4096
207*43a90889SApple OSS Distributions
208*43a90889SApple OSS Distributions    def kvtophys(self, vaddr: int) -> int:
209*43a90889SApple OSS Distributions        return vaddr - self.phsmap_base
210*43a90889SApple OSS Distributions
211*43a90889SApple OSS Distributions    def walk(self, vaddr: int, extra: Optional[dict] = None) -> Optional[int]:
212*43a90889SApple OSS Distributions        return PmapWalkX86_64(value(self.sbv), vaddr, 0)
213*43a90889SApple OSS Distributions
214*43a90889SApple OSS Distributions
215*43a90889SApple OSS Distributionsclass VMMap(object):
216*43a90889SApple OSS Distributions    """ Helper class to manipulate a vm_map_t"""
217*43a90889SApple OSS Distributions
218*43a90889SApple OSS Distributions    def __init__(self, vm_map, name=None):
219*43a90889SApple OSS Distributions        self.sbv  = vm_map
220*43a90889SApple OSS Distributions        self.name = name
221*43a90889SApple OSS Distributions        self.rb   = RB_HEAD(
222*43a90889SApple OSS Distributions            vm_map.chkGetValueForExpressionPath(".hdr.rb_head_store"),
223*43a90889SApple OSS Distributions            "entry",
224*43a90889SApple OSS Distributions            self.entry_compare
225*43a90889SApple OSS Distributions        )
226*43a90889SApple OSS Distributions
227*43a90889SApple OSS Distributions        vme_type = gettype('struct vm_map_entry')
228*43a90889SApple OSS Distributions        self.to_entry = vme_type.xContainerOfTransform('store')
229*43a90889SApple OSS Distributions
230*43a90889SApple OSS Distributions    def entry_compare(self, rb_entry, address):
231*43a90889SApple OSS Distributions        vme = self.to_entry(rb_entry)
232*43a90889SApple OSS Distributions
233*43a90889SApple OSS Distributions        if vme.xGetScalarByPath(".links.end") <= address:
234*43a90889SApple OSS Distributions            return 1
235*43a90889SApple OSS Distributions        if address < vme.xGetScalarByPath(".links.start"):
236*43a90889SApple OSS Distributions            return -1
237*43a90889SApple OSS Distributions        return 0
238*43a90889SApple OSS Distributions
239*43a90889SApple OSS Distributions    def find(self, address):
240*43a90889SApple OSS Distributions        ent = self.rb.find(address)
241*43a90889SApple OSS Distributions        return self.to_entry(ent) if ent else None
242*43a90889SApple OSS Distributions
243*43a90889SApple OSS Distributions    def describe(self, verbose=False):
244*43a90889SApple OSS Distributions        fmt = (
245*43a90889SApple OSS Distributions            "VM Map Info\n"
246*43a90889SApple OSS Distributions            " vm map               : {&v:#x} \n"
247*43a90889SApple OSS Distributions        )
248*43a90889SApple OSS Distributions        if self.name:
249*43a90889SApple OSS Distributions            fmt += (
250*43a90889SApple OSS Distributions                " vm map name          : {m.name:s} \n"
251*43a90889SApple OSS Distributions            )
252*43a90889SApple OSS Distributions        fmt += (
253*43a90889SApple OSS Distributions            " pmap                 : {$v.pmap:#x} \n"
254*43a90889SApple OSS Distributions            " vm size              : {$v.size|human_size} ({$v.size:,d} bytes) \n"
255*43a90889SApple OSS Distributions            " entries              : {$v.hdr.nentries} \n"
256*43a90889SApple OSS Distributions            " map range            : "
257*43a90889SApple OSS Distributions                "{$v.hdr.links.start:#x} - {$v.hdr.links.end:#x}\n"
258*43a90889SApple OSS Distributions            " map pgshift          : {$v.hdr.page_shift}\n"
259*43a90889SApple OSS Distributions        )
260*43a90889SApple OSS Distributions        print(xnu_format(fmt, m=self, v=self.sbv))
261*43a90889SApple OSS Distributions
262*43a90889SApple OSS Distributions
263*43a90889SApple OSS Distributionsclass VMMapEntry(MemoryObject):
264*43a90889SApple OSS Distributions    """ Memory Object for a kernel map memory entry """
265*43a90889SApple OSS Distributions
266*43a90889SApple OSS Distributions    MO_KIND = "kernel map entry"
267*43a90889SApple OSS Distributions
268*43a90889SApple OSS Distributions    def __init__(self, kmem, address, vm_map):
269*43a90889SApple OSS Distributions        super().__init__(kmem, address)
270*43a90889SApple OSS Distributions        self.vm_map = vm_map
271*43a90889SApple OSS Distributions        self.sbv    = vm_map.find(address)
272*43a90889SApple OSS Distributions
273*43a90889SApple OSS Distributions    @property
274*43a90889SApple OSS Distributions    def object_range(self):
275*43a90889SApple OSS Distributions        sbv = self.sbv
276*43a90889SApple OSS Distributions        if sbv:
277*43a90889SApple OSS Distributions            return MemoryRange(
278*43a90889SApple OSS Distributions                sbv.xGetScalarByPath('.links.start'),
279*43a90889SApple OSS Distributions                sbv.xGetScalarByPath('.links.end')
280*43a90889SApple OSS Distributions            )
281*43a90889SApple OSS Distributions
282*43a90889SApple OSS Distributions        base = self.address & ~self.kmem.page_mask
283*43a90889SApple OSS Distributions        return MemoryRange(base, base + self.kmem.page_size)
284*43a90889SApple OSS Distributions
285*43a90889SApple OSS Distributions    @property
286*43a90889SApple OSS Distributions    def vme_offset(self):
287*43a90889SApple OSS Distributions        return self.sbv.xGetScalarByName('vme_offset') << 12
288*43a90889SApple OSS Distributions
289*43a90889SApple OSS Distributions    @property
290*43a90889SApple OSS Distributions    def vme_object_type(self):
291*43a90889SApple OSS Distributions        sbv = self.sbv
292*43a90889SApple OSS Distributions        if sbv.xGetScalarByName('is_sub_map'):
293*43a90889SApple OSS Distributions            return "submap"
294*43a90889SApple OSS Distributions        if sbv.xGetScalarByName('vme_kernel_object'):
295*43a90889SApple OSS Distributions            return "kobject"
296*43a90889SApple OSS Distributions        return "vm object"
297*43a90889SApple OSS Distributions
298*43a90889SApple OSS Distributions    @property
299*43a90889SApple OSS Distributions    def vme_object(self):
300*43a90889SApple OSS Distributions        kmem = self.kmem
301*43a90889SApple OSS Distributions        sbv  = self.sbv
302*43a90889SApple OSS Distributions
303*43a90889SApple OSS Distributions        if sbv.xGetScalarByName('is_sub_map'):
304*43a90889SApple OSS Distributions            addr = sbv.xGetScalarByName('vme_submap') << 2
305*43a90889SApple OSS Distributions            return (addr, kmem.vm_map_type)
306*43a90889SApple OSS Distributions
307*43a90889SApple OSS Distributions        if sbv.xGetScalarByName('vme_kernel_object'):
308*43a90889SApple OSS Distributions            return (kmem.vm_kobject.GetLoadAddress(), kmem.vmo_type)
309*43a90889SApple OSS Distributions
310*43a90889SApple OSS Distributions        packed = sbv.xGetScalarByName('vme_object_or_delta')
311*43a90889SApple OSS Distributions        addr   = kmem.vm_page_packing.unpack(packed)
312*43a90889SApple OSS Distributions        return (addr, kmem.vmo_type)
313*43a90889SApple OSS Distributions
314*43a90889SApple OSS Distributions    @property
315*43a90889SApple OSS Distributions    def pages(self):
316*43a90889SApple OSS Distributions        return self.object_range.size >> self.kmem.page_shift
317*43a90889SApple OSS Distributions
318*43a90889SApple OSS Distributions    def describe(self, verbose=False):
319*43a90889SApple OSS Distributions
320*43a90889SApple OSS Distributions        self.vm_map.describe()
321*43a90889SApple OSS Distributions
322*43a90889SApple OSS Distributions        if not self.sbv:
323*43a90889SApple OSS Distributions            fmt = (
324*43a90889SApple OSS Distributions                "Kernel Map Entry Info\n"
325*43a90889SApple OSS Distributions                " No memory mapped at this address\n"
326*43a90889SApple OSS Distributions            )
327*43a90889SApple OSS Distributions            print(xnu_format(fmt))
328*43a90889SApple OSS Distributions            return
329*43a90889SApple OSS Distributions
330*43a90889SApple OSS Distributions        fmt = (
331*43a90889SApple OSS Distributions            "VM Map Entry Info\n"
332*43a90889SApple OSS Distributions            " vm entry             : {&v:#x}\n"
333*43a90889SApple OSS Distributions            " start / end          : "
334*43a90889SApple OSS Distributions                "{$v.links.start:#x} - {$v.links.end:#x} "
335*43a90889SApple OSS Distributions                "({0.pages:,d} pages)\n"
336*43a90889SApple OSS Distributions            " vm tag               : {$v.vme_alias|vm_kern_tag}\n"
337*43a90889SApple OSS Distributions        )
338*43a90889SApple OSS Distributions        range_id = next((
339*43a90889SApple OSS Distributions            i
340*43a90889SApple OSS Distributions            for i, r in enumerate(self.kmem.kmem_ranges)
341*43a90889SApple OSS Distributions            if r.contains(self.address)
342*43a90889SApple OSS Distributions        ), None)
343*43a90889SApple OSS Distributions        if range_id:
344*43a90889SApple OSS Distributions            fmt += (
345*43a90889SApple OSS Distributions                " vm range id          : {range_id}\n"
346*43a90889SApple OSS Distributions            )
347*43a90889SApple OSS Distributions        fmt += (
348*43a90889SApple OSS Distributions            " protection           : "
349*43a90889SApple OSS Distributions                "{$v.protection|vm_prot}/{$v.max_protection|vm_prot}\n"
350*43a90889SApple OSS Distributions            " vm object            : "
351*43a90889SApple OSS Distributions                "{0.vme_object_type} ({0.vme_object[0]:#x})\n"
352*43a90889SApple OSS Distributions            " entry offset         : {0.vme_offset:#x}\n"
353*43a90889SApple OSS Distributions        )
354*43a90889SApple OSS Distributions        print(xnu_format(fmt, self, v=self.sbv, range_id=range_id))
355*43a90889SApple OSS Distributions
356*43a90889SApple OSS Distributions
357*43a90889SApple OSS Distributions@whatis_provider
358*43a90889SApple OSS Distributionsclass KernelMapWhatisProvider(WhatisProvider):
359*43a90889SApple OSS Distributions    """
360*43a90889SApple OSS Distributions    Whatis Provider for the kernel map ranges
361*43a90889SApple OSS Distributions    """
362*43a90889SApple OSS Distributions
363*43a90889SApple OSS Distributions    def claims(self, address):
364*43a90889SApple OSS Distributions        kmem = self.kmem
365*43a90889SApple OSS Distributions
366*43a90889SApple OSS Distributions        return (
367*43a90889SApple OSS Distributions                any(r.contains(address) for r in kmem.kmem_ranges)
368*43a90889SApple OSS Distributions                or kmem.iokit_range.contains(address)
369*43a90889SApple OSS Distributions        )
370*43a90889SApple OSS Distributions
371*43a90889SApple OSS Distributions    def lookup(self, address):
372*43a90889SApple OSS Distributions        kmem = self.kmem
373*43a90889SApple OSS Distributions
374*43a90889SApple OSS Distributions        if any(r.contains(address) for r in kmem.kmem_ranges):
375*43a90889SApple OSS Distributions            return VMMapEntry(kmem, address, VMMap(kmem.kernel_map, 'kernel_map'))
376*43a90889SApple OSS Distributions
377*43a90889SApple OSS Distributions        iokit_pageable_map_data = kmem.target.chkFindFirstGlobalVariable('gIOKitPageableMap')
378*43a90889SApple OSS Distributions        iokit_pageable_vm_map = iokit_pageable_map_data.chkGetChildMemberWithName("map").Dereference()
379*43a90889SApple OSS Distributions        return VMMapEntry(kmem, address, VMMap(iokit_pageable_vm_map, "gIOKitPageableMap.map"))
380*43a90889SApple OSS Distributions
381*43a90889SApple OSS Distributions
382*43a90889SApple OSS Distributions__all__ = [
383*43a90889SApple OSS Distributions    Pmap.__name__,
384*43a90889SApple OSS Distributions    VMMap.__name__,
385*43a90889SApple OSS Distributions    VMMapEntry.__name__,
386*43a90889SApple OSS Distributions    KernelMapWhatisProvider.__name__,
387*43a90889SApple OSS Distributions]
388