2022-06-15 03:58:14 -04:00
|
|
|
#ifndef KERNAUX_INCLUDED_MEMMAP
|
|
|
|
#define KERNAUX_INCLUDED_MEMMAP
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-06-20 11:19:15 -04:00
|
|
|
#include <kernaux/macro.h>
|
|
|
|
|
2022-06-15 03:58:14 -04:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#define KERNAUX_MEMMAP_ENTRIES_MAX 100
|
|
|
|
|
|
|
|
#define KERNAUX_MEMMAP_ENTRY_TAG_SLEN_MAX 24
|
|
|
|
#define KERNAUX_MEMMAP_ENTRY_TAG_SIZE_MAX (KERNAUX_MEMMAP_ENTRY_TAG_SLEN_MAX + 1)
|
|
|
|
|
2022-06-15 05:53:05 -04:00
|
|
|
typedef const struct KernAux_MemMap_Entry {
|
2022-06-15 03:58:14 -04:00
|
|
|
bool is_available;
|
|
|
|
char tag[KERNAUX_MEMMAP_ENTRY_TAG_SIZE_MAX];
|
|
|
|
size_t start, size, end, limit;
|
2022-06-15 05:53:05 -04:00
|
|
|
} *KernAux_MemMap_Entry;
|
2022-06-15 03:58:14 -04:00
|
|
|
|
|
|
|
typedef struct KernAux_MemMap {
|
2022-06-20 11:19:15 -04:00
|
|
|
bool KERNAUX_PRIVATE_FIELD(is_finished);
|
|
|
|
size_t KERNAUX_PRIVATE_FIELD(memory_size);
|
|
|
|
size_t KERNAUX_PRIVATE_FIELD(entries_count);
|
|
|
|
struct KernAux_MemMap_Entry KERNAUX_PRIVATE_FIELD(entries)[KERNAUX_MEMMAP_ENTRIES_MAX];
|
2022-06-15 03:58:14 -04:00
|
|
|
} KernAux_MemMap[1];
|
|
|
|
|
2022-06-15 06:10:44 -04:00
|
|
|
struct KernAux_MemMap KernAux_MemMap_create(size_t memory_size);
|
2022-06-15 03:58:14 -04:00
|
|
|
void KernAux_MemMap_init(KernAux_MemMap memmap, size_t memory_size);
|
|
|
|
|
2022-06-16 07:15:19 -04:00
|
|
|
/// @warning Must only be called with NOT finished memmap, otherwise panics.
|
2022-06-15 04:50:16 -04:00
|
|
|
bool KernAux_MemMap_add_entry(
|
|
|
|
KernAux_MemMap memmap,
|
|
|
|
bool is_available,
|
|
|
|
const char *tag,
|
|
|
|
size_t start,
|
|
|
|
size_t size
|
|
|
|
);
|
|
|
|
|
2022-06-16 07:15:19 -04:00
|
|
|
/// @warning Must only be called with NOT finished memmap, otherwise panics.
|
2022-06-15 05:16:29 -04:00
|
|
|
bool KernAux_MemMap_finish(KernAux_MemMap memmap);
|
|
|
|
|
2022-06-15 05:49:37 -04:00
|
|
|
/// @warning Must only be called with finished memmap, otherwise panics.
|
2022-06-15 05:53:05 -04:00
|
|
|
KernAux_MemMap_Entry
|
2022-06-15 05:49:37 -04:00
|
|
|
KernAux_MemMap_entry_by_index(KernAux_MemMap memmap, size_t index);
|
|
|
|
|
|
|
|
/// @warning Must only be called with finished memmap, otherwise panics.
|
2022-06-15 05:53:05 -04:00
|
|
|
KernAux_MemMap_Entry
|
2022-06-15 05:49:37 -04:00
|
|
|
KernAux_MemMap_entry_by_start(KernAux_MemMap memmap, size_t start);
|
|
|
|
|
2022-06-15 06:41:10 -04:00
|
|
|
/// @warning Must only be called with finished memmap, otherwise panics.
|
|
|
|
KernAux_MemMap_Entry
|
|
|
|
KernAux_MemMap_entry_by_addr(KernAux_MemMap memmap, size_t addr);
|
|
|
|
|
2022-06-15 03:58:14 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|