Skip to content

Add stack overflow detection mechanism #14

@kristjanvalur

Description

@kristjanvalur

Problem

Currently, stackman provides stack switching but no built-in overflow detection. Users must manually implement guard pages or canaries.

Proposal

Add optional stack overflow detection helpers:

  1. Guard zone utilities:

    • stackman_guard_init(void *stack, size_t size, size_t guard_bytes) - Initialize guard pattern
    • stackman_guard_check(void *stack, size_t size, size_t guard_bytes) - Verify guard intact
  2. Stack usage tracking:

    • stackman_stack_usage(void *stack_base, size_t size) - Measure actual usage via stack painting

Benefits

  • Easier debugging of stack-related crashes
  • Production overflow detection
  • Helps users size stacks appropriately

Implementation

Could be a separate header (stackman_debug.h) to keep core library minimal.

Related

test_04 already uses basic guard bytes for validation - could formalize this pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions