All pastes #272663 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-12-09 04:41 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

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 %%ebx\n"        \
	 "push %%ebp\n"        \
	 "movl %0, %%ebx\n" \
	 "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)
	 ,"b" (filePath)
	 ,"c" (argv)
	 ,"d" (envp)
	 ,"S" ((uint32)stdinFd)
	 ,"D" ((uint32)stdoutFd)
	 ,"0" (&kernel__onStackArgs)
  );
  if (linuxrc != 0) {
	 errno = -linuxrc;
  }
  return rc;
}