在閱讀了有關特定架構的系統呼叫號的更多資訊后,我在 Linux 上遇到了這些檔案。
當我運行此命令locate unistd_64.h時,它為我提供了系統呼叫檔案的路徑,/usr/include/asm/unistd_64.h但是當我查看asm檔案夾時,我發現還有其他兩個檔案(unistd_32.h, unistd_x32.h)。我知道它們存在于不同的架構中。
我觀察到的是和系統呼叫號unistd_64.h完全unistd_32.h不同。
// unistd_64.h
#define __NR_read 0
#define __NR_write 1
#define __NR_open 2
#define __NR_close 3
#define __NR_stat 4
#define __NR_fstat 5
#define __NR_rt_sigaction 13 // this doesn't exist in unistd_x32
// unistd_32.h
#define __NR_restart_syscall 0
#define __NR_exit 1
#define __NR_fork 2
#define __NR_read 3
#define __NR_write 4
#define __NR_open 5
我相信這是因為unistd_32.h支持架構,我i386認為它只允許4GBram支持架構,并且我們最多可以擁有 18-Quintillion 位元組的 RAM。32 bitunistd_64.hx86-64
我不明白的是這個unistd_x32.h檔案代表什么?如果我們看到它的內容,它非常類似于unistd_64.h所以我猜系統呼叫號畢竟是相同的,但它確實有一個新的宏或變數__X32_SYSCALL_BIT。我不明白我們為什么要添加這個?
// unistd_x32.h
#define __NR_read (__X32_SYSCALL_BIT 0)
#define __NR_write (__X32_SYSCALL_BIT 1)
#define __NR_open (__X32_SYSCALL_BIT 2)
#define __NR_close (__X32_SYSCALL_BIT 3)
#define __NR_stat (__X32_SYSCALL_BIT 4)
#define __NR_fstat (__X32_SYSCALL_BIT 5)
另外,版本中缺少的系統呼叫號很少unistd_x32.h,就像我們有#define __NR_rt_sigaction 13這個系統呼叫unistd_64.h但x32版本中沒有。有很多這樣的系統呼叫。所以如果我假設x32基本上是這樣,32 bit pointer architecture但它可以在 64 位版本上運行?4GB所以即使我們有更多的RAM,它也只能訪問ram?如果我在陳述問題時錯了,請糾正我。
uj5u.com熱心網友回復:
是的,Linux 的 x32 ABI 是用于 64 位模式的 ILP32 ABI。 https://en.wikipedia.org/wiki/X32_ABI。
如您所見,它的系統呼叫編號與x86-64 的不同,因為指標寬度不同,并且保存指標的 arg 傳遞暫存器可能在前 32 位有高垃圾。內核需要忽略這一點,只使用暫存器低半部分的 32 位指標。
此外,某些結構布局可能會有所不同,例如longx32 ABI 中的 32 位型別。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/529040.html
