[...]
the two pointers being dereferenced are in user space, thus ineligible to use
the $ptr->field shortcut.
[...]
So here is how I am getting around this:
/*________________CUT HERE________________*/>
%{
#include <sys/times.h>
%}
probe times =
kernel.function("sys_times") {
name = "times"
buf_tms_utime = __uget_tms_m($tbuf,0)
buf_tms_stime = __uget_tms_m($tbuf,1)
buf_tms_cutime = __uget_tms_m($tbuf,2)
buf_tms_cstime = __uget_tms_m($tbuf,3)
}
probe times {
log(string(buf_tms_utime))
log(string(buf_tms_stime))
log(string(buf_tms_cutime))
log(string(buf_tms_cstime))
}
function __uget_tms_m:long(u_addr:long,member:long)
%{
struct tms t;
char *ptr = (char *)(unsigned long)THIS->u_addr;
size_t sz = sizeof(struct tms);
if(copy_from_user(&t,ptr,sz))
THIS->__retvalue = -EFAULT;
switch(THIS->member) {
case 0: THIS->__retvalue = t.tms_utime;
break;
case 1: THIS->__retvalue = t.tms_stime;
break;
case 2: THIS->__retvalue = t.tms_cutime;
break;
case 3: THIS->__retvalue = t.tms_cstime;
break;
default: THIS->__retvalue = -1;
}
%}
/*________________CUT HERE________________*/
This script produces the following compiler
error:
In function ‘function___uget_tms_m’:
/tmp/stapmFByii/stap_9586.c:194: error: storage size of ‘t’ isn’t known
/tmp/stapmFByii/stap_9586.c:196: error: invalid application of ‘sizeof’ to
incomplete type ‘struct tms’
This is the error one would receive if they had forgotten to include the header
sys/times.h file. Although a quick verification proves otherwise:
[root@localhost]# stap -vgp3 foo.stp > tmp.c
[root@localhost]# grep sys/times.h tmp.c
#include <sys/times.h>