public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Jeff Dike <jdike@addtoit.com>
Cc: Andrew Morton <akpm@osdl.org>,
	LKML <linux-kernel@vger.kernel.org>,
	uml-devel <user-mode-linux-devel@lists.sourceforge.net>
Subject: Re: [PATCH 3/4] UML - Implement get_wchan
Date: Tue, 30 Oct 2007 10:40:46 -0700	[thread overview]
Message-ID: <1193766046.24844.19.camel@localhost> (raw)
In-Reply-To: <20071030172849.GA8367@c2.user-mode-linux.org>

On Tue, 2007-10-30 at 13:28 -0400, Jeff Dike wrote:
> +unsigned long get_wchan(struct task_struct *p)
> +{
> +	unsigned long stack_page, sp, ip, count = 0;

Perhaps instead of unsigned long?

bool skipped_ip;	//delayed initialization

> +
> +	if ((p == NULL) || (p == current) || (p->state == TASK_RUNNING))
> +		return 0;
> +
> +	stack_page = (unsigned long) task_stack_page(p);
> +	/* Bail if the process has no kernel stack for some reason */
> +	if (stack_page == 0)
> +		return 0;
> +
> +	sp = p->thread.switch_buf->JB_SP;
> +	/*
> +	 * Bail if the stack pointer is below the bottom of the kernel
> +	 * stack for some reason
> +	 */
> +	if (sp < stack_page)
> +		return 0;
> +

	skipped_ip = false;

> +	while (sp < stack_page + THREAD_SIZE) {
> +		ip = *((unsigned long *) sp);
> +		if (kernel_text_address(ip) && !in_sched_functions(ip)) {
> +			/*
> +			 * Skip one valid IP, which will be the low-level UML
> +			 * context switcher.
> +			 */
> +			if (count++ == 1)
> +				return ip;

			if (skipped_ip)
				return ip;
			skipped_ip = true;
> 
> +		}
> +
> +		sp += sizeof(unsigned long);
> +	}



  reply	other threads:[~2007-10-30 17:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-30 17:28 [PATCH 3/4] UML - Implement get_wchan Jeff Dike
2007-10-30 17:40 ` Joe Perches [this message]
2007-10-30 17:56   ` Jeff Dike

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=1193766046.24844.19.camel@localhost \
    --to=joe@perches.com \
    --cc=akpm@osdl.org \
    --cc=jdike@addtoit.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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