ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
unarch_xz_pool.c
Go to the documentation of this file.
1
20#include "unarch_xz_pool.h"
21
22#include "ra8_check.h"
23
34static uint8_t* s_pool_base = nullptr;
35
44static uint32_t s_pool_len = 0U;
45
55static uint32_t s_pool_off = 0U;
56
57ra8_err_t unarch_xz_pool_install(void* base, uint32_t len)
58{
59 static const char* const tag = "ra8_xz_pool";
60 RA8_CHECK_NULL_PTR(base, tag, "install: null base");
61 if (len == 0U) {
63 }
64 const uintptr_t base_address = (uintptr_t)base;
65 if ((base_address % (uintptr_t)k_unarch_xz_pool_align) != 0U) {
67 }
68 if (s_pool_base != nullptr) {
69 return k_ra8_err_busy;
70 }
71 s_pool_base = (uint8_t*)base;
72 s_pool_len = len;
73 s_pool_off = 0U;
74 return k_ra8_ok;
75}
76
78{
79 s_pool_base = nullptr;
80 s_pool_len = 0U;
81 s_pool_off = 0U;
82}
83
84void* unarch_xz_pool_alloc(uint32_t size)
85{
86 if (s_pool_base == nullptr) {
87 return nullptr;
88 }
89 if (size == 0U) {
90 return nullptr;
91 }
92 const uint32_t align = (uint32_t)k_unarch_xz_pool_align;
93 if (size > (UINT32_MAX - (align - 1U))) {
94 return nullptr; /* rounding would wrap: refuse */
95 }
96 const uint32_t need = (size + (align - 1U)) & ~(align - 1U);
97 if (need > (s_pool_len - s_pool_off)) {
98 return nullptr; /* arena exhausted: xz-embedded aborts init cleanly */
99 }
100 void* const p = &s_pool_base[s_pool_off];
101 s_pool_off += need;
102 return p;
103}
104
106{
107 if (s_pool_base == nullptr) {
108 return 0U;
109 }
110 return s_pool_off;
111}
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
@ k_ra8_err_busy
Resource busy – blocking operation cannot proceed.
Definition ra8_err.h:195
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
Definition ra8_err.h:167
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
void unarch_xz_pool_reset(void)
Release the installed arena (invalidates every pool allocation).
uint32_t unarch_xz_pool_used(void)
Bytes currently bump-allocated from the installed arena.
static uint32_t s_pool_len
Length of the installed arena in bytes (0 when uninstalled).
static uint8_t * s_pool_base
Start of the installed arena (NULL when uninstalled).
void * unarch_xz_pool_alloc(uint32_t size)
Bump-allocate size bytes from the installed arena.
static uint32_t s_pool_off
Bump cursor: bytes consumed from the installed arena.
ra8_err_t unarch_xz_pool_install(void *base, uint32_t len)
Install a caller-owned scratch buffer as the XZ allocation arena.
Caller-owned bump arena backing xz-embedded's allocator seam.
@ k_unarch_xz_pool_align
Bump-allocation alignment, bytes.