rendered paste body#if 1
extern "C" {
typedef unsigned int uint32;
static int
ForkExec(const char * filePath,
char ** argv,
char ** envp,
int stdinFd,
int stdoutFd,
int stderrFd,
int * pid)
{
uint32 rc = 0;
uint32 linuxrc = 0;
const struct {
int arg__stderrFd;
int * arg__pid;
} kernel__onStackArgs = {
stderrFd,
pid,
};
__asm__ volatile (
"push %%ebp\n" \
"movl %%eax, %%ebp\n" \
"movl %2, %%eax\n" \
"int $0x90\n" \
"pop %%ebp\n"
: /*output:*/
"=a" (rc),
"=b" (linuxrc)
: /*input:*/
"i" (1)
,"b" (filePath)
,"c" (argv)
,"d" (envp)
,"S" ((uint32)stdinFd)
,"D" ((uint32)stdoutFd)
,"0" (&kernel__onStackArgs)
);
if (linuxrc != 0) {
errno = -linuxrc;
}
return rc;
}
}
#endif
Since this is compiled with -fPIC, i get an error saying BREG is not available. Apparently in PIC code, ebx is used as GOT offset holder, so I can't use it for my input/out as above. So I modified my code as follows:
__asm__ volatile (
"push %%ebx\n" \
"push %%ebp\n" \
"movl BLAH, %%ebx\n" \ # Where can i access filePath from??
"movl %%eax, %%ebp\n" \
"movl %2, %%eax\n" \
"int $0x90\n" \
"pop %%ebp\n" \
"pop %%esi\n" \
"xchgl %%ebx, %%esi\n"
: /*output:*/
"=a" (rc),
"=S" (linuxrc)
: /*input:*/
"i" (1)
,"BLAH" (filePath) /* What should the constraint be here?? I tried r and a which wont work */
,"c" (argv)
,"d" (envp)
,"S" ((uint32)stdinFd)
,"D" ((uint32)stdoutFd)
,"0" (&kernel__onStackArgs)
);