public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: "Stone, Joshua I" <joshua.i.stone@intel.com>
To: <systemtap@sourceware.org>
Subject: Tapset difficulties w/ pointers
Date: Fri, 28 Apr 2006 23:23:00 -0000	[thread overview]
Message-ID: <CBDB88BFD06F7F408399DBCF8776B3DC07128FF6@scsmsx403.amr.corp.intel.com> (raw)

Hi all,

In working on the 'process' tapset, I've encountered a few difficulties
that I thought I would share, so we can search the collective mind for
solutions. I've split this into two emails to separate the related
parts...

For the process.exec probe, I would like to make the pointer to the new
task_struct available.  This is fine, and then I can make
access-functions for the user to extract data from this, like so:

  function task_pid:long (task:long) %{ /* pure */
      if (unlikely(THIS->task == 0))
          THIS->__retvalue = 0;
      else {
          struct task_struct *t = (struct task_struct
*)(long)THIS->task;
          THIS->__retvalue = t->tgid;
      }
  %}

The obvious problem here is safety.  I can check that the parameter is
not zero, but what do I do if the user calls task_pid(0xDEADBEEF)?
Oops...  Or what happens if the user stashes the pointer away in a
global, and tries to read it later?  Oops...

One solution is to "hide" task_pid(), perhaps by renaming it to
__task_pid(), and then have the tapset provide variables for pid, tid,
etc. and rely on the compiler to elide those that are unused.  Then the
pointer never needs to be given to the user.  This is still not really
safe though, because that __task_pid() is only discouraged, not
protected.  We probably could play a game with naming that only allows
calling some functions from within the same file, but these functions
would need to be duplicated multiple tapsets needs them.

A more general solution would be if we had some sort of "handle" type.
This might be an abstract data type that the script language is unable
to modify.  It can have metadata to identify the type, and perhaps also
to limit the valid lifetime of the pointer.  I haven't thought through
all of the implementation details, but I think that a handle type would
not be too far a stretch.

I welcome any feedback on this idea, and of course other ideas are
welcome as well.


Josh

             reply	other threads:[~2006-04-28 23:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-28 23:23 Stone, Joshua I [this message]
2006-04-28 23:48 ` James Dickens
2006-04-30 18:53 ` Frank Ch. Eigler

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=CBDB88BFD06F7F408399DBCF8776B3DC07128FF6@scsmsx403.amr.corp.intel.com \
    --to=joshua.i.stone@intel.com \
    --cc=systemtap@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).