27SecurePoolCtx s_secure;
33struct SecurePoolStorageCtx
37SecurePoolStorageCtx s_secure_storage;
46inline uintptr_t secure_offset(
const void *p)
48 return (uintptr_t)p - (uintptr_t)s_secure_storage.mem;
51inline int cur_worker()
58inline void assert_single_owner(
int w)
72 assert(s_owner[w] == cur &&
"secure pool borrowed from a foreign task");
83 if (a->
base ==
nullptr)
95 return (a->
base !=
nullptr) ? a :
nullptr;
106inline void wipe_down_to(
pc_arena *a,
size_t mark)
109 if (mark > top && mark <= a->size)
111 pc_secure_wipe(a->
base + top, mark - top);
120 int w = cur_worker();
121 assert_single_owner(w);
129 int w = cur_worker();
130 assert_single_owner(w);
131 wipe_down_to(bind(w), m_mark);
136 int w = cur_worker();
137 assert_single_owner(w);
138 assert((align & (align - 1)) == 0 &&
"secure alignment must be a power of two");
149 int w = cur_worker();
150 assert_single_owner(w);
156 int w = cur_worker();
157 assert_single_owner(w);
158 wipe_down_to(bind(w), mark);
163 int w = cur_worker();
164 assert_single_owner(w);
168 wipe_down_to(a, a->
size);
174 const pc_arena *a = peek(cur_worker());
199 return secure_offset(p) < (uintptr_t)
sizeof(s_secure_storage.mem);
204 const uintptr_t off = secure_offset(p);
205 if (off >= (uintptr_t)
sizeof(s_secure_storage.mem))
void pc_arena_init(pc_arena *a, void *base, size_t size)
Initialize a over the region [base, base+size).
Unified double-ended server arena (Phase 1: core allocator, one region).
size_t pc_arena_scratch_mark(const pc_arena *a)
Capture the current scratch position (a savepoint for pc_arena_scratch_release()).
void pc_arena_scratch_release(pc_arena *a, size_t mark)
Free every scratch allocation made since mark (a value from pc_arena_scratch_mark()).
void * pc_arena_scratch_alloc_aligned(pc_arena *a, size_t n, size_t align)
Bump-allocate n bytes of transient storage, aligned to align.
size_t pc_arena_scratch_used(const pc_arena *a)
Scratch bytes currently allocated.
SecureBorrow(size_t n, size_t align)
#define PC_SECURE_ARENA_SIZE
size_t pc_secure_used(void)
Bytes currently handed out.
int pc_secure_slot_of(const void *p)
Which secure slot owns p, or -1 if p is not in the secure pool.
void pc_secure_reset(void)
Wipe and reclaim the whole slot.
size_t pc_secure_mark(void)
Capture the current position, to be handed to pc_secure_release().
bool pc_secure_owns(const void *p)
True if p points inside the secure pool.
pc_span pc_secure_span(size_t n, size_t align)
Borrow n secure bytes as a span whose capacity is bound to the allocation.
void pc_secure_release(size_t mark)
Wipe and reclaim everything borrowed since mark.
void * pc_secure_alloc(size_t n, size_t align)
Borrow n bytes of secure storage, aligned to align.
size_t pc_secure_high_water(void)
Peak bytes ever handed out, for sizing PC_SECURE_ARENA_SIZE.
size_t pc_secure_capacity(void)
Total per-slot capacity in bytes (PC_SECURE_ARENA_SIZE).
Secure pool accessor - borrows that hold key material.
pc_span pc_span_from(uint8_t *p, size_t cap)
Bind a span to memory whose extent is only known at run time.
Double-ended arena over one region [base, base+size).
uint8_t * base
Region start.
size_t scratch_hw
High-water of scratch use (size - min scratch_top).
size_t size
Region length in bytes.
A writable byte region: the storage, the capacity that belongs to it, and what has been produced into...
int pc_worker_self(void)
Worker id [0, count) of the calling task; 0 by default / single-worker.
Layer 5 (Session) - server worker identity.