Re: Going up the call stack on a system call

Andi Kleen (ak@muc.de)
Sun, 21 Nov 1999 22:22:58 +0100


On Sun, Nov 21, 1999 at 04:03:25PM -0500, Karim Yaghmour wrote:
> Andi Kleen wrote:
> >
> > A much simpler alternative: send some signal (e.g. SIGPWR) with send_sig(),
> > then return with -ERESTARTSYS if you want to be restarted, or some other
> > return value if you don't. Then the user can dump the backtrace with glibc's
> > backtrace() function or with gdb. They work with shared libraries too.
> >
>
> Actually this is for the Linux Trace Toolkit, therefore traces
> have to be done in the kernel and that's why I'm implementing
> backtracing in the kernel. The recording of the instruction
> pointer of the caller has to, therefore, be done transparently
> without affecting or modifying the system's behavior.
>
> That said, I changed the code I posted to the following, this
> is what's in the current LTT release and it doesn't crash
> klogd and others now :
>
> /* Are we in the kernel (This is a kernel thread)? */
> if(!(regs->xcs & 3))
> /* Don't go digining anywhere */
> goto prepare_end;
>
> ....
>
> /* Keep on going until we reach the end of the process' stack limit (wherever it may be) */
> while( (((unsigned long)stack > current->mm->start_data)
> &&((unsigned long)stack < current->mm->end_data))
> ||(((unsigned long)stack > current->mm->start_brk)
> &&((unsigned long)stack < current->mm->brk))
> ||(((unsigned long)stack > current->mm->start_stack - current->rlim[RLIMIT_STACK].rlim_cur)
> &&((unsigned long)stack < current->mm->start_stack)))
> {
> /* Get the current "address" off the stack, if it is addressable */
> addr = *stack;
>
> Will this still crash the machine if the page is swaped out?

It'll not crash the machine for the swapped out case, but it is unsafe
(e.g. when someone calls munmap for the brk region inbetween or when the
page can not be swapped in)

> Won't it simply generate a page fault which will result in
> the page being brought back to memory? If it's the later,
> it is still unacceptable since there's a modification to
> the system's behavior, which is precisely what I want to
> avoid.

It'll cause a kernel oops when the address is not mapped.
You need the special exception handlers the *_user functions set up
to catch it.
Also accessing the user space directly this way is not portable (e.g.
it won't work on the m68k or sparc port, it only works by accident in the
current x86 port because the user space is 1:1 mapped)

The rule is simple: for all user space accesses use *_user(). I don't know
why you don't want it.

-Andi

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/