linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: liqin.chen@sunplusct.com
Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
	Arnd Bergmann <arnd@arndb.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	torvalds@linux-foundation.org
Subject: Re: [PATCH 21/27] score: create kernel files ptrace.c setup.c
Date: Mon, 15 Jun 2009 07:02:40 -0400	[thread overview]
Message-ID: <20090615110240.GA16735@infradead.org> (raw)
In-Reply-To: <OF9E916A44.859476BA-ON482575D0.00243015-482575D0.0024A03A@sunplusct.com>

On Tue, Jun 09, 2009 at 02:35:45PM +0800, liqin.chen@sunplusct.com wrote:
> +long
> +arch_ptrace(struct task_struct *child, long request, long addr, long 
> data)
> +{
> +       int ret;
> +
> +       if (request == PTRACE_TRACEME) {
> +               /* are we already being traced? */
> +               if (current->ptrace & PT_PTRACED)
> +                       return -EPERM;
> +
> +               /* set the ptrace bit in the process flags. */
> +               current->ptrace |= PT_PTRACED;
> +               return 0;
> +       }
> +
> +       ret = -ESRCH;
> +       if (!child)
> +               return ret;
> +
> +       ret = -EPERM;
> +
> +       if (request == PTRACE_ATTACH) {
> +               ret = ptrace_attach(child);
> +               return ret;
> +       }
> +
> +       ret = ptrace_check_attach(child, request == PTRACE_KILL);
> +       if (ret < 0)
> +               return ret;
> +

All this stuff has been done by generic ptrace code for a long time
and is not needed at all.

> +       switch (request) {
> +       case PTRACE_PEEKTEXT: /* read word at location addr. */
> +       case PTRACE_PEEKDATA: {
> +               unsigned long tmp;
> +               int copied;
> +
> +               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 
> 0);
> +               ret = -EIO;
> +               if (copied != sizeof(tmp))
> +                       break;
> +
> +               ret = put_user(tmp, (unsigned long *) data);
> +               return ret;
> +       }
> +

This also has a generic implementation.  Please take a look at a modern
ptrace implementation like sh, powerpc or x86 to model yours after.

      reply	other threads:[~2009-06-15 11:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-09  6:35 [PATCH 21/27] score: create kernel files ptrace.c setup.c liqin.chen
2009-06-15 11:02 ` Christoph Hellwig [this message]

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=20090615110240.GA16735@infradead.org \
    --to=hch@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liqin.chen@sunplusct.com \
    --cc=torvalds@linux-foundation.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).