This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Calling systemtap function from pure code


On Wed, Sep 13, 2017 at 9:41 AM, Daniel Doron <danielmeirdoron@gmail.com> wrote:
> Hi,
>
> Is it possible to call a stap function from kernel code (guru mode)?

No, not really.

Yes, all stap language functions get translated to a C function.
However, you can't call that function easily, for several reasons:

1) The stap language function name gets mangled when it gets
translated to C. That mangling isn't documented and changes from time
to time. The last time it changed was when we implemented function
overloading. We have no plans to document the current mangling scheme
(you could certainly figure it out looking at the generated output)
and we reserve the right to change the mangling scheme in the future.

2) Even if you know the correct C function name for a stap language
function, you can't easily call it. Function parameters aren't passed
on the stack, they are passed in a context structure, which once again
is undocumented and subject to change.

I'm not really sure what you are really trying to do here, but if you
need to call common code from a stap language function and a C
function, I'd put that functionality in a C function, then write a
stap language wrapper for it. Something like the following (untested):

====
%{

int internal_log_event(char *str)
{
    printk(KERN_INFO "name: %s\n", str);
    return 0;
}

%}

function log_event:long(str:string)
%{
    STAP_RETVALUE = internal_log_event(STAP_ARG_str);
%}

function call_me()
{
    log_event("hello world")
}

probe begin {
    call_me()
}
====

Note that the STAP_ARG_ function argument prefix and STAP_RETVALUE
item are documented and are supported.

If this doesn't answer your question, you'll need to let us know what
you are really trying to do.

-- 
David Smith
Principal Software Engineer
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]