Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools headers: Update the linux/unaligned.h copy with the kernel sources

To pick up the changes in:

vdso: Switch get/put_unaligned() from packed struct to memcpy

As the code is dependent on __unqual_scalar_typeof, update also the tools
version of compiler_types.h to include this.

Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20251016205126.2882625-4-irogers@google.com

authored by

Ian Rogers and committed by
Thomas Gleixner
1d7cf255 a339671d

+57 -6
+22
tools/include/linux/compiler_types.h
··· 40 40 #define asm_goto_output(x...) asm goto(x) 41 41 #endif 42 42 43 + /* 44 + * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving 45 + * non-scalar types unchanged. 46 + */ 47 + /* 48 + * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char' 49 + * is not type-compatible with 'signed char', and we define a separate case. 50 + */ 51 + #define __scalar_type_to_expr_cases(type) \ 52 + unsigned type: (unsigned type)0, \ 53 + signed type: (signed type)0 54 + 55 + #define __unqual_scalar_typeof(x) typeof( \ 56 + _Generic((x), \ 57 + char: (char)0, \ 58 + __scalar_type_to_expr_cases(char), \ 59 + __scalar_type_to_expr_cases(short), \ 60 + __scalar_type_to_expr_cases(int), \ 61 + __scalar_type_to_expr_cases(long), \ 62 + __scalar_type_to_expr_cases(long long), \ 63 + default: (x))) 64 + 43 65 #endif /* __LINUX_COMPILER_TYPES_H */
+35 -6
tools/include/vdso/unaligned.h
··· 2 2 #ifndef __VDSO_UNALIGNED_H 3 3 #define __VDSO_UNALIGNED_H 4 4 5 - #define __get_unaligned_t(type, ptr) ({ \ 6 - const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr); \ 7 - __get_pptr->x; \ 5 + #include <linux/compiler_types.h> 6 + 7 + /** 8 + * __get_unaligned_t - read an unaligned value from memory. 9 + * @type: the type to load from the pointer. 10 + * @ptr: the pointer to load from. 11 + * 12 + * Use memcpy to affect an unaligned type sized load avoiding undefined behavior 13 + * from approaches like type punning that require -fno-strict-aliasing in order 14 + * to be correct. As type may be const, use __unqual_scalar_typeof to map to a 15 + * non-const type - you can't memcpy into a const type. The 16 + * __get_unaligned_ctrl_type gives __unqual_scalar_typeof its required 17 + * expression rather than type, a pointer is used to avoid warnings about mixing 18 + * the use of 0 and NULL. The void* cast silences ubsan warnings. 19 + */ 20 + #define __get_unaligned_t(type, ptr) ({ \ 21 + type *__get_unaligned_ctrl_type __always_unused = NULL; \ 22 + __unqual_scalar_typeof(*__get_unaligned_ctrl_type) __get_unaligned_val; \ 23 + __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \ 24 + sizeof(__get_unaligned_val)); \ 25 + __get_unaligned_val; \ 8 26 }) 9 27 10 - #define __put_unaligned_t(type, val, ptr) do { \ 11 - struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr); \ 12 - __put_pptr->x = (val); \ 28 + /** 29 + * __put_unaligned_t - write an unaligned value to memory. 30 + * @type: the type of the value to store. 31 + * @val: the value to store. 32 + * @ptr: the pointer to store to. 33 + * 34 + * Use memcpy to affect an unaligned type sized store avoiding undefined 35 + * behavior from approaches like type punning that require -fno-strict-aliasing 36 + * in order to be correct. The void* cast silences ubsan warnings. 37 + */ 38 + #define __put_unaligned_t(type, val, ptr) do { \ 39 + type __put_unaligned_val = (val); \ 40 + __builtin_memcpy((void *)(ptr), &__put_unaligned_val, \ 41 + sizeof(__put_unaligned_val)); \ 13 42 } while (0) 14 43 15 44 #endif /* __VDSO_UNALIGNED_H */