On Wed, Jul 31, 2002 at 04:56:37PM +0300, Nadav Har'El wrote:
> On Wed, Jul 31, 2002, Muli Ben-Yehuda wrote about "Re: GNU Assembler #2":
> > many arguments, through a function pointer. Here's code that does it,
> > doing in asm only the required bits:
> >
> > #include <stdio.h>
> >
> > typedef void (*pfunc)(void);
> >
> > void caller2(void* pfn, unsigned long* params, unsigned int nargs)
> > {
> > pfunc func = (pfunc)pfn;
> >
> > while (nargs--)
> > asm ("pushl %0" ::"g" (params[nargs]));
> >
> > (*func)();
> > }
>
> What is this "pushl" assembly instruction? Can't you put things on the
> stack with a normal "movl"? (see, I told you my assembly is very
> rusty...)
I'll bet mine is even rustier. AFAIK, pushl does movl + dec on the
stack pointer. RISC is that -----> way.
> Can't something like this work? (I'm assuming the stack in i386 goes
> up. I'm *really* rusty in assembly, so I am probably botching this up.
> I also have no idea how large is each frame on the stack, I added 2
> just as an example)).
>
> void caller2(void* pfn, unsigned long* params, unsigned int nargs)
> {
> /* WARNING: this is very unportable! (if works at all :) ) */
> while (nargs--)
> ((long *)&nargs)[nargs+2]=params[nargs];
>
> (*(pfunc)pfn)();
> }
This is the common "use first function parameter to get the stack
address" trick. I don't know if your version is correct, but the
general technique would work as well. I find the minimal inline asm
version easier to understand, though.
--
http://vipe.technion.ac.il/~mulix/
http://syscalltrack.sf.net/
msg20805/pgp00000.pgp
Description: PGP signature
