diff options
author | Damjan Marion <damarion@cisco.com> | 2020-09-11 22:25:34 +0200 |
---|---|---|
committer | Damjan Marion <damarion@cisco.com> | 2020-09-17 12:38:41 +0200 |
commit | fc639ff2d7abd8599f59078fac99f731026215b3 (patch) | |
tree | d8b8beef5c4f92b0cead53e363ee6d01c1a092ac /src/vlib/unix/main.c | |
parent | 6bfd07670b991c30761ef74fb09f42181dbfd182 (diff) |
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 <damarion@cisco.com>
Diffstat (limited to 'src/vlib/unix/main.c')
-rw-r--r-- | src/vlib/unix/main.c | 19 |
1 files changed, 9 insertions, 10 deletions
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 |