From bd43e0954b15ff1d904749dbc9f4ee52b56f60d8 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 23 Dec 2016 18:44:37 +0000 Subject: [PATCH] tests: add F8ILL_KULONG_* and f8ill_ptr_to_kulong to tests.h * tests/tests.h (F8ILL_KULONG_SUPPORTED, F8ILL_KULONG_MASK): New macros. (f8ill_ptr_to_kulong): New static inline function. --- tests/tests.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/tests.h b/tests/tests.h index 1724124b..202b2224 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -141,6 +141,22 @@ int send_mmsg(int, struct mmsghdr *, unsigned int, unsigned int); /* Create a pipe with maximized descriptor numbers. */ void pipe_maxfd(int pipefd[2]); +#define F8ILL_KULONG_SUPPORTED (sizeof(void *) < sizeof(kernel_ulong_t)) +#define F8ILL_KULONG_MASK ((kernel_ulong_t) 0xffffffff00000000ULL) + +/* + * For 64-bit kernel_ulong_t and 32-bit pointer, + * return a kernel_ulong_t value by filling higher bits. + * For other architertures, return the original pointer. + */ +static inline kernel_ulong_t +f8ill_ptr_to_kulong(const void *const ptr) +{ + const unsigned long uptr = (unsigned long) ptr; + return F8ILL_KULONG_SUPPORTED + ? F8ILL_KULONG_MASK | uptr : (kernel_ulong_t) uptr; +} + # define ARRAY_SIZE(arg) ((unsigned int) (sizeof(arg) / sizeof((arg)[0]))) # define LENGTH_OF(arg) ((unsigned int) sizeof(arg) - 1) -- 2.40.0