Feature Plan: wolfCOSE "Small Stack" Mode
The Problem: "Stack Exhaustion"
In many embedded environments (STM32, ESP32, or custom RTOS tasks), the stack is a precious, fixed resource. wolfCOSE, in its current "no-malloc" state, forces all buffers and structures onto the stack. For complex COSE objects (signatures + certs + payload), this can exceed the available stack depth, leading to hard faults.
Proposed Naming Options
Since we want this to sound functional but "cool," here are a few directions for the --enable flag and the macro:
--enable-small-stack (Simple, clear, user-centric)
--enable-heap-buffers (Technical, explicit about memory location)
--enable-low-stack-footprint (Professional)
WOLFCOSE_LOW_STACK (The internal macro)
Updated Phase 1: Logic & Naming
We will wrap the dynamic allocation logic specifically under a "Small Stack" umbrella.
- Macro Logic:
/* If the user wants to save stack, we default to heap usage */
#if defined(WOLFCOSE_SMALL_STACK) || defined(WOLFCOSE_DYNAMIC_ALLOCATION)
#define WC_COSE_USE_HEAP
#endif
Updated Phase 4: Stack Auditing
Since the goal is to accommodate small stacks, we don't just add malloc—we also need to find where the current code is "stack-heavy."
- Identify Large Locals: Use the Fenrir Prompt (from our previous chat) to specifically target "Category B.4: Stack Minimization."
- Heap-Promotion: Any local array larger than, say, 128 bytes should be conditionally moved to the heap when
WC_COSE_USE_HEAP is defined.
- The "Safety Valve": If
WC_COSE_USE_HEAP is NOT defined and a function detects a payload larger than the static buffer, it must return a specific error code like BUFFER_TOO_SMALL_E rather than overflowing.
Feature Plan: wolfCOSE "Small Stack" Mode
The Problem: "Stack Exhaustion"
In many embedded environments (STM32, ESP32, or custom RTOS tasks), the stack is a precious, fixed resource. wolfCOSE, in its current "no-malloc" state, forces all buffers and structures onto the stack. For complex COSE objects (signatures + certs + payload), this can exceed the available stack depth, leading to hard faults.
Proposed Naming Options
Since we want this to sound functional but "cool," here are a few directions for the
--enableflag and the macro:--enable-small-stack(Simple, clear, user-centric)--enable-heap-buffers(Technical, explicit about memory location)--enable-low-stack-footprint(Professional)WOLFCOSE_LOW_STACK(The internal macro)Updated Phase 1: Logic & Naming
We will wrap the dynamic allocation logic specifically under a "Small Stack" umbrella.
Updated Phase 4: Stack Auditing
Since the goal is to accommodate small stacks, we don't just add
malloc—we also need to find where the current code is "stack-heavy."WC_COSE_USE_HEAPis defined.WC_COSE_USE_HEAPis NOT defined and a function detects a payload larger than the static buffer, it must return a specific error code likeBUFFER_TOO_SMALL_Erather than overflowing.