diff --git a/headers/alloc.h b/headers/alloc.h index 2402b83..fac395a 100644 --- a/headers/alloc.h +++ b/headers/alloc.h @@ -89,3 +89,5 @@ void vfree(void *ptr); void *vrealloc(void *ptr, size_t size); void show_kalloc_mem(void); void show_valloc_mem(void); +size_t ksize(void* virt_addr); +size_t vsize(void* virt_addr); \ No newline at end of file diff --git a/src/kernel.c b/src/kernel.c index 5e0f8c3..618f008 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -33,6 +33,7 @@ void kernel_main(void) kprintf(KERN_NOTICE "KERN_NOTICE\n"); kprintf(KERN_INFO "KERN_INFO\n"); kprintf(KERN_DEBUG "KERN_DEBUG\n"); - vmalloc(10); + void *ptr = vmalloc(100); + kprintf("%d\n", ksize(ptr)); shell_init(); } diff --git a/src/memory/phys/ksize.c b/src/memory/phys/ksize.c new file mode 100644 index 0000000..200ab61 --- /dev/null +++ b/src/memory/phys/ksize.c @@ -0,0 +1,8 @@ +#include "alloc.h" + +size_t ksize(void *ptr) +{ + Block *meta_data = (Block *)((size_t)ptr - sizeof(Block)); + + return meta_data->sub_size; +} \ No newline at end of file diff --git a/src/memory/virt/vsize.c b/src/memory/virt/vsize.c new file mode 100644 index 0000000..d2bfb13 --- /dev/null +++ b/src/memory/virt/vsize.c @@ -0,0 +1,8 @@ +#include "alloc.h" + +size_t vsize(void *ptr) +{ + Block *meta_data = (Block *)((size_t)ptr - sizeof(Block)); + + return meta_data->sub_size; +} \ No newline at end of file