From fc639ff2d7abd8599f59078fac99f731026215b3 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Fri, 11 Sep 2020 22:25:34 +0200 Subject: vlib: map thread stack instead of allocating them from heap Heap may use different page sizes so we will not be able to create stack protection page. Type: improvement Change-Id: Ibb35c9f0a151c464ee0167d17f2bd773ef6f530b Signed-off-by: Damjan Marion --- src/vlib/unix/main.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/vlib/unix/main.c') diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c index 95aeecf2da2..9dde666bbef 100644 --- a/src/vlib/unix/main.c +++ b/src/vlib/unix/main.c @@ -666,18 +666,17 @@ thread0 (uword arg) u8 * vlib_thread_stack_init (uword thread_index) { + void *stack; ASSERT (thread_index < vec_len (vlib_thread_stacks)); - vlib_thread_stacks[thread_index] = clib_mem_alloc_aligned - (VLIB_THREAD_STACK_SIZE, clib_mem_get_page_size ()); + stack = clib_mem_vm_map_stack (VLIB_THREAD_STACK_SIZE, + CLIB_MEM_PAGE_SZ_DEFAULT, + "thread stack: thread %u", thread_index); - /* - * Disallow writes to the bottom page of the stack, to - * catch stack overflows. - */ - if (mprotect (vlib_thread_stacks[thread_index], - clib_mem_get_page_size (), PROT_READ) < 0) - clib_unix_warning ("thread stack"); - return vlib_thread_stacks[thread_index]; + if (stack == CLIB_MEM_VM_MAP_FAILED) + clib_panic ("failed to allocate thread %u stack", thread_index); + + vlib_thread_stacks[thread_index] = stack; + return stack; } int -- cgit 1.2.3-korg