lkml.org 
[lkml]   [2008]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: Make the 32 bit Frame Pointer backtracer fall back to traditional


On Wed, 9 Jan 2008, Arjan van de Ven wrote:
>
> + if (valid_stack_ptr(tinfo, frame, sizeof(*frame)))
> + while (valid_stack_ptr(tinfo, frame, sizeof(*frame))) {

Why?

Why not just make this something like the appended instead?

This is *totally* untested, but the basic notion is very simple: start off
using the frame pointer until it is no longer valid (for any reason -
whether the return address is corrupt, or the next frame info is bad), and
update the stack pointer a you go.

When we've run out of frame pointers, we then scan any remaining stack the
oldfashioned way, regardless of what happened. No unnecessary conditionals
that will just mean that we don't show enough of the stack if *part* of it
is corrupt.

The code is simpler and more robust (assuming it works - as mentioned, I
didn't actually test it, so there may be some stupid thinko there).

Linus

---
arch/x86/kernel/traps_32.c | 27 +++++++++++++++------------
1 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/traps_32.c b/arch/x86/kernel/traps_32.c
index c88bbff..36714d7 100644
--- a/arch/x86/kernel/traps_32.c
+++ b/arch/x86/kernel/traps_32.c
@@ -107,6 +107,11 @@ static inline int valid_stack_ptr(struct thread_info *tinfo, void *p, unsigned s
p <= (void *)tinfo + THREAD_SIZE - size;
}

+static inline int valid_frame_ptr(struct thread_info *tinfo, void *stack, void *p, unsigned size)
+{
+ return p >= stack && valid_stack_ptr(tinfo, p, size);
+}
+
/* The form of the top of the frame on the stack */
struct stack_frame {
struct stack_frame *next_frame;
@@ -119,24 +124,23 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
{
#ifdef CONFIG_FRAME_POINTER
struct stack_frame *frame = (struct stack_frame *)ebp;
- while (valid_stack_ptr(tinfo, frame, sizeof(*frame))) {
- struct stack_frame *next;
+ while (valid_frame_ptr(tinfo, stack, frame, sizeof(*frame))) {
unsigned long addr;

addr = frame->return_address;
+ if (!__kernel_text_address(addr))
+ break;
ops->address(data, addr);
+
/*
- * break out of recursive entries (such as
- * end_of_stack_stop_unwind_function). Also,
- * we can never allow a frame pointer to
- * move downwards!
+ * Update the stack pointer to past the return
+ * address we just printed out, and try the next
+ * frame..
*/
- next = frame->next_frame;
- if (next <= frame)
- break;
- frame = next;
+ stack = 1+&frame->return_address;
+ frame = frame->next_frame;
}
-#else
+#endif
while (valid_stack_ptr(tinfo, stack, sizeof(*stack))) {
unsigned long addr;

@@ -144,7 +148,6 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
if (__kernel_text_address(addr))
ops->address(data, addr);
}
-#endif
return ebp;
}


\
 
 \ /
  Last update: 2008-01-10 17:41    [W:0.102 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site