linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael Kerrisk (man-pages)" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Andrey Vagin <avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	criu-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Roland McGrath <roland-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Oleg Nesterov <oleg-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Andrew Morton
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	"Paul E. McKenney"
	<paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>,
	David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Dave Jones <davej-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Pavel Emelyanov <xemul-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>,
	Linus Torvalds
	<torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Subject: Re: [PATCH] ptrace: add ability to retrieve signals without removing them from a queue
Date: Tue, 19 Feb 2013 13:15:06 +0100	[thread overview]
Message-ID: <CAKgNAkicAGEkvNFnSso__wK6QKao8jyDu5yuRmeyUOeaXLGChw@mail.gmail.com> (raw)
In-Reply-To: <1360768595-31943-1-git-send-email-avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>

On Wed, Feb 13, 2013 at 4:16 PM, Andrey Vagin <avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org> wrote:
> This patch adds a new ptrace request PTRACE_PEEKSIGINFO.
>
> This request is used to retrieve information about a signal with the
> specified sequence number. A siginfo_t structure is copied from the child
> to location data in the parent.
>
> The low 16 bits of addr contains a sequence number of signal in a queue:

I think 16 bits is probably not enough.... Already, on the "out of the
box" system that I have at hand, one can queue more than 2^16-1
signals:

    $ cat /proc/$$/status | grep SigQ
    SigQ:	2/126065

Cheers,

Michael


> All other bits of addr is used for flags. Currently here is only one
> flag PTRACE_PEEK_SHARED for dumping signals from process-wide shared
> queue. If this flag is not set, a signal is read from a per-thread
> queue.  A result siginfo contains a kernel part of si_code which usually
> striped, but it's required for queuing the same siginfo back during
> restore of pending signals.
>
> If a signal with the specified sequence number doesn't exist, ptrace
> returns ENOENT.
>
> This functionality is required for checkpointing pending signals.
>
> The prototype of this code was developed by Oleg Nesterov.
>
> Cc: Roland McGrath <roland-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Cc: Oleg Nesterov <oleg-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Cc: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
> Cc: "Paul E. McKenney" <paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> Cc: David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Cc: Dave Jones <davej-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Cc: "Michael Kerrisk (man-pages)" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Cc: Pavel Emelyanov <xemul-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
> Cc: Linus Torvalds <torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
> Signed-off-by: Andrey Vagin <avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
> ---
>  include/uapi/linux/ptrace.h |  9 +++++++
>  kernel/ptrace.c             | 64 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 73 insertions(+)
>
> diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h
> index 022ab18..5d851d5 100644
> --- a/include/uapi/linux/ptrace.h
> +++ b/include/uapi/linux/ptrace.h
> @@ -52,6 +52,15 @@
>  #define PTRACE_INTERRUPT       0x4207
>  #define PTRACE_LISTEN          0x4208
>
> +#define PTRACE_PEEKSIGINFO     0x4209
> +
> +/*
> + * The lower 16 bits of addr is a sequence number of a signal.
> + * All other bits can be used for flags.
> + */
> +#define PTRACE_PEEKSIGINFO_FLAGS_MASK  (~0UL << 16)
> +#define PTRACE_PEEK_SHARED             (1UL << 31)
> +
>  /* Wait extended result codes for the above trace options.  */
>  #define PTRACE_EVENT_FORK      1
>  #define PTRACE_EVENT_VFORK     2
> diff --git a/kernel/ptrace.c b/kernel/ptrace.c
> index 1599157..27fd31a 100644
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c
> @@ -579,6 +579,40 @@ static int ptrace_setsiginfo(struct task_struct *child, const siginfo_t *info)
>         return error;
>  }
>
> +#ifdef CONFIG_CHECKPOINT_RESTORE
> +static int ptrace_peek_siginfo(struct task_struct *child,
> +                               unsigned long addr, siginfo_t *siginfo)
> +{
> +       struct sigpending *pending;
> +       struct sigqueue *q;
> +       unsigned long flags;
> +       unsigned int nr;
> +       int ret = -ENOENT;
> +
> +       nr = addr & ~PTRACE_PEEKSIGINFO_FLAGS_MASK;
> +       flags = addr & PTRACE_PEEKSIGINFO_FLAGS_MASK;
> +
> +       if (flags & PTRACE_PEEK_SHARED)
> +               pending = &child->signal->shared_pending;
> +       else
> +               pending = &child->pending;
> +
> +       if (flags & ~PTRACE_PEEK_SHARED)
> +               return -EINVAL; /* unknown flags */
> +
> +       spin_lock_irq(&child->sighand->siglock);
> +       list_for_each_entry(q, &pending->list, list) {
> +               if (!nr--) {
> +                       copy_siginfo(siginfo, &q->info);
> +                       ret = 0;
> +                       break;
> +               }
> +       }
> +       spin_unlock_irq(&child->sighand->siglock);
> +
> +       return ret;
> +}
> +#endif
>
>  #ifdef PTRACE_SINGLESTEP
>  #define is_singlestep(request)         ((request) == PTRACE_SINGLESTEP)
> @@ -703,6 +737,21 @@ int ptrace_request(struct task_struct *child, long request,
>                 ret = put_user(child->ptrace_message, datalp);
>                 break;
>
> +#ifdef CONFIG_CHECKPOINT_RESTORE
> +       case PTRACE_PEEKSIGINFO:
> +       {
> +               siginfo_t __user *uinfo = (siginfo_t __user *) data;
> +
> +               ret = ptrace_peek_siginfo(child, addr, &siginfo);
> +
> +               if (!ret)
> +                       ret = copy_siginfo_to_user(uinfo, &siginfo);
> +               if (!ret)
> +                       ret = __put_user(siginfo.si_code, &uinfo->si_code);
> +               break;
> +       }
> +#endif
> +
>         case PTRACE_GETSIGINFO:
>                 ret = ptrace_getsiginfo(child, &siginfo);
>                 if (!ret)
> @@ -959,6 +1008,21 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
>                 ret = put_user((compat_ulong_t) child->ptrace_message, datap);
>                 break;
>
> +#ifdef CONFIG_CHECKPOINT_RESTORE
> +       case PTRACE_PEEKSIGINFO:
> +       {
> +               compat_siginfo_t __user *uinfo = compat_ptr(data);
> +
> +               ret = ptrace_peek_siginfo(child, addr, &siginfo);
> +
> +               if (!ret)
> +                       ret = copy_siginfo_to_user32(uinfo, &siginfo);
> +               if (!ret)
> +                       ret = __put_user(siginfo.si_code, &uinfo->si_code);
> +               break;
> +       }
> +#endif
> +
>         case PTRACE_GETSIGINFO:
>                 ret = ptrace_getsiginfo(child, &siginfo);
>                 if (!ret)
> --
> 1.7.11.7
>



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/

  parent reply	other threads:[~2013-02-19 12:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-13 15:16 [PATCH] ptrace: add ability to retrieve signals without removing them from a queue Andrey Vagin
     [not found] ` <1360768595-31943-1-git-send-email-avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2013-02-13 16:06   ` Oleg Nesterov
2013-02-15 18:44   ` Pedro Alves
     [not found]     ` <511E8223.6010506-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-02-15 19:43       ` Oleg Nesterov
     [not found]         ` <20130215194356.GA12413-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-02-15 19:53           ` Pedro Alves
2013-02-15 20:03         ` Pedro Alves
     [not found]           ` <511E9480.5070202-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-02-19  9:39             ` Andrey Wagin
2013-02-19 12:15   ` Michael Kerrisk (man-pages) [this message]
     [not found]     ` <CAKgNAkicAGEkvNFnSso__wK6QKao8jyDu5yuRmeyUOeaXLGChw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-02-19 17:53       ` Pavel Emelyanov
2013-02-19 19:34         ` Oleg Nesterov
     [not found]           ` <20130219193424.GA9606-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-02-19 19:47             ` Pavel Emelyanov
     [not found]               ` <5123D6D6.7010904-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2013-02-20 22:37                 ` Oleg Nesterov
     [not found]                   ` <20130220223703.GB16194-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-02-21 10:30                     ` Pavel Emelyanov

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=CAKgNAkicAGEkvNFnSso__wK6QKao8jyDu5yuRmeyUOeaXLGChw@mail.gmail.com \
    --to=mtk.manpages-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=avagin-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org \
    --cc=criu-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org \
    --cc=davej-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=oleg-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
    --cc=roland-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=xemul-bzQdu9zFT3WakBO8gow8eQ@public.gmane.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).