什么是更好的"int 0x80"?或"syscall"在Linux上的32位代码中? [英] What is better "int 0x80" or "syscall" in 32-bit code on Linux?

查看:448
本文介绍了什么是更好的"int 0x80"?或"syscall"在Linux上的32位代码中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我研究了Linux内核,发现对于x86_64体系结构,中断int 0x80不适用于调用系统调用 1 .

I study the Linux kernel and found out that for x86_64 architecture the interrupt int 0x80 doesn't work for calling system calls1.

对于i386架构(32位x86用户空间),更优选的是syscallint 0x80,为什么?

For the i386 architecture (32-bit x86 user-space), what is more preferable: syscall or int 0x80 and why?

我使用Linux内核版本3.4.

I use Linux kernel version 3.4.

脚注1:int 0x80在某些情况下可以在64位代码中工作,但从不建议这样做. 如果您以64位代码使用32位int 0x80 Linux ABI,会发生什么情况?

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?

推荐答案

  • syscall是在x86-64上进入内核模式的默认方式.该指令在Intel处理器上的32位操作模式 中不可用.
  • sysenter是最常用于以32位操作模式调用系统调用的指令.它与syscall相似,但使用起来有点困难,但这是内核需要考虑的问题.
  • int 0x80是调用系统调用的传统方式,应避免使用.
    • syscall is 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 kernel's concern.
    • int 0x80 is a legacy way to invoke a system call and should be avoided.
    • 调用系统调用的首选方法是使用VDSO,VDSO是映射在每个进程地址空间中的一部分内存,可以更有效地使用系统调用(例如,在某些情况下根本不进入内核模式).与传统的int 0x80方式相比,VDSO还处理了syscallsysenter指令.

      Preferable way to invoke a system call is to use VDSO, a part of memory mapped in each process address space that allow 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.

      另外,请参见 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆