From 9705048c0ee004664a9beabcc6f87df6cee0ad07 Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Tue, 30 Sep 2025 14:11:12 -0700 Subject: [PATCH] include: implement be{32,64}_to_cpu() and cpu_to_be{32,64}() macros libbpf is now using above macros for libbpf_sha256() implementation, make them available in Github repo. Signed-off-by: Andrii Nakryiko --- include/linux/kernel.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index a26c9cf..dd638d6 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -43,4 +43,18 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define be32_to_cpu(x) __builtin_bswap32(x) +#define cpu_to_be32(x) __builtin_bswap32(x) +#define be64_to_cpu(x) __builtin_bswap64(x) +#define cpu_to_be64(x) __builtin_bswap64(x) +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define be32_to_cpu(x) (x) +#define cpu_to_be32(x) (x) +#define be64_to_cpu(x) (x) +#define cpu_to_be64(x) (x) +#else +# error "__BYTE_ORDER__ undefined or invalid" +#endif + #endif