[Asm] Wywołanie systemowe, Linux

0

http://en.wikipedia.org/wiki/System_call

For many RISC processors this is the only feasible implementation, but CISC architectures such as x86 support additional techniques. One example is SYSCALL/SYSENTER, SYSRET/SYSEXIT (the two mechanisms were independently created by AMD and Intel, respectively, but in essence do the same thing). These are "fast" control transfer instructions that are designed to quickly transfer control to the OS for a system call without the overhead of an interrupt. Linux 2.5 began using this on the x86, where available; formerly it used the INT instruction, where the system call number was placed in the EAX register before interrupt 0x80 was executed.

Może ktoś podać jakiś przykład kodu wykorzystujący jawnie SYSENTER/SYSCALL? Nie mogę doszukać się informacji jak przekazywać dane, które normalnie siedziałyby w edx/rdx. Jeżeli leży to gdzieś na samym początku google, to przepraszam, może złe zapytania formułuje o tej godzinie :P

Żeby nie utrudniać podaję wzorcowy kod z intem ;)

int main(void) {
        char* c = "str";

        asm(
        "movq $4, %%rax\n"
        "movq $1, %%rbx\n"
        "movq $4, %%rdx\n"
        "int $0x80\n"
        :
        :       "c" (c)
        );

        return 0;
}

Pisane pod 64b, ale proszę używać 32b jeśli wygodniej :)

0
int main(void)
{
  char* str = "foo";
  asm(
  "movq $1, %%rax\n"
  "movq $1, %%rdi\n"
  "movq $4, %%rdx\n"
  "syscall\n"
  :: "s"(str) /* tak szło rsi...? */ );
  return 0;
}

Przynajmniej pod 64b. Pomyśleć, wziąłem to z kursu asma (a ściślej to listy przerwań zawartej w nim)...

0

Dzięki za przykład, działa jak powinno :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1