System calls Implementation

前端 未结 3 1933
滥情空心
滥情空心 2020-12-15 14:34

If a user application makes a system call , a software interrupt/exception is triggered. How can I see the source code for generating a software interrupt ?

相关标签:
3条回答
  • 2020-12-15 14:52

    It is explained in Linux Assembly Howto. And you should read wikipedia syscall page (and also about VDSO), and also intro(2) & syscalls(2) man pages. See also this answer and this one. Look also inside Gnu Libc & musl-libc source code. Learn also to use strace to find out which syscalls are made by a given command or process.

    See also the calling conventions and Application Binary Interface specification relevant to your system. For x86-64 it is here.

    0 讨论(0)
  • 2020-12-15 14:55

    long long ago, there is an int 0x80 trap to enter into the kernel, but nowadays sysenter is preferred.

    you can get the code by dumping vsyscall section which mapped into every process automatically by kernel.

    $ cat /proc/self/maps 
    blah blah blah
    ...
    blah blah blah
    ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
    

    for more information check this article

    0 讨论(0)
  • 2020-12-15 15:04

    A software interrupt can be triggered with the Intel x86 assembly instruction int n, where n is the interrupt number. A syscall is a special case of software interrupt; in you can manually do a syscall by

    mov eax, m
    int 0x80
    

    where m should be replaced with the interrupt number. Here are lists of 32-bit syscall numbers and 64-bit syscall numbers that linked to online manpages for the each function. You also need to pass parameters to the syscall via other registers (ebx, ecx, etc.), and you can read more about that here.

    This is the most general way to do syscalls because it is independent of external libraries, like libc, and you can implement this in C/C++ if you need to by using inline assembly.

    0 讨论(0)
提交回复
热议问题