I study the Linux kernel and found out that for x86_64 architecture the interrupt int 0x80
doesn't work for calling system calls1.
For the i386 architecture (32-bit x86 user-space), what is more preferable: syscall
or int 0x80
and why?
I use Linux kernel version 3.4.
Footnote 1: int 0x80
does work in some cases in 64-bit code, but is never recommended. What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?
int 0x80 is the assembly language instruction that is used to invoke system calls in Linux on x86 (i.e., Intel-compatible) processors. An assembly language is a human-readable notation for the machine language that a specific type of processor (also called a central processing unit or CPU) uses.
On the Intel family of microprocessors, such as the Pentium, int 80h is the assembly language op code for interrupt 80h . This is the syscall interrupt on a typical Intel-based Unix system, such as FreeBSD. It allows application programmers to obtain system services from the Unix kernel.
A system call is a programmatic way a program requests a service from the kernel, and strace is a powerful tool that allows you to trace the thin layer between user processes and the Linux kernel. To understand how an operating system works, you first need to understand how system calls work.
On a 64-bit x86 Linux machine, there's a special instruction "syscall" to make system calls: a request to the kernel to do something. You identify which system call you'd like to make by loading a syscall number into register rax.
syscall
is the default way of entering kernel mode on x86-64
. This instruction is not available in 32 bit modes of operation on Intel processors.sysenter
is an instruction most frequently used to invoke system calls in 32 bit modes of operation. It is similar to syscall
, a bit more difficult to use though, but that is the kernel's concern.int 0x80
is a legacy way to invoke a system call and should be avoided.The preferred way to invoke a system call is to use vDSO, a part of memory mapped in each process address space that allows to use system calls more efficiently (for example, by not entering kernel mode in some cases at all). vDSO also takes care of more difficult, in comparison to the legacy int 0x80
way, handling of syscall
or sysenter
instructions.
Also, see this and this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With