Lukas Ruf wrote: >> I would think that, when you call a function using a function pointer, >> gcc will assume that all arguments get passed on the stack >> (asmlinkage) since it can't know anything about the function's actual >> linkage. > > Have you checked what asmlinkage does? IIRC this is defined in > include/linux/linkage.h. Yes I have. It defines __attribute__((regparm(0))), which tells gcc to pass all the function's arguments on the stack - *not* in registers (which is something gcc sometimes does to make things faster). >> So, I need a way to find out (at run-time), for a given function, >> whether it was compiled with asmlinkage so that I will know I can >> safely call it in this way. > > I do not get the point here. OK. Say I have a function foo, which takes one argument, int x. If I call foo through a function pointer (i.e. I have a pointer bar which holds the address of foo, and I execute "bar(3)") then I would say gcc has no choice but to: 1) push 3 onto the stack, 2) call the function whose address is in bar. Thus gcc has essentially assumed stack linkage (aka asmlinkage) for foo. BUT: Suppose that earlier, when we compiled foo, the compiler decided to optimise the calling sequence for foo (since we didn't declare asmlinkage for foo). Then foo would be expecting that you would call it like: 1) load 3 into register EAX, 2) call foo So if we *assume* that a function was compiled with asmlinkage without *knowing* that to be the case we could run into problems. The call "bar(3)" could result in: 1) push 3 onto the stack 2) call the function whose address is in bar (i.e. foo) 3) foo looks for its argument (x) in EAX... OH DEAR! Does that make sense? Best wishes, Bill. -- Dr. William Bland. Computer Programmer, UK. www.abstractnonsense.com -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/