Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function caller in linux kernel

Tags:

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__"

like image 453
BHS Avatar asked Nov 10 '10 04:11

BHS


People also ask

What is function caller?

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.

How do you call a kernel function?

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.

How does Linux kernel system call work?

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.

What is caller in C?

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.


1 Answers

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.

like image 52
mpe Avatar answered Oct 21 '22 11:10

mpe