Kleidos API Search

In development. It changes without notice.

Topic

Platform Memory & Errors

Large blocks of memory, the record of an allocation that failed, names of errors, and where the compiler places a function or a variable.

What a running board reports of itself is in Diagnostics.

See also
Diagnostics, RTOS Facade

Files

file src/platform/base/attributes.h
Compiler placement attributes (IRAM / RTC memory) with native fallbacks.
file src/platform/base/error.cpp
Platform error-code to human-readable name helper.
file src/platform/base/error.h
Platform error-code to human-readable name helper.
file src/platform/base/heap_failure.cpp
Allocation-failure hook and ring-buffer implementation.
file src/platform/base/heap_failure.h
Permanent recorder for failed heap allocations.
file src/platform/base/memory.h
Heap allocation facade with PSRAM-aware helpers.
file src/platform/base/new_nothrow.cpp
Replaceable nothrow allocation functions that really return nullptr.
file src/platform/base/new_nothrow.h
Contract note for the replaceable nothrow allocation functions.

Classes

struct kleidos::platform::heap_failure::Record
One recorded allocation failure. More about kleidos::platform::heap_failure::Record
class kleidos::platform::heap_failure::FallbackAttempt
Marks one allocation attempt that still has a fallback to try. More about kleidos::platform::heap_failure::FallbackAttempt
struct kleidos::platform::memory::InternalDeleter
Deleter for makeInternal objects — destroy, then freeInternal. More about kleidos::platform::memory::InternalDeleter
struct kleidos::platform::memory::InternalArrayDeleter
Deleter for makeInternalArray blocks. More about kleidos::platform::memory::InternalArrayDeleter
struct kleidos::platform::memory::LargeDeleter
Deleter for objects built by makeLarge — destroy, then freeLarge. More about kleidos::platform::memory::LargeDeleter
struct kleidos::platform::memory::LargeArrayDeleter
Deleter for makeLargeArray blocks (trivially destructible elements). More about kleidos::platform::memory::LargeArrayDeleter

Macros

#defineKLEIDOS_IRAM_ATTR
Place a function or datum in IRAM on target; expands to nothing on host.
#defineKLEIDOS_DRAM_ATTR
Place constant data in internal DRAM on target (default .rodata lives in flash and is read through the cache); expands to nothing on host. Pair with KLEIDOS_IRAM_ATTR for hot loops whose lookup tables must never stall on flash-cache misses.
#defineKLEIDOS_RTC_DATA_ATTR
Place data in RTC slow memory so it survives deep sleep; no-op on host.
#defineKLEIDOS_RTC_NOINIT_ATTR
Like KLEIDOS_RTC_DATA_ATTR but the value is not zeroed at boot; no-op on host.
#defineKLEIDOS_EXT_RAM_BSS_DEFINE(name, ...)
Define an external-RAM-resident global, proving at compile time that its value-initialized image is all-zero bytes.

Typedefs

usingkleidos::platform::memory::AllocObserver
Native-test hook: signature of the whole-heap allocation observer.
template<typename T>
usingkleidos::platform::memory::InternalPtr
Owning handle to a makeInternal object (internal SRAM, correctly freed).
template<typename T>
usingkleidos::platform::memory::InternalArrayPtr
Owning handle to a makeInternalArray buffer.
template<typename T>
usingkleidos::platform::memory::LargePtr
Owning handle to a makeLarge object (PSRAM-preferred, correctly freed).
template<typename T>
usingkleidos::platform::memory::LargeArrayPtr
Owning handle to a makeLargeArray buffer.

Functions

const char *kleidos::platform::error::name (int code)
Map a platform error code to a static, human-readable string.
voidkleidos::platform::heap_failure::injectFailureForTest (uint32_t requestedBytes, uint32_t caps, const char *functionName)
Native-test hook: drive the recorder exactly as the allocator hook does.
boolkleidos::platform::heap_failure::begin ()
Install the allocation-failure hook.
uint32_tkleidos::platform::heap_failure::failureCount ()
Total number of allocation failures seen since boot.
uint32_tkleidos::platform::heap_failure::recordCount ()
Number of records currently retained in the ring.
boolkleidos::platform::heap_failure::recordAt (uint32_t index, Record &out)
Read one retained record, oldest first.
voidkleidos::platform::heap_failure::clear ()
Drop every retained record and reset the failure counter.
int &kleidos::platform::memory::testLargeAllocBudget ()
Native-test hook: remaining large allocations allowed to succeed.
voidkleidos::platform::memory::setTestLargeAllocBudget (int allowed)
Native-test hook: install the large-allocation budget.
size_t &kleidos::platform::memory::testLargeAllocLimitBytes ()
Native-test hook: widest single block the host allocator will grant.
voidkleidos::platform::memory::setTestLargeAllocLimitBytes (size_t bytes)
Native-test hook: install the widest grantable block.
boolkleidos::platform::memory::testBlockWidthDenied (size_t size)
Native-test hook: is size wider than the injected block ceiling?
boolkleidos::platform::memory::testLargeAllocDenied (size_t size)
Native-test hook: charge one large allocation against the injectors.
AllocObserver &kleidos::platform::memory::testAllocObserver ()
Native-test hook: the installed allocation observer (null = off).
voidkleidos::platform::memory::setTestAllocObserver (AllocObserver observer)
Native-test hook: install (or clear with nullptr) the observer.
voidkleidos::platform::memory::notifyTestAlloc (const void *ptr, size_t size, bool acquired)
Native-test hook: report one acquire / release to the observer.
size_t &kleidos::platform::memory::testPsramCapacityBytes ()
Native-test hook: size of the emulated PSRAM pool, in bytes.
size_t &kleidos::platform::memory::testPsramLargestBlockBytes ()
Native-test hook: largest block the emulated PSRAM pool still serves.
uint32_t &kleidos::platform::memory::testPsramAttemptCount ()
Native-test hook: emulated PSRAM allocator calls issued since the last setTestPsram.
voidkleidos::platform::memory::setTestPsram (size_t capacityBytes, size_t largestBlockBytes)
Native-test hook: install the emulated PSRAM pool and zero its counter.
size_tkleidos::platform::memory::psramSizeBytes ()
Return the total PSRAM capacity in bytes.
size_tkleidos::platform::memory::psramFreeBytes ()
Return the free PSRAM in bytes.
boolkleidos::platform::memory::hasPsram ()
True when usable PSRAM is present.
void *kleidos::platform::memory::allocPsram (size_t size)
Allocate from PSRAM (SPIRAM, 8-bit).
void *kleidos::platform::memory::allocLarge (size_t size)
Allocate a large buffer, preferring PSRAM and falling back to internal heap.
void *kleidos::platform::memory::allocLargeAligned (size_t size, size_t alignment)
Allocate a large buffer with an explicit alignment, PSRAM-preferred.
voidkleidos::platform::memory::freeLarge (void *ptr)
Free a buffer returned by allocLarge() or allocPsram().
void *kleidos::platform::memory::allocInternal (size_t size)
Allocate a block that must stay in INTERNAL SRAM.
voidkleidos::platform::memory::freeInternal (void *ptr)
Free a buffer returned by allocInternal.
template<typename T, typename... Args>
InternalPtr< T >kleidos::platform::memory::makeInternal (Args &&... args)
Construct one T in INTERNAL SRAM, never throwing.
template<typename T>
InternalArrayPtr< T >kleidos::platform::memory::makeInternalArray (size_t count)
Allocate an uninitialized array of count scalar T pinned to INTERNAL SRAM.
template<typename T, typename... Args>
LargePtr< T >kleidos::platform::memory::makeLarge (Args &&... args)
Construct one T in a PSRAM-preferred block, never throwing.
template<typename T>
LargeArrayPtr< T >kleidos::platform::memory::makeLargeArray (size_t count)
Allocate an uninitialized array of count trivially-destructible T in a PSRAM-preferred block.

Variables

constexpr uint32_tkleidos::platform::heap_failure::kRecordCapacity
Number of failures retained; the oldest is overwritten first.
constexpr uint32_tkleidos::platform::memory::kCapSpiramBit
Bit position of MALLOC_CAP_SPIRAM (external RAM) in the IDF capability mask.
constexpr uint32_tkleidos::platform::memory::kCapByteAddressableBit
Bit position of MALLOC_CAP_8BIT (byte-addressable) in the IDF capability mask.
constexpr uint32_tkleidos::platform::memory::kPsramCaps
Capability mask carried by every PSRAM-preferred attempt.
constexpr uint32_tkleidos::platform::memory::kFallbackCaps
Capability mask of the fallback attempt.
constexpr size_tkleidos::platform::memory::kHeapGuaranteedAlignment
Alignment heap_caps_malloc guarantees; above it the aligned allocator is required.

Back to the top

Macro Definition Documentation

KLEIDOS_EXT_RAM_BSS_DEFINE #

#define KLEIDOS_EXT_RAM_BSS_DEFINE(name, ...)

Define an external-RAM-resident global, proving at compile time that its value-initialized image is all-zero bytes.

The ONLY supported spelling of an external-BSS definition: the raw placement attribute is private (KLEIDOS_EXT_RAM_BSS_PLACE) so a hand-written definition cannot skip the check, and the macro hardcodes the {} initializer so supplying one is a syntax error. It places into external RAM only on a build that actually has an external BSS segment, and expands to a plain definition everywhere else — the host, every board without PSRAM, and every board that has PSRAM but leaves CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY off — so a definition compiles unchanged on every board with no per-site #ifdef.

Why the check exists
.ext_ram.bss is a (NOLOAD) output section (esp_system/ld/esp32/ sections.ld.in), yet the compiler still emits the input section as PROGBITS carrying real initializer bytes. The linker silently DISCARDS them and esp_psram_bss_init() memsets the span to zero, so a global whose static image is not all-zero boots as all zeros — on the external-BSS board only, with no diagnostic from either tool.

GCC has exactly the predicate needed ("only zero initializers are allowed in section"), but it fires only for section names beginning .bss., and IDF's EXT_RAM_BSS_ATTR expands to .ext_ram.bss.<__COUNTER__> (esp_attr.h) — the counter suffix is precisely what makes the real placement silent. So the macro also emits an unreferenced twin of the same type into a .bss.-prefixed section purely to make the compiler run that check; --gc-sections then reclaims the twin, costing zero bytes.

Warning
SECURITY: external RAM leaves the die. Only list-surface plaintext may be tagged — display names, usernames, origin domains, menu row descriptors. Never a password, PIN, passphrase, vault key, derived sub-key, device secret or TOTP shared secret.
Note
Silent no-op without CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y. That option is set on the Core2 v1.3 only (the one board whose internal DRAM cannot hold the capacity-scaled view caches); the other PSRAM boards keep those statics internal on purpose — PSRAM reads are cache-mediated and far slower than DRAM for UI-hot row state, and they have tens of kilobytes of DRAM slack. A change to the option reaches a build only once its generated sdkconfig files are deleted.
.ext_ram.bss is zero-filled by esp_psram_bss_init() at boot, AFTER esp_psram_init(). Nothing defined here may be read by early-boot code or a static constructor that runs before PSRAM is up. It is ordinary RAM otherwise: it still has to be zeroized on the relock paths.
used on the twin is load-bearing: without it the unreferenced twin is discarded before the check runs and the guard disappears from -Og upward (device builds use -Os). The error is unsuppressible — it survives -w and -fpermissive — and needs no -Werror.
The twin is armed on every device build, not only the boards that place into PSRAM, so the mistake is caught on whichever variant is at hand.
Blind spot by design: a type with a non-constexpr user-provided constructor is accepted even if it sets non-zero fields. That is correct — such an object is dynamically initialized long after the PSRAM memset. A constexpr constructor yields a static image and IS checked.
GCC-specific. Re-verify with a good/bad pair after a toolchain bump.
Parameters
NameMeaning
nameIdentifier of the global being defined.
...Its type, variadic so template-ids containing commas (e.g. std::array<T, N>) need no alias.

Back to the top

Typedef Documentation

AllocObserver #

using kleidos::platform::memory::AllocObserver

Native-test hook: signature of the whole-heap allocation observer.

Parameters
NameMeaning
ptrBlock just handed out, or just about to be released.
sizeSize in bytes on an acquire; ignored on a release.
acquiredTrue when the block was acquired, false when released.

Back to the top

Function Documentation

allocInternal() #

void * kleidos::platform::memory::allocInternal(size_t size)
inline

Allocate a block that must stay in INTERNAL SRAM.

The explicit counterpart to allocLarge — use it when the block carries key material or credential plaintext, so "this never goes to PSRAM" is a greppable property of the call site rather than an unwritten assumption.

Parameters
NameMeaning
sizeNumber of bytes to allocate.
Returns
Pointer to internal memory, or nullptr on allocation failure.
See also
allocLarge

allocLarge() #

void * kleidos::platform::memory::allocLarge(size_t size)
inline

Allocate a large buffer, preferring PSRAM and falling back to internal heap.

The PSRAM attempt is marked as having a fallback, so a miss is not entered in the allocation-failure ring: the block is about to be served from the internal heap, and a record that names a byte size which was satisfied is noise in the one instrument that reports real exhaustion.

Parameters
NameMeaning
sizeNumber of bytes to allocate.
Returns
Pointer to allocated memory, or nullptr on allocation failure.

allocLargeAligned() #

void * kleidos::platform::memory::allocLargeAligned(size_t size, size_t alignment)
inline

Allocate a large buffer with an explicit alignment, PSRAM-preferred.

heap_caps_malloc only guarantees 4-byte alignment, so anything whose alignof exceeds that (a struct containing a uint64_t, for instance) needs the aligned allocator. Alignments of 4 or less take the plain allocLarge path unchanged. Blocks from either path are released with freeLarge.

The PSRAM attempt carries the same fallback marking as allocLarge.

Parameters
NameMeaning
sizeNumber of bytes to allocate.
alignmentRequired alignment in bytes (a power of two).
Returns
Pointer to allocated memory, or nullptr on allocation failure.

allocPsram() #

void * kleidos::platform::memory::allocPsram(size_t size)
inline

Allocate from PSRAM (SPIRAM, 8-bit).

Issues no allocator call at all when the board reports no PSRAM: the request could only fail, and ESP-IDF reports every failed heap_caps_malloc to the allocation-failure hook, so the probe would evict a real failure from the heap_failure ring. A failure with PSRAM present is genuine — this entry point has no fallback — and stays recorded.

Parameters
NameMeaning
sizeNumber of bytes to allocate.
Returns
Pointer to allocated PSRAM, or nullptr when PSRAM is absent or the allocation fails.

begin() #

bool kleidos::platform::heap_failure::begin()

Install the allocation-failure hook.

Idempotent; call once during startup, as early as possible so driver and radio bring-up allocations are already covered.

Return values
ValueMeaning
trueHook is installed (or was already).
falseRegistration was refused, or this is the native build.

failureCount() #

uint32_t kleidos::platform::heap_failure::failureCount()

Total number of allocation failures seen since boot.

Counts every failure, including those whose record has since been overwritten, and saturates instead of wrapping.

Returns
Failure count; 0 on the native build.

freeInternal() #

void kleidos::platform::memory::freeInternal(void * ptr)
inline

Free a buffer returned by allocInternal.

Parameters
NameMeaning
ptrPointer to free; nullptr is a no-op.

freeLarge() #

void kleidos::platform::memory::freeLarge(void * ptr)
inline

Free a buffer returned by allocLarge() or allocPsram().

Parameters
NameMeaning
ptrPointer to free; nullptr is a no-op.

hasPsram() #

bool kleidos::platform::memory::hasPsram()
inline

True when usable PSRAM is present.

Deliberately not cached: PSRAM joins the heap allocator during startup, so a value latched by an early allocation would disable external RAM for the whole session. The call walks the registered-heap list, which costs far less than the allocator attempt it replaces.

Returns
True when psramSizeBytes() > 0.

injectFailureForTest() #

void kleidos::platform::heap_failure::injectFailureForTest(uint32_t requestedBytes, uint32_t caps, const char * functionName)

Native-test hook: drive the recorder exactly as the allocator hook does.

The ESP-IDF hook cannot be reached off-target, which would leave the ring's filtering — the part that decides whether a real failure survives — untested. This feeds the same path with a synthetic failure. Compiled out on device.

Parameters
NameDirectionMeaning
requestedBytesinByte count the synthetic failure requested.
capsinRequested MALLOC_CAP_* mask.
functionNameinHeap entry point name to store in the record.

makeInternal() #

template<typename T, typename... Args>
InternalPtr< T > kleidos::platform::memory::makeInternal(Args &&... args)

Construct one T in INTERNAL SRAM, never throwing.

The secret-bearing counterpart of makeLarge, for an object too big to put on a task stack and too sensitive to put in PSRAM — a decrypted credential record is both. With no arguments the object is VALUE-initialized, so a type that relies on zeroed storage keeps that guarantee.

Template Parameters
NameMeaning
TObject type to construct.
Parameters
NameMeaning
argsConstructor arguments (none ⇒ value-initialization).
Returns
Owning handle, or nullptr when the allocation failed.

makeInternalArray() #

template<typename T>
InternalArrayPtr< T > kleidos::platform::memory::makeInternalArray(size_t count)

Allocate an uninitialized array of count scalar T pinned to INTERNAL SRAM.

The secret-bearing counterpart of makeLargeArray — use it for crypto scratch that receives decrypted record content (passwords, notes, TOTP secrets), so the "never PSRAM" property is visible at the call site and survives a future refactor.

Template Parameters
NameMeaning
TTrivially destructible element type.
Parameters
NameMeaning
countElement count.
Returns
Owning handle, or nullptr when the allocation failed.

makeLarge() #

template<typename T, typename... Args>
LargePtr< T > kleidos::platform::memory::makeLarge(Args &&... args)

Construct one T in a PSRAM-preferred block, never throwing.

Drop-in for std::unique_ptr<T>( new ( std::nothrow ) T( args... ) ): with no arguments the object is VALUE-initialized, exactly as new (std::nothrow) T() is, so containers that rely on a zero size / zeroed storage (InplaceVector, std::array<...> = {}) keep that guarantee. Returns nullptr on OOM, so every existing if ( !ptr ) { ... } guard keeps working unchanged.

Warning
SECURITY: the block may land in external RAM. Only list-surface plaintext may be routed here — never passwords, PINs, key material or TOTP secrets. Use allocInternal for those. Wiping is still the caller's job: PSRAM residency does not relax zeroization.
Template Parameters
NameMeaning
TObject type to construct.
Parameters
NameMeaning
argsConstructor arguments (none ⇒ value-initialization).
Returns
Owning handle, or nullptr when the allocation failed.

makeLargeArray() #

template<typename T>
LargeArrayPtr< T > kleidos::platform::memory::makeLargeArray(size_t count)

Allocate an uninitialized array of count trivially-destructible T in a PSRAM-preferred block.

Drop-in for std::unique_ptr<T[]>( new ( std::nothrow ) T[count] ) on scalar element types: the contents are indeterminate, matching the default-init semantics of that expression, and the elements need no destructor.

Warning
SECURITY: same allow-list as makeLarge — the buffer may live in external RAM. Wipe secret-bearing content before the handle dies.
Template Parameters
NameMeaning
TTrivially destructible element type.
Parameters
NameMeaning
countElement count.
Returns
Owning handle, or nullptr when the allocation failed.

name() #

const char * kleidos::platform::error::name(int code)

Map a platform error code to a static, human-readable string.

Parameters
NameMeaning
codeESP-IDF error code (esp_err_t or errno-style).
Returns
Pointer to a static string; returns "native" on the host build.

notifyTestAlloc() #

void kleidos::platform::memory::notifyTestAlloc(const void * ptr, size_t size, bool acquired)
inline

Native-test hook: report one acquire / release to the observer.

Parameters
NameMeaning
ptrBlock acquired or released; a null acquire is not reported.
sizeSize in bytes on an acquire.
acquiredTrue on an acquire, false on a release.

psramFreeBytes() #

size_t kleidos::platform::memory::psramFreeBytes()
inline

Return the free PSRAM in bytes.

Returns
Free PSRAM bytes; 0 when PSRAM is absent (the emulated pool's remaining run on the native build).

psramSizeBytes() #

size_t kleidos::platform::memory::psramSizeBytes()
inline

Return the total PSRAM capacity in bytes.

Returns
Total PSRAM size in bytes; 0 when PSRAM is absent (the emulated pool size on the native build).

recordAt() #

bool kleidos::platform::heap_failure::recordAt(uint32_t index, Record & out)

Read one retained record, oldest first.

Parameters
NameDirectionMeaning
indexinZero-based index into the retained records; 0 is the oldest.
outoutReceives the record on success; untouched otherwise.
Return values
ValueMeaning
trueindex was in range and out was filled.
falseindex was out of range.

recordCount() #

uint32_t kleidos::platform::heap_failure::recordCount()

Number of records currently retained in the ring.

Returns
min(failureCount(), ::kRecordCapacity).

setTestAllocObserver() #

void kleidos::platform::memory::setTestAllocObserver(AllocObserver observer)
inline

Native-test hook: install (or clear with nullptr) the observer.

Parameters
NameMeaning
observerObserver to notify on every acquire / release, or nullptr.

setTestLargeAllocBudget() #

void kleidos::platform::memory::setTestLargeAllocBudget(int allowed)
inline

Native-test hook: install the large-allocation budget.

Parameters
NameMeaning
allowedNumber of further large allocations to grant before failing them all; -1 disables injection.

setTestLargeAllocLimitBytes() #

void kleidos::platform::memory::setTestLargeAllocLimitBytes(size_t bytes)
inline

Native-test hook: install the widest grantable block.

Parameters
NameMeaning
bytesWidest block the host allocator will hand out, for internal and large allocations alike; SIZE_MAX disables injection.

setTestPsram() #

void kleidos::platform::memory::setTestPsram(size_t capacityBytes, size_t largestBlockBytes)
inline

Native-test hook: install the emulated PSRAM pool and zero its counter.

Parameters
NameMeaning
capacityBytesPool size; 0 models a board without PSRAM.
largestBlockBytesLargest block the pool can still serve.

testAllocObserver() #

AllocObserver & kleidos::platform::memory::testAllocObserver()
inline

Native-test hook: the installed allocation observer (null = off).

The block-width injector above can only police what goes through THIS facade. A suite that has to make a claim about MEMORY — "no path asks this heap for more than one flash block" — needs to see the allocations that do not: a std::vector, a std::string, a bare new. So the facade reports every block it hands out to an observer the suite installs, and the suite's own global operator new reports into the same ledger. A gate that cannot see a path is the same defect as a gate that cannot fail.

Returns
Reference to the mutable observer slot.

testBlockWidthDenied() #

bool kleidos::platform::memory::testBlockWidthDenied(size_t size)
inline

Native-test hook: is size wider than the injected block ceiling?

The width half of the injection, without the count budget: an internal allocation is charged against the fragmentation model but not against the "next N allocations fail" budget, which exists to steer specific large-allocation failure paths.

Parameters
NameMeaning
sizeRequested block size in bytes.
Return values
ValueMeaning
trueThe caller must report an allocation failure.
falseThe block fits the injected ceiling (always so while off).

testLargeAllocBudget() #

int & kleidos::platform::memory::testLargeAllocBudget()
inline

Native-test hook: remaining large allocations allowed to succeed.

The host allocator never runs out, so the out-of-memory branches that matter most on a 4 MB board — the ones that decide whether a half-finished vault mutation is reported as durable — would otherwise be unreachable from a unit test. A budget of n >= 0 lets the next n large allocations through and denies every one after that; -1 (the default) disables injection entirely, so suites that never touch it are unaffected. Compiled out on device.

Returns
Reference to the mutable budget.

testLargeAllocDenied() #

bool kleidos::platform::memory::testLargeAllocDenied(size_t size)
inline

Native-test hook: charge one large allocation against the injectors.

Parameters
NameMeaning
sizeRequested block size in bytes.
Return values
ValueMeaning
trueThe caller must report an allocation failure.
falseThe allocation proceeds (always so while injection is off).

testLargeAllocLimitBytes() #

size_t & kleidos::platform::memory::testLargeAllocLimitBytes()
inline

Native-test hook: widest single block the host allocator will grant.

The count-based budget above models an exhausted heap; this models a FRAGMENTED one, which is the state a PSRAM-less board actually reaches: the free total is comfortable, but no single run is wide enough for a capacity-sized block, so the same request fails forever while smaller ones keep succeeding. Any request above the limit is denied; the default SIZE_MAX grants every size, so suites that never touch it are unaffected. Compiled out on device.

The limit covers allocInternal as well as allocLarge, because fragmentation is a property of the DRAM heap and both come out of it on a board without PSRAM. Gating only the PSRAM-preferred path would leave the largest block on a path invisible to the suite that measures that path — which is exactly what hid the whole-vault re-encryption's internal crypto scratch, the widest request on the whole index path, from the capacity harness.

Returns
Reference to the mutable limit, in bytes.

testPsramAttemptCount() #

uint32_t & kleidos::platform::memory::testPsramAttemptCount()
inline

Native-test hook: emulated PSRAM allocator calls issued since the last setTestPsram.

Counts the calls the facade makes, which is what proves a PSRAM-less board spends nothing on an attempt that cannot succeed. Compiled out on device.

Returns
Reference to the mutable counter.

testPsramCapacityBytes() #

size_t & kleidos::platform::memory::testPsramCapacityBytes()
inline

Native-test hook: size of the emulated PSRAM pool, in bytes.

Zero — the default — models the boards built without PSRAM, where hasPsram is false and the external attempt must never be issued. Compiled out on device.

Returns
Reference to the mutable pool size.

testPsramLargestBlockBytes() #

size_t & kleidos::platform::memory::testPsramLargestBlockBytes()
inline

Native-test hook: largest block the emulated PSRAM pool still serves.

The pool is modeled as one contiguous run, so this doubles as its free size. A request above it is denied exactly as heap_caps_malloc denies one that no PSRAM run can hold — which is the state that makes a PSRAM-equipped board take the internal fallback. Compiled out on device.

Returns
Reference to the mutable limit, in bytes.

Back to the top

Variable Documentation

kFallbackCaps #

uint32_t kleidos::platform::memory::kFallbackCaps
constexpr

Capability mask of the fallback attempt.

Byte-addressable with no residency requirement, which lets the allocator use its own preference order — internal DRAM first. A failure with this mask is the real exhaustion the failure ring exists to report.

kPsramCaps #

uint32_t kleidos::platform::memory::kPsramCaps
constexpr

Capability mask carried by every PSRAM-preferred attempt.

Spelled from bit positions so the host build names the same mask the device does — a native test can assert on the exact value the debug console's allocation-failure record would print. The assert below pins it to the ESP-IDF macros.

Back to the top