public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* Cannot access data passed in via gettimeofday
@ 2006-12-14 23:20 Perry Cheng
  2006-12-15  3:16 ` Eugene Teo
  2006-12-15 21:08 ` Frank Ch. Eigler
  0 siblings, 2 replies; 4+ messages in thread
From: Perry Cheng @ 2006-12-14 23:20 UTC (permalink / raw)
  To: systemtap

Hi all,

I am having trouble getting parameters out of what seems to be a simple 
but buggy system-tap script.  The script is included below and the test 
case (a short C program) follows.  Basically, I am trying to hi-jack 
gettimeofday and piggyback some information back by treating the struct it 
passes in as a larger buffer than struct timeval.  However, I need to 
separate regular calls to gettimeofday from the special ones where the 
special path triggers.  To do this, I though I could treat the struct as 
an incoming parameter by looking for unusual bit patterns in the struct. 
Unfortunately, I can't seem to see the data at all despite using the 
copy_from_user function to copy data from user to kernel space.  Any idea 
what's going on here?   I additionally hijack stime so i can distinguish 
in the output my special call to gettimeofday.   The sample out below 
shows that the special values 0xaaaaaaaa and 0xbbbbbbbb are not 
transmitted.   If I use settimeofday instead of gettimeofday, then this 
program seems to work.   It feels like there is some other mechanism at 
work here that I don't know about. 


---------------------------
gettimeofday 0:   sec = 4ec7ed3c  usec = 4eb6db96
---------------------------

**********************system tap script**********************

probe kernel.function("sys_stime")
{
        doTime()
}

function doTime()
%{
        _stp_printf("---------------------------\n");
%}


probe kernel.function("sys_gettimeofday")
{
        doGetTimeOfDay($tv)
}

function doGetTimeOfDay(tv:long)
%{
        struct timeval *tv = (struct timeval *) ((long)THIS->tv);
        struct timeval ltv;
        int notCopied = 0;

        notCopied = copy_from_user(&ltv, tv, sizeof(ltv));
        _stp_printf("gettimeofday %d:   sec = %x  usec = %x\n", notCopied, 
ltv.tv_sec, ltv.tv_usec);
%}


**********************test program**********************

#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>

main() {

    struct timeval tv;
    time_t t;

    stime(&t);
    tv.tv_sec = 0xaaaaaaaa;
    tv.tv_usec = 0xbbbbbbbb;
    gettimeofday(&tv, NULL);
    stime(&t);
}



Perry

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

* Re: Cannot access data passed in via gettimeofday
  2006-12-14 23:20 Cannot access data passed in via gettimeofday Perry Cheng
@ 2006-12-15  3:16 ` Eugene Teo
  2006-12-15 21:08 ` Frank Ch. Eigler
  1 sibling, 0 replies; 4+ messages in thread
From: Eugene Teo @ 2006-12-15  3:16 UTC (permalink / raw)
  To: Perry Cheng; +Cc: systemtap

Perry Cheng wrote:
> I am having trouble getting parameters out of what seems to be a simple 
> but buggy system-tap script.  The script is included below and the test 
> case (a short C program) follows.  Basically, I am trying to hi-jack 
> gettimeofday and piggyback some information back by treating the struct it 
> passes in as a larger buffer than struct timeval.  However, I need to 
> separate regular calls to gettimeofday from the special ones where the 
> special path triggers.  To do this, I though I could treat the struct as 
> an incoming parameter by looking for unusual bit patterns in the struct. 
> Unfortunately, I can't seem to see the data at all despite using the 
> copy_from_user function to copy data from user to kernel space.  Any idea 
> what's going on here?   I additionally hijack stime so i can distinguish 
> in the output my special call to gettimeofday.   The sample out below 
> shows that the special values 0xaaaaaaaa and 0xbbbbbbbb are not 
> transmitted.   If I use settimeofday instead of gettimeofday, then this 
> program seems to work.   It feels like there is some other mechanism at 
> work here that I don't know about. 

[eteo@kerndev tmp]$ stap -g test.stp -c ./test
Password:
---------------------------
gettimeofday 0:   sec = aaaaaaaa  usec = bbbbbbbb
---------------------------
gettimeofday 0:   sec = 23a  usec = 1
...

Eugene
-- 
1024D/58DF8823 print 47B9 90F6 AE4A 9C51 37E0  D6E1 EA84 C6A2 58DF 8823
main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }

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

* Re: Cannot access data passed in via gettimeofday
  2006-12-14 23:20 Cannot access data passed in via gettimeofday Perry Cheng
  2006-12-15  3:16 ` Eugene Teo
@ 2006-12-15 21:08 ` Frank Ch. Eigler
  1 sibling, 0 replies; 4+ messages in thread
From: Frank Ch. Eigler @ 2006-12-15 21:08 UTC (permalink / raw)
  To: Perry Cheng; +Cc: systemtap


Perry Cheng <perryche@us.ibm.com> writes:

> [...]  I can't seem to see the data at all despite using the
> copy_from_user function to copy data from user to kernel space.
> [...]

Please be aware that might_sleep functions such as copy_from_user
should not generally be called from systemtap probe handlers.
Instead, one needs to use the atomic variants provided in the standard
tapset ... except we seem to lack a variant for copying over a struct
or an integer!  We have had one old bug to improve target expression
syntax so this would be automated (#2049, to allow e.g. $tv=>tv_sec).

All that doesn't explain though why you're getting odd results.  Does
the $tv pointer value itself seem plausible?  Kernel/gcc version?


- FChE

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

* Re: Cannot access data passed in via gettimeofday
       [not found] <OF326DF462.A6D86C8A-ON85257245.00099860-85257245.00099F31@mck.us.ray.com>
@ 2006-12-15  3:45 ` Dave Sperry
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Sperry @ 2006-12-15  3:45 UTC (permalink / raw)
  To: Perry Cheng, systemtap

Perry,

The test worked the first time I ran it. The second time I ran it I got
wacky results. Then I noticed I had a number of runaway processes after
the second test.

You may want to try a reboot and run the test again

Dave  



> Perry Cheng wrote:
> > I am having trouble getting parameters out of what seems to be a simple
> > but buggy system-tap script.  The script is included below and the test
> > case (a short C program) follows.  Basically, I am trying to hi-jack
> > gettimeofday and piggyback some information back by treating the struct
> it
> > passes in as a larger buffer than struct timeval.  However, I need to
> > separate regular calls to gettimeofday from the special ones where the
> > special path triggers.  To do this, I though I could treat the struct as
> > an incoming parameter by looking for unusual bit patterns in the struct.
> > Unfortunately, I can't seem to see the data at all despite using the
> > copy_from_user function to copy data from user to kernel space.  Any idea
> 
> > what's going on here?   I additionally hijack stime so i can distinguish
> > in the output my special call to gettimeofday.   The sample out below
> > shows that the special values 0xaaaaaaaa and 0xbbbbbbbb are not
> > transmitted.   If I use settimeofday instead of gettimeofday, then this
> > program seems to work.   It feels like there is some other mechanism at
> > work here that I don't know about.
> 
> [eteo@kerndev tmp]$ stap -g test.stp -c ./test
> Password:
> ---------------------------
> gettimeofday 0:   sec = aaaaaaaa  usec = bbbbbbbb
> ---------------------------
> gettimeofday 0:   sec = 23a  usec = 1
> ...
> 
> Eugene
> --
> 1024D/58DF8823 print 47B9 90F6 AE4A 9C51 37E0  D6E1 EA84 C6A2 58DF 8823
> main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }
> 

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

end of thread, other threads:[~2006-12-15 13:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-14 23:20 Cannot access data passed in via gettimeofday Perry Cheng
2006-12-15  3:16 ` Eugene Teo
2006-12-15 21:08 ` Frank Ch. Eigler
     [not found] <OF326DF462.A6D86C8A-ON85257245.00099860-85257245.00099F31@mck.us.ray.com>
2006-12-15  3:45 ` Dave Sperry

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