MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
config — widths, types, attributes and the call idiom

Build-time settings: widths, region sizes, feature switches and the region cut macros. More...

Macros

#define MMGR_ALIGN_BYTES
 The settings of a build that gives no command line flag.
#define MMGR_DEBUG_CHECKS
 Set to 1 to enable the library's debug-only checks.
#define MMGR_ASSERT(cond, msg)
 Runtime assertion hook: a trap under MMGR_DEBUG_CHECKS, inert otherwise.
#define MMGR_PLAINTEXT_CONFIN_SIZE
 Bytes in the largest plaintext confinium this build will declare.
#define MMGR_SECURE_CONFIN_SIZE
 Bytes in the largest secure confinium this build will declare.
#define MMGR_CARCER_MAX
 Bytes in the larger of the two confinia, the bound on the worst case a scan or a read must cover.
#define MMGR_ENABLE_CLOCK
 Set to 1 to build the memoriam_praetereo DMA path.
#define MMGR_MEMOR_IS_SIZE(x_)
 Microseconds a ring waits before its attach.
#define MMGR_MEMOR_IS_BYTE(x_)
 Fails the build unless x_ has type uint8_t.
#define MMGR_STR_MAX
 Read bound applied to the <string.h> names that take no length of their own.
#define memcpy(dest, source, bytes)
 Replaces memcpy with mmgr_shim_cpy.
#define memmove(dest, source, bytes)
 Replaces memmove with mmgr_shim_move.
#define memset(dest, value, bytes)
 Replaces memset with mmgr_shim_set.
#define memcmp(left, right, bytes)
 Replaces memcmp with mmgr_shim_cmp.
#define memchr(region, value, bytes)
 Replaces memchr with mmgr_shim_chr.
#define strlen(text)
 Replaces strlen with a scan bounded at MMGR_STR_MAX.
#define strnlen(text, limit)
 Replaces strnlen with a scan bounded at limit.
#define strstr(haystack, needle)
 Replaces strstr with a case-sensitive search bounded at MMGR_STR_MAX.
#define strcasestr(haystack, needle)
 Replaces strcasestr with a case-folded search bounded at MMGR_STR_MAX.
#define strcmp(left, right)
 Replaces strcmp with an equality test bounded at MMGR_STR_MAX.
#define strcasecmp(left, right)
 Replaces strcasecmp with a case-folded equality test bounded at MMGR_STR_MAX.
#define strncmp(left, right, limit)
 Replaces strncmp with an equality test over at max limit bytes.
#define strncasecmp(left, right, limit)
 Replaces strncasecmp with a case-folded equality test over at max limit bytes.
#define strlcpy(dest, source, limit)
 Replaces strlcpy with a bounded copy that always terminates unless limit is 0.
#define strchr(text, value)
 Replaces strchr with a search bounded at MMGR_STR_MAX.

Functions

static EMBED_HOST_DEVICE void * mmgr_shim_cpy (void *dest, const void *source, size_t bytes)
 Copies bytes from source to dest and returns dest.
static EMBED_HOST_DEVICE void * mmgr_shim_move (void *dest, const void *source, size_t bytes)
 Copies bytes from source to dest, with overlap allowed, and returns dest.
static EMBED_HOST_DEVICE void * mmgr_shim_set (void *dest, embed_iword value, size_t bytes)
 Fills bytes of dest with the low byte of value and returns dest.
static EMBED_HOST_DEVICE embed_iword mmgr_shim_cmp (const void *left, const void *right, size_t bytes)
 Compares bytes of left against right.
static EMBED_HOST_DEVICE void * mmgr_shim_chr (const void *region, embed_iword value, size_t bytes)
 Finds the first byte in region equal to the low byte of value.

Detailed Description

Build-time settings: widths, region sizes, feature switches and the region cut macros.

Redirects the <string.h> names onto MMgr's bounded implementations.

Note
Each tunable sits behind #ifndef, which lets a build set it first.
embedded_types gives every platform fact and every type: the word, the index, the widths, the byte order, the unaligned load, the attributes and the dispatch layout. This header gives none of them.
Defines the usual <string.h> include guards. A later #include <string.h> contributes nothing.
Warning
strcmp, strcasecmp, strncmp and strncasecmp report equality only and never order.
An include of this header changes what those names mean for the whole translation unit.

Macro Definition Documentation

◆ MMGR_ALIGN_BYTES

#define MMGR_ALIGN_BYTES

The settings of a build that gives no command line flag.

A build sets a tunable on its command line, or in the header mmgr_settings.h on its include path. This tree holds no such header. Where the compiler finds one, this file reads it before the first tunable.

Note
The Arduino IDE gives a library no command line flag. The header is thus the only way to set a tunable there.
The file mmgr.h reads the same header, for the module headers that reach mmgr.h before this file.

Alignment applied to every carved region, and the granularity each pool must be a multiple of.

Note
MMGR_CARCER_CHECK asserts each pool is a whole number of these and at least two of them.

Definition at line 41 of file mmgr_config.h.

◆ MMGR_DEBUG_CHECKS

#define MMGR_DEBUG_CHECKS

Set to 1 to enable the library's debug-only checks.

Note
Declared ahead of MMGR_ASSERT because it selects which of the two the assert becomes.

Definition at line 50 of file mmgr_config.h.

◆ MMGR_ASSERT

#define MMGR_ASSERT ( cond,
msg )

Runtime assertion hook: a trap under MMGR_DEBUG_CHECKS, inert otherwise.

Parameters
[in]condCondition the caller expects to hold.
[in]msgString literal that describes the expectation.
Note
An expectation the library asserts is one a correct caller cannot break, and so the plain build pays nothing for it. It expands to a sizeof, which type checks cond and never evaluates it. The checks build evaluates it instead and stops on the spot. A caller that broke one fails a test and does not carry on with the damage done.
A build may define its own before it includes this header, and neither form below then applies. A test harness wants that. The form here halts and names nothing, and a harness that reports the case defines its own with the report in it.
Warning
With MMGR_DEBUG_CHECKS at 0, a failed expectation produces no diagnostic and no trap. It is not a runtime check and cannot are as one.

Definition at line 84 of file mmgr_config.h.

◆ MMGR_PLAINTEXT_CONFIN_SIZE

#define MMGR_PLAINTEXT_CONFIN_SIZE

Bytes in the largest plaintext confinium this build will declare.

Note
Allocates nothing and sizes no pool. A pool's extent is an argument to mmgr_carcer_init, and nothing in carceribus reads this. It feeds MMGR_CARCER_MAX below, which is a bound other modules size their worst case against. So it is a statement of intent about the regions you will declare, and it must rise if you declare a bigger one.

Definition at line 97 of file mmgr_config.h.

◆ MMGR_SECURE_CONFIN_SIZE

#define MMGR_SECURE_CONFIN_SIZE

Bytes in the largest secure confinium this build will declare.

Note
The same type of number as MMGR_PLAINTEXT_CONFIN_SIZE, and it sizes no pool either.

Definition at line 106 of file mmgr_config.h.

◆ MMGR_CARCER_MAX

#define MMGR_CARCER_MAX

Bytes in the larger of the two confinia, the bound on the worst case a scan or a read must cover.

Note
verbum_scrutor.h derives MMGR_SCAN_MAX_WORDS from this, and mmgr_string_shim.h uses it as MMGR_STR_MAX.
The bound exists because these modules size a worst case at compile time and test no length at run time. A string cannot be longer than the confinium that holds it, and the confinium is the cap. So the scanner can know how many words that is before it ever runs.
Warning
Declare a region larger than both knobs and this bound falls short. The static asserts in verbum_scrutor.h check that the word count covers this value, not that this value covers your regions, which nothing here can see.

Definition at line 123 of file mmgr_config.h.

◆ MMGR_ENABLE_CLOCK

#define MMGR_ENABLE_CLOCK

Set to 1 to build the memoriam_praetereo DMA path.

Note
mmgr.h includes memoriam_praetereo.h only when this holds. The schedule's knobs have their reads in memoriam_praetereo/praet_praefinitum.h and embed_clock.h.

Set to 1 to build the memoria_externa external memory path.

Note
mmgr.h includes memoria_externa.h only when this holds.

Set to 1 to build the time-based ring behavior.

Note
MMGR_RING_ATTACH_US exists only when this holds.

Definition at line 154 of file mmgr_config.h.

◆ MMGR_MEMOR_IS_SIZE

#define MMGR_MEMOR_IS_SIZE ( x_)

Microseconds a ring waits before its attach.

Warning
Defined only when MMGR_ENABLE_CLOCK holds.

Fails the build unless x_ has type size_t.

Parameters
[in]x_Expression under a type check.
Note
Evaluates to void; the _Generic association list admits size_t only.

Definition at line 174 of file mmgr_config.h.

◆ MMGR_MEMOR_IS_BYTE

#define MMGR_MEMOR_IS_BYTE ( x_)

Fails the build unless x_ has type uint8_t.

Parameters
[in]x_Expression under a type check.
Note
Evaluates to void; the _Generic association list admits uint8_t only.

Definition at line 182 of file mmgr_config.h.

◆ MMGR_STR_MAX

#define MMGR_STR_MAX

Read bound applied to the <string.h> names that take no length of their own.

Note
Defaults to MMGR_CARCER_MAX, the largest confinium a string can occupy.
Warning
strlen, strstr, strcmp and strchr stop at this many bytes even without a terminator.

Definition at line 26 of file mmgr_string_shim.h.

◆ memcpy

#define memcpy ( dest,
source,
bytes )

Replaces memcpy with mmgr_shim_cpy.

Note
Every argument sits in parentheses. Any expression may go in.

Definition at line 139 of file mmgr_string_shim.h.

◆ memmove

#define memmove ( dest,
source,
bytes )

Replaces memmove with mmgr_shim_move.

Definition at line 144 of file mmgr_string_shim.h.

◆ memset

#define memset ( dest,
value,
bytes )

Replaces memset with mmgr_shim_set.

Definition at line 149 of file mmgr_string_shim.h.

◆ memcmp

#define memcmp ( left,
right,
bytes )

Replaces memcmp with mmgr_shim_cmp.

Note
Retains the ordering the standard requires; the sign follows the first byte pair that differs.

Definition at line 156 of file mmgr_string_shim.h.

◆ memchr

#define memchr ( region,
value,
bytes )

Replaces memchr with mmgr_shim_chr.

Definition at line 161 of file mmgr_string_shim.h.

◆ strlen

#define strlen ( text)

Replaces strlen with a scan bounded at MMGR_STR_MAX.

Warning
Returns MMGR_STR_MAX when no terminator appears within it, and scans no further.

Definition at line 168 of file mmgr_string_shim.h.

◆ strnlen

#define strnlen ( text,
limit )

Replaces strnlen with a scan bounded at limit.

Note
Returns limit when no terminator appears within it, as strnlen does.

Definition at line 175 of file mmgr_string_shim.h.

◆ strstr

#define strstr ( haystack,
needle )

Replaces strstr with a case-sensitive search bounded at MMGR_STR_MAX.

Note
The cast through size_t drops the const the backend returns, as the strstr signature requires.
Warning
The read of both operands reaches MMGR_STR_MAX, and both must have a terminator within it.

Definition at line 183 of file mmgr_string_shim.h.

◆ strcasestr

#define strcasestr ( haystack,
needle )

Replaces strcasestr with a case-folded search bounded at MMGR_STR_MAX.

Note
Differs from the strstr shim only in that it passes ci as EMBED_TRUE.
Warning
The read of both operands reaches MMGR_STR_MAX, and both must have a terminator within it.

Definition at line 193 of file mmgr_string_shim.h.

◆ strcmp

#define strcmp ( left,
right )

Replaces strcmp with an equality test bounded at MMGR_STR_MAX.

Note
Gives 0 when the two agree and 1 when they do not, and so == 0 and ! both test equality.
Warning
Never negative and never above 1: it cannot order strings.

Definition at line 203 of file mmgr_string_shim.h.

◆ strcasecmp

#define strcasecmp ( left,
right )

Replaces strcasecmp with a case-folded equality test bounded at MMGR_STR_MAX.

Note
Gives 0 when the two agree and 1 when they do not.
Warning
Never negative and never above 1: it cannot order strings.

Definition at line 212 of file mmgr_string_shim.h.

◆ strncmp

#define strncmp ( left,
right,
limit )

Replaces strncmp with an equality test over at max limit bytes.

Note
Gives 0 when the two agree through limit and 1 when they differ before it.
Warning
Never negative and never above 1: it cannot order strings.
A terminator does not end the comparison; all limit bytes must be readable in both operands.

Definition at line 222 of file mmgr_string_shim.h.

◆ strncasecmp

#define strncasecmp ( left,
right,
limit )

Replaces strncasecmp with a case-folded equality test over at max limit bytes.

Note
Gives 0 when the two agree through limit and 1 when they differ before it.
Warning
Never negative and never above 1: it cannot order strings.
A terminator does not end the comparison; all limit bytes must be readable in both operands.

Definition at line 233 of file mmgr_string_shim.h.

◆ strlcpy

#define strlcpy ( dest,
source,
limit )

Replaces strlcpy with a bounded copy that always terminates unless limit is 0.

Note
Returns the bytes copied, the truncated length and not the source length.

Definition at line 242 of file mmgr_string_shim.h.

◆ strchr

#define strchr ( text,
value )

Replaces strchr with a search bounded at MMGR_STR_MAX.

Note
A value of 0 returns the address of the terminator, as strchr does.
The cast through size_t drops the const the backend returns, as the strchr signature requires.
Warning
The read of text reaches MMGR_STR_MAX, and so it must have a terminator within it.

Definition at line 252 of file mmgr_string_shim.h.

Function Documentation

◆ mmgr_shim_cpy()

EMBED_HOST_DEVICE void * mmgr_shim_cpy ( void * dest,
const void * source,
size_t bytes )
inlinestatic

Copies bytes from source to dest and returns dest.

Parameters
[out]destDestination to write [BORROWS].
[in]sourceBytes to read [BORROWS].
[in]bytesNumber of bytes to copy.
Returns
dest [BORROWS].
Warning
The two regions must not overlap; use mmgr_shim_move when they might.

Definition at line 62 of file mmgr_string_shim.h.

References MemoriaCfg::dst, and mmgr_shim_cpy().

Referenced by mmgr_shim_cpy().

◆ mmgr_shim_move()

EMBED_HOST_DEVICE void * mmgr_shim_move ( void * dest,
const void * source,
size_t bytes )
inlinestatic

Copies bytes from source to dest, with overlap allowed, and returns dest.

Parameters
[out]destDestination to write [BORROWS].
[in]sourceBytes to read [BORROWS].
[in]bytesNumber of bytes to copy.
Returns
dest [BORROWS].
Note
Compares the two addresses and walks upwards or downwards so a read of each shared byte comes before the write to it.

Definition at line 78 of file mmgr_string_shim.h.

References MemoriaCfg::dst, and mmgr_shim_move().

Referenced by mmgr_shim_move().

◆ mmgr_shim_set()

EMBED_HOST_DEVICE void * mmgr_shim_set ( void * dest,
embed_iword value,
size_t bytes )
inlinestatic

Fills bytes of dest with the low byte of value and returns dest.

Parameters
[out]destDestination to write [BORROWS].
[in]valueFill value; only its low eight bits count.
[in]bytesNumber of bytes to write.
Returns
dest [BORROWS].
Note
Explicit cast narrows value to uint8_t, the byte the fill writes.

Definition at line 100 of file mmgr_string_shim.h.

References MemoriaCfg::dst, and mmgr_shim_set().

Referenced by mmgr_shim_set().

◆ mmgr_shim_cmp()

EMBED_HOST_DEVICE embed_iword mmgr_shim_cmp ( const void * left,
const void * right,
size_t bytes )
inlinestatic

Compares bytes of left against right.

Parameters
[in]leftFirst region [BORROWS].
[in]rightSecond region [BORROWS].
[in]bytesNumber of bytes to compare.
Returns
Difference of the first unequal byte pair, or 0 when all bytes match.
Note
Unlike the strcmp shims, this one does order: the sign follows the bytes that differ.

Definition at line 115 of file mmgr_string_shim.h.

References mmgr_shim_cmp(), and MemoriaCfg::src.

Referenced by mmgr_shim_cmp().

◆ mmgr_shim_chr()

EMBED_HOST_DEVICE void * mmgr_shim_chr ( const void * region,
embed_iword value,
size_t bytes )
inlinestatic

Finds the first byte in region equal to the low byte of value.

Parameters
[in]regionBytes to search [BORROWS].
[in]valueByte sought; only its low eight bits count.
[in]bytesNumber of bytes to search.
Returns
Address of the match, or NULL when the byte does not occur [BORROWS].
Note
The cast through size_t drops the const the backend returns, as the memchr signature requires.

Definition at line 129 of file mmgr_string_shim.h.

References mmgr_shim_chr(), and MemoriaCfg::src.

Referenced by mmgr_shim_chr().