From 9aada05f4c7f95220a5b16416f530419db6b4dff Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 23 Jul 2021 08:00:00 +0000 Subject: [PATCH] tests: change sockopt-timestamp test to use syscall(__NR_recvmsg) Since the glibc recvmsg wrapper became unsuitable for our needs, invoke __NR_recvmsg syscall directly. * tests/sockopt-timestamp.c: Include "scno.h" and , conditionalize on __NR_recvmsg. (TEST_OLD_SCM_TIMESTAMPS): Remove. (k_recvmsg): New function. (test_sockopt): Use it instead of recvmsg. --- tests/sockopt-timestamp.c | 72 ++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/tests/sockopt-timestamp.c b/tests/sockopt-timestamp.c index 56627bb..ed73ca1 100644 --- a/tests/sockopt-timestamp.c +++ b/tests/sockopt-timestamp.c @@ -9,44 +9,45 @@ */ #include "tests.h" -#include -#include -#include -#include - -#if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ - || defined HAVE_STRUCT___KERNEL_TIMESPEC -# include -#endif +#include "scno.h" -#include "kernel_timeval.h" -#include "kernel_old_timespec.h" +#ifdef __NR_recvmsg -#define XLAT_MACROS_ONLY -# include "xlat/sock_options.h" -#undef XLAT_MACROS_ONLY +# include +# include +# include +# include +# include -#undef TEST_OLD_SCM_TIMESTAMPS +# if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ + || defined HAVE_STRUCT___KERNEL_TIMESPEC +# include +# endif -/* - * Sadly, starting with commit - * glibc-2.33.9000-707-g13c51549e2077f2f3bf84e8fd0b46d8b0c615912, on every - * 32-bit architecture where 32-bit time_t support is enabled, - * glibc mangles old scm timestamps. - */ -#if GLIBC_PREREQ_GE(2, 33) && defined __TIMESIZE && __TIMESIZE != 64 -# define TEST_OLD_SCM_TIMESTAMPS 0 -#endif +# include "kernel_timeval.h" +# include "kernel_old_timespec.h" -#ifndef TEST_OLD_SCM_TIMESTAMPS -# define TEST_OLD_SCM_TIMESTAMPS 1 -#endif +# define XLAT_MACROS_ONLY +# include "xlat/sock_options.h" +# undef XLAT_MACROS_ONLY -#if TEST_OLD_SCM_TIMESTAMPS \ - || defined HAVE_STRUCT___KERNEL_TIMESPEC \ - || defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL +static const char *errstr; + +static long +k_recvmsg(const unsigned int fd, const void *const ptr, const unsigned int flags) +{ + const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL; + const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL; + const kernel_ulong_t arg1 = fill | fd; + const kernel_ulong_t arg2 = (uintptr_t) ptr; + const kernel_ulong_t arg3 = fill | flags; + const long rc = syscall(__NR_recvmsg, arg1, arg2, arg3, bad, bad, bad); + if (rc && errno == ENOSYS) + perror_msg_and_skip("recvmsg"); + errstr = sprintrc(rc); + return rc; +} -# if TEST_OLD_SCM_TIMESTAMPS static void print_timestamp_old(const struct cmsghdr *c) { @@ -84,7 +85,6 @@ print_timestampns_old(const struct cmsghdr *c) printf("{tv_sec=%lld, tv_nsec=%lld}", (long long) ts.tv_sec, (long long) ts.tv_nsec); } -# endif /* TEST_OLD_SCM_TIMESTAMPS */ # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL static void @@ -162,7 +162,7 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *)) .msg_controllen = sizeof(control) }; - if (recvmsg(sv[0], &mh, 0) != (int) size) + if (k_recvmsg(sv[0], &mh, 0) != (int) size) perror_msg_and_fail("recvmsg"); if (close(sv[0])) perror_msg_and_fail("close recv"); @@ -210,10 +210,8 @@ main(void) const char *str; void (*fun)(const struct cmsghdr *); } tests[] = { -# if TEST_OLD_SCM_TIMESTAMPS { SO_TIMESTAMP_OLD, "SO_TIMESTAMP_OLD", print_timestamp_old }, { SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS_OLD", print_timestampns_old }, -# endif # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL { SO_TIMESTAMP_NEW, "SO_TIMESTAMP_NEW", print_timestamp_new }, # endif @@ -235,8 +233,6 @@ main(void) #else -SKIP_MAIN_UNDEFINED("TEST_OLD_SCM_TIMESTAMPS" - " || HAVE_STRUCT___KERNEL_TIMESPEC" - " || HAVE_STRUCT___KERNEL_SOCK_TIMEVAL") +SKIP_MAIN_UNDEFINED("__NR_recvmsg") #endif diff --git a/tests-m32/sockopt-timestamp.c b/tests-m32/sockopt-timestamp.c index 56627bb..ed73ca1 100644 --- a/tests-m32/sockopt-timestamp.c +++ b/tests-m32/sockopt-timestamp.c @@ -9,44 +9,45 @@ */ #include "tests.h" -#include -#include -#include -#include - -#if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ - || defined HAVE_STRUCT___KERNEL_TIMESPEC -# include -#endif +#include "scno.h" -#include "kernel_timeval.h" -#include "kernel_old_timespec.h" +#ifdef __NR_recvmsg -#define XLAT_MACROS_ONLY -# include "xlat/sock_options.h" -#undef XLAT_MACROS_ONLY +# include +# include +# include +# include +# include -#undef TEST_OLD_SCM_TIMESTAMPS +# if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ + || defined HAVE_STRUCT___KERNEL_TIMESPEC +# include +# endif -/* - * Sadly, starting with commit - * glibc-2.33.9000-707-g13c51549e2077f2f3bf84e8fd0b46d8b0c615912, on every - * 32-bit architecture where 32-bit time_t support is enabled, - * glibc mangles old scm timestamps. - */ -#if GLIBC_PREREQ_GE(2, 33) && defined __TIMESIZE && __TIMESIZE != 64 -# define TEST_OLD_SCM_TIMESTAMPS 0 -#endif +# include "kernel_timeval.h" +# include "kernel_old_timespec.h" -#ifndef TEST_OLD_SCM_TIMESTAMPS -# define TEST_OLD_SCM_TIMESTAMPS 1 -#endif +# define XLAT_MACROS_ONLY +# include "xlat/sock_options.h" +# undef XLAT_MACROS_ONLY -#if TEST_OLD_SCM_TIMESTAMPS \ - || defined HAVE_STRUCT___KERNEL_TIMESPEC \ - || defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL +static const char *errstr; + +static long +k_recvmsg(const unsigned int fd, const void *const ptr, const unsigned int flags) +{ + const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL; + const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL; + const kernel_ulong_t arg1 = fill | fd; + const kernel_ulong_t arg2 = (uintptr_t) ptr; + const kernel_ulong_t arg3 = fill | flags; + const long rc = syscall(__NR_recvmsg, arg1, arg2, arg3, bad, bad, bad); + if (rc && errno == ENOSYS) + perror_msg_and_skip("recvmsg"); + errstr = sprintrc(rc); + return rc; +} -# if TEST_OLD_SCM_TIMESTAMPS static void print_timestamp_old(const struct cmsghdr *c) { @@ -84,7 +85,6 @@ print_timestampns_old(const struct cmsghdr *c) printf("{tv_sec=%lld, tv_nsec=%lld}", (long long) ts.tv_sec, (long long) ts.tv_nsec); } -# endif /* TEST_OLD_SCM_TIMESTAMPS */ # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL static void @@ -162,7 +162,7 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *)) .msg_controllen = sizeof(control) }; - if (recvmsg(sv[0], &mh, 0) != (int) size) + if (k_recvmsg(sv[0], &mh, 0) != (int) size) perror_msg_and_fail("recvmsg"); if (close(sv[0])) perror_msg_and_fail("close recv"); @@ -210,10 +210,8 @@ main(void) const char *str; void (*fun)(const struct cmsghdr *); } tests[] = { -# if TEST_OLD_SCM_TIMESTAMPS { SO_TIMESTAMP_OLD, "SO_TIMESTAMP_OLD", print_timestamp_old }, { SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS_OLD", print_timestampns_old }, -# endif # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL { SO_TIMESTAMP_NEW, "SO_TIMESTAMP_NEW", print_timestamp_new }, # endif @@ -235,8 +233,6 @@ main(void) #else -SKIP_MAIN_UNDEFINED("TEST_OLD_SCM_TIMESTAMPS" - " || HAVE_STRUCT___KERNEL_TIMESPEC" - " || HAVE_STRUCT___KERNEL_SOCK_TIMEVAL") +SKIP_MAIN_UNDEFINED("__NR_recvmsg") #endif diff --git a/tests-mx32/sockopt-timestamp.c b/tests-mx32/sockopt-timestamp.c index 56627bb..ed73ca1 100644 --- a/tests-mx32/sockopt-timestamp.c +++ b/tests-mx32/sockopt-timestamp.c @@ -9,44 +9,45 @@ */ #include "tests.h" -#include -#include -#include -#include - -#if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ - || defined HAVE_STRUCT___KERNEL_TIMESPEC -# include -#endif +#include "scno.h" -#include "kernel_timeval.h" -#include "kernel_old_timespec.h" +#ifdef __NR_recvmsg -#define XLAT_MACROS_ONLY -# include "xlat/sock_options.h" -#undef XLAT_MACROS_ONLY +# include +# include +# include +# include +# include -#undef TEST_OLD_SCM_TIMESTAMPS +# if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ + || defined HAVE_STRUCT___KERNEL_TIMESPEC +# include +# endif -/* - * Sadly, starting with commit - * glibc-2.33.9000-707-g13c51549e2077f2f3bf84e8fd0b46d8b0c615912, on every - * 32-bit architecture where 32-bit time_t support is enabled, - * glibc mangles old scm timestamps. - */ -#if GLIBC_PREREQ_GE(2, 33) && defined __TIMESIZE && __TIMESIZE != 64 -# define TEST_OLD_SCM_TIMESTAMPS 0 -#endif +# include "kernel_timeval.h" +# include "kernel_old_timespec.h" -#ifndef TEST_OLD_SCM_TIMESTAMPS -# define TEST_OLD_SCM_TIMESTAMPS 1 -#endif +# define XLAT_MACROS_ONLY +# include "xlat/sock_options.h" +# undef XLAT_MACROS_ONLY -#if TEST_OLD_SCM_TIMESTAMPS \ - || defined HAVE_STRUCT___KERNEL_TIMESPEC \ - || defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL +static const char *errstr; + +static long +k_recvmsg(const unsigned int fd, const void *const ptr, const unsigned int flags) +{ + const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL; + const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL; + const kernel_ulong_t arg1 = fill | fd; + const kernel_ulong_t arg2 = (uintptr_t) ptr; + const kernel_ulong_t arg3 = fill | flags; + const long rc = syscall(__NR_recvmsg, arg1, arg2, arg3, bad, bad, bad); + if (rc && errno == ENOSYS) + perror_msg_and_skip("recvmsg"); + errstr = sprintrc(rc); + return rc; +} -# if TEST_OLD_SCM_TIMESTAMPS static void print_timestamp_old(const struct cmsghdr *c) { @@ -84,7 +85,6 @@ print_timestampns_old(const struct cmsghdr *c) printf("{tv_sec=%lld, tv_nsec=%lld}", (long long) ts.tv_sec, (long long) ts.tv_nsec); } -# endif /* TEST_OLD_SCM_TIMESTAMPS */ # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL static void @@ -162,7 +162,7 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *)) .msg_controllen = sizeof(control) }; - if (recvmsg(sv[0], &mh, 0) != (int) size) + if (k_recvmsg(sv[0], &mh, 0) != (int) size) perror_msg_and_fail("recvmsg"); if (close(sv[0])) perror_msg_and_fail("close recv"); @@ -210,10 +210,8 @@ main(void) const char *str; void (*fun)(const struct cmsghdr *); } tests[] = { -# if TEST_OLD_SCM_TIMESTAMPS { SO_TIMESTAMP_OLD, "SO_TIMESTAMP_OLD", print_timestamp_old }, { SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS_OLD", print_timestampns_old }, -# endif # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL { SO_TIMESTAMP_NEW, "SO_TIMESTAMP_NEW", print_timestamp_new }, # endif @@ -235,8 +233,6 @@ main(void) #else -SKIP_MAIN_UNDEFINED("TEST_OLD_SCM_TIMESTAMPS" - " || HAVE_STRUCT___KERNEL_TIMESPEC" - " || HAVE_STRUCT___KERNEL_SOCK_TIMEVAL") +SKIP_MAIN_UNDEFINED("__NR_recvmsg") #endif -- 2.1.4