[task] Make sure we free everything. WARNING: this actually breaks some things as is

This commit is contained in:
Kevin Lange 2011-04-11 20:05:40 -05:00
parent b66432c94f
commit 7eb44a784b
3 changed files with 30 additions and 0 deletions

View File

@ -346,6 +346,12 @@ static void klmalloc_skip_list_insert(klmalloc_big_bin_header * value) {
*/
assert(value != NULL);
assert(value->head != NULL);
assert((uintptr_t)value->head > (uintptr_t)value);
if (value->size > NUM_BINS) {
assert((uintptr_t)value->head < (uintptr_t)value + value->size);
} else {
assert((uintptr_t)value->head < (uintptr_t)value + PAGE_SIZE);
}
assert((uintptr_t)value % PAGE_SIZE == 0);
assert((value->size + sizeof(klmalloc_big_bin_header)) % PAGE_SIZE == 0);
assert(value->size != 0);
@ -415,6 +421,12 @@ static void klmalloc_skip_list_delete(klmalloc_big_bin_header * value) {
*/
assert(value != NULL);
assert(value->head);
assert((uintptr_t)value->head > (uintptr_t)value);
if (value->size > NUM_BINS) {
assert((uintptr_t)value->head < (uintptr_t)value + value->size);
} else {
assert((uintptr_t)value->head < (uintptr_t)value + PAGE_SIZE);
}
/*
* Starting from the bin header, again...
@ -507,6 +519,12 @@ static void * klmalloc_stack_pop(klmalloc_bin_header *header) {
*/
static void klmalloc_stack_push(klmalloc_bin_header *header, void *ptr) {
assert(ptr != NULL);
assert((uintptr_t)ptr > (uintptr_t)header);
if (header->size > NUM_BINS) {
assert((uintptr_t)ptr < (uintptr_t)header + header->size);
} else {
assert((uintptr_t)ptr < (uintptr_t)header + PAGE_SIZE);
}
size_t **item = (size_t **)ptr;
*item = (size_t *)header->head;
header->head = item;
@ -596,6 +614,7 @@ static void * __attribute__ ((malloc)) klmalloc(size_t size) {
*/
klmalloc_big_bin_header * bin_header = klmalloc_skip_list_findbest(size);
if (bin_header) {
assert(bin_header->size >= size);
/*
* If we found one, delete it from the skip list
*/

View File

@ -248,6 +248,8 @@ void task_exit(int retval) {
prev->next = current_task->next;
}
free((void *)current_task->stack);
free((void *)current_task->page_directory);
free((void *)current_task);
__asm__ __volatile__ ("sti");
}

View File

@ -35,6 +35,8 @@
#include <boot.h>
#include <ext2.h>
extern uintptr_t heap_end;
/*
* kernel entry point
*
@ -154,5 +156,12 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
start_shell();
while (1) {
if (!fork()) {
kprintf("%d 0x%x\n", getpid(), heap_end);
kexit(0);
}
}
return 0;
}