diff --git a/sources/apps/demo/main.c b/sources/apps/demo/main.c index 33ecdcd15..c3b7ffab5 100644 --- a/sources/apps/demo/main.c +++ b/sources/apps/demo/main.c @@ -1,4 +1,3 @@ -#include #include #include diff --git a/sources/kernel/init.c b/sources/kernel/init.c index a227b5fab..98790a0f3 100644 --- a/sources/kernel/init.c +++ b/sources/kernel/init.c @@ -1,7 +1,8 @@ -#include "kernel/init.h" #include #include + #include "kernel/heap.h" +#include "kernel/init.h" #include "kernel/kernel.h" #include "kernel/mmap.h" #include "kernel/sched.h" diff --git a/sources/libs/brutal-alloc/global.c b/sources/libs/brutal-alloc/global.c index 90ecaeed8..0e1d6297b 100644 --- a/sources/libs/brutal-alloc/global.c +++ b/sources/libs/brutal-alloc/global.c @@ -2,43 +2,29 @@ #include "heap.h" -static Alloc *heap(void) -{ - static HeapAlloc heap; - static bool init = false; - - if (!init) - { - heap_alloc_init(&heap, NODE_DEFAULT); - init = true; - } - - return (Alloc *)&heap; -} - void *alloc_global_acquire(MAYBE_UNUSED Alloc *alloc, size_t size) { - embed_mem_lock(); - void *result = alloc_acquire(heap(), size); - embed_mem_unlock(); + embed_heap_lock(); + void *result = embed_heap_acquire(size); + embed_heap_unlock(); return result; } void *alloc_global_resize(MAYBE_UNUSED Alloc *alloc, void *ptr, size_t new_size) { - embed_mem_lock(); - void *result = alloc_resize(heap(), ptr, new_size); - embed_mem_unlock(); + embed_heap_lock(); + void *result = embed_heap_resize(ptr, new_size); + embed_heap_unlock(); return result; } void alloc_global_release(MAYBE_UNUSED Alloc *alloc, void *ptr) { - embed_mem_lock(); - alloc_release(heap(), ptr); - embed_mem_unlock(); + embed_heap_lock(); + embed_heap_release(ptr); + embed_heap_unlock(); } Alloc *alloc_global(void) diff --git a/sources/libs/brutal-alloc/heap.c b/sources/libs/brutal-alloc/heap.c index a23437622..d7b804b68 100644 --- a/sources/libs/brutal-alloc/heap.c +++ b/sources/libs/brutal-alloc/heap.c @@ -157,14 +157,16 @@ void *heap_alloc_acquire(HeapAlloc *alloc, size_t req_size) // CASE 2: It's a brand new block. if (maj->first == nullptr) { - maj->first = (HeapMinor *)((uintptr_t)maj + MAJOR_BLOCK_HEADER_SIZE); - - maj->first->magic = ALLOC_HEAP_MAGIC; - maj->first->prev = nullptr; - maj->first->next = nullptr; - maj->first->block = maj; - maj->first->size = size; - maj->first->req_size = req_size; + HeapMinor *min = (HeapMinor *)((uintptr_t)maj + MAJOR_BLOCK_HEADER_SIZE); + + min->magic = ALLOC_HEAP_MAGIC; + min->prev = nullptr; + min->next = nullptr; + min->block = maj; + min->size = size; + min->req_size = req_size; + + maj->first = min; maj->usage += size + MINOR_BLOCK_HEADER_SIZE; return (void *)((uintptr_t)(maj->first) + MINOR_BLOCK_HEADER_SIZE); @@ -182,7 +184,6 @@ void *heap_alloc_acquire(HeapAlloc *alloc, size_t req_size) maj->first->prev = (HeapMinor *)((uintptr_t)maj + MAJOR_BLOCK_HEADER_SIZE); maj->first->prev->next = maj->first; maj->first = maj->first->prev; - maj->first->magic = ALLOC_HEAP_MAGIC; maj->first->prev = nullptr; maj->first->block = maj; @@ -306,7 +307,6 @@ void heap_alloc_release(HeapAlloc *alloc, void *ptr) } HeapMajor *maj = min->block; - maj->usage -= (min->size + MINOR_BLOCK_HEADER_SIZE); min->magic = ALLOC_HEAP_DEAD; diff --git a/sources/libs/brutal-fmt/fmt.c b/sources/libs/brutal-fmt/fmt.c index 84817890a..482790411 100644 --- a/sources/libs/brutal-fmt/fmt.c +++ b/sources/libs/brutal-fmt/fmt.c @@ -325,6 +325,11 @@ IoResult fmt_unsigned(Fmt self, IoWriter writer, uint64_t value) buf[i++] = '0'; } + if (self.prefix_plus) + { + buf[i++] = '+'; + } + while (i < self.width) { buf[i++] = self.fill; diff --git a/sources/libs/brutal-gfx/font.h b/sources/libs/brutal-gfx/font.h index ef8c2237e..96f8687c8 100644 --- a/sources/libs/brutal-gfx/font.h +++ b/sources/libs/brutal-gfx/font.h @@ -7,7 +7,7 @@ struct _Gfx; /** - ``` + <- line_ascend _____ _ _ <- ascend / ____| | | | | <- captop @@ -19,7 +19,7 @@ struct _Gfx; |___/ <- descend | ---- | ...advance <- line_descend - ``` + */ typedef struct { diff --git a/sources/libs/brutal-test/hook-alloc.h b/sources/libs/brutal-test/hook-alloc.h index e298b3019..5316c01e1 100644 --- a/sources/libs/brutal-test/hook-alloc.h +++ b/sources/libs/brutal-test/hook-alloc.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "runner.h" diff --git a/sources/libs/embed/brutal/mem.c b/sources/libs/embed/brutal/mem.c index a4f0d53c6..a8f0d1357 100644 --- a/sources/libs/embed/brutal/mem.c +++ b/sources/libs/embed/brutal/mem.c @@ -1,16 +1,8 @@ #include +#include +#include #include -void embed_mem_lock(void) -{ - // NO-OP -} - -void embed_mem_unlock(void) -{ - // NO-OP -} - Error embed_mem_acquire(size_t size, void **out_result, MAYBE_UNUSED enum embed_mem_flag flags) { // Create the memory object @@ -63,3 +55,39 @@ Error embed_mem_release(void *addr, size_t size) return br_result_to_error(result); } + +static HeapAlloc _heap; + +static Alloc *ensure_heap(void) +{ + static bool init = false; + if (!init) + { + heap_alloc_init(&_heap, NODE_DEFAULT); + init = true; + } + return (Alloc *)&_heap; +} + +void embed_heap_lock(void) +{ +} + +void embed_heap_unlock(void) +{ +} + +void *embed_heap_acquire(size_t size) +{ + return alloc_acquire(ensure_heap(), size); +} + +void *embed_heap_resize(void *ptr, size_t size) +{ + return alloc_resize(ensure_heap(), ptr, size); +} + +void embed_heap_release(void *ptr) +{ + alloc_release(ensure_heap(), ptr); +} diff --git a/sources/libs/embed/efi/mem.c b/sources/libs/embed/efi/mem.c index 9b9a3ceb8..3d4e05154 100644 --- a/sources/libs/embed/efi/mem.c +++ b/sources/libs/embed/efi/mem.c @@ -1,7 +1,9 @@ +#include +#include +#include #include #include #include -#include Error embed_mem_acquire(size_t size, void **out_result, MAYBE_UNUSED enum embed_mem_flag flags) { @@ -23,10 +25,38 @@ Error embed_mem_release(void *addr, MAYBE_UNUSED size_t size) return ERR_SUCCESS; } -void embed_mem_lock(void) +static HeapAlloc _heap; + +static Alloc *ensure_heap(void) +{ + static bool init = false; + if (!init) + { + heap_alloc_init(&_heap, NODE_DEFAULT); + init = true; + } + return (Alloc *)&_heap; +} + +void embed_heap_lock(void) +{ +} + +void embed_heap_unlock(void) +{ +} + +void *embed_heap_acquire(size_t size) +{ + return alloc_acquire(ensure_heap(), size); +} + +void *embed_heap_resize(void *ptr, size_t size) { + return alloc_resize(ensure_heap(), ptr, size); } -void embed_mem_unlock(void) +void embed_heap_release(void *ptr) { + alloc_release(ensure_heap(), ptr); } diff --git a/sources/libs/embed/kernel/mem.c b/sources/libs/embed/kernel/mem.c index 81f37e478..05cfa37ce 100644 --- a/sources/libs/embed/kernel/mem.c +++ b/sources/libs/embed/kernel/mem.c @@ -1,20 +1,11 @@ -#include #include #include +#include + #include "kernel/heap.h" static Lock _lock; -void embed_mem_lock(void) -{ - lock_acquire(&_lock); -} - -void embed_mem_unlock(void) -{ - lock_release(&_lock); -} - Error embed_mem_acquire(size_t size, void **out_result, MAYBE_UNUSED enum embed_mem_flag flags) { HeapResult alloc_result = heap_alloc(size); @@ -35,3 +26,42 @@ Error embed_mem_release(void *addr, size_t size) heap_free((HeapRange){(uintptr_t)addr, size}); return ERR_SUCCESS; } + +static Lock _lock; +static HeapAlloc _heap; + +static Alloc *ensure_heap(void) +{ + static bool init = false; + if (!init) + { + heap_alloc_init(&_heap, NODE_DEFAULT); + init = true; + } + return (Alloc *)&_heap; +} + +void embed_heap_lock(void) +{ + lock_acquire(&_lock); +} + +void embed_heap_unlock(void) +{ + lock_release(&_lock); +} + +void *embed_heap_acquire(size_t size) +{ + return alloc_acquire(ensure_heap(), size); +} + +void *embed_heap_resize(void *ptr, size_t size) +{ + return alloc_resize(ensure_heap(), ptr, size); +} + +void embed_heap_release(void *ptr) +{ + alloc_release(ensure_heap(), ptr); +} diff --git a/sources/libs/embed/mem.h b/sources/libs/embed/mem.h index 3bd3e011b..6dfd446b3 100644 --- a/sources/libs/embed/mem.h +++ b/sources/libs/embed/mem.h @@ -12,10 +12,6 @@ enum embed_mem_flag EMBED_MEM_NONE, }; -void embed_mem_lock(void); - -void embed_mem_unlock(void); - Error embed_mem_acquire(size_t size, void **out_result, enum embed_mem_flag flags); Error embed_mem_release(void *addr, size_t size); @@ -23,3 +19,13 @@ Error embed_mem_release(void *addr, size_t size); void *embed_mem_set(void *d, uint8_t s, size_t c); void *embed_mem_copy(void *to, void const *from, size_t size); + +void embed_heap_lock(void); + +void embed_heap_unlock(void); + +void *embed_heap_acquire(size_t size); + +void *embed_heap_resize(void *ptr, size_t size); + +void embed_heap_release(void *ptr); diff --git a/sources/libs/embed/posix/mem.c b/sources/libs/embed/posix/mem.c index b0a20c35e..5d4bf74f8 100644 --- a/sources/libs/embed/posix/mem.c +++ b/sources/libs/embed/posix/mem.c @@ -1,8 +1,9 @@ +#include #include #include +#include #include #include -#include void embed_mem_lock(void) { @@ -35,3 +36,28 @@ Error embed_mem_release(void *addr, size_t size) return ERR_SUCCESS; } + +void embed_heap_lock(void) +{ + // no-op +} + +void embed_heap_unlock(void) +{ + // no-op +} + +void *embed_heap_acquire(size_t size) +{ + return calloc(1, size); +} + +void *embed_heap_resize(void *ptr, size_t size) +{ + return realloc(ptr, size); +} + +void embed_heap_release(void *ptr) +{ + free(ptr); +} diff --git a/sources/utils/test/brutal/fmt/printf.c b/sources/utils/test/brutal/fmt/printf.c index 0689e3122..e5c013ddb 100644 --- a/sources/utils/test/brutal/fmt/printf.c +++ b/sources/utils/test/brutal/fmt/printf.c @@ -50,4 +50,6 @@ test$(fmt_printf) TEST_CASE("00012", "%05d", 12); TEST_CASE("00123", "%05d", 123); TEST_CASE("0x123", "%#05x", 0x123); + TEST_CASE("0x123", "%#05x", 0x123); + TEST_CASE("0x123", "%#010x", 0x123); }