1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00
libkernaux/include/kernaux/memmap.h

63 lines
1.8 KiB
C
Raw Normal View History

2022-06-15 03:58:14 -04:00
#ifndef KERNAUX_INCLUDED_MEMMAP
#define KERNAUX_INCLUDED_MEMMAP
#ifdef __cplusplus
extern "C" {
#endif
#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)
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;
} *KernAux_MemMap_Entry;
2022-06-15 03:58:14 -04:00
typedef struct KernAux_MemMap {
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);
/// @warning Must only be called with NOT finished memmap, otherwise panics.
bool KernAux_MemMap_add_entry(
KernAux_MemMap memmap,
bool is_available,
const char *tag,
size_t start,
size_t size
);
/// @warning Must only be called with NOT finished memmap, otherwise panics.
bool KernAux_MemMap_finish(KernAux_MemMap memmap);
/// @warning Must only be called with finished memmap, otherwise panics.
KernAux_MemMap_Entry
KernAux_MemMap_entry_by_index(KernAux_MemMap memmap, size_t index);
/// @warning Must only be called with finished memmap, otherwise panics.
KernAux_MemMap_Entry
KernAux_MemMap_entry_by_start(KernAux_MemMap memmap, size_t start);
/// @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