1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00

detect stack overflow by adding a guard page

This commit is contained in:
Stefan Lankes 2016-05-14 09:13:39 +02:00
parent ecce99e54c
commit 3c79ad7aa0

View file

@ -333,10 +333,14 @@ int clone_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio)
curr_task = per_core(current_task);
stack = kmalloc(DEFAULT_STACK_SIZE);
stack = kmalloc(DEFAULT_STACK_SIZE + PAGE_SIZE);
if (BUILTIN_EXPECT(!stack, 0))
return -ENOMEM;
// unmap the first page to detect a stack overflow
page_unmap((size_t)stack, 1);
stack = (void*) ((size_t) stack + PAGE_SIZE);
spinlock_irqsave_lock(&table_lock);
core_id = get_next_core_id();
@ -419,10 +423,14 @@ int create_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio, uint32_t c
if (BUILTIN_EXPECT(!readyqueues[core_id].idle, 0))
return -EINVAL;
stack = kmalloc(DEFAULT_STACK_SIZE);
stack = kmalloc(DEFAULT_STACK_SIZE + PAGE_SIZE);
if (BUILTIN_EXPECT(!stack, 0))
return -ENOMEM;
// unmap the first page to detect a stack overflow
page_unmap((size_t)stack, 1);
stack = (void*) ((size_t) stack + PAGE_SIZE);
counter = kmalloc(sizeof(atomic_int64_t));
if (BUILTIN_EXPECT(!counter, 0)) {
kfree(stack);