diff options
author | Marvin Borner | 2020-05-03 22:44:24 +0200 |
---|---|---|
committer | Marvin Borner | 2020-05-03 22:44:24 +0200 |
commit | 2ac25568839df7af2e271db9efa84bbd6fcb1f88 (patch) | |
tree | 3747958b729275c07115c579def55d246d72669e /src/kernel/memory | |
parent | 5a02853da5c454ff34e65ddaea5e677a3285bc79 (diff) |
Added missing memory functions
Diffstat (limited to 'src/kernel/memory')
-rw-r--r-- | src/kernel/memory/alloc.c | 14 | ||||
-rw-r--r-- | src/kernel/memory/alloc.h | 2 | ||||
-rw-r--r-- | src/kernel/memory/paging.c | 8 | ||||
-rw-r--r-- | src/kernel/memory/paging.h | 1 |
4 files changed, 25 insertions, 0 deletions
diff --git a/src/kernel/memory/alloc.c b/src/kernel/memory/alloc.c index 098eb75..825c639 100644 --- a/src/kernel/memory/alloc.c +++ b/src/kernel/memory/alloc.c @@ -165,6 +165,13 @@ void *kmalloc(uint32_t size) return malloc_internal(kheap, size); } +void *kcalloc(uint32_t num, uint32_t size) +{ + void *ptr = kmalloc(num * size); + memset(ptr, 0, num * size); + return ptr; +} + void kfree(void *address) { if (kheap == NULL) @@ -178,6 +185,13 @@ void *umalloc(size_t size) return malloc_internal(uheap, size); } +void *ucalloc(uint32_t num, uint32_t size) +{ + void *ptr = umalloc(num * size); + memset(ptr, 0, num * size); + return ptr; +} + void ufree(void *address) { free_internal(uheap, address); diff --git a/src/kernel/memory/alloc.h b/src/kernel/memory/alloc.h index 7ce5739..6739eeb 100644 --- a/src/kernel/memory/alloc.h +++ b/src/kernel/memory/alloc.h @@ -26,11 +26,13 @@ struct heap_footer { void kheap_init(); void *fmalloc(uint32_t size); +void *kcalloc(uint32_t num, uint32_t size); void *kmalloc(uint32_t size); void *kmalloc_a(uint32_t size); void kfree(void *ptr); void *umalloc(size_t size); +void *ucalloc(uint32_t num, uint32_t size); void ufree(void *address); void init_heap(struct heap_header *heap, size_t size); diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index f355449..67c471f 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -112,6 +112,14 @@ void paging_map_user(struct page_directory *dir, uint32_t phys, uint32_t virt) } } +// Hmm +uint32_t paging_get_phys(uint32_t virt) +{ + uint32_t pdi = virt >> 22; + uint32_t pti = (virt >> 12) & 0x03FF; + return (*(uint32_t *)&paging_current_directory->tables[pdi]->pages[pti]) & 0xFFFFF000; +} + void paging_install() { kheap_init(); diff --git a/src/kernel/memory/paging.h b/src/kernel/memory/paging.h index 1941cb9..a2ea396 100644 --- a/src/kernel/memory/paging.h +++ b/src/kernel/memory/paging.h @@ -36,6 +36,7 @@ void paging_switch_directory(struct page_directory *dir); struct page_directory *paging_make_directory(); struct page_table *paging_make_table(); +uint32_t paging_get_phys(uint32_t virt); void paging_install(); void paging_map(struct page_directory *cr3, uint32_t virt, uint32_t phys); |