32 位 Linux 上的 Syscall 或 sysenter? [英] Syscall or sysenter on 32 bits Linux?
问题描述
从 MS‑DOS 开始,我就知道使用中断进行系统调用.在旧论文中,我看到引用 int 80h
在 Linux 上调用系统函数.很长一段时间以来,我知道 int 80h
已被弃用,取而代之的是 syscall
指令.但我无法在我的 32 位机器上运行.
问题
syscall
指令只能在 64 位平台上使用吗?32 位 Linux 不使用 syscall
吗?
样本测试
在我的 32 位 Linux (Ubuntu Precise) 上,此程序以核心转储终止:
全局 _start_开始:移动 eax, 4 ;4是写移动 ebx, 1 ;1 是标准输出mov ecx, 消息;字符串地址mov edx,长度;字节数系统调用移动 eax, 1 ;1 是退出异或 ebx, ebx ;返回码 0系统调用信息:db 10,"你好,世界",10,10length equ $ - 消息
我尝试过使用 sysenter
而不是 syscall
,但它以同样的方式崩溃.
经过一些网络搜索,我在 StackOverflow 上找到了另一个主题:Linux 通过 sysenter 教程调用系统调用.它说调用系统的推荐方式,既不是使用 int 80h
也不是 syscall
也不是 sysenter
,而是 linux-gate.so
.
仍然是关于崩溃和核心转储的问题.我的最终猜测是,尽管 syscall
或 sysenter
指令都可以作为 CPU 指令使用,但可能是 Linux 内核没有正确设置这个入口点",当它决定它在给定的硬件平台上并不是真正有用.
似乎在 32 位平台上,sysenter
或 syscall
可能可用,但它始终可用,仅在 64 位平台上可用.>
虽然我觉得这回答了我的问题,但我仍然欢迎更多的材料,比如我上面的猜测的权威参考.
-- 更新--
至少,我可以找到证实上述内容的这个.这仍然不是权威参考,但我相信它似乎足够值得信赖.
<块引用>调用系统调用的首选方式是由内核在启动时决定,以及显然这个框使用了sysenter.
此外,来自另一个来源的示例 FASM 汇编源代码(如果您使用 NASM,则需要一些翻译),以通过 linux-gate.so
调用系统函数:在Assembly中查找linux-gate.so.1.
Since MS‑DOS, I know system invocation using interrupts. In old papers, I saw reference to int 80h
to invoke system functions on Linux. Since a rather long time now, I know int 80h
is deprecated in favour of the syscall
instruction. But I can't get it working on my 32 bits machine.
The question
Is the syscall
instruction to be used on 64 bits platform only? Doesn't 32 bits Linux makes use of syscall
?
A sample test
On my 32 bits Linux (Ubuntu Precise), this program terminates with a core dump:
global _start
_start:
mov eax, 4 ; 4 is write
mov ebx, 1 ; 1 is stdout
mov ecx, message ; address of string
mov edx, length ; number of bytes
syscall
mov eax, 1 ; 1 is exit
xor ebx, ebx ; return code 0
syscall
message:
db 10,"Hello, World",10,10
length equ $ - message
I've tried with sysenter
instead of syscall
, but it crashes the same way.
After some web searching, I landed to this other topic on StackOverflow: Linux invoke a system call via sysenter tutorial. It says the recommended way to invoke the system, is neither using int 80h
nor syscall
nor sysenter
, but linux-gate.so
.
Still remains the question about the crash and core‑dump. My guess is finally that although either syscall
or sysenter
instructions are available as a CPU instruction, may be the Linux kernel just does not set‑up properly this "entry point" when it decide it's not really useful on a given hardware platform.
Seems on 32 bits platform, sysenter
or syscall
may be available, while it's always available, only on 64 bits platform.
Although I feel this answer my question, I still welcome more material, like an authoritative reference for my above guess.
-- update --
At least, I could find this which confirm the above. That's still not an authoritative reference but seems trustable enough I believe.
What is linux-gate.so.1?, says:
The preferred way of invoking a system call is determined by the kernel at boot time, and evidently this box uses sysenter.
Also, from another source, a sample FASM assembly source (needs some translations if you use NASM), to call a system function via linux-gate.so
: Finding linux-gate.so.1 in Assembly .
这篇关于32 位 Linux 上的 Syscall 或 sysenter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!