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

查看:33
本文介绍了什么是更好的“int 0x80"?或“系统调用"在 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?

推荐答案

  • syscallx86-64 上进入内核模式的默认方式.此指令不适用于英特尔处理器的 32 位操作模式.
  • sysenter 是在 32 位操作模式下最常用于调用系统调用的指令.它类似于syscall,虽然使用起来有点困难,但这是内核所关心的.
  • int 0x80 是调用系统调用的传统方式,应避免使用.
    • 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.
    • 调用系统调用的首选方法是使用 vDSO,这是内存映射的一部分在允许更有效地使用系统调用的每个进程地址空间中(例如,在某些情况下根本不进入内核模式).与传统的 int 0x80 方式相比,vDSO 还处理更困难的 syscallsysenter 指令.

      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.

      另请参阅this这个.

      这篇关于什么是更好的“int 0x80"?或“系统调用"在 Linux 上的 32 位代码中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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