Is there a way to get function caller in linux kernel? I know __func__ returns the function name which is executing. I am looking for the function which called "__func__"
A Function Caller block calls and executes a function defined with a Simulink Function block or an exported Stateflow® function. Using Function Caller blocks, you can call a function from anywhere in a model or chart hierarchy.
The canonical way to invoke kernel functions from a user application is to use syscalls(2). You could make some kernel module -providing some device- which, thru the interface of the device (i.e. read , write , ioctl on that device) is calling your kernel functions.
A system call is implemented by a ``software interrupt'' that transfers control to kernel code; in Linux/i386 this is ``interrupt 0x80''. The specific system call being invoked is stored in the EAX register, abd its arguments are held in the other processor registers.
The C Caller supports code generation. In the code generated from your model, each execution of a C Caller block corresponds to a call to the external C function associated with the block.
You can get the caller with __builtin_return_address(0)
.
The caller's caller is __builtin_return_address(1)
and so on.
It's a GCC extension, documented in the gcc manual: http://gcc.gnu.org/onlinedocs/gcc/Return-Address.html
Edit: I should probably point out, that gets you the address of the caller. If you want the function name you can print it with %pS
, eg:
printk("Caller is %pS\n", __builtin_return_address(0));
If you don't want to print it, you can use kallsyms_lookup()
etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With