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 ?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Kernel oops Oops: 80000005 on arm embedded system
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
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.
A software interrupt can be triggered with the Intel x86 assembly instruction
int n
, wheren
is the interrupt number. A syscall is a special case of software interrupt; in you can manually do a syscall bywhere
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.
long long ago, there is an
int 0x80
trap to enter into the kernel, but nowadayssysenter
is preferred.you can get the code by dumping
vsyscall
section which mapped into every process automatically by kernel.for more information check this article