public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* deferencing variable with embedded C code
@ 2008-09-09  3:26 Jun Koi
  2008-09-09  4:57 ` Wenji Huang
  0 siblings, 1 reply; 3+ messages in thread
From: Jun Koi @ 2008-09-09  3:26 UTC (permalink / raw)
  To: SystemTAP

Hi,

I am still not an experience Systemtap user, so sorry for the naive question.

I am looking at the documentation on embedded C code, and see that to
dereference a field of structure (like skb->dev->name), we need to do
something like below:

struct net_device *dev;
char *name;
dev = kread(&(skb->dev));
name = kread(&(dev->name));

Why is that? Because embedded C is running in kernel context, and
compiled with kernel code, it has access to all kernel structure, but
why it cannot deference structure itself?

It seems that do do the above, we need Dwarf information supplied to
Systemtap, correct?

Many thanks,
Jun

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: deferencing variable with embedded C code
  2008-09-09  3:26 deferencing variable with embedded C code Jun Koi
@ 2008-09-09  4:57 ` Wenji Huang
  2008-09-10  0:54   ` Stone, Joshua I
  0 siblings, 1 reply; 3+ messages in thread
From: Wenji Huang @ 2008-09-09  4:57 UTC (permalink / raw)
  To: Jun Koi; +Cc: SystemTAP

Jun Koi wrote:
> Hi,
> 
> I am still not an experience Systemtap user, so sorry for the naive question.
Welcome to Systemtap.
> 
> I am looking at the documentation on embedded C code, and see that to
> dereference a field of structure (like skb->dev->name), we need to do
> something like below:
> 
> struct net_device *dev;
> char *name;
> dev = kread(&(skb->dev));
> name = kread(&(dev->name));
> 
> Why is that? Because embedded C is running in kernel context, and
> compiled with kernel code, it has access to all kernel structure, but
> why it cannot deference structure itself?

This is the safe way to avoid deference of incorrect pointer.
> 
> It seems that do do the above, we need Dwarf information supplied to
> Systemtap, correct?

Embedded code doesn't read Dwarf information.

Regards,
Wenji

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: deferencing variable with embedded C code
  2008-09-09  4:57 ` Wenji Huang
@ 2008-09-10  0:54   ` Stone, Joshua I
  0 siblings, 0 replies; 3+ messages in thread
From: Stone, Joshua I @ 2008-09-10  0:54 UTC (permalink / raw)
  To: Wenji Huang; +Cc: Jun Koi, SystemTAP

Wenji Huang wrote:
> Jun Koi wrote:
> > I am looking at the documentation on embedded C code, and see that to
> > dereference a field of structure (like skb->dev->name), we need to do
> > something like below:
> >
> > struct net_device *dev;
> > char *name;
> > dev = kread(&(skb->dev));
> > name = kread(&(dev->name));
> >
> > Why is that? Because embedded C is running in kernel context, and
> > compiled with kernel code, it has access to all kernel structure, but
> > why it cannot deference structure itself?
> 
> This is the safe way to avoid deference of incorrect pointer.

Just to expand a little on this -- we use kread out of paranoia.  If
your pointers are all valid, then you certainly could use skb->dev->name
in your embedded code and it would work just fine.  However, if a
pointer is bad, then an unprotected read will probably crash the whole
system.

While uncommon, there are still several causes for an embedded-C
function to receive a bad pointer, including incorrect debug
information, paged-out memory, or simple user error.  We want it to be
impossible for non-guru users to crash the system, so we need to be very
careful about what pointers we trust.

If you're writing embedded C for your own guru-mode scripts, then you're
welcome to read pointers directly if you think they're safe, and you'll
only have yourself to blame if you're wrong.  If that code is in a
tapset though, we have to be prepared for non-guru users to call those
functions with possibly dangerous values, so we protect the dereferences
with kread().

Josh

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-09-10  0:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-09  3:26 deferencing variable with embedded C code Jun Koi
2008-09-09  4:57 ` Wenji Huang
2008-09-10  0:54   ` Stone, Joshua I

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).