29#ifndef MMGR_LOCUS_CARCERUM_H
30#define MMGR_LOCUS_CARCERUM_H
52#ifndef MMGR_ENABLE_HW_MEM_CAPACITY_CB
53#define MMGR_ENABLE_HW_MEM_CAPACITY_CB 0
55#if (MMGR_ENABLE_HW_MEM_CAPACITY_CB != 0) && (MMGR_ENABLE_HW_MEM_CAPACITY_CB != 1)
56#error "MMGR_ENABLE_HW_MEM_CAPACITY_CB must be 0 or 1"
65#ifndef MMGR_CARCER_OWNERS
66#define MMGR_CARCER_OWNERS 128u
75#ifndef MMGR_MOVABLE_SETTLE_PERCENT
76#define MMGR_MOVABLE_SETTLE_PERCENT 25u
78#if (MMGR_MOVABLE_SETTLE_PERCENT < 1u) || (MMGR_MOVABLE_SETTLE_PERCENT > 100u)
79#error "MMGR_MOVABLE_SETTLE_PERCENT must be from 1 to 100"
83#ifndef MMGR_MOVABLE_READ_MS
84#define MMGR_MOVABLE_READ_MS 100u
88#ifndef MMGR_MOVABLE_QUIET_READINGS
89#define MMGR_MOVABLE_QUIET_READINGS 3u
93#ifndef MMGR_MOVABLE_BACKOFF_MAX_MS
94#define MMGR_MOVABLE_BACKOFF_MAX_MS 25600u
100#ifndef MMGR_MOVABLE_IDLE_MAX_MS
101#define MMGR_MOVABLE_IDLE_MAX_MS 1000u
118#ifndef MMGR_CARCER_REGIONS
119#define MMGR_CARCER_REGIONS 0u
127#ifndef MMGR_CARCER_REGION_BYTES
128#define MMGR_CARCER_REGION_BYTES 0u
139#ifndef MMGR_CARCER_LARGE_REGION_BYTES
140#define MMGR_CARCER_LARGE_REGION_BYTES 0u
144#define MMGR_CARCER_LARGE_REGIONS ((size_t)(MMGR_CARCER_LARGE_REGION_BYTES > 0u))
147#define MMGR_CARCER_REGION_COUNT ((size_t)MMGR_CARCER_REGIONS + MMGR_CARCER_LARGE_REGIONS)
150#define MMGR_CARCER_REGION_AREA \
151 (((size_t)MMGR_CARCER_REGIONS * (size_t)MMGR_CARCER_REGION_BYTES) + (size_t)MMGR_CARCER_LARGE_REGION_BYTES)
153#include "embed_atomic.h"
154#include "embed_lane.h"
155#include "embed_turnstile.h"
168#define MMGR_CARCER_ALIGN \
169 ((sizeof(embed_word) > EMBED_ALIGNOF(embed_atomic_usize)) ? (size_t)sizeof(embed_word) \
170 : (size_t)EMBED_ALIGNOF(embed_atomic_usize))
179 "the cellblock rounds offsets by masking, which needs a power of two alignment");
188 "MMGR_ALIGN_BYTES must be a multiple of MMGR_CARCER_ALIGN, the grain a cell's words are on");
190#if MMGR_CARCER_REGIONS > 0u
195 "MMGR_CARCER_REGION_BYTES must be a multiple of MMGR_CARCER_ALIGN");
197 "MMGR_CARCER_REGION_BYTES is too small for one cell");
199 "MMGR_CARCER_LARGE_REGION_BYTES must be a multiple of MMGR_CARCER_ALIGN");
202 "MMGR_CARCER_LARGE_REGION_BYTES must be above MMGR_CARCER_REGION_BYTES, or 0");
205 "MMGR_CARCER_LARGE_REGION_BYTES needs MMGR_CARCER_REGIONS above 0");
234 embed_atomic_usize
hw;
254#if MMGR_CARCER_OWNERS < 0x10u
255#define MMGR_OWNER_PLACE_BITS 4u
256#elif MMGR_CARCER_OWNERS < 0x20u
257#define MMGR_OWNER_PLACE_BITS 5u
258#elif MMGR_CARCER_OWNERS < 0x40u
259#define MMGR_OWNER_PLACE_BITS 6u
260#elif MMGR_CARCER_OWNERS < 0x80u
261#define MMGR_OWNER_PLACE_BITS 7u
262#elif MMGR_CARCER_OWNERS < 0x100u
263#define MMGR_OWNER_PLACE_BITS 8u
264#elif MMGR_CARCER_OWNERS < 0x200u
265#define MMGR_OWNER_PLACE_BITS 9u
266#elif MMGR_CARCER_OWNERS < 0x400u
267#define MMGR_OWNER_PLACE_BITS 10u
268#elif MMGR_CARCER_OWNERS < 0x800u
269#define MMGR_OWNER_PLACE_BITS 11u
270#elif MMGR_CARCER_OWNERS < 0x1000u
271#define MMGR_OWNER_PLACE_BITS 12u
272#elif MMGR_CARCER_OWNERS < 0x2000u
273#define MMGR_OWNER_PLACE_BITS 13u
274#elif MMGR_CARCER_OWNERS < 0x4000u
275#define MMGR_OWNER_PLACE_BITS 14u
276#elif MMGR_CARCER_OWNERS < 0x8000u
277#define MMGR_OWNER_PLACE_BITS 15u
278#elif MMGR_CARCER_OWNERS < 0x10000u
279#define MMGR_OWNER_PLACE_BITS 16u
281#error "MMGR_CARCER_OWNERS must be below 65536: the owner word's place field is 16 bits at max"
283#define MMGR_OWNER_SIGNAL_BITS 3u
285 "the owner word must have a timestamp bit left after its place, completion and signaling bits");
286#define MMGR_OWNER_TIME_BITS (EMBED_WORD_BITS - MMGR_OWNER_PLACE_BITS - 1u - MMGR_OWNER_SIGNAL_BITS)
287#define MMGR_OWNER_TIME_MASK (((embed_atomic_usize_value)1u << MMGR_OWNER_TIME_BITS) - 1u)
288#define MMGR_OWNER_SIGNAL_SHIFT MMGR_OWNER_TIME_BITS
289#define MMGR_OWNER_COMPLETE ((embed_atomic_usize_value)1u << (MMGR_OWNER_TIME_BITS + MMGR_OWNER_SIGNAL_BITS))
290#define MMGR_OWNER_PLACE_SHIFT (MMGR_OWNER_TIME_BITS + MMGR_OWNER_SIGNAL_BITS + 1u)
291#define MMGR_OWNER_PLACE_MASK ((((embed_atomic_usize_value)1u << MMGR_OWNER_PLACE_BITS) - 1u) << MMGR_OWNER_PLACE_SHIFT)
293 "MMGR_CARCER_OWNERS must fit the owner word's place field");
321#define MMGR_OWNER_PLACE(name_, text_) mmgr_owner_place_##name_,
329#define MMGR_OWNER_RECORD(name_, text_) \
330 {(text_), (size_t)mmgr_owner_place_##name_ + 1u, EMBED_ATOMIC_INIT(0u), EMBED_ATOMIC_INIT(0u)},
340#define MMGR_OWNER_POINTER(name_, text_) \
341 EMBED_PASS_LOCAL(const CellOwner *const, name_, &EMBED_PASS_NAME(mmgr_owner_table)[mmgr_owner_place_##name_]);
349#define MMGR_OWNER_EXTERN(name_, text_) extern const CellOwner *const name_;
367#define MMGR_OWNERS(list_) \
370 list_(MMGR_OWNER_PLACE) mmgr_owner_table_positioned \
372 EMBED_STATIC_ASSERT((size_t)mmgr_owner_table_positioned <= (size_t)MMGR_CARCER_OWNERS, \
373 "more owners are declared than MMGR_CARCER_OWNERS allows"); \
374 EMBED_PASS_OBJECT(CellOwner, mmgr_owner_table, [], {list_(MMGR_OWNER_RECORD)}); \
375 EMBED_PASS_OBJECT(const size_t, mmgr_owner_table_count, , (size_t)mmgr_owner_table_positioned); \
376 list_(MMGR_OWNER_POINTER)
395 return (
size_t)EMBED_CALL(embed_atomic_usize_table.load, EmbedAtomicUsizeLoadCfg, .word = &owner->
in_use);
407 return (
size_t)EMBED_CALL(embed_atomic_usize_table.load, EmbedAtomicUsizeLoadCfg, .word = &owner->
hw);
427#define MMGR_CARCER_HALF_BITS ((unsigned int)((sizeof(embed_atomic_usize_value) * 8u) / 2u))
428#define MMGR_CARCER_HALF_MASK ((embed_atomic_usize_value)(((embed_atomic_usize_value)1u << MMGR_CARCER_HALF_BITS) - 1u))
437#define MMGR_CARCER_BYTES_MAX ((size_t)1u << (MMGR_CARCER_HALF_BITS - 1u))
444#define MMGR_CARCER_WANT_MAX ((size_t)1u << (MMGR_CARCER_HALF_BITS - 8u))
457#ifndef MMGR_CARCER_BANK_SHIFT
458#define MMGR_CARCER_BANK_SHIFT (MMGR_CARCER_HALF_BITS - 2u)
462#define MMGR_CARCER_BANK_BYTES ((size_t)1u << MMGR_CARCER_BANK_SHIFT)
468#define MMGR_CARCER_BANK_FIELD_BITS ((unsigned int)(((sizeof(embed_atomic_word_value) * 8u) - 4u) / 3u))
471#define MMGR_CARCER_BANK_FIELD_MASK \
472 ((embed_atomic_word_value)(((embed_atomic_word_value)1u << MMGR_CARCER_BANK_FIELD_BITS) - 1u))
475#define MMGR_CARCER_BANK_COUNT_AT 4u
476#define MMGR_CARCER_BANK_END_AT (4u + MMGR_CARCER_BANK_FIELD_BITS)
477#define MMGR_CARCER_BANK_TOP_AT (4u + (2u * MMGR_CARCER_BANK_FIELD_BITS))
485#define MMGR_CARCER_POOL_BYTES_MAX \
486 ((size_t)((((size_t)1u << MMGR_CARCER_BANK_FIELD_BITS) - 1u) << MMGR_CARCER_BANK_SHIFT))
489#define MMGR_CARCER_BANK_OF(off_) (((size_t)(off_)) >> MMGR_CARCER_BANK_SHIFT)
492#define MMGR_CARCER_BANK_COUNT(bytes_) MMGR_CARCER_BANK_OF((size_t)(bytes_) + (MMGR_CARCER_BANK_BYTES - 1u))
500#define MMGR_CARCER_FRAME_CAP(bytes_) \
501 ((MMGR_CARCER_BANK_COUNT(bytes_) > 2u) ? (MMGR_CARCER_BANK_COUNT(bytes_) - 2u) : (size_t)0u)
504#define MMGR_CARCER_END_FRAME(end_, bytes_) \
505 ((MMGR_CARCER_BANK_OF(end_) < MMGR_CARCER_FRAME_CAP(bytes_)) ? MMGR_CARCER_BANK_OF(end_) \
506 : MMGR_CARCER_FRAME_CAP(bytes_))
509#define MMGR_CARCER_BANK_BELOW(top_) (MMGR_CARCER_BANK_OF(top_) - (size_t)(MMGR_CARCER_BANK_OF(top_) != 0u))
515#define MMGR_CARCER_TOP_FRAME(top_, bytes_) \
516 ((MMGR_CARCER_BANK_BELOW(top_) < MMGR_CARCER_FRAME_CAP(bytes_)) ? MMGR_CARCER_BANK_BELOW(top_) \
517 : MMGR_CARCER_FRAME_CAP(bytes_))
523#define MMGR_CARCER_CLOSED_AT_REST(bytes_) \
524 ((embed_atomic_word_value)((((embed_atomic_word_value)MMGR_CARCER_BANK_COUNT(bytes_)) << MMGR_CARCER_BANK_COUNT_AT) | \
525 ((embed_atomic_word_value)MMGR_CARCER_TOP_FRAME( \
526 (size_t)(bytes_) - MMGR_CARCER_REGION_AREA, bytes_) \
527 << MMGR_CARCER_BANK_TOP_AT)))
530#define MMGR_CARCER_BOUNDS_AT_REST(bytes_) \
531 ((embed_atomic_usize_value)(((size_t)(bytes_) - MMGR_CARCER_REGION_AREA) - \
532 (MMGR_CARCER_TOP_FRAME((size_t)(bytes_) - MMGR_CARCER_REGION_AREA, bytes_) \
533 << MMGR_CARCER_BANK_SHIFT)) \
534 << MMGR_CARCER_HALF_BITS)
571#if MMGR_CARCER_REGIONS > 0u
575 EMBED_ALIGN(EMBED_LANE_BYTES) embed_atomic_usize depth;
593#if MMGR_ENABLE_HW_MEM_CAPACITY_CB
594 embed_atomic_usize persistent_hw;
595 embed_atomic_usize temporary_hw;
598#if MMGR_CARCER_REGIONS > 0u
604#if MMGR_ENABLE_HW_MEM_CAPACITY_CB
605#define MMGR_CARCER_STATE_HW , EMBED_ATOMIC_INIT(0u), EMBED_ATOMIC_INIT(0u)
607#define MMGR_CARCER_STATE_HW
611#if MMGR_CARCER_REGIONS > 0u
612#define MMGR_CARCER_STATE_REGIONS \
616 EMBED_ATOMIC_INIT(0u) \
620#define MMGR_CARCER_STATE_REGIONS
629#define MMGR_CARCER_STATE_TURNSTILES {{{EMBED_ATOMIC_INIT(0u)}}, EMBED_ATOMIC_INIT(0u), EMBED_ATOMIC_INIT(0u)}
640#define MMGR_CARCER_STATE(base_, bytes_) \
643 EMBED_ATOMIC_INIT(MMGR_CARCER_BOUNDS_AT_REST(bytes_)), \
644 EMBED_ATOMIC_INIT(0u), \
645 EMBED_ATOMIC_INIT(0u), \
646 EMBED_ATOMIC_INIT(0u), \
647 EMBED_ATOMIC_INIT(0u), \
648 EMBED_ATOMIC_INIT(0u), \
649 EMBED_ATOMIC_INIT(MMGR_CARCER_CLOSED_AT_REST(bytes_)), \
650 EMBED_ATOMIC_INIT(0u), \
651 EMBED_ATOMIC_INIT(0u) MMGR_CARCER_STATE_HW, \
652 MMGR_CARCER_STATE_TURNSTILES MMGR_CARCER_STATE_REGIONS}
658#define MMGR_CARCER_STATE_HOSPES \
661 EMBED_ATOMIC_INIT(0u), \
662 EMBED_ATOMIC_INIT(0u), \
663 EMBED_ATOMIC_INIT(0u), \
664 EMBED_ATOMIC_INIT(0u), \
665 EMBED_ATOMIC_INIT(0u), \
666 EMBED_ATOMIC_INIT(0u), \
667 EMBED_ATOMIC_INIT(0u), \
668 EMBED_ATOMIC_INIT(0u), \
669 EMBED_ATOMIC_INIT(0u) MMGR_CARCER_STATE_HW, \
670 MMGR_CARCER_STATE_TURNSTILES MMGR_CARCER_STATE_REGIONS}
732#define MMGR_MOVABLE_HEAD_BYTES 192u
735#define MMGR_MOVABLE_CLAIM_BITS ((size_t)(8u * sizeof(embed_atomic_usize)))
746#define MMGR_MOVABLE_STORAGE_BYTES(cells_, width_, rows_) \
747 (MMGR_MOVABLE_HEAD_BYTES + \
748 (((cells_) + (((cells_) + MMGR_MOVABLE_CLAIM_BITS - 1u) / MMGR_MOVABLE_CLAIM_BITS) + (2u * (rows_))) * \
749 sizeof(embed_atomic_usize)))
780 return (
size_t)((EMBED_CALL(embed_atomic_word_table.load, EmbedAtomicWordLoadCfg, .word = &series->
closed) >>
794#if MMGR_CARCER_REGIONS > 0u
796 return (
size_t)EMBED_CALL(embed_atomic_usize_table.load, EmbedAtomicUsizeLoadCfg,
797 .word = &series->regions[region].depth);
813#if MMGR_CARCER_REGIONS > 0u
822 return (embed_bool)(held == 0u);
840 return (embed_bool)((series->
size == 0u) ||
854#if MMGR_ENABLE_HW_MEM_CAPACITY_CB
856 return (
size_t)EMBED_CALL(embed_atomic_usize_table.load, EmbedAtomicUsizeLoadCfg, .word = &series->persistent_hw);
871#if MMGR_ENABLE_HW_MEM_CAPACITY_CB
873 return (
size_t)EMBED_CALL(embed_atomic_usize_table.load, EmbedAtomicUsizeLoadCfg, .word = &series->temporary_hw);
886#define MMGR_GUARD_MOVABLE_TAKE_MEMBERS \
887 embed_bool (*movable_init)(const CarcerMovableInitCfg *args); \
888 const CarcerMovableEntry *(*movable_buf_alloc)(size_t size, const CellOwner *owner);
896#define MMGR_GUARD_MOVABLE_SPAN_MEMBERS \
897 embed_bool (*movable_buf_read)(const CarcerMovableCfg *args); \
898 embed_bool (*movable_buf_write)(const CarcerMovableCfg *args); \
899 embed_iword (*movable_buf_compare)(const CarcerMovableCfg *args); \
900 size_t (*movable_buf_measure)(const CarcerMovableCfg *args);
905#define MMGR_GUARD_MEMBER_NAMES \
906 persistent_buf_alloc, persistent_buf_release, temporary_buf_alloc, who_owns_buf, buf_available, buf_grow, \
907 movable_init, movable_buf_alloc, movable_buf_release, movable_buf_read, movable_buf_write, \
908 movable_buf_compare, movable_buf_measure
924 void *(*persistent_buf_alloc)(
930 void *(*temporary_buf_alloc)(
936 void *prisoner,
size_t size,
955 void *(*persistent_buf_alloc)(
960 void *(*temporary_buf_alloc)(
964 void *(*buf_grow)(
void *prisoner,
size_t size,
982#define MMGR_CARCER_MOVABLE_ENTRIES(prisonsite_, name_, wipe_to_zero_on_release_, series_cellularum_) \
983 EMBED_HOST_DEVICE static embed_bool prisonsite_##_##name_##_movable_init(const CarcerMovableInitCfg *args) \
985 return mmgr_movable_init((series_cellularum_), args, (wipe_to_zero_on_release_)); \
987 EMBED_HOST_DEVICE static const CarcerMovableEntry *prisonsite_##_##name_##_movable_buf_alloc( \
988 size_t size, const CellOwner *owner) \
990 return mmgr_movable_buf_alloc((series_cellularum_), size, owner); \
992 EMBED_HOST_DEVICE static embed_bool prisonsite_##_##name_##_movable_buf_release(const CarcerMovableEntry *cell, \
993 const CellOwner *owner) \
995 return mmgr_movable_buf_release((series_cellularum_), cell, owner); \
997 EMBED_HOST_DEVICE static embed_bool prisonsite_##_##name_##_movable_buf_read(const CarcerMovableCfg *args) \
999 return mmgr_movable_buf_read((series_cellularum_), args); \
1001 EMBED_HOST_DEVICE static embed_bool prisonsite_##_##name_##_movable_buf_write(const CarcerMovableCfg *args) \
1003 return mmgr_movable_buf_write((series_cellularum_), args); \
1005 EMBED_HOST_DEVICE static embed_iword prisonsite_##_##name_##_movable_buf_compare(const CarcerMovableCfg *args) \
1007 return mmgr_movable_buf_compare((series_cellularum_), args); \
1009 EMBED_HOST_DEVICE static size_t prisonsite_##_##name_##_movable_buf_measure(const CarcerMovableCfg *args) \
1011 return mmgr_movable_buf_measure((series_cellularum_), args); \
1039#define MMGR_CARCER_BODY(prisonsite_, type_, name_, wipe_to_zero_on_release_, hospes_) \
1040 MMGR_PARS_CLAIMED_ONCE(name_); \
1041 EMBED_CAT(MMGR_CARCER_STORAGE_, hospes_)(prisonsite_, name_) MMGR_ALLOC_SIZE(1) EMBED_HOST_DEVICE static void * \
1042 prisonsite_##_##name_##_persistent_buf_alloc(size_t size, const CellOwner *owner) \
1044 if (wipe_to_zero_on_release_) \
1046 return mmgr_persistent_max_security_buf_alloc(&prisonsite_##_##name_##_ctx, size, owner); \
1048 return mmgr_persistent_buf_alloc(&prisonsite_##_##name_##_ctx, size, owner); \
1050 EMBED_HOST_DEVICE static void prisonsite_##_##name_##_persistent_buf_release(void *prisoner, \
1051 const CellOwner *owner) \
1053 if (wipe_to_zero_on_release_) \
1055 mmgr_persistent_max_security_buf_release(&prisonsite_##_##name_##_ctx, prisoner, owner); \
1059 mmgr_persistent_buf_release(&prisonsite_##_##name_##_ctx, prisoner, owner); \
1062 MMGR_ALLOC_SIZE(1) \
1063 EMBED_HOST_DEVICE static void *prisonsite_##_##name_##_temporary_buf_alloc(size_t size, const CellOwner *owner) \
1065 if (wipe_to_zero_on_release_) \
1067 return mmgr_temporary_max_security_buf_alloc(&prisonsite_##_##name_##_ctx, size, owner); \
1069 return mmgr_temporary_buf_alloc(&prisonsite_##_##name_##_ctx, size, owner); \
1071 EMBED_HOST_DEVICE static embed_bool prisonsite_##_##name_##_who_owns_buf(const void *at) \
1073 return mmgr_who_owns_buf(&prisonsite_##_##name_##_ctx, at); \
1075 EMBED_HOST_DEVICE static size_t prisonsite_##_##name_##_buf_available(void) \
1077 const size_t available = mmgr_buf_available(&prisonsite_##_##name_##_ctx); \
1080 MMGR_ALLOC_SIZE(2) \
1081 EMBED_HOST_DEVICE static void *prisonsite_##_##name_##_buf_grow(void *prisoner, size_t size, \
1082 const CellOwner *owner) \
1084 if (wipe_to_zero_on_release_) \
1086 return mmgr_max_security_buf_grow(&prisonsite_##_##name_##_ctx, prisoner, size, owner); \
1088 return mmgr_buf_grow(&prisonsite_##_##name_##_ctx, prisoner, size, owner); \
1090 MMGR_CARCER_MOVABLE_ENTRIES(prisonsite_, name_, wipe_to_zero_on_release_, &prisonsite_##_##name_##_ctx)
1099#define MMGR_CARCER_STORAGE_0(prisonsite_, name_) \
1100 EMBED_STATIC_ASSERT(sizeof(mmgr_pars_storage_##name_) >= (MMGR_CARCER_REGION_AREA + (2u * MMGR_CARCER_ALIGN)), \
1101 #prisonsite_ "." #name_ " is too small for its regions and one cell"); \
1102 EMBED_STATIC_ASSERT(sizeof(mmgr_pars_storage_##name_) <= MMGR_CARCER_POOL_BYTES_MAX, \
1103 #prisonsite_ "." #name_ " is larger than the closed word's banks can name"); \
1104 static EMBED_PASS_MEMORY SeriesCellularum prisonsite_##_##name_##_ctx = \
1105 MMGR_CARCER_STATE(mmgr_pars_storage_##name_, name_##_bytes);
1113#define MMGR_CARCER_STORAGE_1(prisonsite_, name_) \
1114 static EMBED_PASS_MEMORY SeriesCellularum prisonsite_##_##name_##_ctx = MMGR_CARCER_STATE_HOSPES;
1127#define MMGR_CARCER_MEM(prisonsite_, type_, name_, wipe_to_zero_on_release_, hospes_) type_ name_;
1140#define MMGR_CARCER_SEAT(prisonsite_, type_, name_, wipe_to_zero_on_release_, hospes_) \
1141 {prisonsite_##_##name_##_persistent_buf_alloc, prisonsite_##_##name_##_persistent_buf_release, \
1142 prisonsite_##_##name_##_temporary_buf_alloc, prisonsite_##_##name_##_who_owns_buf, \
1143 prisonsite_##_##name_##_buf_available, prisonsite_##_##name_##_buf_grow, \
1144 prisonsite_##_##name_##_movable_init, prisonsite_##_##name_##_movable_buf_alloc, \
1145 prisonsite_##_##name_##_movable_buf_release, prisonsite_##_##name_##_movable_buf_read, \
1146 prisonsite_##_##name_##_movable_buf_write, prisonsite_##_##name_##_movable_buf_compare, \
1147 prisonsite_##_##name_##_movable_buf_measure},
1163#define MMGR_MINIMUM_SECURITY(name_) (MinimumSecurityGuard, name_, 0, 0)
1175#define MMGR_MAXIMUM_SECURITY(name_) (MaxSecurityGuard, name_, 1, 0)
1186#define MMGR_MINIMUM_SECURITY_HOSPES(name_) (MinimumSecurityGuard, name_, 0, 1)
1194#define MMGR_MAXIMUM_SECURITY_HOSPES(name_) (MaxSecurityGuard, name_, 1, 1)
1203#define MMGR_UNTUPLE(...) __VA_ARGS__
1215#define MMGR_CARCER_APPLY(what_, prisonsite_, tuple_) MMGR_CARCER_APPLY_(what_, prisonsite_, MMGR_UNTUPLE tuple_)
1228#define MMGR_CARCER_APPLY_(what_, prisonsite_, ...) what_(prisonsite_, __VA_ARGS__)
1238#define MMGR_CARCER_W1(what_, prisonsite_, SeriesCellularum1_) MMGR_CARCER_APPLY(what_, prisonsite_, SeriesCellularum1_)
1251#define MMGR_CARCER_W2(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_) \
1252 MMGR_CARCER_W1(what_, prisonsite_, SeriesCellularum1_) \
1253 MMGR_CARCER_APPLY(what_, prisonsite_, SeriesCellularum2_)
1265#define MMGR_CARCER_W3(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_) \
1266 MMGR_CARCER_W2(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_) \
1267 MMGR_CARCER_APPLY(what_, prisonsite_, SeriesCellularum3_)
1280#define MMGR_CARCER_W4(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, \
1281 SeriesCellularum4_) \
1282 MMGR_CARCER_W3(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_) \
1283 MMGR_CARCER_APPLY(what_, prisonsite_, SeriesCellularum4_)
1297#define MMGR_CARCER_W5(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, \
1298 SeriesCellularum4_, SeriesCellularum5_) \
1299 MMGR_CARCER_W4(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, SeriesCellularum4_) \
1300 MMGR_CARCER_APPLY(what_, prisonsite_, SeriesCellularum5_)
1315#define MMGR_CARCER_W6(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, \
1316 SeriesCellularum4_, SeriesCellularum5_, SeriesCellularum6_) \
1317 MMGR_CARCER_W5(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, SeriesCellularum4_, \
1318 SeriesCellularum5_) \
1319 MMGR_CARCER_APPLY(what_, prisonsite_, SeriesCellularum6_)
1335#define MMGR_CARCER_W7(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, \
1336 SeriesCellularum4_, SeriesCellularum5_, SeriesCellularum6_, SeriesCellularum7_) \
1337 MMGR_CARCER_W6(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, SeriesCellularum4_, \
1338 SeriesCellularum5_, SeriesCellularum6_) \
1339 MMGR_CARCER_APPLY(what_, prisonsite_, SeriesCellularum7_)
1359#define MMGR_CARCER_W8(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, \
1360 SeriesCellularum4_, SeriesCellularum5_, SeriesCellularum6_, SeriesCellularum7_, \
1361 SeriesCellularum8_) \
1362 MMGR_CARCER_W7(what_, prisonsite_, SeriesCellularum1_, SeriesCellularum2_, SeriesCellularum3_, SeriesCellularum4_, \
1363 SeriesCellularum5_, SeriesCellularum6_, SeriesCellularum7_) \
1364 MMGR_CARCER_APPLY(what_, prisonsite_, SeriesCellularum8_)
1376#define MMGR_CARCER_WALK(what_, prisonsite_, ...) \
1377 EMBED_CAT(MMGR_CARCER_W, EMBED_NARG(__VA_ARGS__))(what_, prisonsite_, __VA_ARGS__)
1396#define LocusCarcerum(prisonsite_, ...) \
1397 MMGR_CARCER_WALK(MMGR_CARCER_BODY, prisonsite_, __VA_ARGS__) \
1398 EMBED_TABLE_STORAGE struct \
1400 MMGR_CARCER_WALK(MMGR_CARCER_MEM, prisonsite_, __VA_ARGS__) \
1401 } prisonsite_ EMBED_UNUSED = {MMGR_CARCER_WALK(MMGR_CARCER_SEAT, prisonsite_, __VA_ARGS__)}
EMBED_PASS_DECLARE(const uint8_t, mmgr_ancorae_impensa_table, [256])
Cost of each byte value under the profile this build links, indexed by the byte itself.
static EMBED_HOST_DEVICE size_t mmgr_series_cellularum_temporary_hw(const SeriesCellularum *series)
The max bytes a cellblock's temporary tier took from the top at one time.
EMBED_HOST_DEVICE embed_bool mmgr_movable_buf_read(const SeriesCellularum *series, const CarcerMovableCfg *args)
Copies args->bytes from args->offset of a movable cell to args->dst.
EMBED_HOST_DEVICE void mmgr_movable_run(SeriesCellularum *series)
The mover: what the thread the program gave runs, until its thread_wait answers EMBED_FALSE.
#define MMGR_GUARD_MOVABLE_TAKE_MEMBERS
The two movable members both guards hold ahead of their movable release.
EMBED_HOST_DEVICE embed_bool mmgr_movable_buf_write(SeriesCellularum *series, const CarcerMovableCfg *args)
Copies args->bytes from args->src to args->offset of a movable cell.
EMBED_HOST_DEVICE embed_bool mmgr_movable_touches(const SeriesCellularum *series, size_t at, size_t *id, size_t *touches)
One row of touches a lane, counted as passes go through it.
EMBED_HOST_DEVICE void mmgr_series_cellularum_emptied(SeriesCellularum *series)
Puts a cellblock back to the state of its declaration. Both tiers are empty, the closed word and the ...
EMBED_HOST_DEVICE void * mmgr_temporary_max_security_buf_alloc(SeriesCellularum *series, size_t size, const CellOwner *owner)
Takes size bytes from a max security cellblock's temporary tier.
EMBED_HOST_DEVICE void mmgr_zero_buf(void *prisoner, size_t size)
Zeroes size bytes at prisoner and releases nothing.
void(*) CarcerIdleEach(void *context, void *at, size_t bytes)
A span of a cellblock's storage no cell holds, passed to the program: where it starts and its bytes.
EMBED_HOST_DEVICE void mmgr_persistent_max_security_buf_release(SeriesCellularum *series, void *prisoner, const CellOwner *owner)
Zeroes a cell, then releases the prisoner.
EMBED_HOST_DEVICE void * mmgr_temporary_buf_alloc(SeriesCellularum *series, size_t size, const CellOwner *owner)
Takes size bytes from a cellblock's temporary tier.
static EMBED_HOST_DEVICE size_t mmgr_owner_hw(const CellOwner *owner)
The max payload bytes an owner has had at once.
EMBED_HOST_DEVICE void mmgr_owner_bytes_given(const CellOwner *owner, size_t bytes)
Takes bytes mmgr_owner_bytes_taken counted off their owner.
EMBED_HOST_DEVICE void mmgr_owner_bytes_taken(const CellOwner *owner, size_t bytes)
Counts bytes that lie in no cellblock to an owner, as a ring's or a page's are.
EMBED_HOST_DEVICE uint64_t mmgr_carcer_hw_clock_ns(void)
The library's clock in nanoseconds, which a cell's owner word carries the take on.
EMBED_HOST_DEVICE const CarcerMovableEntry * mmgr_movable_buf_alloc(SeriesCellularum *series, size_t size, const CellOwner *owner)
Takes a persistent cell a move may move, and names it in the table.
static EMBED_HOST_DEVICE size_t mmgr_series_cellularum_banks(const SeriesCellularum *series)
The banks a cellblock's bytes take, as its closed word holds the count.
EMBED_HOST_DEVICE embed_bool mmgr_series_cellularum_placed(SeriesCellularum *series, uint8_t *storage, size_t bytes)
Places a cellblock declared over a hospes pool on the storage the program gives: its base and its siz...
#define MMGR_CARCER_REGION_BYTES
Bytes of each region: its cells with their headers and owner words. A multiple of MMGR_CARCER_ALIGN.
EMBED_HOST_DEVICE embed_iword mmgr_movable_buf_compare(const SeriesCellularum *series, const CarcerMovableCfg *args)
Orders args->bytes of a movable cell against args->src, or against another cell where args->other_cel...
EMBED_HOST_DEVICE embed_bool mmgr_owner_listed(const CellOwner *owner)
Whether an owner is one of the table's.
static EMBED_HOST_DEVICE size_t mmgr_series_cellularum_region_depth(const SeriesCellularum *series, size_t region)
The bytes one region's stack holds from its end down.
#define MMGR_OWNER_PLACE_BITS
The owner word a cell carries behind its payload, one machine word positioned as fields,...
EMBED_HOST_DEVICE size_t mmgr_buf_available(SeriesCellularum *series)
The bytes between the two tiers.
EMBED_HOST_DEVICE embed_bool mmgr_who_owns_buf(const SeriesCellularum *series, const void *at)
Whether at lies inside the cellblock's bytes.
EMBED_HOST_DEVICE const CellOwner * mmgr_owner_of_buf(const SeriesCellularum *series, const void *prisoner)
The owner a cell counts to, read off the word behind its payload.
#define MMGR_GUARD_MEMBER_NAMES
The thirteen member names of both guards, in their order, for EMBED_TABLE_LAYOUT.
EMBED_HOST_DEVICE embed_bool mmgr_movable_buf_release(SeriesCellularum *series, const CarcerMovableEntry *cell, const CellOwner *owner)
Gives a movable cell back and frees its entry.
EMBED_HOST_DEVICE void mmgr_carcer_hw_misnamed(const CellOwner *named, const CellOwner *cell_owner, size_t bytes)
Told of each give or growth that names an owner other than the one the cell counts to.
#define MMGR_CARCER_LARGE_REGION_BYTES
Bytes of the one large region, at the top of the cellblock, that every temporary take over a region's...
EMBED_HOST_DEVICE void * mmgr_persistent_max_security_buf_alloc(SeriesCellularum *series, size_t size, const CellOwner *owner)
Takes size bytes from a max security cellblock's persistent tier.
#define MMGR_CARCER_ALIGN
Alignment of every prisoner on the way out: one machine word, or the atomic size word's alignment whe...
EMBED_HOST_DEVICE embed_bool mmgr_movable_init(SeriesCellularum *series, const CarcerMovableInitCfg *args, embed_bool wipes)
Assigns a cellblock's movable option: the translation table, its claim bits, the rows of touches and ...
static EMBED_HOST_DEVICE size_t mmgr_series_cellularum_persistent_hw(const SeriesCellularum *series)
The furthest point of a cellblock's persistent tier so far.
EMBED_HOST_DEVICE size_t mmgr_movable_buf_measure(const SeriesCellularum *series, const CarcerMovableCfg *args)
The bytes from args->offset of a movable cell to the next zero byte.
EMBED_HOST_DEVICE size_t mmgr_align_up_buf(size_t size)
Rounds size up to a whole machine word.
#define MMGR_CARCER_REGION_COUNT
The regions in all: one for each place, and the large one where the build declares it.
EMBED_HOST_DEVICE size_t mmgr_movable_queue_depth(const SeriesCellularum *series)
The contexts queued at the cellblock's turnstiles now: those that found every open lane busy and wait...
struct CarcerMovableEntry CarcerMovableEntry
The identity a movable cell's taker holds: a const pointer to the cell's entry in the cellblock's tra...
EMBED_HOST_DEVICE void mmgr_persistent_buf_release(SeriesCellularum *series, void *prisoner, const CellOwner *owner)
Releases a prisoner and leaves the cell's bytes as they are.
#define MMGR_GUARD_MOVABLE_SPAN_MEMBERS
The four movable members both guards hold after their movable release.
EMBED_HOST_DEVICE void * mmgr_buf_grow(SeriesCellularum *series, void *prisoner, size_t size, const CellOwner *owner)
Grows a cell to size payload bytes in place, where it is the newest cell of its tier.
EMBED_HOST_DEVICE embed_bool mmgr_movable_buf_move(SeriesCellularum *series)
Moves one movable cell into the first free cell below it, highest cell first.
#define MMGR_CARCER_BANK_FIELD_MASK
The mask of one field, at bit 0.
EMBED_HOST_DEVICE size_t mmgr_series_cellularum_fragmentation(const SeriesCellularum *series)
A cellblock's fragmentation: the bytes its persistent tier occupies and no cell's payload holds,...
EMBED_HOST_DEVICE size_t mmgr_series_cellularum_temporary_top(const SeriesCellularum *series)
Offset of the lowest temporary cell.
static EMBED_HOST_DEVICE embed_bool mmgr_series_cellularum_idle(const SeriesCellularum *series)
Whether a cellblock has no cell out.
EMBED_HOST_DEVICE void * mmgr_max_security_buf_grow(SeriesCellularum *series, void *prisoner, size_t size, const CellOwner *owner)
Grows a cell in place as mmgr_buf_grow does, and zeroes the bytes the growth adds.
static EMBED_HOST_DEVICE embed_bool mmgr_series_cellularum_regions_idle(const SeriesCellularum *series)
Whether every region is empty.
#define MMGR_CARCER_REGION_AREA
Bytes the regions take off the top of every cellblock, 0 where the temporary tier is one stack.
EMBED_HOST_DEVICE void * mmgr_persistent_buf_alloc(SeriesCellularum *series, size_t size, const CellOwner *owner)
Takes size bytes from a cellblock's persistent tier.
EMBED_HOST_DEVICE size_t mmgr_series_cellularum_persistent_end(const SeriesCellularum *series)
Offset just past the last persistent cell.
EMBED_HOST_DEVICE void mmgr_series_cellularum_idle_each(SeriesCellularum *series, CarcerIdleEach each, void *context)
Passes each span of the cellblock's storage that no cell holds to each, with the cellblock closed: th...
#define MMGR_CARCER_OWNERS
The max owners a program's owner table holds.
static EMBED_HOST_DEVICE size_t mmgr_owner_in_use(const CellOwner *owner)
The payload bytes of the cells an owner has now.
#define MMGR_CARCER_BANK_COUNT_AT
The bit of the closed word that each field starts at.
The embedded_types headers every module builds on.
#define MMGR_ALIGN_BYTES
The settings of a build that gives no command line flag. This is the hook of config/mmgr_config....
#define MMGR_ALLOC_SIZE(arg_)
States which argument of an allocation entry gives the extent of what it returns.
Arguments for the calls that reach a movable cell's bytes, each of which reads the members it names.
const CarcerMovableEntry *const cell
const CarcerMovableEntry *const other_cell
const size_t other_offset
What a program gives a cellblock for the movable option, once, through its guard's movable_init.
void(*const) thread_yield(void)
embed_bool(*const) thread_wait(uint32_t milliseconds)
void(*const) thread_moving(embed_bool moving)
embed_bool(*const) thread_started(void(*run)(void *context), void *context)
size_t(*const) thread_id(void)
const size_t storage_bytes
Asserts MMGR_CARCER_ALIGN is a power of two.
embed_atomic_usize in_use
The max security guard over one cellblock: every release zeroes the cell first.
size_t(*) buf_available(void)
void(*) persistent_buf_release(void *prisoner, const CellOwner *owner)
embed_bool(*) who_owns_buf(const void *at)
embed_bool(*) movable_buf_release(const CarcerMovableEntry *cell, const CellOwner *owner)
The minimum security guard over one cellblock: a released cell retains whatever is in it.
void(*) persistent_buf_release(void *prisoner, const CellOwner *owner)
embed_bool(*) movable_buf_release(const CarcerMovableEntry *cell, const CellOwner *owner)
size_t(*) buf_available(void)
embed_bool(*) who_owns_buf(const void *at)
One cellblock's state: its bytes, the two boundaries that grow toward each other, and the closed word...
embed_atomic_uptr movable
embed_atomic_usize in_use
EmbedTurnstiles turnstiles
embed_atomic_usize persistent_overrun
embed_atomic_usize persistent_in_use
embed_atomic_usize bounds
embed_atomic_usize temporary_overrun