diff --git a/include/kernaux/pfa.h b/include/kernaux/pfa.h index 2a63f6d..d91863f 100644 --- a/include/kernaux/pfa.h +++ b/include/kernaux/pfa.h @@ -24,6 +24,13 @@ void KernAux_PFA_mark_available( ) __attribute__((nonnull)); +void KernAux_PFA_mark_unavailable( + struct KernAux_PFA *pfa, + unsigned int start, + unsigned int end +) +__attribute__((nonnull)); + unsigned int KernAux_PFA_alloc_page(struct KernAux_PFA *pfa) __attribute__((nonnull)); diff --git a/src/pfa.c b/src/pfa.c index 360a1da..78aade2 100644 --- a/src/pfa.c +++ b/src/pfa.c @@ -3,6 +3,14 @@ #include #include +static void KernAux_PFA_mark( + struct KernAux_PFA *pfa, + kernaux_bool status, + unsigned int start, + unsigned int end +) +__attribute__((nonnull)); + void KernAux_PFA_initialize(struct KernAux_PFA *const pfa) { kernaux_memset(pfa->pages, KERNAUX_FALSE, sizeof(pfa->pages)); @@ -12,6 +20,23 @@ void KernAux_PFA_mark_available( struct KernAux_PFA *const pfa, unsigned int start, unsigned int end +) { + KernAux_PFA_mark(pfa, KERNAUX_TRUE, start, end); +} + +void KernAux_PFA_mark_unavailable( + struct KernAux_PFA *const pfa, + unsigned int start, + unsigned int end +) { + KernAux_PFA_mark(pfa, KERNAUX_FALSE, start, end); +} + +void KernAux_PFA_mark( + struct KernAux_PFA *const pfa, + const kernaux_bool status, + unsigned int start, + unsigned int end ) { if (start >= end) { return; @@ -32,7 +57,7 @@ void KernAux_PFA_mark_available( const unsigned int end_index = end / KERNAUX_PFA_PAGE_SIZE; for (unsigned int index = start_index; index <= end_index; ++index) { - pfa->pages[index] = KERNAUX_TRUE; + pfa->pages[index] = status; } } diff --git a/tests/test_pfa.c b/tests/test_pfa.c index 04ad6dd..da23316 100644 --- a/tests/test_pfa.c +++ b/tests/test_pfa.c @@ -14,6 +14,7 @@ int main() KernAux_PFA_mark_available(&pfa, 0, 654335); KernAux_PFA_mark_available(&pfa, 1048576, 134086655); + KernAux_PFA_mark_unavailable(&pfa, 4194304, 6291455); // [4 MB, 6 MB) for (unsigned int index = 0; index < 159; ++index) { assert(pfa.pages[index] == KERNAUX_TRUE); @@ -23,7 +24,15 @@ int main() assert(pfa.pages[index] == KERNAUX_FALSE); } - for (unsigned int index = 256; index < 32736; ++index) { + for (unsigned int index = 256; index < 1024; ++index) { // [1 MB, 4 MB) + assert(pfa.pages[index] == KERNAUX_TRUE); + } + + for (unsigned int index = 1024; index < 1536; ++index) { // [4 MB, 6 MB) + assert(pfa.pages[index] == KERNAUX_FALSE); + } + + for (unsigned int index = 1536; index < 32736; ++index) { // [6 MB, ~127 MB) assert(pfa.pages[index] == KERNAUX_TRUE); }