[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: (E)GLIBC: inline syscalls



There will be also significant slowdown, as we have to prepare aguments
on stack, alter stack to get exactly the same stack layout as the
standard syscall would be used. We will lose correct unwinding info, et cetera, et cetera.

After some discussions on IRC, it seems the easiest way do to it, is to
fill all the arguments in a table, replace %esp by the address of
this table in the asm inline code, and restore the old value just after
the syscall.

It is not async signal safe. We cannot gurantee the space under esp will not be used by a signal handler, just try execute code bellow.

In theory, we could prepare all the arguments in a table,
decrement esp by appropriate amount and copy the original table just above new esp, perform syscall and restore previous esp.

Petr

-------------------------------------------------------------------------------

#include <signal.h>
#include <stdio.h>

volatile int a,b;

#define gsp(a)                          \
({                                              \
  register long int result;                     \
  asm volatile (                                \
                "mov %%esp,%0\n\t"              \
                : "=a" (result));               \
  result;                                       \
})


void xsig(void)
{
  a = gsp(t);
}

void stack(int i)
{
 char c[4096];
 if (i) return stack(--i);
 b = gsp(p);
 raise(SIGUSR1);
 printf("%08x %08x \n", b, a);
}

int main(void)
{
  signal(SIGUSR1,xsig);
  b = gsp(p);
  raise(SIGUSR1);
  printf("%08x %08x \n", b, a);

  xsig();
  printf("%08x %08x \n", b, a);

  stack(15);

  b = gsp(p);
  raise(SIGUSR1);
  printf("%08x %08x \n", b, a);
}


Reply to: