unistd_64.h 在 Linux
unistd_64.h in Linux
目前,我在 x86 上使用 linux 内核 v5.8。
在我的 ubuntu 机器上,/usr/include/x86_64-linux-gnu/asm/unistd_64.h
比 /usr/src/linux-headers-5.8.0-50-generic/arch/x86/include/generated/uapi/asm/unistd_64.h
旧。
因此,我无法在 /usr/include/x86_64-linux-gnu/asm/unistd_64.h
中看到从 linux v5.6 添加的新系统调用,例如 openat2
(当然,我在/usr/src/linux-headers-5.8.0-50-generic/arch/x86/include/generated/uapi/asm/unistd_64.h
中也能看到这样的系统调用。)
我认为 /usr/include/x86_64-linux-gnu/asm/unistd_64.h
与我使用的先前内核版本相同 /usr/src/linux-headers-5.4.0-73-generic/arch/x86/include/generated/uapi/asm/unistd_64.h
。
为什么 /usr/include/x86_64-linux-gnu/asm/unistd_64.h
没有更新?
参考:unistd_64.h in Ubuntu
您的内核提供的系统调用不必与您的 C 库知道的系统调用相匹配。 openat2
已于 2020 年 4 月通过提交 e788bea
添加到 glibc
:
Update syscall lists for Linux 5.6.
Linux 5.6 has new openat2 and pidfd_getfd syscalls. This patch adds
them to syscall-names.list and regenerates the arch-syscall.h files.
下一个 glibc
版本是 2.32
,于 2020 年 8 月发布。在 Ubuntu 中,libc6
版本 >=2.32
的软件包目前仅适用于 groovy
和 hirsute
:
Package libc6
- bionic-updates (libs): GNU C Library: Shared libraries
2.27-3ubuntu1.4: amd64 arm64 armhf i386 ppc64el s390x
also provided by: libc6-udeb
- focal-updates (libs): GNU C Library: Shared libraries
2.31-0ubuntu9.2: amd64 arm64 armhf i386 ppc64el s390x
also provided by: libc6-udeb
- groovy (20.10) (libs): GNU C Library: Shared libraries
2.32-0ubuntu3: amd64 arm64 armhf i386 ppc64el s390x
also provided by: libc6-udeb
- hirsute (21.04) (libs): GNU C Library: Shared libraries
2.33-0ubuntu5: amd64 arm64 armhf i386 ppc64el s390x
但是由于无论如何都需要 glibc>=2.32
和 linux-kernel>=5.6
不会获得太多可移植性,因此您可以在代码中定义系统调用编号 (ifndef
) 并使用 syscall(2)
代替。
目前,我在 x86 上使用 linux 内核 v5.8。
在我的 ubuntu 机器上,/usr/include/x86_64-linux-gnu/asm/unistd_64.h
比 /usr/src/linux-headers-5.8.0-50-generic/arch/x86/include/generated/uapi/asm/unistd_64.h
旧。
因此,我无法在 /usr/include/x86_64-linux-gnu/asm/unistd_64.h
中看到从 linux v5.6 添加的新系统调用,例如 openat2
(当然,我在/usr/src/linux-headers-5.8.0-50-generic/arch/x86/include/generated/uapi/asm/unistd_64.h
中也能看到这样的系统调用。)
我认为 /usr/include/x86_64-linux-gnu/asm/unistd_64.h
与我使用的先前内核版本相同 /usr/src/linux-headers-5.4.0-73-generic/arch/x86/include/generated/uapi/asm/unistd_64.h
。
为什么 /usr/include/x86_64-linux-gnu/asm/unistd_64.h
没有更新?
参考:unistd_64.h in Ubuntu
您的内核提供的系统调用不必与您的 C 库知道的系统调用相匹配。 openat2
已于 2020 年 4 月通过提交 e788bea
添加到 glibc
:
Update syscall lists for Linux 5.6.
Linux 5.6 has new openat2 and pidfd_getfd syscalls. This patch adds them to syscall-names.list and regenerates the arch-syscall.h files.
下一个 glibc
版本是 2.32
,于 2020 年 8 月发布。在 Ubuntu 中,libc6
版本 >=2.32
的软件包目前仅适用于 groovy
和 hirsute
:
Package libc6
- bionic-updates (libs): GNU C Library: Shared libraries
2.27-3ubuntu1.4: amd64 arm64 armhf i386 ppc64el s390x
also provided by: libc6-udeb- focal-updates (libs): GNU C Library: Shared libraries
2.31-0ubuntu9.2: amd64 arm64 armhf i386 ppc64el s390x
also provided by: libc6-udeb- groovy (20.10) (libs): GNU C Library: Shared libraries
2.32-0ubuntu3: amd64 arm64 armhf i386 ppc64el s390x
also provided by: libc6-udeb- hirsute (21.04) (libs): GNU C Library: Shared libraries
2.33-0ubuntu5: amd64 arm64 armhf i386 ppc64el s390x
但是由于无论如何都需要 glibc>=2.32
和 linux-kernel>=5.6
不会获得太多可移植性,因此您可以在代码中定义系统调用编号 (ifndef
) 并使用 syscall(2)
代替。