mirror of
https://github.com/tailix/libkernaux.git
synced 2025-04-21 17:42:26 -04:00
Main: include/kernaux/memmap.h: Add functions to get entries
This commit is contained in:
parent
0495da5145
commit
71c2ea8883
3 changed files with 53 additions and 0 deletions
|
@ -20,5 +20,21 @@ int main()
|
|||
|
||||
assert(KernAux_MemMap_finish(memmap));
|
||||
|
||||
// You can get entry by it's index:
|
||||
assert( KernAux_MemMap_entry_by_index(memmap, 0)->is_available == true);
|
||||
assert(strcmp(KernAux_MemMap_entry_by_index(memmap, 0)->tag, "") == 0);
|
||||
assert( KernAux_MemMap_entry_by_index(memmap, 0)->start == 0);
|
||||
assert( KernAux_MemMap_entry_by_index(memmap, 0)->size == SIZE_256MiB);
|
||||
assert( KernAux_MemMap_entry_by_index(memmap, 0)->end == SIZE_256MiB - 1);
|
||||
assert( KernAux_MemMap_entry_by_index(memmap, 0)->limit == SIZE_256MiB);
|
||||
|
||||
// You can get entry by it's start address:
|
||||
assert( KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->is_available == false);
|
||||
assert(strcmp(KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->tag, "foo") == 0);
|
||||
assert( KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->start == SIZE_256MiB);
|
||||
assert( KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->size == SIZE_256MiB);
|
||||
assert( KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->end == SIZE_512MiB - 1);
|
||||
assert( KernAux_MemMap_entry_by_start(memmap, SIZE_256MiB)->limit == SIZE_512MiB);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,14 @@ bool KernAux_MemMap_add_entry(
|
|||
/// @warning Must only be called with unfinished memmap, otherwise panics.
|
||||
bool KernAux_MemMap_finish(KernAux_MemMap memmap);
|
||||
|
||||
/// @warning Must only be called with finished memmap, otherwise panics.
|
||||
const struct KernAux_MemMap_Entry*
|
||||
KernAux_MemMap_entry_by_index(KernAux_MemMap memmap, size_t index);
|
||||
|
||||
/// @warning Must only be called with finished memmap, otherwise panics.
|
||||
const struct KernAux_MemMap_Entry*
|
||||
KernAux_MemMap_entry_by_start(KernAux_MemMap memmap, size_t start);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
29
src/memmap.c
29
src/memmap.c
|
@ -92,3 +92,32 @@ bool KernAux_MemMap_finish(KernAux_MemMap memmap)
|
|||
|
||||
return MEMMAP.is_finished = true;
|
||||
}
|
||||
|
||||
const struct KernAux_MemMap_Entry*
|
||||
KernAux_MemMap_entry_by_index(KernAux_MemMap memmap, const size_t index)
|
||||
{
|
||||
if (!MEMMAP.is_finished) {
|
||||
KERNAUX_PANIC("memmap is not finished");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (index >= MEMMAP.entries_count) return NULL;
|
||||
return MEMMAP.entries[index];
|
||||
}
|
||||
|
||||
const struct KernAux_MemMap_Entry*
|
||||
KernAux_MemMap_entry_by_start(KernAux_MemMap memmap, const size_t start)
|
||||
{
|
||||
if (!MEMMAP.is_finished) {
|
||||
KERNAUX_PANIC("memmap is not finished");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (size_t index = 0; index < MEMMAP.entries_count; ++index) {
|
||||
if (MEMMAP.entries[index]->start == start) {
|
||||
return MEMMAP.entries[index];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue