mirror of
https://github.com/tailix/libkernaux.git
synced 2024-10-30 11:54:01 -04:00
38 lines
1.7 KiB
C
38 lines
1.7 KiB
C
#include <kernaux/memmap.h>
|
|
|
|
#include <assert.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
#define SIZE_256MiB ( 256 * 1024 * 1024)
|
|
#define SIZE_512MiB ( 512 * 1024 * 1024)
|
|
#define SIZE_1GiB (1024 * 1024 * 1024)
|
|
|
|
int main()
|
|
{
|
|
KernAux_MemMap memmap = { KernAux_MemMap_create(SIZE_1GiB) };
|
|
|
|
assert(KernAux_MemMap_add_entry(memmap, true, NULL, 0, SIZE_256MiB));
|
|
assert(KernAux_MemMap_add_entry(memmap, false, "foo", SIZE_256MiB, SIZE_256MiB));
|
|
assert(KernAux_MemMap_add_entry(memmap, true, "bar", SIZE_512MiB, SIZE_512MiB));
|
|
|
|
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;
|
|
}
|