add: ksize and vsize

This commit is contained in:
starnakin 2024-09-26 17:06:03 +02:00
parent a66f9174f4
commit 0bcc99997a
4 changed files with 20 additions and 1 deletions

View File

@ -89,3 +89,5 @@ void vfree(void *ptr);
void *vrealloc(void *ptr, size_t size); void *vrealloc(void *ptr, size_t size);
void show_kalloc_mem(void); void show_kalloc_mem(void);
void show_valloc_mem(void); void show_valloc_mem(void);
size_t ksize(void* virt_addr);
size_t vsize(void* virt_addr);

View File

@ -33,6 +33,7 @@ void kernel_main(void)
kprintf(KERN_NOTICE "KERN_NOTICE\n"); kprintf(KERN_NOTICE "KERN_NOTICE\n");
kprintf(KERN_INFO "KERN_INFO\n"); kprintf(KERN_INFO "KERN_INFO\n");
kprintf(KERN_DEBUG "KERN_DEBUG\n"); kprintf(KERN_DEBUG "KERN_DEBUG\n");
vmalloc(10); void *ptr = vmalloc(100);
kprintf("%d\n", ksize(ptr));
shell_init(); shell_init();
} }

8
src/memory/phys/ksize.c Normal file
View File

@ -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;
}

8
src/memory/virt/vsize.c Normal file
View File

@ -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;
}