Linux 内核中的 64 位 time_t [英] 64-bit time_t in Linux Kernel
问题描述
我已经编译了内核 3.19.1,但是 time_t
仍然有问题.只是一个带有 cout << 的简单程序sizeof (time_t);
给出了 4 个字节的大小,而不是我原先想要的 8 个字节.
I have compiled kernel 3.19.1 but still have a problem with time_t
. Just a simple program with cout << sizeof (time_t);
gives size of 4 bytes, not 8 bytes as was my intention.
我应该在 make menuconfig 期间打开特定选项吗?
Should I switch on a particular option during make menuconfig?
推荐答案
32 位 Linux 上的 64 位时间支持 首先在 5.1 内核 中引入,所以如果你年纪比那个大,抱歉.因为改变旧系统调用的返回类型会破坏旧应用程序,新的 *time64
系统调用 必须被添加.检查此表,您会发现这些系统调用仅适用于 32 位平台.
64-bit time support on 32-bit Linux was first introduced in the 5.1 kernel so if you're older than that, sorry. Because changing the return type of the old system calls breaks old applications, new *time64
syscalls had to be added instead. Check this table and you'll see that those syscalls are only available on 32-bit platforms.
现在,如果您正在为 32 位系统编写代码,则可以直接调用 clock_gettime64
(从内联汇编,或从带有 syscall()
函数)获取当前时间.但是在那之后你就完全靠自己了.要获得完整的用户空间支持,您必须使用 Linux 5.6 或更高版本以及 musl 1.2+ 或 glibc 2.32+.只需重新构建您的代码,time_t
就会变成 64 位长
Now if you're writing code for 32-bit systems you can call clock_gettime64
directly (from inline assembly, or from C with syscall()
function) to get the current time. However after that you're completely on your own. For full userspace support you must be on Linux 5.6 or higher along with musl 1.2+ or glibc 2.32+. Just rebuild your code and time_t
will become 64-bit long
所有用户空间都必须使用 64 位
time_t
编译,即将发布的 musl-1.2 和 glibc-2.32 版本以及来自 linux- 的已安装内核头文件都将支持5.6 或更高.
All user space must be compiled with a 64-bit
time_t
, which will be supported in the coming musl-1.2 and glibc-2.32 releases, along with installed kernel headers from linux-5.6 or higher.
直接使用系统调用接口的应用程序需要移植到使用 linux-5.1 中添加的 time64
系统调用来代替现有的系统调用.这会影响 futex()
和 seccomp()
的大多数用户以及拥有自己的不基于 libc 的运行时环境的编程语言.
Applications that use the system call interfaces directly need to be ported to use the time64
syscalls added in linux-5.1 in place of the existing system calls. This impacts most users of futex()
and seccomp()
as well as programming languages that have their own runtime environment not based on libc.
https://lkml.org/lkml/2020/1/29/355?anz=web
欲了解更多信息,请阅读
For more information read
这篇关于Linux 内核中的 64 位 time_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!