From 5f8d689fc7830ef33672bad04bb44b78a087026d Mon Sep 17 00:00:00 2001 From: xuhuijie <546391727@qq.com> Date: Wed, 12 May 2021 14:27:46 +0800 Subject: [PATCH] pthread_cond_clockwait: add pre-patch to prevent adaptions (cherry picked from commit f56ebf8358af3a352d6a7bf1eae27eae9ccebcbe) --- ..._ASSUME_FUTEX_CLOCK_REALTIME-support.patch | 443 +++++++++ ...-parameter-to-futex-timed-wait-calls.patch | 22 +- ...-0003-support-Add-timespec.h-xtime.h.patch | 913 +++++++++--------- ...OSIX-proposed-pthread_cond_clockwait.patch | 3 + glibc.spec | 12 +- 5 files changed, 924 insertions(+), 469 deletions(-) create mode 100644 backport-0001-nptl-Assume-__ASSUME_FUTEX_CLOCK_REALTIME-support.patch rename backport-0001-nptl-Add-clockid-parameter-to-futex-timed-wait-calls.patch => backport-0002-nptl-Add-clockid-parameter-to-futex-timed-wait-calls.patch (97%) rename backport-0002-support-Add-timespec.h-xtime.h.patch => backport-0003-support-Add-timespec.h-xtime.h.patch (97%) rename backport-0003-nptl-Add-POSIX-proposed-pthread_cond_clockwait.patch => backport-0004-nptl-Add-POSIX-proposed-pthread_cond_clockwait.patch (99%) diff --git a/backport-0001-nptl-Assume-__ASSUME_FUTEX_CLOCK_REALTIME-support.patch b/backport-0001-nptl-Assume-__ASSUME_FUTEX_CLOCK_REALTIME-support.patch new file mode 100644 index 0000000..c9e92c4 --- /dev/null +++ b/backport-0001-nptl-Assume-__ASSUME_FUTEX_CLOCK_REALTIME-support.patch @@ -0,0 +1,443 @@ +From 0ddb7ea842abf63516b74d4b057c052afc6ba863 Mon Sep 17 00:00:00 2001 +From: Adhemerval Zanella +Date: Thu, 28 Feb 2019 11:33:22 -0300 +Subject: [PATCH] nptl: Assume __ASSUME_FUTEX_CLOCK_REALTIME support + +Conflict:NA +Reference:https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=0ddb7ea842abf63516b74d4b057c052afc6ba863 + +This patch assumes realtime clock support for nptl and thus removes +all the associated code. + +For __pthread_mutex_timedlock the fallback usage for the case where +lll_futex_timed_wait_bitset it not set define is also removed. The +generic lowlevellock-futex.h always define it, so for NPTL code the +check always yield true. + +Checked on x86_64-linux-gnu and i686-linux-gnu. + + * nptl/nptl-init.c (__have_futex_clock_realtime, + __have_futex_clock_realtime): Remove definition. + (__pthread_initialize_minimal_internal): Remove FUTEX_CLOCK_REALTIME + check test for !__ASSUME_FUTEX_CLOCK_REALTIME. + * nptl/pthread_mutex_timedlock.c (__pthread_mutex_timedlock): Assume + __ASSUME_FUTEX_CLOCK_REALTIME support. + * sysdeps/unix/sysv/linux/i386/lowlevellock.S: Likewise. + * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: Likewise. + * sysdeps/unix/sysv/linux/kernel-features.h + (__ASSUME_FUTEX_CLOCK_REALTIME): Remove. + * sysdeps/nptl/lowlevellock-futex.h (lll_futex_timed_wait_bitset): + Adjust comment. +--- + ChangeLog | 15 +++ + nptl/nptl-init.c | 29 ----- + nptl/pthread_mutex_timedlock.c | 27 ---- + sysdeps/nptl/lowlevellock-futex.h | 3 +- + sysdeps/unix/sysv/linux/i386/lowlevellock.S | 100 --------------- + sysdeps/unix/sysv/linux/kernel-features.h | 3 - + sysdeps/unix/sysv/linux/x86_64/lowlevellock.S | 115 ------------------ + 7 files changed, 16 insertions(+), 276 deletions(-) + +diff --git a/ChangeLog b/ChangeLog +index 3a70b618ab..53c5d2fcef 100644 +--- a/ChangeLog ++++ b/ChangeLog +@@ -1,3 +1,18 @@ ++2019-03-05 Adhemerval Zanella ++ ++ * nptl/nptl-init.c (__have_futex_clock_realtime, ++ __have_futex_clock_realtime): Remove definition. ++ (__pthread_initialize_minimal_internal): Remove FUTEX_CLOCK_REALTIME ++ check test for !__ASSUME_FUTEX_CLOCK_REALTIME. ++ * nptl/pthread_mutex_timedlock.c (__pthread_mutex_timedlock): Assume ++ __ASSUME_FUTEX_CLOCK_REALTIME support. ++ * sysdeps/unix/sysv/linux/i386/lowlevellock.S: Likewise. ++ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: Likewise. ++ * sysdeps/unix/sysv/linux/kernel-features.h ++ (__ASSUME_FUTEX_CLOCK_REALTIME): Remove. ++ * sysdeps/nptl/lowlevellock-futex.h (lll_futex_timed_wait_bitset): ++ Adjust comment. ++ + 2019-04-23 Adhemerval Zanella + + [BZ #18035] +diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c +index b5895fabf3..61ec8ed12a 100644 +--- a/nptl/nptl-init.c ++++ b/nptl/nptl-init.c +@@ -58,15 +58,6 @@ int __set_robust_list_avail; + # define set_robust_list_not_avail() do { } while (0) + #endif + +-#ifndef __ASSUME_FUTEX_CLOCK_REALTIME +-/* Nonzero if we do not have FUTEX_CLOCK_REALTIME. */ +-int __have_futex_clock_realtime; +-# define __set_futex_clock_realtime() \ +- __have_futex_clock_realtime = 1 +-#else +-#define __set_futex_clock_realtime() do { } while (0) +-#endif +- + /* Version of the library, used in libthread_db to detect mismatches. */ + static const char nptl_version[] __attribute_used__ = VERSION; + +@@ -298,26 +289,6 @@ __pthread_initialize_minimal_internal (void) + set_robust_list_not_avail (); + } + +-#ifdef __NR_futex +-# ifndef __ASSUME_FUTEX_CLOCK_REALTIME +- { +- int word = 0; +- /* NB: the syscall actually takes six parameters. The last is the +- bit mask. But since we will not actually wait at all the value +- is irrelevant. Given that passing six parameters is difficult +- on some architectures we just pass whatever random value the +- calling convention calls for to the kernel. It causes no harm. */ +- INTERNAL_SYSCALL_DECL (err); +- word = INTERNAL_SYSCALL (futex, err, 5, &word, +- FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME +- | FUTEX_PRIVATE_FLAG, 1, NULL, 0); +- assert (INTERNAL_SYSCALL_ERROR_P (word, err)); +- if (INTERNAL_SYSCALL_ERRNO (word, err) != ENOSYS) +- __set_futex_clock_realtime (); +- } +-# endif +-#endif +- + /* Set initial thread's stack block from 0 up to __libc_stack_end. + It will be bigger than it actually is, but for unwind.c/pt-longjmp.c + purposes this is good enough. */ +diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c +index 2f61a7d0d5..270b072c97 100644 +--- a/nptl/pthread_mutex_timedlock.c ++++ b/nptl/pthread_mutex_timedlock.c +@@ -240,27 +240,6 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex, + values despite them being valid. */ + if (__glibc_unlikely (abstime->tv_sec < 0)) + return ETIMEDOUT; +-#if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \ +- || !defined lll_futex_timed_wait_bitset) +- struct timeval tv; +- struct timespec rt; +- +- /* Get the current time. */ +- (void) __gettimeofday (&tv, NULL); +- +- /* Compute relative timeout. */ +- rt.tv_sec = abstime->tv_sec - tv.tv_sec; +- rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000; +- if (rt.tv_nsec < 0) +- { +- rt.tv_nsec += 1000000000; +- --rt.tv_sec; +- } +- +- /* Already timed out? */ +- if (rt.tv_sec < 0) +- return ETIMEDOUT; +-#endif + + /* We cannot acquire the mutex nor has its owner died. Thus, try + to block using futexes. Set FUTEX_WAITERS if necessary so that +@@ -287,18 +266,12 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex, + assume_other_futex_waiters |= FUTEX_WAITERS; + + /* Block using the futex. */ +-#if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \ +- || !defined lll_futex_timed_wait_bitset) +- lll_futex_timed_wait (&mutex->__data.__lock, oldval, +- &rt, PTHREAD_ROBUST_MUTEX_PSHARED (mutex)); +-#else + int err = lll_futex_timed_wait_bitset (&mutex->__data.__lock, + oldval, abstime, FUTEX_CLOCK_REALTIME, + PTHREAD_ROBUST_MUTEX_PSHARED (mutex)); + /* The futex call timed out. */ + if (err == -ETIMEDOUT) + return -err; +-#endif + /* Reload current lock value. */ + oldval = mutex->__data.__lock; + } +diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex.h +index bb8effe288..63d917d8da 100644 +--- a/sysdeps/nptl/lowlevellock-futex.h ++++ b/sysdeps/nptl/lowlevellock-futex.h +@@ -43,8 +43,7 @@ + #define lll_futex_timed_wait(futexp, val, timeout, private) \ + -ENOSYS + +-/* This macro should be defined only if FUTEX_CLOCK_REALTIME is also defined. +- If CLOCKBIT is zero, this is identical to lll_futex_timed_wait. ++/* If CLOCKBIT is zero, this is identical to lll_futex_timed_wait. + If CLOCKBIT has FUTEX_CLOCK_REALTIME set, then it's the same but + TIMEOUT is counted by CLOCK_REALTIME rather than CLOCK_MONOTONIC. */ + #define lll_futex_timed_wait_bitset(futexp, val, timeout, clockbit, private) \ +diff --git a/sysdeps/unix/sysv/linux/i386/lowlevellock.S b/sysdeps/unix/sysv/linux/i386/lowlevellock.S +index 83191a3899..a9898e94fd 100644 +--- a/sysdeps/unix/sysv/linux/i386/lowlevellock.S ++++ b/sysdeps/unix/sysv/linux/i386/lowlevellock.S +@@ -148,16 +148,6 @@ __lll_timedlock_wait: + cfi_adjust_cfa_offset(4) + cfi_rel_offset(%ebx, 0) + +-# ifndef __ASSUME_FUTEX_CLOCK_REALTIME +-# ifdef PIC +- LOAD_PIC_REG (bx) +- cmpl $0, __have_futex_clock_realtime@GOTOFF(%ebx) +-# else +- cmpl $0, __have_futex_clock_realtime +-# endif +- je .Lreltmo +-# endif +- + cmpl $0, (%edx) + js 8f + +@@ -199,96 +189,6 @@ __lll_timedlock_wait: + 8: movl $ETIMEDOUT, %eax + jmp 7b + +-# ifndef __ASSUME_FUTEX_CLOCK_REALTIME +-.Lreltmo: +- /* Check for a valid timeout value. */ +- cmpl $1000000000, 4(%edx) +- jae 3f +- +- pushl %esi +- cfi_adjust_cfa_offset(4) +- cfi_rel_offset(%esi, 0) +- pushl %edi +- cfi_adjust_cfa_offset(4) +- cfi_rel_offset(%edi, 0) +- +- /* Stack frame for the timespec and timeval structs. */ +- subl $8, %esp +- cfi_adjust_cfa_offset(8) +- +- movl %ecx, %ebp +- movl %edx, %edi +- +- movl $2, %edx +- xchgl %edx, (%ebp) +- +- test %edx, %edx +- je 6f +- +-1: +- /* Get current time. */ +- movl %esp, %ebx +- xorl %ecx, %ecx +- movl $__NR_gettimeofday, %eax +- ENTER_KERNEL +- +- /* Compute relative timeout. */ +- movl 4(%esp), %eax +- movl $1000, %edx +- mul %edx /* Milli seconds to nano seconds. */ +- movl (%edi), %ecx +- movl 4(%edi), %edx +- subl (%esp), %ecx +- subl %eax, %edx +- jns 4f +- addl $1000000000, %edx +- subl $1, %ecx +-4: testl %ecx, %ecx +- js 2f /* Time is already up. */ +- +- /* Store relative timeout. */ +- movl %ecx, (%esp) +- movl %edx, 4(%esp) +- +- /* Futex call. */ +- movl %ebp, %ebx +- movl $2, %edx +- movl %esp, %esi +- movl 16(%esp), %ecx +- LOAD_FUTEX_WAIT (%ecx) +- movl $SYS_futex, %eax +- ENTER_KERNEL +- +- /* NB: %edx == 2 */ +- xchgl %edx, (%ebp) +- +- testl %edx, %edx +- je 6f +- +- cmpl $-ETIMEDOUT, %eax +- jne 1b +-2: movl $ETIMEDOUT, %edx +- +-6: addl $8, %esp +- cfi_adjust_cfa_offset(-8) +- popl %edi +- cfi_adjust_cfa_offset(-4) +- cfi_restore(%edi) +- popl %esi +- cfi_adjust_cfa_offset(-4) +- cfi_restore(%esi) +-7: popl %ebx +- cfi_adjust_cfa_offset(-4) +- cfi_restore(%ebx) +- popl %ebp +- cfi_adjust_cfa_offset(-4) +- cfi_restore(%ebp) +- movl %edx, %eax +- ret +- +-3: movl $EINVAL, %edx +- jmp 7b +-# endif + cfi_endproc + .size __lll_timedlock_wait,.-__lll_timedlock_wait + #endif +diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h +index 0db1b987a4..bc5c959f58 100644 +--- a/sysdeps/unix/sysv/linux/kernel-features.h ++++ b/sysdeps/unix/sysv/linux/kernel-features.h +@@ -57,9 +57,6 @@ + 2.6.27. */ + #define __ASSUME_IN_NONBLOCK 1 + +-/* Support for the FUTEX_CLOCK_REALTIME flag was added in 2.6.29. */ +-#define __ASSUME_FUTEX_CLOCK_REALTIME 1 +- + /* Support for preadv and pwritev was added in 2.6.30. */ + #define __ASSUME_PREADV 1 + #define __ASSUME_PWRITEV 1 +diff --git a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S +index 166dbcfd3b..00ba88d5d2 100644 +--- a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S ++++ b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S +@@ -127,15 +127,6 @@ __lll_lock_wait: + .align 16 + __lll_timedlock_wait: + cfi_startproc +-# ifndef __ASSUME_FUTEX_CLOCK_REALTIME +-# ifdef PIC +- cmpl $0, __have_futex_clock_realtime(%rip) +-# else +- cmpl $0, __have_futex_clock_realtime +-# endif +- je .Lreltmo +-# endif +- + cmpq $0, (%rdx) + js 5f + +@@ -176,112 +167,6 @@ __lll_timedlock_wait: + 5: movl $ETIMEDOUT, %eax + retq + +-# ifndef __ASSUME_FUTEX_CLOCK_REALTIME +-.Lreltmo: +- /* Check for a valid timeout value. */ +- cmpq $1000000000, 8(%rdx) +- jae 3f +- +- pushq %r8 +- cfi_adjust_cfa_offset(8) +- pushq %r9 +- cfi_adjust_cfa_offset(8) +- pushq %r12 +- cfi_adjust_cfa_offset(8) +- pushq %r13 +- cfi_adjust_cfa_offset(8) +- pushq %r14 +- cfi_adjust_cfa_offset(8) +- cfi_offset(%r8, -16) +- cfi_offset(%r9, -24) +- cfi_offset(%r12, -32) +- cfi_offset(%r13, -40) +- cfi_offset(%r14, -48) +- pushq %rsi +- cfi_adjust_cfa_offset(8) +- +- /* Stack frame for the timespec and timeval structs. */ +- subq $24, %rsp +- cfi_adjust_cfa_offset(24) +- +- movq %rdi, %r12 +- movq %rdx, %r13 +- +- movl $2, %edx +- xchgl %edx, (%r12) +- +- testl %edx, %edx +- je 6f +- +-1: +- /* Get current time. */ +- movq %rsp, %rdi +- xorl %esi, %esi +- /* This call works because we directly jump to a system call entry +- which preserves all the registers. */ +- call JUMPTARGET(__gettimeofday) +- +- /* Compute relative timeout. */ +- movq 8(%rsp), %rax +- movl $1000, %edi +- mul %rdi /* Milli seconds to nano seconds. */ +- movq (%r13), %rdi +- movq 8(%r13), %rsi +- subq (%rsp), %rdi +- subq %rax, %rsi +- jns 4f +- addq $1000000000, %rsi +- decq %rdi +-4: testq %rdi, %rdi +- js 2f /* Time is already up. */ +- +- /* Store relative timeout. */ +- movq %rdi, (%rsp) +- movq %rsi, 8(%rsp) +- +- /* Futex call. */ +- movl $2, %edx +- movl $1, %eax +- movq %rsp, %r10 +- movl 24(%rsp), %esi +- LOAD_FUTEX_WAIT (%esi) +- movq %r12, %rdi +- movl $SYS_futex, %eax +- syscall +- +- /* NB: %edx == 2 */ +- xchgl %edx, (%r12) +- +- testl %edx, %edx +- je 6f +- +- cmpl $-ETIMEDOUT, %eax +- jne 1b +-2: movl $ETIMEDOUT, %edx +- +-6: addq $32, %rsp +- cfi_adjust_cfa_offset(-32) +- popq %r14 +- cfi_adjust_cfa_offset(-8) +- cfi_restore(%r14) +- popq %r13 +- cfi_adjust_cfa_offset(-8) +- cfi_restore(%r13) +- popq %r12 +- cfi_adjust_cfa_offset(-8) +- cfi_restore(%r12) +- popq %r9 +- cfi_adjust_cfa_offset(-8) +- cfi_restore(%r9) +- popq %r8 +- cfi_adjust_cfa_offset(-8) +- cfi_restore(%r8) +- movl %edx, %eax +- retq +- +-3: movl $EINVAL, %eax +- retq +-# endif + cfi_endproc + .size __lll_timedlock_wait,.-__lll_timedlock_wait + #endif +-- +2.21.0.windows.1 + diff --git a/backport-0001-nptl-Add-clockid-parameter-to-futex-timed-wait-calls.patch b/backport-0002-nptl-Add-clockid-parameter-to-futex-timed-wait-calls.patch similarity index 97% rename from backport-0001-nptl-Add-clockid-parameter-to-futex-timed-wait-calls.patch rename to backport-0002-nptl-Add-clockid-parameter-to-futex-timed-wait-calls.patch index 0128c4e..2991c27 100644 --- a/backport-0001-nptl-Add-clockid-parameter-to-futex-timed-wait-calls.patch +++ b/backport-0002-nptl-Add-clockid-parameter-to-futex-timed-wait-calls.patch @@ -3,6 +3,9 @@ From: Mike Crowe Date: Fri, 21 Jun 2019 14:53:40 +0000 Subject: [PATCH] nptl: Add clockid parameter to futex timed wait calls +Conflict:NA +Reference:https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=99d01ffcc386d1bfb681fb0684fcf6a6a996beb3 + In preparation for adding POSIX clockwait variants of timedwait functions, add a clockid_t parameter to futex_abstimed_wait functions and pass CLOCK_REALTIME from all callers for the time being. @@ -48,10 +51,10 @@ Reviewed-by: Adhemerval Zanella nptl/pthread_rwlock_common.c | 8 ++--- nptl/sem_waitcommon.c | 6 ++-- sysdeps/nptl/futex-internal.h | 9 +++++- - sysdeps/nptl/lowlevellock-futex.h | 14 ++++++--- + sysdeps/nptl/lowlevellock-futex.h | 13 ++++++--- sysdeps/unix/sysv/linux/futex-internal.h | 24 ++++++++++---- sysdeps/unix/sysv/linux/lowlevellock-futex.h | 32 +++++++++++++++---- - 9 files changed, 110 insertions(+), 52 deletions(-) + 9 files changed, 110 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24a97096..1f8cf24f 100644 @@ -91,9 +94,9 @@ index 24a97096..1f8cf24f 100644 + * nptl/pthread_mutex_timedlock.c (__pthread_mutex_timedlock): + Switch to lll_futex_clock_wait_bitset and pass CLOCK_REALTIME + - 2019-04-23 Adhemerval Zanella + 2019-03-05 Adhemerval Zanella - [BZ #18035] + * nptl/nptl-init.c (__have_futex_clock_realtime, diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index 3e110541..3294fa3a 100644 --- a/nptl/pthread_cond_wait.c @@ -145,9 +148,9 @@ index 888c12fe..46fcf8d8 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -292,8 +292,8 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex, - lll_futex_timed_wait (&mutex->__data.__lock, oldval, - &rt, PTHREAD_ROBUST_MUTEX_PSHARED (mutex)); - #else + assume_other_futex_waiters |= FUTEX_WAITERS; + + /* Block using the futex. */ - int err = lll_futex_timed_wait_bitset (&mutex->__data.__lock, - oldval, abstime, FUTEX_CLOCK_REALTIME, + int err = lll_futex_clock_wait_bitset (&mutex->__data.__lock, @@ -256,12 +259,11 @@ diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex index 27b81b83..68ce7516 100644 --- a/sysdeps/nptl/lowlevellock-futex.h +++ b/sysdeps/nptl/lowlevellock-futex.h -@@ -43,11 +43,15 @@ +@@ -43,10 +43,15 @@ #define lll_futex_timed_wait(futexp, val, timeout, private) \ -ENOSYS --/* This macro should be defined only if FUTEX_CLOCK_REALTIME is also defined. -- If CLOCKBIT is zero, this is identical to lll_futex_timed_wait. +-/* If CLOCKBIT is zero, this is identical to lll_futex_timed_wait. - If CLOCKBIT has FUTEX_CLOCK_REALTIME set, then it's the same but - TIMEOUT is counted by CLOCK_REALTIME rather than CLOCK_MONOTONIC. */ -#define lll_futex_timed_wait_bitset(futexp, val, timeout, clockbit, private) \ diff --git a/backport-0002-support-Add-timespec.h-xtime.h.patch b/backport-0003-support-Add-timespec.h-xtime.h.patch similarity index 97% rename from backport-0002-support-Add-timespec.h-xtime.h.patch rename to backport-0003-support-Add-timespec.h-xtime.h.patch index 32c7728..b184ea4 100644 --- a/backport-0002-support-Add-timespec.h-xtime.h.patch +++ b/backport-0003-support-Add-timespec.h-xtime.h.patch @@ -1,455 +1,458 @@ -From 519839965197291924895a3988804e325035beee Mon Sep 17 00:00:00 2001 -From: Mike Crowe -Date: Thu, 9 May 2019 14:19:21 -0300 -Subject: [PATCH] support: Add timespec.h xtime.h Add xclock_gettime - -It adds useful functions for tests that use struct timespec. - -Checked on x86_64-linux-gnu and i686-linux-gnu. - - * support/timespec.h: New file. Provide timespec helper functions - along with macros in the style of those in check.h. - * support/timespec.c: New file. Implement check functions declared - in support/timespec.h. - * support/timespec-add.c: New file from gnulib containing - timespec_add implementation that handles overflow. - * support/timespec-sub.c: New file from gnulib containing - timespec_sub implementation that handles overflow. - * support/xclock_gettime.c (xclock_gettime): New file. Provide - clock_gettime wrapper for use in tests that fails the test rather - than returning failure. - * support/xtime.h: New file to declare xclock_gettime. - * support/Makefile: Add xclock_gettime.c timespec.c timespec-add.c timespec-sub.c. - -Reviewed-by: Adhemerval Zanella ---- - support/Makefile | 4 ++ - support/timespec-add.c | 71 ++++++++++++++++++++++++++++++++++++ - support/timespec-sub.c | 71 ++++++++++++++++++++++++++++++++++++ - support/timespec.c | 59 ++++++++++++++++++++++++++++++ - support/timespec.h | 79 ++++++++++++++++++++++++++++++++++++++++ - support/xclock_gettime.c | 31 ++++++++++++++++ - support/xtime.h | 43 ++++++++++++++++++++++ - 7 files changed, 358 insertions(+) - create mode 100644 support/timespec-add.c - create mode 100644 support/timespec-sub.c - create mode 100644 support/timespec.c - create mode 100644 support/timespec.h - create mode 100644 support/xclock_gettime.c - create mode 100644 support/xtime.h - -diff --git a/support/Makefile b/support/Makefile -index 9bc68583..90c10bac 100644 ---- a/support/Makefile -+++ b/support/Makefile -@@ -65,6 +65,9 @@ libsupport-routines = \ - support_test_main \ - support_test_verify_impl \ - temp_file \ -+ timespec \ -+ timespec-add \ -+ timespec-sub \ - write_message \ - xaccept \ - xaccept4 \ -@@ -72,6 +75,7 @@ libsupport-routines = \ - xbind \ - xcalloc \ - xchroot \ -+ xclock_gettime \ - xclose \ - xconnect \ - xdlfcn \ -diff --git a/support/timespec-add.c b/support/timespec-add.c -new file mode 100644 -index 00000000..f26abce1 ---- /dev/null -+++ b/support/timespec-add.c -@@ -0,0 +1,71 @@ -+/* Add two struct timespec values. -+ Copyright (C) 2011-2019 Free Software Foundation, Inc. -+ This file is part of the GNU C Library and is also part of gnulib. -+ Patches to this file should be submitted to both projects. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, see -+ . */ -+ -+/* Return the sum of two timespec values A and B. On overflow, return -+ an extremal value. This assumes 0 <= tv_nsec < TIMESPEC_HZ. */ -+ -+#include -+#include "timespec.h" -+ -+#include "intprops.h" -+ -+struct timespec -+timespec_add (struct timespec a, struct timespec b) -+{ -+ time_t rs = a.tv_sec; -+ time_t bs = b.tv_sec; -+ int ns = a.tv_nsec + b.tv_nsec; -+ int nsd = ns - TIMESPEC_HZ; -+ int rns = ns; -+ time_t tmin = TYPE_MINIMUM (time_t); -+ time_t tmax = TYPE_MAXIMUM (time_t); -+ -+ if (0 <= nsd) -+ { -+ rns = nsd; -+ if (bs < tmax) -+ bs++; -+ else if (rs < 0) -+ rs++; -+ else -+ goto high_overflow; -+ } -+ -+ /* INT_ADD_WRAPV is not appropriate since time_t might be unsigned. -+ In theory time_t might be narrower than int, so plain -+ INT_ADD_OVERFLOW does not suffice. */ -+ if (! INT_ADD_OVERFLOW (rs, bs) && tmin <= rs + bs && rs + bs <= tmax) -+ rs += bs; -+ else -+ { -+ if (rs < 0) -+ { -+ rs = tmin; -+ rns = 0; -+ } -+ else -+ { -+ high_overflow: -+ rs = tmax; -+ rns = TIMESPEC_HZ - 1; -+ } -+ } -+ -+ return make_timespec (rs, rns); -+} -diff --git a/support/timespec-sub.c b/support/timespec-sub.c -new file mode 100644 -index 00000000..7c33a59f ---- /dev/null -+++ b/support/timespec-sub.c -@@ -0,0 +1,71 @@ -+/* Subtract two struct timespec values. -+ Copyright (C) 2011-2019 Free Software Foundation, Inc. -+ This file is part of the GNU C Library and is also part of gnulib. -+ Patches to this file should be submitted to both projects. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, see -+ . */ -+ -+/* Return the difference between two timespec values A and B. On -+ overflow, return an extremal value. This assumes 0 <= tv_nsec < -+ TIMESPEC_HZ. */ -+ -+#include -+#include "timespec.h" -+ -+#include "intprops.h" -+ -+struct timespec -+timespec_sub (struct timespec a, struct timespec b) -+{ -+ time_t rs = a.tv_sec; -+ time_t bs = b.tv_sec; -+ int ns = a.tv_nsec - b.tv_nsec; -+ int rns = ns; -+ time_t tmin = TYPE_MINIMUM (time_t); -+ time_t tmax = TYPE_MAXIMUM (time_t); -+ -+ if (ns < 0) -+ { -+ rns = ns + TIMESPEC_HZ; -+ if (bs < tmax) -+ bs++; -+ else if (- TYPE_SIGNED (time_t) < rs) -+ rs--; -+ else -+ goto low_overflow; -+ } -+ -+ /* INT_SUBTRACT_WRAPV is not appropriate since time_t might be unsigned. -+ In theory time_t might be narrower than int, so plain -+ INT_SUBTRACT_OVERFLOW does not suffice. */ -+ if (! INT_SUBTRACT_OVERFLOW (rs, bs) && tmin <= rs - bs && rs - bs <= tmax) -+ rs -= bs; -+ else -+ { -+ if (rs < 0) -+ { -+ low_overflow: -+ rs = tmin; -+ rns = 0; -+ } -+ else -+ { -+ rs = tmax; -+ rns = TIMESPEC_HZ - 1; -+ } -+ } -+ -+ return make_timespec (rs, rns); -+} -diff --git a/support/timespec.c b/support/timespec.c -new file mode 100644 -index 00000000..0a1a13ff ---- /dev/null -+++ b/support/timespec.c -@@ -0,0 +1,59 @@ -+/* Support code for timespec checks. -+ Copyright (C) 2019 Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, see -+ . */ -+ -+#include -+#include -+#include -+ -+void -+test_timespec_before_impl (const char *file, int line, -+ const struct timespec left, -+ const struct timespec right) -+{ -+ if (left.tv_sec > right.tv_sec -+ || (left.tv_sec == right.tv_sec -+ && left.tv_nsec > right.tv_nsec)) { -+ support_record_failure (); -+ const struct timespec diff = timespec_sub (left, right); -+ printf ("%s:%d: %jd.%09jds not before %jd.%09jds " -+ "(difference %jd.%09jds)\n", -+ file, line, -+ (intmax_t) left.tv_sec, (intmax_t) left.tv_nsec, -+ (intmax_t) right.tv_sec, (intmax_t) right.tv_nsec, -+ (intmax_t) diff.tv_sec, (intmax_t) diff.tv_nsec); -+ } -+} -+ -+void -+test_timespec_equal_or_after_impl (const char *file, int line, -+ const struct timespec left, -+ const struct timespec right) -+{ -+ if (left.tv_sec < right.tv_sec -+ || (left.tv_sec == right.tv_sec -+ && left.tv_nsec < right.tv_nsec)) { -+ support_record_failure (); -+ const struct timespec diff = timespec_sub (right, left); -+ printf ("%s:%d: %jd.%09jds not after %jd.%09jds " -+ "(difference %jd.%09jds)\n", -+ file, line, -+ (intmax_t) left.tv_sec, (intmax_t) left.tv_nsec, -+ (intmax_t) right.tv_sec, (intmax_t) right.tv_nsec, -+ (intmax_t) diff.tv_sec, (intmax_t) diff.tv_nsec); -+ } -+} -diff --git a/support/timespec.h b/support/timespec.h -new file mode 100644 -index 00000000..cf2c0318 ---- /dev/null -+++ b/support/timespec.h -@@ -0,0 +1,79 @@ -+/* Useful functions for tests that use struct timespec. -+ Copyright (C) 2019 Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, see -+ . */ -+ -+#ifndef SUPPORT_TIMESPEC_H -+#define SUPPORT_TIMESPEC_H -+ -+#include -+#include -+#include -+#include -+ -+struct timespec timespec_add (struct timespec, struct timespec) -+ __attribute__((const)); -+struct timespec timespec_sub (struct timespec, struct timespec) -+ __attribute__((const)); -+ -+static inline struct timespec -+make_timespec (time_t s, long int ns) -+{ -+ struct timespec r; -+ r.tv_sec = s; -+ r.tv_nsec = ns; -+ return r; -+} -+ -+enum { TIMESPEC_HZ = 1000000000 }; -+ -+void test_timespec_before_impl (const char *file, int line, -+ const struct timespec left, -+ const struct timespec right); -+ -+void test_timespec_equal_or_after_impl (const char *file, int line, -+ const struct timespec left, -+ const struct timespec right); -+ -+/* Check that the timespec on the left represents a time before the -+ time on the right. */ -+#define TEST_TIMESPEC_BEFORE(left, right) \ -+ test_timespec_before_impl (__FILE__, __LINE__, (left), (right)) -+ -+#define TEST_TIMESPEC_BEFORE_NOW(left, clockid) \ -+ ({ \ -+ struct timespec now; \ -+ const int saved_errno = errno; \ -+ xclock_gettime ((clockid), &now); \ -+ TEST_TIMESPEC_BEFORE ((left), now); \ -+ errno = saved_errno; \ -+ }) -+ -+/* Check that the timespec on the left represents a time equal to or -+ after the time on the right. */ -+#define TEST_TIMESPEC_EQUAL_OR_AFTER(left, right) \ -+ test_timespec_equal_or_after_impl (__FILE__, __LINE__, left, right) -+ -+#define TEST_TIMESPEC_NOW_OR_AFTER(clockid, right) \ -+ ({ \ -+ struct timespec now; \ -+ const int saved_errno = errno; \ -+ xclock_gettime ((clockid), &now); \ -+ TEST_TIMESPEC_EQUAL_OR_AFTER (now, (right)); \ -+ errno = saved_errno; \ -+ }) -+ -+#endif /* SUPPORT_TIMESPEC_H */ -diff --git a/support/xclock_gettime.c b/support/xclock_gettime.c -new file mode 100644 -index 00000000..5dd3ae9b ---- /dev/null -+++ b/support/xclock_gettime.c -@@ -0,0 +1,31 @@ -+/* clock_gettime with error checking. -+ Copyright (C) 2019 Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, see -+ . */ -+ -+#include -+#include -+#include -+ -+void -+xclock_gettime (clockid_t clockid, -+ struct timespec *ts) -+{ -+ const int ret = clock_gettime (clockid, ts); -+ if (ret < 0) -+ FAIL_EXIT1 ("clock_gettime (%d): %m", -+ clockid); -+} -diff --git a/support/xtime.h b/support/xtime.h -new file mode 100644 -index 00000000..9e6df5b9 ---- /dev/null -+++ b/support/xtime.h -@@ -0,0 +1,43 @@ -+/* Support functionality for using time. -+ Copyright (C) 2019 Free Software Foundation, Inc. -+ This file is part of the GNU C Library. -+ -+ The GNU C Library is free software; you can redistribute it and/or -+ modify it under the terms of the GNU Lesser General Public -+ License as published by the Free Software Foundation; either -+ version 2.1 of the License, or (at your option) any later version. -+ -+ The GNU C Library is distributed in the hope that it will be useful, -+ but WITHOUT ANY WARRANTY; without even the implied warranty of -+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ Lesser General Public License for more details. -+ -+ You should have received a copy of the GNU Lesser General Public -+ License along with the GNU C Library; if not, see -+ . */ -+ -+#ifndef SUPPORT_TIME_H -+#define SUPPORT_TIME_H -+ -+#include -+ -+__BEGIN_DECLS -+ -+/* The following functions call the corresponding libc functions and -+ terminate the process on error. */ -+ -+void xclock_gettime (clockid_t clock, struct timespec *ts); -+ -+/* This helper can often simplify tests by avoiding an explicit -+ variable declaration or allowing that declaration to be const. */ -+ -+static inline struct timespec xclock_now (clockid_t clock) -+{ -+ struct timespec ts; -+ xclock_gettime (clock, &ts); -+ return ts; -+} -+ -+__END_DECLS -+ -+#endif /* SUPPORT_TIME_H */ --- -2.23.0 - +From 519839965197291924895a3988804e325035beee Mon Sep 17 00:00:00 2001 +From: Mike Crowe +Date: Thu, 9 May 2019 14:19:21 -0300 +Subject: [PATCH] support: Add timespec.h xtime.h Add xclock_gettime + +Conflict:NA +Reference:https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=519839965197291924895a3988804e325035beee + +It adds useful functions for tests that use struct timespec. + +Checked on x86_64-linux-gnu and i686-linux-gnu. + + * support/timespec.h: New file. Provide timespec helper functions + along with macros in the style of those in check.h. + * support/timespec.c: New file. Implement check functions declared + in support/timespec.h. + * support/timespec-add.c: New file from gnulib containing + timespec_add implementation that handles overflow. + * support/timespec-sub.c: New file from gnulib containing + timespec_sub implementation that handles overflow. + * support/xclock_gettime.c (xclock_gettime): New file. Provide + clock_gettime wrapper for use in tests that fails the test rather + than returning failure. + * support/xtime.h: New file to declare xclock_gettime. + * support/Makefile: Add xclock_gettime.c timespec.c timespec-add.c timespec-sub.c. + +Reviewed-by: Adhemerval Zanella +--- + support/Makefile | 4 ++ + support/timespec-add.c | 71 ++++++++++++++++++++++++++++++++++++ + support/timespec-sub.c | 71 ++++++++++++++++++++++++++++++++++++ + support/timespec.c | 59 ++++++++++++++++++++++++++++++ + support/timespec.h | 79 ++++++++++++++++++++++++++++++++++++++++ + support/xclock_gettime.c | 31 ++++++++++++++++ + support/xtime.h | 43 ++++++++++++++++++++++ + 7 files changed, 358 insertions(+) + create mode 100644 support/timespec-add.c + create mode 100644 support/timespec-sub.c + create mode 100644 support/timespec.c + create mode 100644 support/timespec.h + create mode 100644 support/xclock_gettime.c + create mode 100644 support/xtime.h + +diff --git a/support/Makefile b/support/Makefile +index 9bc68583..90c10bac 100644 +--- a/support/Makefile ++++ b/support/Makefile +@@ -65,6 +65,9 @@ libsupport-routines = \ + support_test_main \ + support_test_verify_impl \ + temp_file \ ++ timespec \ ++ timespec-add \ ++ timespec-sub \ + write_message \ + xaccept \ + xaccept4 \ +@@ -72,6 +75,7 @@ libsupport-routines = \ + xbind \ + xcalloc \ + xchroot \ ++ xclock_gettime \ + xclose \ + xconnect \ + xdlfcn \ +diff --git a/support/timespec-add.c b/support/timespec-add.c +new file mode 100644 +index 00000000..f26abce1 +--- /dev/null ++++ b/support/timespec-add.c +@@ -0,0 +1,71 @@ ++/* Add two struct timespec values. ++ Copyright (C) 2011-2019 Free Software Foundation, Inc. ++ This file is part of the GNU C Library and is also part of gnulib. ++ Patches to this file should be submitted to both projects. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++/* Return the sum of two timespec values A and B. On overflow, return ++ an extremal value. This assumes 0 <= tv_nsec < TIMESPEC_HZ. */ ++ ++#include ++#include "timespec.h" ++ ++#include "intprops.h" ++ ++struct timespec ++timespec_add (struct timespec a, struct timespec b) ++{ ++ time_t rs = a.tv_sec; ++ time_t bs = b.tv_sec; ++ int ns = a.tv_nsec + b.tv_nsec; ++ int nsd = ns - TIMESPEC_HZ; ++ int rns = ns; ++ time_t tmin = TYPE_MINIMUM (time_t); ++ time_t tmax = TYPE_MAXIMUM (time_t); ++ ++ if (0 <= nsd) ++ { ++ rns = nsd; ++ if (bs < tmax) ++ bs++; ++ else if (rs < 0) ++ rs++; ++ else ++ goto high_overflow; ++ } ++ ++ /* INT_ADD_WRAPV is not appropriate since time_t might be unsigned. ++ In theory time_t might be narrower than int, so plain ++ INT_ADD_OVERFLOW does not suffice. */ ++ if (! INT_ADD_OVERFLOW (rs, bs) && tmin <= rs + bs && rs + bs <= tmax) ++ rs += bs; ++ else ++ { ++ if (rs < 0) ++ { ++ rs = tmin; ++ rns = 0; ++ } ++ else ++ { ++ high_overflow: ++ rs = tmax; ++ rns = TIMESPEC_HZ - 1; ++ } ++ } ++ ++ return make_timespec (rs, rns); ++} +diff --git a/support/timespec-sub.c b/support/timespec-sub.c +new file mode 100644 +index 00000000..7c33a59f +--- /dev/null ++++ b/support/timespec-sub.c +@@ -0,0 +1,71 @@ ++/* Subtract two struct timespec values. ++ Copyright (C) 2011-2019 Free Software Foundation, Inc. ++ This file is part of the GNU C Library and is also part of gnulib. ++ Patches to this file should be submitted to both projects. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++/* Return the difference between two timespec values A and B. On ++ overflow, return an extremal value. This assumes 0 <= tv_nsec < ++ TIMESPEC_HZ. */ ++ ++#include ++#include "timespec.h" ++ ++#include "intprops.h" ++ ++struct timespec ++timespec_sub (struct timespec a, struct timespec b) ++{ ++ time_t rs = a.tv_sec; ++ time_t bs = b.tv_sec; ++ int ns = a.tv_nsec - b.tv_nsec; ++ int rns = ns; ++ time_t tmin = TYPE_MINIMUM (time_t); ++ time_t tmax = TYPE_MAXIMUM (time_t); ++ ++ if (ns < 0) ++ { ++ rns = ns + TIMESPEC_HZ; ++ if (bs < tmax) ++ bs++; ++ else if (- TYPE_SIGNED (time_t) < rs) ++ rs--; ++ else ++ goto low_overflow; ++ } ++ ++ /* INT_SUBTRACT_WRAPV is not appropriate since time_t might be unsigned. ++ In theory time_t might be narrower than int, so plain ++ INT_SUBTRACT_OVERFLOW does not suffice. */ ++ if (! INT_SUBTRACT_OVERFLOW (rs, bs) && tmin <= rs - bs && rs - bs <= tmax) ++ rs -= bs; ++ else ++ { ++ if (rs < 0) ++ { ++ low_overflow: ++ rs = tmin; ++ rns = 0; ++ } ++ else ++ { ++ rs = tmax; ++ rns = TIMESPEC_HZ - 1; ++ } ++ } ++ ++ return make_timespec (rs, rns); ++} +diff --git a/support/timespec.c b/support/timespec.c +new file mode 100644 +index 00000000..0a1a13ff +--- /dev/null ++++ b/support/timespec.c +@@ -0,0 +1,59 @@ ++/* Support code for timespec checks. ++ Copyright (C) 2019 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#include ++#include ++#include ++ ++void ++test_timespec_before_impl (const char *file, int line, ++ const struct timespec left, ++ const struct timespec right) ++{ ++ if (left.tv_sec > right.tv_sec ++ || (left.tv_sec == right.tv_sec ++ && left.tv_nsec > right.tv_nsec)) { ++ support_record_failure (); ++ const struct timespec diff = timespec_sub (left, right); ++ printf ("%s:%d: %jd.%09jds not before %jd.%09jds " ++ "(difference %jd.%09jds)\n", ++ file, line, ++ (intmax_t) left.tv_sec, (intmax_t) left.tv_nsec, ++ (intmax_t) right.tv_sec, (intmax_t) right.tv_nsec, ++ (intmax_t) diff.tv_sec, (intmax_t) diff.tv_nsec); ++ } ++} ++ ++void ++test_timespec_equal_or_after_impl (const char *file, int line, ++ const struct timespec left, ++ const struct timespec right) ++{ ++ if (left.tv_sec < right.tv_sec ++ || (left.tv_sec == right.tv_sec ++ && left.tv_nsec < right.tv_nsec)) { ++ support_record_failure (); ++ const struct timespec diff = timespec_sub (right, left); ++ printf ("%s:%d: %jd.%09jds not after %jd.%09jds " ++ "(difference %jd.%09jds)\n", ++ file, line, ++ (intmax_t) left.tv_sec, (intmax_t) left.tv_nsec, ++ (intmax_t) right.tv_sec, (intmax_t) right.tv_nsec, ++ (intmax_t) diff.tv_sec, (intmax_t) diff.tv_nsec); ++ } ++} +diff --git a/support/timespec.h b/support/timespec.h +new file mode 100644 +index 00000000..cf2c0318 +--- /dev/null ++++ b/support/timespec.h +@@ -0,0 +1,79 @@ ++/* Useful functions for tests that use struct timespec. ++ Copyright (C) 2019 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#ifndef SUPPORT_TIMESPEC_H ++#define SUPPORT_TIMESPEC_H ++ ++#include ++#include ++#include ++#include ++ ++struct timespec timespec_add (struct timespec, struct timespec) ++ __attribute__((const)); ++struct timespec timespec_sub (struct timespec, struct timespec) ++ __attribute__((const)); ++ ++static inline struct timespec ++make_timespec (time_t s, long int ns) ++{ ++ struct timespec r; ++ r.tv_sec = s; ++ r.tv_nsec = ns; ++ return r; ++} ++ ++enum { TIMESPEC_HZ = 1000000000 }; ++ ++void test_timespec_before_impl (const char *file, int line, ++ const struct timespec left, ++ const struct timespec right); ++ ++void test_timespec_equal_or_after_impl (const char *file, int line, ++ const struct timespec left, ++ const struct timespec right); ++ ++/* Check that the timespec on the left represents a time before the ++ time on the right. */ ++#define TEST_TIMESPEC_BEFORE(left, right) \ ++ test_timespec_before_impl (__FILE__, __LINE__, (left), (right)) ++ ++#define TEST_TIMESPEC_BEFORE_NOW(left, clockid) \ ++ ({ \ ++ struct timespec now; \ ++ const int saved_errno = errno; \ ++ xclock_gettime ((clockid), &now); \ ++ TEST_TIMESPEC_BEFORE ((left), now); \ ++ errno = saved_errno; \ ++ }) ++ ++/* Check that the timespec on the left represents a time equal to or ++ after the time on the right. */ ++#define TEST_TIMESPEC_EQUAL_OR_AFTER(left, right) \ ++ test_timespec_equal_or_after_impl (__FILE__, __LINE__, left, right) ++ ++#define TEST_TIMESPEC_NOW_OR_AFTER(clockid, right) \ ++ ({ \ ++ struct timespec now; \ ++ const int saved_errno = errno; \ ++ xclock_gettime ((clockid), &now); \ ++ TEST_TIMESPEC_EQUAL_OR_AFTER (now, (right)); \ ++ errno = saved_errno; \ ++ }) ++ ++#endif /* SUPPORT_TIMESPEC_H */ +diff --git a/support/xclock_gettime.c b/support/xclock_gettime.c +new file mode 100644 +index 00000000..5dd3ae9b +--- /dev/null ++++ b/support/xclock_gettime.c +@@ -0,0 +1,31 @@ ++/* clock_gettime with error checking. ++ Copyright (C) 2019 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#include ++#include ++#include ++ ++void ++xclock_gettime (clockid_t clockid, ++ struct timespec *ts) ++{ ++ const int ret = clock_gettime (clockid, ts); ++ if (ret < 0) ++ FAIL_EXIT1 ("clock_gettime (%d): %m", ++ clockid); ++} +diff --git a/support/xtime.h b/support/xtime.h +new file mode 100644 +index 00000000..9e6df5b9 +--- /dev/null ++++ b/support/xtime.h +@@ -0,0 +1,43 @@ ++/* Support functionality for using time. ++ Copyright (C) 2019 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ ++#ifndef SUPPORT_TIME_H ++#define SUPPORT_TIME_H ++ ++#include ++ ++__BEGIN_DECLS ++ ++/* The following functions call the corresponding libc functions and ++ terminate the process on error. */ ++ ++void xclock_gettime (clockid_t clock, struct timespec *ts); ++ ++/* This helper can often simplify tests by avoiding an explicit ++ variable declaration or allowing that declaration to be const. */ ++ ++static inline struct timespec xclock_now (clockid_t clock) ++{ ++ struct timespec ts; ++ xclock_gettime (clock, &ts); ++ return ts; ++} ++ ++__END_DECLS ++ ++#endif /* SUPPORT_TIME_H */ +-- +2.23.0 + diff --git a/backport-0003-nptl-Add-POSIX-proposed-pthread_cond_clockwait.patch b/backport-0004-nptl-Add-POSIX-proposed-pthread_cond_clockwait.patch similarity index 99% rename from backport-0003-nptl-Add-POSIX-proposed-pthread_cond_clockwait.patch rename to backport-0004-nptl-Add-POSIX-proposed-pthread_cond_clockwait.patch index dab152e..a6734db 100644 --- a/backport-0003-nptl-Add-POSIX-proposed-pthread_cond_clockwait.patch +++ b/backport-0004-nptl-Add-POSIX-proposed-pthread_cond_clockwait.patch @@ -3,6 +3,9 @@ From: Mike Crowe Date: Fri, 21 Jun 2019 17:36:56 +0000 Subject: [PATCH] nptl: Add POSIX-proposed pthread_cond_clockwait +Conflict:NA +Reference:https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=afe4de7d283ebd88157126c5494ce1796194c16e + Add: int pthread_cond_clockwait (pthread_cond_t *cond, diff --git a/glibc.spec b/glibc.spec index ea151d9..7fc4b6a 100644 --- a/glibc.spec +++ b/glibc.spec @@ -59,7 +59,7 @@ ############################################################################## Name: glibc Version: 2.28 -Release: 65 +Release: 66 Summary: The GNU libc libraries License: %{all_license} URL: http://www.gnu.org/software/glibc/ @@ -119,9 +119,10 @@ Patch35: backport-aarch64-revert-memcpy-optimze-for-kunpeng-to-avoid-p.patch Patch36: backport-elf-Allow-dlopen-of-filter-object-to-work-BZ-16272.patch Patch37: backport-elf-Fix-pldd-BZ-18035.patch Patch38: backport-CVE-2021-3326-gconv-Fix-assertion-failure-in-ISO-2022-JP-3-module-.patch -Patch39: backport-0001-nptl-Add-clockid-parameter-to-futex-timed-wait-calls.patch -Patch40: backport-0002-support-Add-timespec.h-xtime.h.patch -Patch41: backport-0003-nptl-Add-POSIX-proposed-pthread_cond_clockwait.patch +Patch39: backport-0001-nptl-Assume-__ASSUME_FUTEX_CLOCK_REALTIME-support.patch +Patch40: backport-0002-nptl-Add-clockid-parameter-to-futex-timed-wait-calls.patch +Patch41: backport-0003-support-Add-timespec.h-xtime.h.patch +Patch42: backport-0004-nptl-Add-POSIX-proposed-pthread_cond_clockwait.patch Provides: ldconfig rtld(GNU_HASH) bundled(gnulib) @@ -1146,6 +1147,9 @@ fi %doc hesiod/README.hesiod %changelog +* Wed May 12 2021 xuhuijie - 2.28-66 +- pthread_cond_clockwait: add pre-patch to prevent adaptions + * Wed Apr 21 2021 xuhuijie - 2.28-65 - Add POSIX-proposed pthread_cond_clockwait -- Gitee