diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/link.ld b/src/userland/link.ld index 0fe5e27..cd5fb81 100644 --- a/src/userland/link.ld +++ b/src/userland/link.ld @@ -21,7 +21,7 @@ *(.bss) . = ALIGN(4); allocationData = .; - . += 0x1000 * 12; + . += 4 * 12; } . = 0xFF000000; diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/link.ld b/src/userland/link.ld index 0fe5e27..cd5fb81 100644 --- a/src/userland/link.ld +++ b/src/userland/link.ld @@ -21,7 +21,7 @@ *(.bss) . = ALIGN(4); allocationData = .; - . += 0x1000 * 12; + . += 4 * 12; } . = 0xFF000000; diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 0f56bed..f48495c 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -8,7 +6,9 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pic"); loadFromInitrd("pit"); + loadFromInitrd("keyboard"); loadFromInitrd("mouse"); loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/link.ld b/src/userland/link.ld index 0fe5e27..cd5fb81 100644 --- a/src/userland/link.ld +++ b/src/userland/link.ld @@ -21,7 +21,7 @@ *(.bss) . = ALIGN(4); allocationData = .; - . += 0x1000 * 12; + . += 4 * 12; } . = 0xFF000000; diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 0f56bed..f48495c 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -8,7 +6,9 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pic"); loadFromInitrd("pit"); + loadFromInitrd("keyboard"); loadFromInitrd("mouse"); loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index d9700c3..fbbe21d 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include "pci.h" #include #include diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/link.ld b/src/userland/link.ld index 0fe5e27..cd5fb81 100644 --- a/src/userland/link.ld +++ b/src/userland/link.ld @@ -21,7 +21,7 @@ *(.bss) . = ALIGN(4); allocationData = .; - . += 0x1000 * 12; + . += 4 * 12; } . = 0xFF000000; diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 0f56bed..f48495c 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -8,7 +6,9 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pic"); loadFromInitrd("pit"); + loadFromInitrd("keyboard"); loadFromInitrd("mouse"); loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index d9700c3..fbbe21d 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include "pci.h" #include #include diff --git a/src/userland/mouse/main.c b/src/userland/mouse/main.c index 09713f4..a438b68 100644 --- a/src/userland/mouse/main.c +++ b/src/userland/mouse/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include volatile int32_t x = 0, y = 0; diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/link.ld b/src/userland/link.ld index 0fe5e27..cd5fb81 100644 --- a/src/userland/link.ld +++ b/src/userland/link.ld @@ -21,7 +21,7 @@ *(.bss) . = ALIGN(4); allocationData = .; - . += 0x1000 * 12; + . += 4 * 12; } . = 0xFF000000; diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 0f56bed..f48495c 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -8,7 +6,9 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pic"); loadFromInitrd("pit"); + loadFromInitrd("keyboard"); loadFromInitrd("mouse"); loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index d9700c3..fbbe21d 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include "pci.h" #include #include diff --git a/src/userland/mouse/main.c b/src/userland/mouse/main.c index 09713f4..a438b68 100644 --- a/src/userland/mouse/main.c +++ b/src/userland/mouse/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include volatile int32_t x = 0, y = 0; diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index a9b2dc5..7b2880b 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include #include diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/link.ld b/src/userland/link.ld index 0fe5e27..cd5fb81 100644 --- a/src/userland/link.ld +++ b/src/userland/link.ld @@ -21,7 +21,7 @@ *(.bss) . = ALIGN(4); allocationData = .; - . += 0x1000 * 12; + . += 4 * 12; } . = 0xFF000000; diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 0f56bed..f48495c 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -8,7 +6,9 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pic"); loadFromInitrd("pit"); + loadFromInitrd("keyboard"); loadFromInitrd("mouse"); loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index d9700c3..fbbe21d 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include "pci.h" #include #include diff --git a/src/userland/mouse/main.c b/src/userland/mouse/main.c index 09713f4..a438b68 100644 --- a/src/userland/mouse/main.c +++ b/src/userland/mouse/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include volatile int32_t x = 0, y = 0; diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index a9b2dc5..7b2880b 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include #include diff --git a/src/userland/pit/main.c b/src/userland/pit/main.c index 582335d..5b48159 100644 --- a/src/userland/pit/main.c +++ b/src/userland/pit/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #define PIT_A 0x40 @@ -22,10 +21,7 @@ #define CMD_COUNTER0 0x00 #define CMD_COUNTER2 0x80 -#include "../hlib/include/syscalls.h" - uint32_t systemTime = 0; -ListElement *sleepNotifications = NULL; uint32_t serviceId, timeEvent; bool initialized = false; diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/link.ld b/src/userland/link.ld index 0fe5e27..cd5fb81 100644 --- a/src/userland/link.ld +++ b/src/userland/link.ld @@ -21,7 +21,7 @@ *(.bss) . = ALIGN(4); allocationData = .; - . += 0x1000 * 12; + . += 4 * 12; } . = 0xFF000000; diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 0f56bed..f48495c 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -8,7 +6,9 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pic"); loadFromInitrd("pit"); + loadFromInitrd("keyboard"); loadFromInitrd("mouse"); loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index d9700c3..fbbe21d 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include "pci.h" #include #include diff --git a/src/userland/mouse/main.c b/src/userland/mouse/main.c index 09713f4..a438b68 100644 --- a/src/userland/mouse/main.c +++ b/src/userland/mouse/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include volatile int32_t x = 0, y = 0; diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index a9b2dc5..7b2880b 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include #include diff --git a/src/userland/pit/main.c b/src/userland/pit/main.c index 582335d..5b48159 100644 --- a/src/userland/pit/main.c +++ b/src/userland/pit/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #define PIT_A 0x40 @@ -22,10 +21,7 @@ #define CMD_COUNTER0 0x00 #define CMD_COUNTER2 0x80 -#include "../hlib/include/syscalls.h" - uint32_t systemTime = 0; -ListElement *sleepNotifications = NULL; uint32_t serviceId, timeEvent; bool initialized = false; diff --git a/src/userland/ps2/main.c b/src/userland/ps2/main.c index 37ad972..d14cc99 100644 --- a/src/userland/ps2/main.c +++ b/src/userland/ps2/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/link.ld b/src/userland/link.ld index 0fe5e27..cd5fb81 100644 --- a/src/userland/link.ld +++ b/src/userland/link.ld @@ -21,7 +21,7 @@ *(.bss) . = ALIGN(4); allocationData = .; - . += 0x1000 * 12; + . += 4 * 12; } . = 0xFF000000; diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 0f56bed..f48495c 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -8,7 +6,9 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pic"); loadFromInitrd("pit"); + loadFromInitrd("keyboard"); loadFromInitrd("mouse"); loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index d9700c3..fbbe21d 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include "pci.h" #include #include diff --git a/src/userland/mouse/main.c b/src/userland/mouse/main.c index 09713f4..a438b68 100644 --- a/src/userland/mouse/main.c +++ b/src/userland/mouse/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include volatile int32_t x = 0, y = 0; diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index a9b2dc5..7b2880b 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include #include diff --git a/src/userland/pit/main.c b/src/userland/pit/main.c index 582335d..5b48159 100644 --- a/src/userland/pit/main.c +++ b/src/userland/pit/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #define PIT_A 0x40 @@ -22,10 +21,7 @@ #define CMD_COUNTER0 0x00 #define CMD_COUNTER2 0x80 -#include "../hlib/include/syscalls.h" - uint32_t systemTime = 0; -ListElement *sleepNotifications = NULL; uint32_t serviceId, timeEvent; bool initialized = false; diff --git a/src/userland/ps2/main.c b/src/userland/ps2/main.c index 37ad972..d14cc99 100644 --- a/src/userland/ps2/main.c +++ b/src/userland/ps2/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/shell/main.c b/src/userland/shell/main.c index 7cb1e25..d74fa74 100644 --- a/src/userland/shell/main.c +++ b/src/userland/shell/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/link.ld b/src/userland/link.ld index 0fe5e27..cd5fb81 100644 --- a/src/userland/link.ld +++ b/src/userland/link.ld @@ -21,7 +21,7 @@ *(.bss) . = ALIGN(4); allocationData = .; - . += 0x1000 * 12; + . += 4 * 12; } . = 0xFF000000; diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 0f56bed..f48495c 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -8,7 +6,9 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pic"); loadFromInitrd("pit"); + loadFromInitrd("keyboard"); loadFromInitrd("mouse"); loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index d9700c3..fbbe21d 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include "pci.h" #include #include diff --git a/src/userland/mouse/main.c b/src/userland/mouse/main.c index 09713f4..a438b68 100644 --- a/src/userland/mouse/main.c +++ b/src/userland/mouse/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include volatile int32_t x = 0, y = 0; diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index a9b2dc5..7b2880b 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include #include diff --git a/src/userland/pit/main.c b/src/userland/pit/main.c index 582335d..5b48159 100644 --- a/src/userland/pit/main.c +++ b/src/userland/pit/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #define PIT_A 0x40 @@ -22,10 +21,7 @@ #define CMD_COUNTER0 0x00 #define CMD_COUNTER2 0x80 -#include "../hlib/include/syscalls.h" - uint32_t systemTime = 0; -ListElement *sleepNotifications = NULL; uint32_t serviceId, timeEvent; bool initialized = false; diff --git a/src/userland/ps2/main.c b/src/userland/ps2/main.c index 37ad972..d14cc99 100644 --- a/src/userland/ps2/main.c +++ b/src/userland/ps2/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/shell/main.c b/src/userland/shell/main.c index 7cb1e25..d74fa74 100644 --- a/src/userland/shell/main.c +++ b/src/userland/shell/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index d443b0f..35b4018 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -1,6 +1,4 @@ -#define ALLOC_MAIN #include - #include uint32_t serviceId, xhciEvent; diff --git a/link.ld b/link.ld index c4875c1..c5cf24d 100644 --- a/link.ld +++ b/link.ld @@ -31,6 +31,9 @@ .bss :AT(ADDR(.bss) - 0xFFB00000) { *(.bss) + . = ALIGN(4); + allocationData = .; + . += 4 * 12; . = ALIGN(4M); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 364956a..a8da877 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -79,8 +79,8 @@ extern void sleep(uint32_t millis); extern uint32_t fork(void (f)(), void *, void *, void *); -extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); -#define listAdd(list, data) _listAdd(malloc, list, data) +extern void _listAdd(AllocationData, ListElement **list, void *data); +#define listAdd(list, data) _listAdd(allocationData, list, data) extern void listClear(ListElement **list, bool freeData); #define REQUEST(functionName, service, function) \ @@ -100,4 +100,9 @@ return request(serviceId, functionId, data1, data2); \ } +extern void _printf(AllocationData, const char *format, ...); +extern char *_asprintf(AllocationData, const char *format, ...); +#define printf(...) _printf(allocationData, __VA_ARGS__) +#define asprintf(...) _asprintf(allocationData, __VA_ARGS__) + #endif diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 2bbb8fe..5f96d55 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -3,6 +3,7 @@ #include #include +#include "../kernel/memory/malloc.h" #define ADDRESS(pageId) PTR((pageId) << 12) #define PAGE_ID(address) (U32(address) >> 12) @@ -46,7 +47,6 @@ extern void unmapPage(void *pageAddress); extern void free(void *address); -extern void *malloc(uint32_t size); extern void *getPhysicalAddressKernel(void *address); extern void *getPhysicalAddress(PageDirectoryEntry *pageDirectory, diff --git a/src/kernel/main.c b/src/kernel/main.c index fd20d8d..538ad99 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,7 +1,5 @@ #include -#define ALLOC_MAIN #include "memory/malloc.h" - #include #include #include diff --git a/src/kernel/memory/malloc.c b/src/kernel/memory/malloc.c index 66efaf7..b166229 100644 --- a/src/kernel/memory/malloc.c +++ b/src/kernel/memory/malloc.c @@ -18,12 +18,12 @@ #define NULL 0 -void *_malloc(AllocationData *allocationData, uint32_t size) { +void *_malloc(AllocationData allocationData, uint32_t size) { uint32_t sizeBit = LOG2(size) + 1; if (sizeBit > 10) { return getPagesCount(((size - 1) >> 12) + 1); } - AllocationBlock *block = (*allocationData)[sizeBit], *last = 0; + AllocationBlock *block = allocationData[sizeBit], *last = 0; while (1) { if (!block) { block = getPage(); @@ -33,7 +33,7 @@ block->previous = last; last->next = block; } else { - (*allocationData)[sizeBit] = block; + allocationData[sizeBit] = block; block->previous = NULL; } block->magic = ALLOCATION_MAGIC; diff --git a/src/kernel/memory/malloc.h b/src/kernel/memory/malloc.h index eb4ccb9..c887791 100644 --- a/src/kernel/memory/malloc.h +++ b/src/kernel/memory/malloc.h @@ -25,25 +25,10 @@ typedef AllocationBlock *AllocationData[12]; +extern AllocationData allocationData; + extern void free(void *); - -extern void _printf(void *(malloc)(uint32_t), const char *format, ...); -extern char *_asprintf(void *(malloc)(uint32_t), const char *format, ...); - -#define printf(...) _printf(malloc, __VA_ARGS__) -#define asprintf(...) _asprintf(malloc, __VA_ARGS__) - -#ifdef ALLOC_MAIN -#undef ALLOC_MAIN - -AllocationData allocationData; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - -#else -extern void *malloc(uint32_t size); - -#endif +extern void *_malloc(AllocationData, uint32_t); +#define malloc(size) _malloc(allocationData, size) #endif diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 834c6a7..dc34680 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -1,10 +1,5 @@ #include -extern AllocationData allocationData[]; - -extern void *_malloc(void *, uintptr_t); -void *malloc(uint32_t size) { return _malloc(&allocationData, size); } - void testFunction() { printf("0/0 = %i\n", 0 / 0); } int32_t main() { diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index a7516d9..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/hlib/link.ld b/src/userland/hlib/link.ld index 3ff2142..e38b0df 100644 --- a/src/userland/hlib/link.ld +++ b/src/userland/hlib/link.ld @@ -6,7 +6,7 @@ .hlib : { *(.text) *(.rodata) - *(.data) + *(.data) *(.bss) } } diff --git a/src/userland/hlib/list.c b/src/userland/hlib/list.c index 0f2ee65..ffc0ed6 100644 --- a/src/userland/hlib/list.c +++ b/src/userland/hlib/list.c @@ -1,6 +1,6 @@ #include -void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data) { +void _listAdd(AllocationData allocationData, ListElement **list, void *data) { ListElement *element = malloc(sizeof(ListElement)); element->data = data; element->next = NULL; diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index ac4f9a5..43ac97d 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,7 +28,6 @@ if (!service) { return syscall(SYS_LOAD_INITRD, id, 1, 0, 0); } - request(service, 0, 0, 0); return service; } diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index fa8531f..e717154 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -170,7 +170,7 @@ va_end(valist); } -char *_asprintf(void *(malloc)(uint32_t), const char *format, ...) { +char *_asprintf(AllocationData allocationData, const char *format, ...) { va_list valist; va_start(valist, format); uint32_t size = printfSize(format, &valist); @@ -181,7 +181,7 @@ return data; } -void _printf(void *(malloc)(uint32_t), const char *format, ...) { +void _printf(AllocationData allocationData, const char *format, ...) { // I have absolutely no idea why this line fixes an issue where the first // printf operation consistently doesn't correctly insert its string free(malloc(1)); diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index 69ebfdb..03711c7 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -129,8 +127,6 @@ globalService = loadFromInitrd("parallel"); globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); createFunction("setForeground", (void *)setForeground); keyEvent = createEvent("keyPress"); newLineEvent = createEvent("newLine"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8725035..c72d8e2 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/link.ld b/src/userland/link.ld index 0fe5e27..cd5fb81 100644 --- a/src/userland/link.ld +++ b/src/userland/link.ld @@ -21,7 +21,7 @@ *(.bss) . = ALIGN(4); allocationData = .; - . += 0x1000 * 12; + . += 4 * 12; } . = 0xFF000000; diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 0f56bed..f48495c 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include @@ -8,7 +6,9 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pic"); loadFromInitrd("pit"); + loadFromInitrd("keyboard"); loadFromInitrd("mouse"); loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index d9700c3..fbbe21d 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include "pci.h" #include #include diff --git a/src/userland/mouse/main.c b/src/userland/mouse/main.c index 09713f4..a438b68 100644 --- a/src/userland/mouse/main.c +++ b/src/userland/mouse/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include volatile int32_t x = 0, y = 0; diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index a9b2dc5..7b2880b 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include #include diff --git a/src/userland/pit/main.c b/src/userland/pit/main.c index 582335d..5b48159 100644 --- a/src/userland/pit/main.c +++ b/src/userland/pit/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #define PIT_A 0x40 @@ -22,10 +21,7 @@ #define CMD_COUNTER0 0x00 #define CMD_COUNTER2 0x80 -#include "../hlib/include/syscalls.h" - uint32_t systemTime = 0; -ListElement *sleepNotifications = NULL; uint32_t serviceId, timeEvent; bool initialized = false; diff --git a/src/userland/ps2/main.c b/src/userland/ps2/main.c index 37ad972..d14cc99 100644 --- a/src/userland/ps2/main.c +++ b/src/userland/ps2/main.c @@ -1,4 +1,3 @@ -#define ALLOC_MAIN #include #include diff --git a/src/userland/shell/main.c b/src/userland/shell/main.c index 7cb1e25..d74fa74 100644 --- a/src/userland/shell/main.c +++ b/src/userland/shell/main.c @@ -1,5 +1,3 @@ -#define ALLOC_MAIN - #include #include diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index d443b0f..35b4018 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -1,6 +1,4 @@ -#define ALLOC_MAIN #include - #include uint32_t serviceId, xhciEvent; diff --git a/src/userland/vga/main.c b/src/userland/vga/main.c index 36c2a33..2875fcf 100644 --- a/src/userland/vga/main.c +++ b/src/userland/vga/main.c @@ -53,5 +53,4 @@ int32_t main() { videoSource = requestMemory(2, NULL, PTR(0xB8000)); createFunction("writeChar", (void *)write); - return 0; }