LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
memory_block.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) 2025 Robin A. Onsay
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files
8 (the "Software"), to deal in the Software without restriction,
9 including without limitation the rights to use, copy, modify, merge,
10 publish, distribute, sublicense, and/or sell copies of the Software,
11 and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16*/
17
63#ifndef JUNO_MEMORY_BLOCK_H
64#define JUNO_MEMORY_BLOCK_H
65#include "juno/module.h"
66#include "juno/status.h"
68#ifdef __cplusplus
69extern "C"
70{
71#endif
72
82#ifdef __cplusplus
83#define JUNO_MEMORY_BLOCK(name, type, length) static type name[length] = {}
84#else
85#define JUNO_MEMORY_BLOCK(name, type, length) static type name[length] = {0}
86#endif
87
95#ifdef __cplusplus
96#define JUNO_MEMORY_BLOCK_METADATA(name, length) static JUNO_MEMORY_BLOCK_METADATA_T name[length] = {}
97#else
98#define JUNO_MEMORY_BLOCK_METADATA(name, length) static JUNO_MEMORY_BLOCK_METADATA_T name[length] = {0}
99#endif
100
101
103typedef struct JUNO_MEMORY_ALLOC_BLOCK_TAG JUNO_MEMORY_ALLOC_BLOCK_T;
104
115
123struct JUNO_MEMORY_ALLOC_BLOCK_TAG JUNO_MODULE_DERIVE(JUNO_MEMORY_ALLOC_ROOT_T,
124 uint8_t *pvMemory;
125 JUNO_MEMORY_BLOCK_METADATA_T *ptMetadata;
126 size_t zTypeSize;
127 size_t zAlignment;
128 size_t zLength;
129 size_t zUsed;
130 size_t zFreed;
131);
132
133
134
152 JUNO_MEMORY_ALLOC_BLOCK_T *ptJunoMemory,
153 const JUNO_POINTER_API_T *ptPointerApi,
154 void *pvMemory,
156 size_t zTypeSize,
157 size_t zAlignment,
158 size_t zLength,
159 JUNO_FAILURE_HANDLER_T pfcnFailureHandler,
160 JUNO_USER_DATA_T *pvFailureUserData
161);
162
170#define JunoMemory_BlockGetT(ptBlkRoot, type) (ptBlkRoot)->tRoot.ptApi->Get(&(ptBlkRoot)->tRoot, sizeof(type))
178#define JunoMemory_BlockPutT(ptBlkRoot, pPtr) (ptBlkRoot)->tRoot.ptApi->Put(&(ptBlkRoot)->tRoot, (pPtr))
179
180#ifdef __cplusplus
181}
182#endif
183#endif // JUNO_MEMORY_BLOCK_H
184
JUNO_STATUS_T JunoMemory_BlockInit(JUNO_MEMORY_ALLOC_BLOCK_T *ptJunoMemory, const JUNO_POINTER_API_T *ptPointerApi, void *pvMemory, JUNO_MEMORY_BLOCK_METADATA_T *ptMetadata, size_t zTypeSize, size_t zAlignment, size_t zLength, JUNO_FAILURE_HANDLER_T pfcnFailureHandler, JUNO_USER_DATA_T *pvFailureUserData)
Initialize a fixed-size block allocator over a caller-supplied region.
Definition juno_memory_block.c:245
#define JUNO_MODULE_DERIVE(ROOT_T,...)
Implement a derived module embedding the root as the first member.
Definition module.h:157
void(* JUNO_FAILURE_HANDLER_T)(JUNO_STATUS_T tStatus, const char *pcCustomMessage, JUNO_USER_DATA_T *pvUserData)
Failure handler callback signature.
Definition status.h:104
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:49
void JUNO_USER_DATA_T
Opaque user data type for failure callbacks.
Definition status.h:96
Abstract memory allocation API and verification helpers.
struct JUNO_MEMORY_ALLOC_ROOT_TAG JUNO_MEMORY_ALLOC_ROOT_T
Definition memory_api.h:70
struct JUNO_MEMORY_ALLOC_BLOCK_TAG JUNO_MEMORY_ALLOC_BLOCK_T
Definition memory_block.h:103
Module system and dependency injection primitives for LibJuno.
Status codes and failure-handling helpers for LibJuno.
Metadata for a memory block entry (allocator-specific).
Definition memory_block.h:112
uint8_t * ptFreeMem
Definition memory_block.h:113
Pointer operations API (copy/reset).
Definition pointer_api.h:74