lkml.org 
[lkml]   [2003]   [May]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: top stack (l)users for 2.5.69
On Wed, 7 May 2003 13:14:14 -0700, Dave Hansen wrote:
> Jörn Engel wrote:
> >>The stack overflow checking in -mjb uses gcc's mcount mechanism to
> >>detect overflows. It should get called on every single function call.
> >
> > Nice trick. Do you have better documentation on that machanism than
> > man gcc? The paragraph to -p is quite short and I cannot make the
> > connection to the rest of the patch immediately.
>
> It is a nice trick, but I didn't write it :) I stole the code from Ben
> LaHaise, around 2.5.20. All that I've needed to know to maintain the
> patch is that a "jmp mcount" gets placed in the critical places.

Sure. But exactly that information is not contained in the manpage (as
of Debians 3.2.3). I guess I'll have to dig deeper.

> I've attached a fairly recent version of the stack check patch. If you
> need some more examples, check out kernprof's use of it. It's acg
> functionality used mcount as well.

Oh, kernprof was too advanced already. It basically worked out of the
box for me, porting it to ppc took maybe one hour, not counting a
linker problem that was loosely related to that patch. Never bothered
to really understand what it does. :(

> diff -Nru a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
> --- a/arch/i386/kernel/process.c Mon Jan 27 11:40:03 2003
> +++ b/arch/i386/kernel/process.c Mon Jan 27 11:40:03 2003
> @@ -159,7 +159,22 @@
>
> __setup("idle=", idle_setup);
>
> -void show_regs(struct pt_regs * regs)
> +void stack_overflow(unsigned long esp, unsigned long eip)
> +{
> + int panicing = ((esp&(THREAD_SIZE-1)) <= STACK_PANIC);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +
> + if (panicing)
> + print_symbol("stack overflow from %s\n", eip);
> + else
> + print_symbol("excessive stack use from %s\n", eip);
> + printk("esp: %p\n", (void*)esp);
> + show_trace((void*)esp);
> +
> + if (panicing)
> + panic("stack overflow\n");
> +}
> +
> +asmlinkage void show_regs(struct pt_regs * regs)
> {
> unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;

> diff -Nru a/include/asm-i386/thread_info.h b/include/asm-i386/thread_info.h
> --- a/include/asm-i386/thread_info.h Mon Jan 27 11:40:03 2003
> +++ b/include/asm-i386/thread_info.h Mon Jan 27 11:40:03 2003
> @@ -63,6 +63,8 @@
> */
> #define THREAD_ORDER 1
> #define INIT_THREAD_SIZE THREAD_SIZE
> +#define STACK_PANIC 0x200ul
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +#define STACK_WARN ((THREAD_SIZE)>>1)

> #ifndef __ASSEMBLY__

If I read this correctly, your patch doesn't catch everything, if
there are functions remaining that use stack frames >0x200ul. Ok,
tell me I'm wrong and should go through the assembler code first.

Jörn

--
Fantasy is more important than knowlegde. Knowlegde is limited,
while fantasy embraces the whole world.
-- Albert Einstein
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:35    [from the cache]
©2003-2011 Jasper Spaans