diff --git a/kernel/include/Kernel/Bootstrap.h b/kernel/include/Kernel/Bootstrap.h index 8c7c9f0..ccd23cd 100644 --- a/kernel/include/Kernel/Bootstrap.h +++ b/kernel/include/Kernel/Bootstrap.h @@ -5,6 +5,6 @@ #endif VOID -CommonStartupRoutine( - PAGE_ALLOCATOR *BumpAllocator +CommonStartupRoutine ( + PAGE_ALLOCATOR* BumpAllocator ); diff --git a/kernel/include/Kernel/Logging.h b/kernel/include/Kernel/Logging.h new file mode 100644 index 0000000..366da8b --- /dev/null +++ b/kernel/include/Kernel/Logging.h @@ -0,0 +1,44 @@ +#pragma once + +#ifndef __KERNEL_H__ + #error "This file should be included from Kernel.h" +#endif + +#include + +#define LOG_LEVEL_DEBUG 0 +#define LOG_LEVEL_INFO 1 +#define LOG_LEVEL_WARNING 2 +#define LOG_LEVEL_ERROR 3 + +/** + * @brief Logs a message. + * + * @param[in] _ID The Filter ID. LFID_DEFAULT for default filter. + * @param[in] _LEVEL The log level. + * @param[in] _Format The format string. + **/ +#define LOG(_ID, _LEVEL, _Format, ...) + +/// Default filter, used to everything that doesn't have a specific filter. +DEFINE_GUID (LFID_DEFAULT, 0x8BA890B8, 0xF167, 0x4AFD, 0x86, 0x45, 0x44, 0x07, 0x43, 0xA0, 0x30, 0x6A); + +/// Memory filter, used to log memory related messages. +DEFINE_GUID (LFID_MEMORY, 0x8BA890B8, 0xF167, 0x4AFD, 0x86, 0x45, 0x44, 0x07, 0x43, 0xA0, 0x30, 0x6B); + +typedef struct _LOG_FILTER { + GUID ID; + CHAR8 Name[64]; + BOOLEAN Enabled; + UINT8 Level; +} LOG_FILTER; + +typedef struct _LOG_ENTRY { + GUID FilterID; + UINTN Level; + CHAR8* Message; +} LOG_ENTRY; + +typedef VOID (* LOG_CALLBACK)( + LOG_ENTRY* Entry + ); diff --git a/kernel/source/Bootstrap/Common.c b/kernel/source/Bootstrap/Common.c index 7ae4866..8e99bfe 100644 --- a/kernel/source/Bootstrap/Common.c +++ b/kernel/source/Bootstrap/Common.c @@ -4,8 +4,8 @@ PAGE_ALLOCATOR* g_PageAllocator; VOID -CommonStartupRoutine( - PAGE_ALLOCATOR *BumpAllocator +CommonStartupRoutine ( + PAGE_ALLOCATOR* BumpAllocator ) { // TODO: g_PageAllocator = BuddyAllocatorInit (BumpAllocator); diff --git a/kernel/source/Bootstrap/Limine.c b/kernel/source/Bootstrap/Limine.c index 3f5dbbe..a77043a 100644 --- a/kernel/source/Bootstrap/Limine.c +++ b/kernel/source/Bootstrap/Limine.c @@ -11,14 +11,14 @@ BUMP_ALLOCATOR g_BumpAllocator; // See specification for further info. // -LIMINE_BASE_REVISION(1); +LIMINE_BASE_REVISION (1); // // Memory map // struct limine_memmap_request g_LimineMemmap = { - .id = LIMINE_MEMMAP_REQUEST, + .id = LIMINE_MEMMAP_REQUEST, .revision = 0 }; @@ -33,17 +33,14 @@ StartupRoutine ( IDTInit (); BumperIdx = 0; - for (UINT64 i = 0; i < g_LimineMemmap.response->entry_count; i++) - { - if (g_LimineMemmap.response->entries[i]->type == LIMINE_MEMMAP_USABLE) - { - BUMPER *bumper = &g_BumpAllocator.bumpers[BumperIdx++]; + for (UINT64 i = 0; i < g_LimineMemmap.response->entry_count; i++) { + if (g_LimineMemmap.response->entries[i]->type == LIMINE_MEMMAP_USABLE) { + BUMPER* bumper = &g_BumpAllocator.bumpers[BumperIdx++]; bumper->heap_start = g_LimineMemmap.response->entries[i]->base; - bumper->heap_end = g_LimineMemmap.response->entries[i]->base + g_LimineMemmap.response->entries[i]->length; - bumper->next = bumper->heap_start; + bumper->heap_end = g_LimineMemmap.response->entries[i]->base + g_LimineMemmap.response->entries[i]->length; + bumper->next = bumper->heap_start; - if (BumperIdx == MAXIMUM_BUMPERS) - { + if (BumperIdx == MAXIMUM_BUMPERS) { // Memory is too fragmented, we can't continue. This is fine but we'll use // some usable memory. @@ -53,5 +50,5 @@ StartupRoutine ( } } - CommonStartupRoutine ((PAGE_ALLOCATOR *)&g_BumpAllocator); + CommonStartupRoutine ((PAGE_ALLOCATOR*)&g_BumpAllocator); } diff --git a/lib/compat_c/include/stdint.h b/lib/compat_c/include/stdint.h index f4498e6..9c5981f 100644 --- a/lib/compat_c/include/stdint.h +++ b/lib/compat_c/include/stdint.h @@ -2,12 +2,12 @@ #include -typedef INT8 int8_t; -typedef INT16 int16_t; -typedef INT32 int32_t; -typedef INT64 int64_t; +typedef INT8 int8_t; +typedef INT16 int16_t; +typedef INT32 int32_t; +typedef INT64 int64_t; -typedef UINT8 uint8_t; +typedef UINT8 uint8_t; typedef UINT16 uint16_t; typedef UINT32 uint32_t; typedef UINT64 uint64_t; diff --git a/lib/runtime/include/RuntimeLib/Error.h b/lib/runtime/include/RuntimeLib/Error.h index 81cb6ad..94ad6d5 100644 --- a/lib/runtime/include/RuntimeLib/Error.h +++ b/lib/runtime/include/RuntimeLib/Error.h @@ -83,15 +83,15 @@ EXTERN_C_START #define STATUS_FACILITY(_Status) (((_Status) >> 16) & 0x1FFF) #define STATUS_ERROR_CODE(_Status) ((_Status) & 0xFFFF) -#define IS_SUCCESS(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_SUCCESS) -#define IS_WARNING(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_WARNING) -#define IS_INFORMATIONAL(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_INFORMATIONAL) -#define IS_ERROR(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_ERROR) +#define IS_SUCCESS(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_SUCCESS) +#define IS_WARNING(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_WARNING) +#define IS_INFORMATIONAL(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_INFORMATIONAL) +#define IS_ERROR(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_ERROR) -#define SUCCEEDED(_Status) (IS_SUCCESS(_Status) || IS_INFORMATIONAL(_Status) || IS_WARNING(_Status)) -#define FAILED(_Status) (IS_ERROR(_Status)) +#define SUCCEEDED(_Status) (IS_SUCCESS(_Status) || IS_INFORMATIONAL(_Status) || IS_WARNING(_Status)) +#define FAILED(_Status) (IS_ERROR(_Status)) -#define QUICK_CHECK(_F) Status = (_F); if (FAILED(Status)) { goto Exit; } +#define QUICK_CHECK(_F) Status = (_F); if (FAILED(Status)) { goto Exit; } // -------------------------------------------------------------------- Generic diff --git a/lib/runtime/include/RuntimeLib/TypeDefs.h b/lib/runtime/include/RuntimeLib/TypeDefs.h index 94a0abf..6694b39 100644 --- a/lib/runtime/include/RuntimeLib/TypeDefs.h +++ b/lib/runtime/include/RuntimeLib/TypeDefs.h @@ -81,7 +81,7 @@ EXTERN_C_START // ------------------------------------------------------------------- Typedefs -typedef VOID* HANDLE; +typedef VOID* HANDLE; #define NULL_HANDLE ((HANDLE) NULL) // --------------------------------------------------------------------- Macros diff --git a/lib/runtime/source/Memory/SlabAllocator.c b/lib/runtime/source/Memory/SlabAllocator.c index 3318d1d..767f2df 100644 --- a/lib/runtime/source/Memory/SlabAllocator.c +++ b/lib/runtime/source/Memory/SlabAllocator.c @@ -115,7 +115,7 @@ RtlDestroySlabCache ( goto Exit; } - if (CachePtr->Empty != NULL || CachePtr->Partial != NULL || CachePtr->Full != NULL) { + if ((CachePtr->Empty != NULL) || (CachePtr->Partial != NULL) || (CachePtr->Full != NULL)) { SLAB* Slab; SLAB* Next; @@ -125,7 +125,7 @@ RtlDestroySlabCache ( Slab = CachePtr->Full; while (Slab != NULL) { Next = Slab->Next; // Save the next slab - DestroySlab(Slab); + DestroySlab (Slab); Slab = Next; } @@ -135,7 +135,7 @@ RtlDestroySlabCache ( Slab = CachePtr->Partial; while (Slab != NULL) { Next = Slab->Next; - DestroySlab(Slab); + DestroySlab (Slab); Slab = Next; } @@ -145,7 +145,7 @@ RtlDestroySlabCache ( Slab = CachePtr->Empty; while (Slab != NULL) { Next = Slab->Next; - DestroySlab(Slab); + DestroySlab (Slab); Slab = Next; } } diff --git a/lib/runtime/source/Memory/SlabAllocatorUtilities.c b/lib/runtime/source/Memory/SlabAllocatorUtilities.c index 3f7f5b0..c68676c 100644 --- a/lib/runtime/source/Memory/SlabAllocatorUtilities.c +++ b/lib/runtime/source/Memory/SlabAllocatorUtilities.c @@ -67,9 +67,9 @@ DestroySlab ( IN OUT SLAB* Slab ) { - STATUS Status; - UINTN SlabPages; - UINTN SlabDataPages; + STATUS Status; + UINTN SlabPages; + UINTN SlabDataPages; SLAB_CACHE* Cache; Status = STATUS_SUCCESS; @@ -88,7 +88,7 @@ DestroySlab ( // Destroy all objects inside // for (UINTN i = 0; i < Cache->ObjectCount; i++) { - Status = FreeObjectInSlab(Slab, Cache->Flags, i); + Status = FreeObjectInSlab (Slab, Cache->Flags, i); if (FAILED (Status)) { goto Exit; } diff --git a/lib/runtime/tests/Allocators/BumpAllocator.cpp b/lib/runtime/tests/Allocators/BumpAllocator.cpp index 5bc33c6..d16f26b 100644 --- a/lib/runtime/tests/Allocators/BumpAllocator.cpp +++ b/lib/runtime/tests/Allocators/BumpAllocator.cpp @@ -5,8 +5,9 @@ TEST_CASE ("AllocatePages", "[BumpAllocator]") { BUMP_ALLOCATOR allocator { }; - SECTION("Make sure allocator cannot be NULL") { + SECTION ("Make sure allocator cannot be NULL") { STATUS status = RtlBumpAllocatorInitialize (NULL); + REQUIRE (status == STATUS_INVALID_PARAMETER); } @@ -23,12 +24,12 @@ TEST_CASE ("AllocatePages", "[BumpAllocator]") { allocator.bumpers[1].heap_end = allocator.bumpers[1].heap_start + PAGE_SIZE_4K * 2; allocator.bumpers[1].next = allocator.bumpers[1].heap_start; - SECTION("Make sure we cannot allocate using NULL as Self") { + SECTION ("Make sure we cannot allocate using NULL as Self") { VOID* address = NULL; - STATUS status = allocator.AllocatePages(NULL, &address, 1, PAGE_SIZE_4K); + STATUS status = allocator.AllocatePages (NULL, &address, 1, PAGE_SIZE_4K); - assert(address == NULL); - assert(status == STATUS_NOT_INITIALIZED); + assert (address == NULL); + assert (status == STATUS_NOT_INITIALIZED); } SECTION ("Allocates 4K page") { @@ -126,8 +127,9 @@ TEST_CASE ("AllocatePages", "[BumpAllocator]") { TEST_CASE ("FreePages", "[BumpAllocator]") { BUMP_ALLOCATOR allocator { }; - SECTION("Make sure allocator cannot be NULL") { + SECTION ("Make sure allocator cannot be NULL") { STATUS status = RtlBumpAllocatorInitialize (NULL); + REQUIRE (status == STATUS_INVALID_PARAMETER); } @@ -142,33 +144,37 @@ TEST_CASE ("FreePages", "[BumpAllocator]") { allocator.bumpers[1].heap_end = allocator.bumpers[1].heap_start + PAGE_SIZE_4K * 2; allocator.bumpers[1].next = allocator.bumpers[1].heap_start; - SECTION("Make sure we cannot free while using NULL as Self") { - STATUS status = allocator.FreePages(NULL, NULL, 1, PAGE_SIZE_4K); - assert(status == STATUS_NOT_INITIALIZED); + SECTION ("Make sure we cannot free while using NULL as Self") { + STATUS status = allocator.FreePages (NULL, NULL, 1, PAGE_SIZE_4K); + + assert (status == STATUS_NOT_INITIALIZED); } - SECTION("Free should always succeed") { + SECTION ("Free should always succeed") { VOID* address = NULL; - STATUS status = PA_ALLOCATE(&allocator, &address, 1, PAGE_SIZE_4K); - REQUIRE(status == STATUS_SUCCESS); + STATUS status = PA_ALLOCATE (&allocator, &address, 1, PAGE_SIZE_4K); - status = PA_FREE(&allocator, &address, 1, PAGE_SIZE_4K); - REQUIRE(status == STATUS_SUCCESS); + REQUIRE (status == STATUS_SUCCESS); + + status = PA_FREE (&allocator, &address, 1, PAGE_SIZE_4K); + REQUIRE (status == STATUS_SUCCESS); REQUIRE (address == NULL); } - SECTION("Free cannot be NULL") { - STATUS status = PA_FREE(&allocator, NULL, 1, PAGE_SIZE_4K); - REQUIRE(status == STATUS_INVALID_PARAMETER); + SECTION ("Free cannot be NULL") { + STATUS status = PA_FREE (&allocator, NULL, 1, PAGE_SIZE_4K); + + REQUIRE (status == STATUS_INVALID_PARAMETER); } - SECTION("Free cannot be zero") { + SECTION ("Free cannot be zero") { VOID* address = NULL; - STATUS status = PA_ALLOCATE(&allocator, &address, 1, PAGE_SIZE_4K); - REQUIRE(status == STATUS_SUCCESS); + STATUS status = PA_ALLOCATE (&allocator, &address, 1, PAGE_SIZE_4K); - status = PA_FREE(&allocator, &address, 0, PAGE_SIZE_4K); - REQUIRE(status == STATUS_INVALID_PARAMETER); + REQUIRE (status == STATUS_SUCCESS); + + status = PA_FREE (&allocator, &address, 0, PAGE_SIZE_4K); + REQUIRE (status == STATUS_INVALID_PARAMETER); } delete[] (UINT8*)allocator.bumpers[0].heap_start; diff --git a/lib/runtime/tests/Allocators/SlabAllocator.cpp b/lib/runtime/tests/Allocators/SlabAllocator.cpp index 758a41f..6271c4d 100644 --- a/lib/runtime/tests/Allocators/SlabAllocator.cpp +++ b/lib/runtime/tests/Allocators/SlabAllocator.cpp @@ -11,7 +11,7 @@ PAGE_ALLOCATOR g_MallocAllocator = { Align = PAGE_SIZE_4K; } - if (Address == NULL || (Align != PAGE_SIZE_4K && Align != PAGE_SIZE_2M && Align != PAGE_SIZE_1G)) { + if ((Address == NULL) || ((Align != PAGE_SIZE_4K) && (Align != PAGE_SIZE_2M) && (Align != PAGE_SIZE_1G))) { return STATUS_INVALID_PARAMETER; } @@ -19,7 +19,7 @@ PAGE_ALLOCATOR g_MallocAllocator = { return STATUS_INVALID_PARAMETER; } - *Address = malloc(Pages * Align); + *Address = malloc (Pages * Align); if (*Address == NULL) { return STATUS_OUT_OF_MEMORY; } @@ -27,7 +27,7 @@ PAGE_ALLOCATOR g_MallocAllocator = { return STATUS_SUCCESS; }, [](PAGE_ALLOCATOR* Self, VOID** Address, UINTN Pages, UINTN Align) -> STATUS { - if (Address == NULL || Pages == 0 || (Align != PAGE_SIZE_4K && Align != PAGE_SIZE_2M && Align != PAGE_SIZE_1G)) { + if ((Address == NULL) || (Pages == 0) || ((Align != PAGE_SIZE_4K) && (Align != PAGE_SIZE_2M) && (Align != PAGE_SIZE_1G))) { return STATUS_INVALID_PARAMETER; } @@ -35,7 +35,7 @@ PAGE_ALLOCATOR g_MallocAllocator = { return STATUS_INVALID_PARAMETER; } - free(*Address); + free (*Address); return STATUS_SUCCESS; } @@ -53,186 +53,186 @@ PAGE_ALLOCATOR g_NullAllocator = { } }; -TEST_CASE("RtlCreateSlabCache", "[SlabAllocator]") { - SLAB_CACHE* Cache = NULL; - STATUS Status = STATUS_SUCCESS; +TEST_CASE ("RtlCreateSlabCache", "[SlabAllocator]") { + SLAB_CACHE* Cache = NULL; + STATUS Status = STATUS_SUCCESS; - SECTION("Check for invalid parameter") { - Status = RtlCreateSlabCache(NULL, &g_MallocAllocator, sizeof(UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); - REQUIRE(Status == STATUS_INVALID_PARAMETER); + SECTION ("Check for invalid parameter") { + Status = RtlCreateSlabCache (NULL, &g_MallocAllocator, sizeof (UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); + REQUIRE (Status == STATUS_INVALID_PARAMETER); - Status = RtlCreateSlabCache(&Cache, NULL, sizeof(UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); - REQUIRE(Status == STATUS_INVALID_PARAMETER); + Status = RtlCreateSlabCache (&Cache, NULL, sizeof (UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); + REQUIRE (Status == STATUS_INVALID_PARAMETER); - Status = RtlCreateSlabCache(&Cache, &g_MallocAllocator, 0, SLAB_CACHE_FLAGS_NONE, NULL, NULL); - REQUIRE(Status == STATUS_INVALID_PARAMETER); + Status = RtlCreateSlabCache (&Cache, &g_MallocAllocator, 0, SLAB_CACHE_FLAGS_NONE, NULL, NULL); + REQUIRE (Status == STATUS_INVALID_PARAMETER); - Status = RtlCreateSlabCache(&Cache, &g_MallocAllocator, sizeof(UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); - REQUIRE(Status == STATUS_SUCCESS); + Status = RtlCreateSlabCache (&Cache, &g_MallocAllocator, sizeof (UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); + REQUIRE (Status == STATUS_SUCCESS); - Status = RtlDestroySlabCache(&Cache); - REQUIRE(Status == STATUS_SUCCESS); + Status = RtlDestroySlabCache (&Cache); + REQUIRE (Status == STATUS_SUCCESS); } - SECTION("Create and destroy a slab cache") { - Status = RtlCreateSlabCache(&Cache, &g_MallocAllocator, sizeof(UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); + SECTION ("Create and destroy a slab cache") { + Status = RtlCreateSlabCache (&Cache, &g_MallocAllocator, sizeof (UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); - REQUIRE(Status == STATUS_SUCCESS); + REQUIRE (Status == STATUS_SUCCESS); - REQUIRE(Cache != NULL); - REQUIRE(Cache->BaseAllocator == &g_MallocAllocator); - REQUIRE(Cache->ObjectSize == sizeof(UINTN)); - REQUIRE(Cache->ObjectCount == ALIGN_UP (PAGE_SIZE_4K, sizeof(UINTN)) / sizeof(UINTN)); - REQUIRE(Cache->Flags == SLAB_CACHE_FLAGS_NONE); - REQUIRE(Cache->Ctor == RtlDefaultSlabCtor); - REQUIRE(Cache->Dtor == RtlDefaultSlabDtor); - REQUIRE(Cache->Empty == NULL); - REQUIRE(Cache->Partial == NULL); - REQUIRE(Cache->Full == NULL); + REQUIRE (Cache != NULL); + REQUIRE (Cache->BaseAllocator == &g_MallocAllocator); + REQUIRE (Cache->ObjectSize == sizeof (UINTN)); + REQUIRE (Cache->ObjectCount == ALIGN_UP (PAGE_SIZE_4K, sizeof (UINTN)) / sizeof (UINTN)); + REQUIRE (Cache->Flags == SLAB_CACHE_FLAGS_NONE); + REQUIRE (Cache->Ctor == RtlDefaultSlabCtor); + REQUIRE (Cache->Dtor == RtlDefaultSlabDtor); + REQUIRE (Cache->Empty == NULL); + REQUIRE (Cache->Partial == NULL); + REQUIRE (Cache->Full == NULL); - Status = RtlDestroySlabCache(&Cache); - REQUIRE(Status == STATUS_SUCCESS); + Status = RtlDestroySlabCache (&Cache); + REQUIRE (Status == STATUS_SUCCESS); } - SECTION("Make sure we cannot allocate a cache if the base allocator is full") { - Status = RtlCreateSlabCache(&Cache, &g_NullAllocator, sizeof(UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); - REQUIRE(Status == STATUS_OUT_OF_MEMORY); + SECTION ("Make sure we cannot allocate a cache if the base allocator is full") { + Status = RtlCreateSlabCache (&Cache, &g_NullAllocator, sizeof (UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); + REQUIRE (Status == STATUS_OUT_OF_MEMORY); } } -TEST_CASE("RtlDestroySlabCache", "[SlabAllocator]") { - SLAB_CACHE* Cache = NULL; - STATUS Status = STATUS_SUCCESS; +TEST_CASE ("RtlDestroySlabCache", "[SlabAllocator]") { + SLAB_CACHE* Cache = NULL; + STATUS Status = STATUS_SUCCESS; - SECTION("Invalid arguments") { - Status = RtlDestroySlabCache(NULL); - REQUIRE(Status == STATUS_INVALID_PARAMETER); + SECTION ("Invalid arguments") { + Status = RtlDestroySlabCache (NULL); + REQUIRE (Status == STATUS_INVALID_PARAMETER); - Status = RtlDestroySlabCache(&Cache); - REQUIRE(Status == STATUS_INVALID_PARAMETER); + Status = RtlDestroySlabCache (&Cache); + REQUIRE (Status == STATUS_INVALID_PARAMETER); } } -TEST_CASE("RtlSlabAllocate", "[SlabAllocator]") { - SLAB_CACHE* Cache = NULL; - STATUS Status = STATUS_SUCCESS; +TEST_CASE ("RtlSlabAllocate", "[SlabAllocator]") { + SLAB_CACHE* Cache = NULL; + STATUS Status = STATUS_SUCCESS; - Status = RtlCreateSlabCache(&Cache, &g_MallocAllocator, sizeof(UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); - REQUIRE(Status == STATUS_SUCCESS); + Status = RtlCreateSlabCache (&Cache, &g_MallocAllocator, sizeof (UINTN), SLAB_CACHE_FLAGS_NONE, NULL, NULL); + REQUIRE (Status == STATUS_SUCCESS); - SECTION("Allocate a single object") { + SECTION ("Allocate a single object") { UINTN* Object = NULL; - Status = RtlSlabAllocate(Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); - REQUIRE(Status == STATUS_SUCCESS); + Status = RtlSlabAllocate (Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); + REQUIRE (Status == STATUS_SUCCESS); // We need an object - REQUIRE(Object != NULL); + REQUIRE (Object != NULL); // Make sure we correctly moved the object from the empty list to the partial list - REQUIRE(Cache->Empty == NULL); - REQUIRE(Cache->Partial != NULL); - REQUIRE(Cache->Partial->FreeCount == Cache->ObjectCount - 1); - REQUIRE(Cache->Partial->Next == NULL); + REQUIRE (Cache->Empty == NULL); + REQUIRE (Cache->Partial != NULL); + REQUIRE (Cache->Partial->FreeCount == Cache->ObjectCount - 1); + REQUIRE (Cache->Partial->Next == NULL); // And it shouldn't be in the full list - REQUIRE(Cache->Full == NULL); + REQUIRE (Cache->Full == NULL); } - SECTION("Allocate all Objects") { + SECTION ("Allocate all Objects") { UINTN* Object = NULL; for (UINTN i = 0; i < Cache->ObjectCount; i++) { - Status = RtlSlabAllocate(Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); - REQUIRE(Status == STATUS_SUCCESS); + Status = RtlSlabAllocate (Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); + REQUIRE (Status == STATUS_SUCCESS); // We need an object - REQUIRE(Object != NULL); - REQUIRE(Cache->Empty == NULL); + REQUIRE (Object != NULL); + REQUIRE (Cache->Empty == NULL); if (i <= Cache->ObjectCount - 2) { - REQUIRE(Cache->Partial != NULL); - REQUIRE(Cache->Partial->FreeCount == Cache->ObjectCount - i - 1); - REQUIRE(Cache->Partial->Next == NULL); + REQUIRE (Cache->Partial != NULL); + REQUIRE (Cache->Partial->FreeCount == Cache->ObjectCount - i - 1); + REQUIRE (Cache->Partial->Next == NULL); } } // We should have allocated all objects - REQUIRE(Cache->Full != NULL); + REQUIRE (Cache->Full != NULL); } - SECTION("Don't allocate at all") { + SECTION ("Don't allocate at all") { // Just to test the teardown code } - SECTION("Allocate invalid arguments") { + SECTION ("Allocate invalid arguments") { UINTN* Object = NULL; - Status = RtlSlabAllocate(NULL, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); - REQUIRE(Status == STATUS_INVALID_PARAMETER); + Status = RtlSlabAllocate (NULL, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); + REQUIRE (Status == STATUS_INVALID_PARAMETER); - Status = RtlSlabAllocate(Cache, SLAB_CACHE_FLAGS_NONE, NULL); - REQUIRE(Status == STATUS_INVALID_PARAMETER); + Status = RtlSlabAllocate (Cache, SLAB_CACHE_FLAGS_NONE, NULL); + REQUIRE (Status == STATUS_INVALID_PARAMETER); - Status = RtlSlabAllocate(Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); - REQUIRE(Status == STATUS_SUCCESS); + Status = RtlSlabAllocate (Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); + REQUIRE (Status == STATUS_SUCCESS); - Status = RtlSlabAllocate(Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); - REQUIRE(Status == STATUS_SUCCESS); + Status = RtlSlabAllocate (Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); + REQUIRE (Status == STATUS_SUCCESS); } - SECTION("Over-allocate") { + SECTION ("Over-allocate") { UINTN* Object = NULL; for (UINTN i = 0; i < Cache->ObjectCount; i++) { - Status = RtlSlabAllocate(Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); - REQUIRE(Status == STATUS_SUCCESS); + Status = RtlSlabAllocate (Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); + REQUIRE (Status == STATUS_SUCCESS); } - Status = RtlSlabAllocate(Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); - REQUIRE(Status == STATUS_SUCCESS); // This should be a new slab - REQUIRE(Cache->Full != NULL); - REQUIRE(Cache->Full->Next == NULL); - REQUIRE(Cache->Full->FreeCount == 0); + Status = RtlSlabAllocate (Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); + REQUIRE (Status == STATUS_SUCCESS); // This should be a new slab + REQUIRE (Cache->Full != NULL); + REQUIRE (Cache->Full->Next == NULL); + REQUIRE (Cache->Full->FreeCount == 0); - REQUIRE(Cache->Partial != NULL); - REQUIRE(Cache->Partial->Next == NULL); - REQUIRE(Cache->Partial->FreeCount == Cache->ObjectCount - 1); + REQUIRE (Cache->Partial != NULL); + REQUIRE (Cache->Partial->Next == NULL); + REQUIRE (Cache->Partial->FreeCount == Cache->ObjectCount - 1); } - SECTION("Allocate and free") { + SECTION ("Allocate and free") { UINTN* Object = NULL; // Allocate - Status = RtlSlabAllocate(Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); - REQUIRE(Status == STATUS_SUCCESS); // This should be a new slab - REQUIRE(Cache->Partial != NULL); - REQUIRE(Cache->Partial->Next == NULL); - REQUIRE(Cache->Partial->FreeCount == Cache->ObjectCount - 1); + Status = RtlSlabAllocate (Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); + REQUIRE (Status == STATUS_SUCCESS); // This should be a new slab + REQUIRE (Cache->Partial != NULL); + REQUIRE (Cache->Partial->Next == NULL); + REQUIRE (Cache->Partial->FreeCount == Cache->ObjectCount - 1); // Free - Status = RtlSlabFree(Cache, SLAB_CACHE_FLAGS_NONE, (VOID **)&Object); - REQUIRE(Status == STATUS_SUCCESS); - REQUIRE(Object == NULL); - REQUIRE(Cache->Empty != NULL); - REQUIRE(Cache->Empty->Next == NULL); - REQUIRE(Cache->Empty->FreeCount == Cache->ObjectCount); - REQUIRE(Cache->Partial == NULL); + Status = RtlSlabFree (Cache, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); + REQUIRE (Status == STATUS_SUCCESS); + REQUIRE (Object == NULL); + REQUIRE (Cache->Empty != NULL); + REQUIRE (Cache->Empty->Next == NULL); + REQUIRE (Cache->Empty->FreeCount == Cache->ObjectCount); + REQUIRE (Cache->Partial == NULL); } - SECTION("Free with invalid arguments") { + SECTION ("Free with invalid arguments") { UINTN* Object = NULL; - Status = RtlSlabFree(NULL, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); - REQUIRE(Status == STATUS_INVALID_PARAMETER); + Status = RtlSlabFree (NULL, SLAB_CACHE_FLAGS_NONE, (VOID**)&Object); + REQUIRE (Status == STATUS_INVALID_PARAMETER); - Status = RtlSlabFree(Cache, SLAB_CACHE_FLAGS_NONE, NULL); - REQUIRE(Status == STATUS_INVALID_PARAMETER); + Status = RtlSlabFree (Cache, SLAB_CACHE_FLAGS_NONE, NULL); + REQUIRE (Status == STATUS_INVALID_PARAMETER); } // // Teardown // - Status = RtlDestroySlabCache(&Cache); - REQUIRE(Status == STATUS_SUCCESS); + Status = RtlDestroySlabCache (&Cache); + REQUIRE (Status == STATUS_SUCCESS); } diff --git a/lib/runtime/tests/Error.cpp b/lib/runtime/tests/Error.cpp index d3ca8bf..b1b656e 100644 --- a/lib/runtime/tests/Error.cpp +++ b/lib/runtime/tests/Error.cpp @@ -15,30 +15,30 @@ TEST_CASE ("COMBINE_STATUS", "[Status]") { // Severity // SECTION ("STATUS_SEVERITY_SUCCESS") { - Status = COMBINE_STATUS(STATUS_SEVERITY_SUCCESS, 0, STATUS_FACILITY_GENERIC, 0x00); + Status = COMBINE_STATUS (STATUS_SEVERITY_SUCCESS, 0, STATUS_FACILITY_GENERIC, 0x00); - REQUIRE (STATUS_SEVERITY(Status) == STATUS_SEVERITY_SUCCESS); + REQUIRE (STATUS_SEVERITY (Status) == STATUS_SEVERITY_SUCCESS); REQUIRE (Status == 0b00000000000000000000000000000000); } SECTION ("STATUS_SEVERITY_INFORMATIONAL") { - Status = COMBINE_STATUS(STATUS_SEVERITY_INFORMATIONAL, 0, STATUS_FACILITY_GENERIC, 0x00); + Status = COMBINE_STATUS (STATUS_SEVERITY_INFORMATIONAL, 0, STATUS_FACILITY_GENERIC, 0x00); - REQUIRE (STATUS_SEVERITY(Status) == STATUS_SEVERITY_INFORMATIONAL); + REQUIRE (STATUS_SEVERITY (Status) == STATUS_SEVERITY_INFORMATIONAL); REQUIRE (Status == 0b01000000000000000000000000000000); } SECTION ("STATUS_SEVERITY_WARNING") { - Status = COMBINE_STATUS(STATUS_SEVERITY_WARNING, 0, STATUS_FACILITY_GENERIC, 0x00); + Status = COMBINE_STATUS (STATUS_SEVERITY_WARNING, 0, STATUS_FACILITY_GENERIC, 0x00); - REQUIRE (STATUS_SEVERITY(Status) == STATUS_SEVERITY_WARNING); + REQUIRE (STATUS_SEVERITY (Status) == STATUS_SEVERITY_WARNING); REQUIRE (Status == 0b10000000000000000000000000000000); } SECTION ("STATUS_SEVERITY_ERROR") { - Status = COMBINE_STATUS(STATUS_SEVERITY_ERROR, 0, STATUS_FACILITY_GENERIC, 0x00); + Status = COMBINE_STATUS (STATUS_SEVERITY_ERROR, 0, STATUS_FACILITY_GENERIC, 0x00); - REQUIRE (STATUS_SEVERITY(Status) == STATUS_SEVERITY_ERROR); + REQUIRE (STATUS_SEVERITY (Status) == STATUS_SEVERITY_ERROR); REQUIRE (Status == 0b11000000000000000000000000000000); } @@ -46,9 +46,9 @@ TEST_CASE ("COMBINE_STATUS", "[Status]") { // User-defined // SECTION ("STATUS_USERDEFINED") { - Status = COMBINE_STATUS(STATUS_SEVERITY_SUCCESS, 1, STATUS_FACILITY_GENERIC, 0x00); + Status = COMBINE_STATUS (STATUS_SEVERITY_SUCCESS, 1, STATUS_FACILITY_GENERIC, 0x00); - REQUIRE (STATUS_USER_DEFINED(Status) == 1); + REQUIRE (STATUS_USER_DEFINED (Status) == 1); REQUIRE (Status == 0b00100000000000000000000000000000); } @@ -56,29 +56,29 @@ TEST_CASE ("COMBINE_STATUS", "[Status]") { // Facility // SECTION ("STATUS_FACILITY") { - Status = COMBINE_STATUS(STATUS_SEVERITY_SUCCESS, 0, 0x1234, 0x00); + Status = COMBINE_STATUS (STATUS_SEVERITY_SUCCESS, 0, 0x1234, 0x00); - REQUIRE (STATUS_FACILITY(Status) == 0x1234); + REQUIRE (STATUS_FACILITY (Status) == 0x1234); } // // Error code // SECTION ("STATUS_ERROR_CODE") { - Status = COMBINE_STATUS(STATUS_SEVERITY_SUCCESS, 0, STATUS_FACILITY_GENERIC, 0x1234); + Status = COMBINE_STATUS (STATUS_SEVERITY_SUCCESS, 0, STATUS_FACILITY_GENERIC, 0x1234); - REQUIRE (STATUS_ERROR_CODE(Status) == 0x1234); + REQUIRE (STATUS_ERROR_CODE (Status) == 0x1234); } // // ALL // SECTION ("ALL") { - Status = COMBINE_STATUS(STATUS_SEVERITY_ERROR, 1, 0x1234, 0x5678); + Status = COMBINE_STATUS (STATUS_SEVERITY_ERROR, 1, 0x1234, 0x5678); - REQUIRE (STATUS_SEVERITY(Status) == STATUS_SEVERITY_ERROR); - REQUIRE (STATUS_USER_DEFINED(Status) == 1); - REQUIRE (STATUS_FACILITY(Status) == 0x1234); - REQUIRE (STATUS_ERROR_CODE(Status) == 0x5678); + REQUIRE (STATUS_SEVERITY (Status) == STATUS_SEVERITY_ERROR); + REQUIRE (STATUS_USER_DEFINED (Status) == 1); + REQUIRE (STATUS_FACILITY (Status) == 0x1234); + REQUIRE (STATUS_ERROR_CODE (Status) == 0x5678); } -} \ No newline at end of file +} diff --git a/lib/runtime/tests/Memory.cpp b/lib/runtime/tests/Memory.cpp index c91da40..8458769 100644 --- a/lib/runtime/tests/Memory.cpp +++ b/lib/runtime/tests/Memory.cpp @@ -105,9 +105,9 @@ TEST_CASE ("RtlCopyMemory", "[Memory]") { REQUIRE (status == STATUS_INVALID_PARAMETER); } - SECTION("Make sure to fail if Source overlaps with Destination (STATUS_INVALID_PARAMETER)") { - UINT8 buffer[10] = { 0 }; - STATUS status = RtlCopyMemory (buffer, sizeof (buffer), buffer + 1, sizeof (buffer) - 1); + SECTION ("Make sure to fail if Source overlaps with Destination (STATUS_INVALID_PARAMETER)") { + UINT8 buffer[10] = { 0 }; + STATUS status = RtlCopyMemory (buffer, sizeof (buffer), buffer + 1, sizeof (buffer) - 1); REQUIRE (status == STATUS_INVALID_PARAMETER); }