aboutsummaryrefslogtreecommitdiff
path: root/core/utils.c
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2014-11-18 14:43:47 +1100
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2014-11-18 14:43:47 +1100
commit20410452b956edaf7790803d441768fbf707b36c (patch)
treee72d2826778c8c51c91641788bebb5892379d9be /core/utils.c
parentefa6bbc48ff549cd70352106b8d93f6e156295f5 (diff)
downloadskiboot-20410452b956edaf7790803d441768fbf707b36c.zip
skiboot-20410452b956edaf7790803d441768fbf707b36c.tar.gz
skiboot-20410452b956edaf7790803d441768fbf707b36c.tar.bz2
Rename backtrace.c to stack.c and move stack related bits
... from util.c to stack.c Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'core/utils.c')
-rw-r--r--core/utils.c81
1 files changed, 0 insertions, 81 deletions
diff --git a/core/utils.c b/core/utils.c
index 1b1a8bf..63046fc 100644
--- a/core/utils.c
+++ b/core/utils.c
@@ -68,84 +68,3 @@ char __attrconst tohex(uint8_t nibble)
return __tohex[nibble];
}
-void __noreturn __nomcount __stack_chk_fail(void);
-void __noreturn __nomcount __stack_chk_fail(void)
-{
- prlog(PR_EMERG, "Stack corruption detected !\n");
- abort();
-}
-
-#ifdef STACK_CHECK_ENABLED
-
-void __nomcount __mcount_stack_check(uint64_t sp, uint64_t lr);
-void __nomcount __mcount_stack_check(uint64_t sp, uint64_t lr)
-{
- struct cpu_thread *c = this_cpu();
- uint64_t base = (uint64_t)c;
- uint64_t bot = base + sizeof(struct cpu_thread);
- int64_t mark = sp - bot;
- uint64_t top = base + NORMAL_STACK_SIZE;
-
- /*
- * Don't re-enter on this CPU or don't enter at all if somebody
- * has spotted an overflow
- */
- if (c->in_mcount)
- return;
- c->in_mcount = true;
-
- /* Capture lowest stack for this thread */
- if (mark < c->stack_bot_mark) {
- c->stack_bot_mark = mark;
- c->stack_bot_pc = lr;
- c->stack_bot_tok = c->current_token;
- }
-
- /* Stack is within bounds ? check for warning and bail */
- if (sp >= (bot + STACK_SAFETY_GAP) && sp < top) {
- if (mark < STACK_WARNING_GAP) {
- prlog(PR_EMERG, "CPU %04x Stack usage danger !"
- " pc=%08llx sp=%08llx (gap=%lld) token=%lld\n",
- c->pir, lr, sp, mark, c->current_token);
- backtrace();
- }
- c->in_mcount = false;
- return;
- }
-
- prlog(PR_EMERG, "CPU %04x Stack overflow detected !"
- " pc=%08llx sp=%08llx (gap=%lld) token=%lld\n",
- c->pir, lr, sp, mark, c->current_token);
- abort();
-}
-
-static int64_t lowest_stack_mark = LONG_MAX;
-static struct lock stack_check_lock = LOCK_UNLOCKED;
-
-void check_stacks(void)
-{
- struct cpu_thread *c;
- uint64_t lmark, lpc, ltok;
- int found = -1;
-
- for_each_cpu(c) {
- if (!c->stack_bot_mark ||
- c->stack_bot_mark >= lowest_stack_mark)
- continue;
- lock(&stack_check_lock);
- if (c->stack_bot_mark >= lowest_stack_mark) {
- unlock(&stack_check_lock);
- continue;
- }
- lmark = lowest_stack_mark = c->stack_bot_mark;
- lpc = c->stack_bot_pc;
- ltok = c->stack_bot_tok;
- found = c->pir;
- unlock(&stack_check_lock);
- }
- if (found >= 0)
- prlog(PR_NOTICE, "CPU %04x lowest stack mark %lld bytes left"
- " pc=%08llx token=%lld\n", found, lmark, lpc, ltok);
-}
-
-#endif /* STACK_CHECK_ENABLED */