Add function "KernAux_PFA_mark_unavailable"

This commit is contained in:
Alex Kotov 2020-12-04 08:04:42 +05:00
parent 76bcd5a732
commit d6202e2ce5
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
3 changed files with 43 additions and 2 deletions

View File

@ -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));

View File

@ -3,6 +3,14 @@
#include <kernaux/pfa.h>
#include <kernaux/stdlib.h>
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;
}
}

View File

@ -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);
}