linux-parisc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Randolph Chung <randolph@tausq.org>
To: Helge Deller <deller@gmx.de>
Cc: linux-parisc@vger.kernel.org, Kyle McMartin <kyle@mcmartin.ca>
Subject: Re: [PATCH] parisc: add CALLER_ADDR{0-6} macros
Date: Tue, 27 Oct 2009 12:49:49 +0800	[thread overview]
Message-ID: <4AE67BED.8040705@tausq.org> (raw)
In-Reply-To: <20091025214836.GA15038@p100.box>

Helge,

> +unsigned long return_address(unsigned int level)
> +{
> +	struct unwind_frame_info info;
> +	struct pt_regs r;
> +	unsigned long sp;
> +
> +	/* initialize unwind info */
> +	asm volatile ("copy %%r30, %0" : "=r"(sp));
> +	memset(&r, 0, sizeof(struct pt_regs));
> +	r.iaoq[0] = (unsigned long) current_text_addr();
> +	r.gr[2] = (unsigned long) __builtin_return_address(0);
> +	r.gr[30] = sp;
> +	unwind_frame_init(&info, current, &r);
> +
> +	/* unwind stack */
> +	++level;
> +	do {
> +		if (unwind_once(&info) < 0 || info.ip == 0)
> +			return 0;
> +		if (!__kernel_text_address(info.ip)) {
> +			return 0;
> +		}
> +	} while (info.ip && level--);
> +
> +	return info.ip;
> +}
> +

Can you show an objdump of this function once it is compiled? I suspect 
the stack pointer initialization here is not reliable.

Ideally unwind_frame_init is called with the frame address in gr[30]. 
With a big struct like pt_regs on the stack, the sp initialization might 
be quite far from the actual frame address.

The unwind_once() code uses like heuristics to try to recover from 
inaccurate stack pointers (by aligning and stepping the frame 64 bytes 
at a time) but that is really a brute force guess.

I realize I used a similar construct in traps.c, but even there I think 
it doesn't work reliably.

Maybe somebody else on the list (Dave? :) can suggest a better way to do 
this.

randolph

  reply	other threads:[~2009-10-27  4:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-25 21:48 [PATCH] parisc: add CALLER_ADDR{0-6} macros Helge Deller
2009-10-27  4:49 ` Randolph Chung [this message]
2009-10-27 13:41   ` Helge Deller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AE67BED.8040705@tausq.org \
    --to=randolph@tausq.org \
    --cc=deller@gmx.de \
    --cc=kyle@mcmartin.ca \
    --cc=linux-parisc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).