scripts/gdb/linux/kasan.py
Source file repositories/reference/linux-study-clean/scripts/gdb/linux/kasan.py
File Facts
- System
- Linux kernel
- Corpus path
scripts/gdb/linux/kasan.py- Extension
.py- Size
- 1408 bytes
- Lines
- 45
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: scripts
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
# SPDX-License-Identifier: GPL-2.0
#
# Copyright 2024 Canonical Ltd.
#
# Authors:
# Kuan-Ying Lee <kuan-ying.lee@canonical.com>
#
import gdb
from linux import constants, mm
def help():
t = """Usage: lx-kasan_mem_to_shadow [Hex memory addr]
Example:
lx-kasan_mem_to_shadow 0xffff000008eca008\n"""
gdb.write("Unrecognized command\n")
raise gdb.GdbError(t)
class KasanMemToShadow(gdb.Command):
"""Translate memory address to kasan shadow address"""
p_ops = None
def __init__(self):
if constants.LX_CONFIG_KASAN_GENERIC or constants.LX_CONFIG_KASAN_SW_TAGS:
super(KasanMemToShadow, self).__init__("lx-kasan_mem_to_shadow", gdb.COMMAND_SUPPORT)
def invoke(self, args, from_tty):
if not constants.LX_CONFIG_KASAN_GENERIC or constants.LX_CONFIG_KASAN_SW_TAGS:
raise gdb.GdbError('CONFIG_KASAN_GENERIC or CONFIG_KASAN_SW_TAGS is not set')
argv = gdb.string_to_argv(args)
if len(argv) == 1:
if self.p_ops is None:
self.p_ops = mm.page_ops().ops
addr = int(argv[0], 16)
shadow_addr = self.kasan_mem_to_shadow(addr)
gdb.write('shadow addr: 0x%x\n' % shadow_addr)
else:
help()
def kasan_mem_to_shadow(self, addr):
return (addr >> self.p_ops.KASAN_SHADOW_SCALE_SHIFT) + self.p_ops.KASAN_SHADOW_OFFSET
KasanMemToShadow()
Annotation
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.