Skip to content

Commit d0a48dc

Browse files
Terry TrittonKAGA-KOKO
authored andcommitted
selftests/futex: Convert 32-bit timespec to 64-bit version for 32-bit compatibility mode
sys_futex_wait() expects a struct __kernel_timespec pointer for the timeout, but the provided struct timespec pointer is of type struct old_timespec32 when compiled for 32-bit architectures, unless they use 64-bit timespecs already. Make it work for all variants by converting the provided timespec value into a local struct __kernel_timespec and provide a pointer to it to the syscall. This is a pointless operation for 64-bit, but this is not a hotpath operation, so keep it simple. This fix is based off [1] Originally-by: Wei Gao <[email protected]> Signed-off-by: Terry Tritton <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/all/[email protected] Link: https://lore.kernel.org/all/[email protected]/ [1]
1 parent 46b0a67 commit d0a48dc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tools/testing/selftests/futex/include/futex2test.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* Copyright 2021 Collabora Ltd.
66
*/
7+
#include <linux/time_types.h>
78
#include <stdint.h>
89

910
#define u64_to_ptr(x) ((void *)(uintptr_t)(x))
@@ -65,7 +66,12 @@ struct futex32_numa {
6566
static inline int futex_waitv(volatile struct futex_waitv *waiters, unsigned long nr_waiters,
6667
unsigned long flags, struct timespec *timo, clockid_t clockid)
6768
{
68-
return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
69+
struct __kernel_timespec ts = {
70+
.tv_sec = timo->tv_sec,
71+
.tv_nsec = timo->tv_nsec,
72+
};
73+
74+
return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &ts, clockid);
6975
}
7076

7177
/*

0 commit comments

Comments
 (0)