Skip to content

mallocng ¤

Commands that help with debugging musl's allocator, mallocng.

Functions:

Attributes:

search_on_fail module-attribute ¤

search_on_fail = add_param(
    "ng-search-on-fail",
    True,
    "let the ng-slot* commands search the heap if necessary",
    help_docstring="\nFor freed, avail(able) and corrupted slots, it may be\nimpossible to recover the start of the group and meta.\n\nWhen this option is set to True, the ng-slotu and ng-slots\ncommands will search the heap to try to find the correct meta/group.\n    ",
    param_class=PARAM_BOOLEAN,
    scope=heap,
)

state_alloc_color module-attribute ¤

state_alloc_color = BLUE

state_alloc_color_alt module-attribute ¤

state_alloc_color_alt = CYAN

state_freed_color module-attribute ¤

state_freed_color = RED

state_freed_color_alt module-attribute ¤

state_freed_color_alt = LIGHT_RED

state_avail_color module-attribute ¤

state_avail_color = GRAY

state_avail_color_alt module-attribute ¤

state_avail_color_alt = LIGHT_GRAY

VALID_CHARS module-attribute ¤

VALID_CHARS = list(map(ord, set(printable) - set('\t\r\n\x0c\x0b')))

vis_cyclic_offset_color module-attribute ¤

vis_cyclic_offset_color = YELLOW

vis_offset_color module-attribute ¤

vis_offset_color = LIGHT_YELLOW

vis_cycled_mark_color module-attribute ¤

vis_cycled_mark_color = PURPLE

vis_pn3_reserved_color module-attribute ¤

vis_pn3_reserved_color = LIGHT_CYAN

vis_big_offset_check_color module-attribute ¤

vis_big_offset_check_color = BLACK

vis_ftr_reserved_color module-attribute ¤

vis_ftr_reserved_color = GREEN

default_vis_count module-attribute ¤

default_vis_count = add_param(
    "ng-vis-count",
    10,
    "default count for ng-vis",
    param_class=PARAM_UINTEGER,
    scope=heap,
)

parser module-attribute ¤

parser = ArgumentParser(
    description="Utility for inspecting the mallocng (musl) allocator."
)

subparsers module-attribute ¤

subparsers = add_subparsers(dest='command')

explain_parser module-attribute ¤

explain_parser = add_parser(
    "explain",
    description="Gives a quick explanation of musl's mallocng allocator.",
    help="Gives a quick explanation of musl's mallocng allocator.",
)

dump_parser module-attribute ¤

dump_parser = add_parser('dump', description=f'
Dump the mallocng heap.

Since the command may produce lots of output, you may want to pipe it to
less with `| ng-dump | less -R`.

The [index] next to the metas is their index in the doubly linked list
pointed to by ctx.freed_meta_head. The [index] next to the slots is
the slot's index inside of its group (thus, these will always be sequential).

Notice that the pointers in the output of this command aren't colored according
to their mapping's color but rather according to the object's allocation status.
Color legend: {colorize('allocated', state_alloc_color)}; {colorize('freed', state_freed_color)}; {colorize('available', state_avail_color)}.
', help='Dump the mallocng heap.')

vis_parser module-attribute ¤

vis_parser = add_parser(
    "vis",
    description="Visualize slots in a group.",
    help="Visualize slots in a group.",
)

find_parser module-attribute ¤

find_parser = add_parser(
    "find",
    description="\nFind slot which contains the given address.\n\nReturns the `start` of the slot. We say a slot 'contains'\nan address if the address is in [start, start + stride).\n    ",
    help="Find slot which contains the given address.",
)

ctx_parser module-attribute ¤

ctx_parser = add_parser(
    "ctx",
    description="Print out the mallocng __malloc_context (ctx) object.",
    help="Print out the mallocng __malloc_context (ctx) object.",
)

metaarea_parser module-attribute ¤

metaarea_parser = add_parser(
    "metaarea",
    aliases=["ma"],
    description="Print out a mallocng meta_area object at the given address.",
    help="Print out a mallocng meta_area object at the given address.",
)

group_parser module-attribute ¤

group_parser = add_parser(
    "group",
    description="Print out information about a mallocng group at the given address.",
    help="Print out information about a mallocng group at the given address.",
)

meta_parser module-attribute ¤

meta_parser = add_parser(
    "meta",
    description="Print out information about a mallocng group given the address of its meta.",
    help="Print out information about a mallocng group given the address of its meta.",
)

slots_parser module-attribute ¤

slots_parser = add_parser(
    "slots",
    description="Dump information about a mallocng slot, given its start address.",
    help="Dump information about a mallocng slot, given its start address.",
)

slotu_parser module-attribute ¤

slotu_parser = add_parser(
    "slotu",
    description="Dump information about a mallocng slot, given its user address.",
    help="Dump information about a mallocng slot, given its user address.",
)

get_slot_color ¤

get_slot_color(state: SlotState, last_color: str = '') -> str

get_colored_slot_state ¤

get_colored_slot_state(ss: SlotState) -> str

get_colored_slot_state_short ¤

get_colored_slot_state_short(ss: SlotState) -> str

dump_group ¤

dump_group(group: Group) -> str

dump_meta ¤

dump_meta(meta: Meta, focus_slot: int | None = None) -> str

Parameters:

  • meta (Meta) –

    the meta to dump

  • focus_slot (int | None, default: None ) –

    the index of the slot to highlight in the slot statuses list

dump_grouped_slot ¤

dump_grouped_slot(gslot: GroupedSlot, all: bool) -> str

dump_slot ¤

dump_slot(
    slot: Slot, all: bool, successful_preload: bool, will_dump_gslot: bool
) -> str

smart_dump_slot ¤

smart_dump_slot(slot: Slot, all: bool, gslot: GroupedSlot | None = None) -> str

dump_meta_area ¤

dump_meta_area(meta_area: MetaArea, coming_from_dump: bool = False) -> str

dump_malloc_context ¤

dump_malloc_context(ctx: MallocContext) -> str

mallocng_slot_user ¤

mallocng_slot_user(address: int, all: bool) -> None

mallocng_slot_start ¤

mallocng_slot_start(address: int, all: bool) -> None

mallocng_meta ¤

mallocng_meta(address: int) -> None

mallocng_group ¤

mallocng_group(address: int, index: int | None = None) -> None

mallocng_meta_area ¤

mallocng_meta_area(address: int, index: int | None = None) -> None

mallocng_malloc_context ¤

mallocng_malloc_context(address: int | None = None) -> None

mallocng_find ¤

mallocng_find(
    address: int,
    all: bool = False,
    metadata: bool = False,
    shallow: bool = False,
) -> None

bin_ascii ¤

bin_ascii(bs: bytearray)

colorize_pointer ¤

colorize_pointer(
    address: int, ptrvalue: int, state: SlotState, slot: Slot
) -> str

colorize_start_header_line ¤

colorize_start_header_line(shline: str, state: SlotState, slot: Slot) -> str

line_decoration ¤

line_decoration(addr: int, slot_state: SlotState, slot: Slot) -> str

Maybe append extra clarification to a line.

Currently only appends to p headers.

mallocng_visualize_slots ¤

mallocng_visualize_slots(address: int, count: int = int(default_vis_count))

mallocng_dump ¤

mallocng_dump(meta_area: int | None = None) -> None

mallocng_explain ¤

mallocng_explain() -> None

mallocng_command ¤

mallocng_command(
    command: str,
    meta_area: int | None = None,
    address: int | None = None,
    count: int = int(default_vis_count),
    all: bool = False,
    metadata: bool = False,
    shallow: bool = False,
    index: int | None = None,
) -> None