LibJuno 1.0.4
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
memory_api.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
56#ifndef JUNO_MEMORY_API_H
57#define JUNO_MEMORY_API_H
58#include "juno/macros.h"
59#include "juno/status.h"
60#include "juno/module.h"
61#include <stddef.h>
62#include <stdalign.h>
64#ifdef __cplusplus
65extern "C"
66{
67#endif
68
70typedef struct JUNO_MEMORY_ALLOC_ROOT_TAG JUNO_MEMORY_ALLOC_ROOT_T;
71
72// @{"req": ["REQ-MEMORY-002"]}
73struct JUNO_MEMORY_ALLOC_ROOT_TAG JUNO_MODULE_ROOT(JUNO_MEMORY_ALLOC_API_T,
74 const JUNO_POINTER_API_T *ptPointerApi;
75);
76
80// @{"req": ["REQ-MEMORY-001"]}
82{
87 JUNO_RESULT_POINTER_T (*Get)(JUNO_MEMORY_ALLOC_ROOT_T *ptMem, size_t zSize);
88
94 JUNO_STATUS_T (*Update)(JUNO_MEMORY_ALLOC_ROOT_T *ptMem, JUNO_POINTER_T *ptMemory, size_t zNewSize);
95
101};
102
110{
112 ptAllocApi &&
113 ptAllocApi->Get &&
114 ptAllocApi->Put &&
115 ptAllocApi->Update
116 );
117 return JUNO_STATUS_SUCCESS;
118}
119
127{
129 ptAlloc &&
130 ptAlloc->ptApi &&
131 ptAlloc->ptPointerApi
132 );
133 JUNO_STATUS_T tStatus = JunoMemory_AllocApiVerify(ptAlloc->ptApi);
134 JUNO_ASSERT_SUCCESS(tStatus, return tStatus);
135 tStatus = JunoMemory_PointerApiVerify(ptAlloc->ptPointerApi);
136 JUNO_ASSERT_SUCCESS(tStatus, return tStatus);
137 return tStatus;
138}
139
140#ifdef __cplusplus
141}
142#endif
143#endif // JUNO_MEMORY_API_H
#define JUNO_ASSERT_EXISTS(ptr)
Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.
Definition macros.h:51
#define JUNO_ASSERT_SUCCESS(tStatus,...)
Execute the provided failure operation(s) if status is not success.
Definition macros.h:89
static JUNO_STATUS_T JunoMemory_AllocVerify(const JUNO_MEMORY_ALLOC_ROOT_T *ptAlloc)
Verify a memory allocator instance and its dependent pointer API.
Definition memory_api.h:126
static JUNO_STATUS_T JunoMemory_AllocApiVerify(const JUNO_MEMORY_ALLOC_API_T *ptAllocApi)
Verify that a memory allocator API provides required functions.
Definition memory_api.h:109
static JUNO_STATUS_T JunoMemory_PointerApiVerify(const JUNO_POINTER_API_T *ptPointerApi)
Verify that a pointer API provides required functions.
Definition pointer_api.h:157
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:129
#define JUNO_STATUS_SUCCESS
Operation completed successfully.
Definition status.h:59
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:51
Common assertion and helper macros for LibJuno modules.
struct JUNO_MEMORY_ALLOC_ROOT_TAG JUNO_MEMORY_ALLOC_ROOT_T
Definition memory_api.h:70
Module system and dependency injection primitives for LibJuno.
Pointer trait and helpers for memory operations.
struct JUNO_POINTER_TAG JUNO_POINTER_T
Definition pointer_api.h:49
Status codes and failure-handling helpers for LibJuno.
Vtable for memory allocation operations.
Definition memory_api.h:82
JUNO_STATUS_T(* Put)(JUNO_MEMORY_ALLOC_ROOT_T *ptMem, JUNO_POINTER_T *pvAddr)
Free a previously allocated memory region.
Definition memory_api.h:100
JUNO_STATUS_T(* Update)(JUNO_MEMORY_ALLOC_ROOT_T *ptMem, JUNO_POINTER_T *ptMemory, size_t zNewSize)
Update an existing allocation to a new size (in-place descriptor update).
Definition memory_api.h:94
JUNO_RESULT_POINTER_T(* Get)(JUNO_MEMORY_ALLOC_ROOT_T *ptMem, size_t zSize)
Allocate a memory region of at least zSize bytes.
Definition memory_api.h:87
Pointer operations API (copy/reset).
Definition pointer_api.h:75