function arguments are passed in registers

Greg Smith gsmith@nc.rr.com
Fri Jan 4 23:41:00 GMT 2008


As far as I know, arguments are passed to a function either in registers
or in the stack based on the prototype of the called function.  See the
regparm __attribute__.  My understanding is that this is also arch
dependent, for example s390x always passes arguments in registers (and
then the stack if there are too many).

So your function calling the kernel function should be fine as long as
you have the correct function prototype.

Greg Smith

On Thu, 2008-01-03 at 11:00 +0800, Zheng Da wrote:
> I'm writing a Linux kernel module which needs to call a static
> function in the kernel.
> Unfortunately, the static functions are compiled with arguments passed
> in registers.
> I don't want to change the kernel, so I have to use some trick to pass
> arguments in different ways.
> Currently, I use inline assembly, but I thought maybe GCC provides a better way.
> By the way, how does Linux kernel handle it?
> As I know, static functions pass their arguments in registers, and
> others in the stack.
> How does Linux kernel use them together?
> 
> Zheng Da




More information about the Gcc-help mailing list