diff --git a/Makefile.am b/Makefile.am index 294d763..ef28d17 100644 --- a/Makefile.am +++ b/Makefile.am @@ -68,11 +68,3 @@ if ASM_X86_64 libkernaux_la_SOURCES += src/asm/x86_64.S endif endif - -#################### -# Default packages # -#################### - -if WITH_PFA -libkernaux_la_SOURCES += src/pfa.c -endif diff --git a/README.md b/README.md index ea7a437..9958a35 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,6 @@ zero). Work-in-progress APIs can change at any time. * [Runtime environment](/include/kernaux/runtime.h) (*non-breaking since* **0.7.0**) * [Macros](/include/kernaux/macro.h) (*non-breaking since* **0.6.0**) * Stack trace *(planned)* -* Algorithms - * [Page Frame Allocator](/include/kernaux/pfa.h) (*work in progress*) * libc replacement (*work in progress*) * [ctype.h](/libc/include/ctype.h) * [errno.h](/libc/include/errno.h) diff --git a/configure.ac b/configure.ac index ab98184..fdb4b28 100644 --- a/configure.ac +++ b/configure.ac @@ -66,7 +66,6 @@ AC_ARG_WITH( [arch-i386], AS_HELP_STRING([--without-arch-i386], [wit AC_ARG_WITH( [arch-riscv64], AS_HELP_STRING([--without-arch-riscv64], [without architecture riscv64])) AC_ARG_WITH( [arch-x86-64], AS_HELP_STRING([--without-arch-x86-64], [without architecture x86-64])) AC_ARG_WITH( [asm], AS_HELP_STRING([--without-asm], [without kernel assembler helpers])) -AC_ARG_WITH( [pfa], AS_HELP_STRING([--without-pfa], [without Page Frame Allocator])) dnl Packages (disabled by default) AC_ARG_WITH( [libc], AS_HELP_STRING([--with-libc], [with libc replacement])) @@ -98,7 +97,6 @@ if test -z "$with_arch_i386"; then with_arch_i386=no; fi if test -z "$with_arch_riscv64"; then with_arch_riscv64=no; fi if test -z "$with_arch_x86_64"; then with_arch_x86_64=no; fi if test -z "$with_asm"; then with_asm=no; fi -if test -z "$with_pfa"; then with_pfa=no; fi ]) AS_IF([test "$with_all" = no], do_without_all) @@ -131,7 +129,6 @@ AS_IF([test "$with_arch_i386" = no ], [with_arch_i386=no], [wit AS_IF([test "$with_arch_riscv64" = no ], [with_arch_riscv64=no], [with_arch_riscv64=yes]) AS_IF([test "$with_arch_x86_64" = no ], [with_arch_x86_64=no], [with_arch_x86_64=yes]) AS_IF([test "$with_asm" = no ], [with_asm=no], [with_asm=yes]) -AS_IF([test "$with_pfa" = no ], [with_pfa=no], [with_pfa=yes]) dnl Packages (disabled by default) AS_IF([test "$with_libc" = yes], [with_libc=yes], [with_libc=no]) @@ -178,7 +175,6 @@ AM_CONDITIONAL([WITH_ARCH_I386], [test "$with_arch_i386" = yes]) AM_CONDITIONAL([WITH_ARCH_RISCV64], [test "$with_arch_riscv64" = yes]) AM_CONDITIONAL([WITH_ARCH_X86_64], [test "$with_arch_x86_64" = yes]) AM_CONDITIONAL([WITH_ASM], [test "$with_asm" = yes]) -AM_CONDITIONAL([WITH_PFA], [test "$with_pfa" = yes]) dnl Packages (disabled by default) AM_CONDITIONAL([WITH_LIBC], [test "$with_libc" = yes]) @@ -217,7 +213,6 @@ AS_IF([test "$with_arch_i386" = yes], [AC_DEFINE([WITH_ARCH_I386], AS_IF([test "$with_arch_riscv64" = yes], [AC_DEFINE([WITH_ARCH_RISCV64], [1], [with architecture riscv64])]) AS_IF([test "$with_arch_x86_64" = yes], [AC_DEFINE([WITH_ARCH_X86_64], [1], [with architecture x86_64])]) AS_IF([test "$with_asm" = yes], [AC_DEFINE([WITH_ASM], [1], [with kernel assembler helpers])]) -AS_IF([test "$with_pfa" = yes], [AC_DEFINE([WITH_PFA], [1], [with Page Frame Allocator])]) dnl Packages (disabled by default) AS_IF([test "$with_libc" = yes], [AC_DEFINE([WITH_LIBC], [1], [with libc replacement])]) @@ -239,7 +234,6 @@ dnl Packages (enabled by default) AS_IF([test "$with_arch_i386" = no], [AC_SUBST([comment_line_arch_i386], [//])]) AS_IF([test "$with_arch_riscv64" = no], [AC_SUBST([comment_line_arch_riscv64], [//])]) AS_IF([test "$with_arch_x86_64" = no], [AC_SUBST([comment_line_arch_x86_64], [//])]) -AS_IF([test "$with_pfa" = no], [AC_SUBST([comment_line_pfa], [//])]) diff --git a/include/Makefile.am b/include/Makefile.am index 4fc7da9..f081bd7 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -12,6 +12,5 @@ nobase_include_HEADERS = \ kernaux/macro.h \ kernaux/macro/packing_end.run \ kernaux/macro/packing_start.run \ - kernaux/pfa.h \ kernaux/runtime.h \ kernaux/version.h diff --git a/include/kernaux.h b/include/kernaux.h index cbdc8d4..5c9da6e 100644 --- a/include/kernaux.h +++ b/include/kernaux.h @@ -7,6 +7,5 @@ #include #include #include -#include #include #include diff --git a/include/kernaux/pfa.h b/include/kernaux/pfa.h deleted file mode 100644 index c6904bb..0000000 --- a/include/kernaux/pfa.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef KERNAUX_INCLUDED_PFA -#define KERNAUX_INCLUDED_PFA - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -#define KERNAUX_PFA_PAGE_SIZE (4 * 1024) -#define KERNAUX_PFA_PAGES_COUNT_MAX (1024 * 1024) -#define KERNAUX_PFA_FLAGS_SIZE (KERNAUX_PFA_PAGES_COUNT_MAX / 8) - -typedef struct KernAux_PFA *KernAux_PFA; - -struct KernAux_PFA { - uint8_t flags[KERNAUX_PFA_FLAGS_SIZE]; -}; - -void KernAux_PFA_initialize(KernAux_PFA pfa); - -bool KernAux_PFA_is_available(KernAux_PFA pfa, size_t page_addr); - -void KernAux_PFA_mark_available(KernAux_PFA pfa, size_t start, size_t end); -void KernAux_PFA_mark_unavailable(KernAux_PFA pfa, size_t start, size_t end); - -size_t KernAux_PFA_alloc_pages(KernAux_PFA pfa, size_t mem_size); -void KernAux_PFA_free_pages(KernAux_PFA pfa, size_t page_addr, size_t mem_size); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/kernaux/version.h.in b/include/kernaux/version.h.in index 592f362..bc2da7c 100644 --- a/include/kernaux/version.h.in +++ b/include/kernaux/version.h.in @@ -1,6 +1,4 @@ #ifndef KERNAUX_INCLUDED_VERSION #define KERNAUX_INCLUDED_VERSION -@comment_line_pfa@#define KERNAUX_VERSION_WITH_PFA - #endif diff --git a/pkgs/freebsd/devel/libkernaux/pkg-plist b/pkgs/freebsd/devel/libkernaux/pkg-plist index c59d863..08f227e 100644 --- a/pkgs/freebsd/devel/libkernaux/pkg-plist +++ b/pkgs/freebsd/devel/libkernaux/pkg-plist @@ -11,7 +11,6 @@ include/kernaux/asm/x86_64.h include/kernaux/macro.h include/kernaux/macro/packing_end.run include/kernaux/macro/packing_start.run -include/kernaux/pfa.h include/kernaux/runtime.h include/kernaux/version.h lib/libkernaux.a diff --git a/src/pfa.c b/src/pfa.c deleted file mode 100644 index f4535a6..0000000 --- a/src/pfa.c +++ /dev/null @@ -1,163 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "assert.h" - -#include -#include - -#include - -#define PAGE_INDEX(page_addr) ((page_addr) / KERNAUX_PFA_PAGE_SIZE) - -#define FLAG_INDEX_FROM_INDEX(page_index) ((page_index) / 8) -#define FLAG_MASK_FROM_INDEX(page_index) KERNAUX_BITS((page_index) % 8) - -#define FLAG_INDEX_FROM_ADDR(page_addr) \ - (FLAG_INDEX_FROM_INDEX(PAGE_INDEX(page_addr))) -#define FLAG_MASK_FROM_ADDR(page_addr) \ - (FLAG_MASK_FROM_INDEX(PAGE_INDEX(page_addr))) - -#define GET_FLAG_FROM_INDEX(pfa, page_index) \ - (!!((pfa)->flags[FLAG_INDEX_FROM_INDEX(page_index)] & \ - FLAG_MASK_FROM_INDEX(page_index))) -#define GET_FLAG_FROM_ADDR(pfa, page_addr) \ - (!!((pfa)->flags[FLAG_INDEX_FROM_ADDR(page_addr)] & \ - FLAG_MASK_FROM_ADDR(page_addr))) - -#define FLAG_TRUE_FROM_INDEX(pfa, page_index) \ - ((pfa)->flags[FLAG_INDEX_FROM_INDEX(page_index)] |= \ - FLAG_MASK_FROM_INDEX(page_index)) -#define FLAG_FALSE_FROM_INDEX(pfa, page_index) \ - ((pfa)->flags[FLAG_INDEX_FROM_INDEX(page_index)] &= \ - ~FLAG_MASK_FROM_INDEX(page_index)) - -static void KernAux_PFA_mark( - KernAux_PFA pfa, - bool status, - size_t start, - size_t end -); - -void KernAux_PFA_initialize(const KernAux_PFA pfa) -{ - KERNAUX_NOTNULL(pfa); - // cppcheck-suppress ctunullpointer - memset(pfa->flags, 0, sizeof(pfa->flags)); -} - -bool KernAux_PFA_is_available(const KernAux_PFA pfa, const size_t page_addr) -{ - KERNAUX_NOTNULL(pfa); - KERNAUX_ASSERT(page_addr % KERNAUX_PFA_PAGE_SIZE == 0); - - // cppcheck-suppress ctunullpointer - return GET_FLAG_FROM_ADDR(pfa, page_addr); -} - -void KernAux_PFA_mark_available( - const KernAux_PFA pfa, - const size_t start, - const size_t end -) { - KernAux_PFA_mark(pfa, true, start, end); -} - -void KernAux_PFA_mark_unavailable( - const KernAux_PFA pfa, - const size_t start, - const size_t end -) { - KernAux_PFA_mark(pfa, false, start, end); -} - -void KernAux_PFA_mark( - const KernAux_PFA pfa, - const bool status, - size_t start, - size_t end -) { - KERNAUX_NOTNULL(pfa); - KERNAUX_ASSERT(start < end); - - const size_t start_rem = start % KERNAUX_PFA_PAGE_SIZE; - const size_t end_rem = (end + 1) % KERNAUX_PFA_PAGE_SIZE; - - if (start_rem != 0) { - start = start - start_rem + KERNAUX_PFA_PAGE_SIZE; - } - - if (end_rem != 0) { - end = end - end_rem; - } - - const size_t start_index = start / KERNAUX_PFA_PAGE_SIZE; - const size_t end_index = end / KERNAUX_PFA_PAGE_SIZE; - - for (size_t index = start_index; index <= end_index; ++index) { - if (status) { - FLAG_TRUE_FROM_INDEX(pfa, index); - } else { - FLAG_FALSE_FROM_INDEX(pfa, index); - } - } -} - -size_t KernAux_PFA_alloc_pages(const KernAux_PFA pfa, size_t mem_size) -{ - KERNAUX_NOTNULL(pfa); - - const size_t mem_rem = mem_size % KERNAUX_PFA_PAGE_SIZE; - - if (mem_rem != 0) { - mem_size = mem_size - mem_rem + KERNAUX_PFA_PAGE_SIZE; - } - - const size_t pages_count = mem_size / KERNAUX_PFA_PAGE_SIZE; - - // We start from 1 because 0 indicates failure. - // It is not very useful to alloc page at address 0; - for (size_t index = 1, start = 0; - index < KERNAUX_PFA_PAGES_COUNT_MAX; - ++index) - { - if (!GET_FLAG_FROM_INDEX(pfa, index)) { - start = 0; - continue; - } - - if (start == 0) start = index; - - if (index - start + 1 == pages_count) { - for (; index >= start; --index) { - FLAG_FALSE_FROM_INDEX(pfa, index); - } - return start * KERNAUX_PFA_PAGE_SIZE; - } - } - - return 0; -} - -void KernAux_PFA_free_pages( - const KernAux_PFA pfa, - const size_t page_addr, - size_t mem_size -) { - KERNAUX_NOTNULL(pfa); - KERNAUX_ASSERT(page_addr % KERNAUX_PFA_PAGE_SIZE == 0); - - const size_t mem_rem = mem_size % KERNAUX_PFA_PAGE_SIZE; - - if (mem_rem != 0) { - mem_size = mem_size - mem_rem + KERNAUX_PFA_PAGE_SIZE; - } - - const size_t start_index = page_addr / KERNAUX_PFA_PAGE_SIZE; - const size_t pages_count = mem_size / KERNAUX_PFA_PAGE_SIZE; - - for (size_t index = 0; index < pages_count; ++index) { - FLAG_TRUE_FROM_INDEX(pfa, start_index + index); - } -} diff --git a/tests/.gitignore b/tests/.gitignore index 83eef67..c48eda6 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,3 +1 @@ /test_arch_i386 -/test_pfa -/test_pfa_assert diff --git a/tests/Makefile.am b/tests/Makefile.am index 4865ac2..1f25f99 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -15,29 +15,3 @@ test_arch_i386_SOURCES = \ main.c \ test_arch_i386.c endif - -############ -# test_pfa # -############ - -if WITH_PFA -TESTS += test_pfa -test_pfa_LDADD = $(top_builddir)/libkernaux.la -test_pfa_SOURCES = \ - main.c \ - test_pfa.c -endif - -################### -# test_pfa_assert # -################### - -if ENABLE_ASSERT -if WITH_PFA -TESTS += test_pfa_assert -test_pfa_assert_LDADD = $(top_builddir)/libkernaux.la -test_pfa_assert_SOURCES = \ - main.c \ - test_pfa_assert.c -endif -endif diff --git a/tests/test_pfa.c b/tests/test_pfa.c deleted file mode 100644 index 70a3620..0000000 --- a/tests/test_pfa.c +++ /dev/null @@ -1,86 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include - -void test_main() -{ - struct KernAux_PFA pfa; - - KernAux_PFA_initialize(&pfa); - - for (size_t index = 0; index < KERNAUX_PFA_PAGES_COUNT_MAX; ++index) { - assert(!KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE)); - } - - 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 (size_t index = 0; index < 159; ++index) { - assert(KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE)); - } - - for (size_t index = 159; index < 256; ++index) { - assert(!KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE)); - } - - for (size_t index = 256; index < 1024; ++index) { // [1 MB, 4 MB) - assert(KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE)); - } - - for (size_t index = 1024; index < 1536; ++index) { // [4 MB, 6 MB) - assert(!KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE)); - } - - for (size_t index = 1536; index < 32736; ++index) { // [6 MB, ~127 MB) - assert(KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE)); - } - - for (size_t index = 32736; index < KERNAUX_PFA_PAGES_COUNT_MAX; ++index) { - assert(!KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE)); - } - - { - const size_t page_addr = KernAux_PFA_alloc_pages(&pfa, 1); - - assert(page_addr != 0); - assert(page_addr % KERNAUX_PFA_PAGE_SIZE == 0); - assert(!KernAux_PFA_is_available(&pfa, page_addr)); - - KernAux_PFA_free_pages(&pfa, page_addr, 1); - - assert(KernAux_PFA_is_available(&pfa, page_addr)); - } - - { - const size_t page_addr = - KernAux_PFA_alloc_pages(&pfa, 10 * KERNAUX_PFA_PAGE_SIZE); - - assert(page_addr != 0); - assert(page_addr % KERNAUX_PFA_PAGE_SIZE == 0); - - for (size_t index = 0, addr = page_addr; index < 10; ++index) { - assert(!KernAux_PFA_is_available(&pfa, addr)); - addr += KERNAUX_PFA_PAGE_SIZE; - } - - KernAux_PFA_free_pages(&pfa, page_addr, 10 * KERNAUX_PFA_PAGE_SIZE); - - for (size_t index = 0, addr = page_addr; index < 10; ++index) { - assert(KernAux_PFA_is_available(&pfa, addr)); - addr += KERNAUX_PFA_PAGE_SIZE; - } - } - - for (size_t index = 0; index < KERNAUX_PFA_PAGES_COUNT_MAX; ++index) { - if (KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE)) { - assert(KernAux_PFA_alloc_pages(&pfa, 1) != 0); - } - } - - assert(KernAux_PFA_alloc_pages(&pfa, 1) == 0); -} diff --git a/tests/test_pfa_assert.c b/tests/test_pfa_assert.c deleted file mode 100644 index 78ce5ac..0000000 --- a/tests/test_pfa_assert.c +++ /dev/null @@ -1,99 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include -#include -#include -#include - -static unsigned int count = 0; -static jmp_buf jmpbuf; - -static void assert_cb( - const char *const file KERNAUX_UNUSED, - const int line KERNAUX_UNUSED, - const char *const str KERNAUX_UNUSED -) { - ++count; - longjmp(jmpbuf, 1); -} - -void test_main() -{ - if (setjmp(jmpbuf) != 0) abort(); - - kernaux_assert_cb = assert_cb; - - struct KernAux_PFA pfa; - - if (setjmp(jmpbuf) == 0) { - KernAux_PFA_initialize(&pfa); - } else { - assert(count == 0); - } - - if (setjmp(jmpbuf) == 0) { - KernAux_PFA_initialize(NULL); - } else { - assert(count == 1); - } - - if (setjmp(jmpbuf) == 0) { - assert(!KernAux_PFA_is_available(NULL, KERNAUX_PFA_PAGE_SIZE)); - } else { - assert(count == 2); - } - - if (setjmp(jmpbuf) == 0) { - assert(!KernAux_PFA_is_available(&pfa, 123)); - } else { - assert(count == 3); - } - - if (setjmp(jmpbuf) == 0) { - KernAux_PFA_mark_available(NULL, 0, KERNAUX_PFA_PAGE_SIZE); - } else { - assert(count == 4); - } - - if (setjmp(jmpbuf) == 0) { - KernAux_PFA_mark_available(&pfa, KERNAUX_PFA_PAGE_SIZE, 0); - } else { - assert(count == 5); - } - - if (setjmp(jmpbuf) == 0) { - KernAux_PFA_mark_unavailable(NULL, 0, KERNAUX_PFA_PAGE_SIZE); - } else { - assert(count == 6); - } - - if (setjmp(jmpbuf) == 0) { - KernAux_PFA_mark_unavailable(&pfa, KERNAUX_PFA_PAGE_SIZE, 0); - } else { - assert(count == 7); - } - - if (setjmp(jmpbuf) == 0) { - assert(KernAux_PFA_alloc_pages(NULL, KERNAUX_PFA_PAGE_SIZE) == 0); - } else { - assert(count == 8); - } - - if (setjmp(jmpbuf) == 0) { - KernAux_PFA_free_pages(NULL, KERNAUX_PFA_PAGE_SIZE, KERNAUX_PFA_PAGE_SIZE); - } else { - assert(count == 9); - } - - if (setjmp(jmpbuf) == 0) { - KernAux_PFA_free_pages(&pfa, 123, KERNAUX_PFA_PAGE_SIZE); - } else { - assert(count == 10); - } -}