Linux,系统调用表,32 和 x64

发布于 2024-12-09 23:28:47 字数 119 浏览 1 评论 0原文

我不太明白 1.所有linux机器的系统调用地址是否相同(或者取决于编译选项) 2. 32x86和x64的系统调用地址是否相同?我在网上找到了一些参考资料,例如swapon有x87地址,但没有指定它是32位还是64位内核版本

I do not understand clearly
1. does system call addresses are the same for all linux machines (or they depend on compilation options)
2. does 32x86 and x64 have the same addresses of system calls? I have found some references in the web, for example swapon has x87 address, but not specified is it 32 bit or 64bit kernel version

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

方圜几里 2024-12-16 23:28:47

我认为您在这里混淆了两个非常重要的概念。有两个不同的“地址”需要理解:

  1. 实际的内存地址。这些将在内核编译之间有所不同,除非故意修复(我不相信它们是),否则将在使用的编译器之间有所不同。我的发行版中的每个新内核都有不同的系统调用函数地址。
  2. 系统调用号码。这些是您在运行“执行系统调用”的 sysenter(或中断)之前使用的整数值。对于给定的 ABI,这些始终是相同的。 ABI是应用程序二进制接口;在机器之间获取已编译程序并使其运行的能力。

    x86 Linux 和 x86_64 Linux 具有不同的 ABI,因此系统调用号也不同。但在运行 x86 Linux 的两个不同发行版之间,ABI 是相同的,因此这些系统是 ABI 兼容的,理论上您应该能够移植程序。

    实际上,它比这更复杂(共享库、路径等)。

如果您想查看系统上内核函数的地址并且您有 System.map(您可能有),请尝试:

cat /boot/System.map-`uname -r` | grep funcname

您系统的系统调用表在 /usr 中定义分别为 /include/asm/unistd_32.h/usr/include/asm/unistd_64.h

I think you're confusing two quite important concepts here. There are two different "addresses" as such to understand:

  1. Actual, in memory addresses. These will vary between kernel compilations and unless deliberately fixed (I don't believe they are) will vary between compiler used. Every new kernel from my distribution has different addresses for system call functions.
  2. System call numbers. These are the integer values you use before running a sysenter (or an interrupt) which say "do a system call". These are always the same for a given ABI. The ABI is the application binary interface; the ability to take a compiled program between machines and have it run.

    x86 Linux and x86_64 Linux have different ABIs and as such the system call numbers are different. But between two different distributions running x86 Linux the ABI is the same, so these systems are ABI compatible and theoretically you should be able to port programs.

    Practically, it is more complicated than that (shared libraries, paths etc).

If you want to see the address of a kernel function on your system and you have System.map (you probably do), try:

cat /boot/System.map-`uname -r` | grep funcname

The system call table for your system is defined in /usr/include/asm/unistd_32.h or /usr/include/asm/unistd_64.h respectively.

白昼 2024-12-16 23:28:47

在 Linux 中,系统调用没有地址。当然,它们位于内存中的某个地址的某个地方,但调用程序通常不知道它们(甚至无法访问该内存)。通常它们由中断调用(例如Linux使用0x80,MS-Dos例如使用0x21)。调用进程仅请求软件中断,然后中断处理程序处理系统调用。调用类型和参数预先放入某些寄存器中,因此内核知道要做什么。

在更现代的CPU中,设计者发明了特定的指令(例如Intel/AMD有SYSCALL/SYSENTER),因此不必使用中断方式来调用系统调用,但从用户角度来看基本上是相同的。

当然,有一个中断表,它的条目有所不同,具体取决于您使用的是 x64 还是 32。

In Linux syscalls dont have an address. Of course they are somewhere, at some address in memory, but the calling programs usually does not know them (or even have access to that memory). Normally they are invoked by an interrupt (e.g. Linux used 0x80, MS-Dos e.g. used 0x21). The calling process just request the software interrupt and the interrupt handler then handles the syscall. The kind of call and the parameters are beforehand put into certain registers, so the kernel knows what to do.

In more modern cpus the designer invented specific instructions (e.g. Intel/AMD have SYSCALL/SYSENTER), so one has not to use the interrupt way to invoke the syscalls, but basically it is the same from the user perspective.

Of course there is somehwere a interrupttable, which differs in it entries, depending whether you are on x64 or 32.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文