From a7dd2b3171f25a2aa7db3c80acc87ba52e51ba6d Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Fri, 21 Feb 2014 10:59:39 +0100 Subject: [PATCH] base: ABI specific stack creation ref #1042 --- base/include/arm/cpu/consts.h | 6 ++++++ base/include/x86/cpu/consts.h | 14 ++++++++++++++ base/src/base/thread/thread.cc | 7 +------ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/base/include/arm/cpu/consts.h b/base/include/arm/cpu/consts.h index 39758f6ba..5f3180d1e 100644 --- a/base/include/arm/cpu/consts.h +++ b/base/include/arm/cpu/consts.h @@ -17,11 +17,17 @@ #include namespace Abi { + /** * On ARM a call (or branch) will not change the stack pointer, so we do not * need stack adjustment */ static constexpr Genode::size_t stack_adjustment() { return 0; } + + /** + * Do ABI specific initialization to a freshly created stack + */ + inline void init_stack(Genode::addr_t) { } } #endif /* _INCLUDE__ARM__CPU__CONSTS_H_ */ diff --git a/base/include/x86/cpu/consts.h b/base/include/x86/cpu/consts.h index d8c6edef2..8ca567911 100644 --- a/base/include/x86/cpu/consts.h +++ b/base/include/x86/cpu/consts.h @@ -39,6 +39,20 @@ namespace Abi { * On x86 a call will result in a growth of the stack by machine word size */ static constexpr Genode::size_t stack_adjustment() { return sizeof(Genode::addr_t); } + + /** + * Do ABI specific initialization to a freshly created stack + * + * \param stack_top top of the stack + */ + inline void init_stack(Genode::addr_t const stack_top) + { + /* + * The value at the top of the stack might get interpreted as return + * address of the thread start function by GDB, so we set it to 0. + */ + *(Genode::addr_t *)stack_top = 0; + } } #endif /* _INCLUDE__X86__CPU__CONSTS_H_ */ diff --git a/base/src/base/thread/thread.cc b/base/src/base/thread/thread.cc index ff1938ea7..71aa008cc 100644 --- a/base/src/base/thread/thread.cc +++ b/base/src/base/thread/thread.cc @@ -91,12 +91,7 @@ Thread_base::_alloc_context(size_t stack_size, bool main_thread) context->stack_base = ds_addr; context->ds_cap = ds_cap; - /* - * The value at the top of the stack might get interpreted as return - * address of the thread start function by GDB, so we set it to 0. - */ - *(addr_t*)context->stack_top() = 0; - + Abi::init_stack(context->stack_top()); return context; }