[libc-commits] [libc] [libc] Fix alarm layout mismatch on 32-bit time64 (PR #201276)
Eli Friedman via libc-commits
libc-commits at lists.llvm.org
Wed Jun 10 10:52:39 PDT 2026
================
@@ -30,16 +30,29 @@ LLVM_LIBC_FUNCTION(unsigned int, alarm, (unsigned int seconds)) {
return static_cast<unsigned int>(
LIBC_NAMESPACE::syscall_impl<long>(SYS_alarm, seconds));
#elif defined(SYS_setitimer)
- struct itimerval itv, old_itv;
- itv.it_interval.tv_sec = 0;
- itv.it_interval.tv_usec = 0;
- itv.it_value.tv_sec = seconds;
- itv.it_value.tv_usec = 0;
- if (LIBC_NAMESPACE::syscall_impl<int>(SYS_setitimer, 0 /* ITIMER_REAL */,
- &itv, &old_itv) < 0)
- return 0;
- return static_cast<unsigned int>(old_itv.it_value.tv_sec +
- (old_itv.it_value.tv_usec > 0 ? 1 : 0));
+ // On 32-bit architectures with 64-bit time_t, SYS_setitimer still expects
+ // 32-bit fields. We must convert itimerval to use 32-bit fields.
+ if constexpr (sizeof(time_t) > sizeof(long)) {
+ long itv32[4] = {0, 0, static_cast<long>(seconds), 0};
----------------
efriedma-quic wrote:
Do we need to handle overflow? (The API takes an unsigned 32-bit integer, and this casts it to a signed 32-bit integer.)
https://github.com/llvm/llvm-project/pull/201276
More information about the libc-commits
mailing list