diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-12-07 18:31:27 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-12-08 15:30:31 +0100 |
commit | 4f07388360a3513b9fc8d2773568b8def941f4a4 (patch) | |
tree | a15b17bf89ba2f0743113bbe82e200736564265f /src/fundamental | |
parent | 22e339761be66ae5b7c92b27b4e2b59074ebfbb1 (diff) | |
download | systemd-4f07388360a3513b9fc8d2773568b8def941f4a4.tar.gz |
macro: add generic IS_ALIGNED32() anf friends
Let's generalize (and invert) the UNALIGNED32_P() macro from the sha256
code, and let's add a test for it.
Diffstat (limited to 'src/fundamental')
-rw-r--r-- | src/fundamental/macro-fundamental.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index c11a5b15f4..65c9e042cd 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -327,14 +327,23 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) { return ((l + ali - 1) & ~(ali - 1)); } +#define ALIGN2(l) ALIGN_TO(l, 2) #define ALIGN4(l) ALIGN_TO(l, 4) #define ALIGN8(l) ALIGN_TO(l, 8) +#define ALIGN2_PTR(p) ((void*) ALIGN2((uintptr_t) p)) +#define ALIGN4_PTR(p) ((void*) ALIGN4((uintptr_t) p)) +#define ALIGN8_PTR(p) ((void*) ALIGN8((uintptr_t) p)) #ifndef SD_BOOT /* libefi also provides ALIGN, and we do not use them in sd-boot explicitly. */ #define ALIGN(l) ALIGN_TO(l, sizeof(void*)) #define ALIGN_PTR(p) ((void*) ALIGN((uintptr_t) (p))) #endif +/* Checks if the specified pointer is aligned as appropriate for the specific type */ +#define IS_ALIGNED16(p) (((uintptr_t) p) % __alignof__(uint16_t) == 0) +#define IS_ALIGNED32(p) (((uintptr_t) p) % __alignof__(uint32_t) == 0) +#define IS_ALIGNED64(p) (((uintptr_t) p) % __alignof__(uint64_t) == 0) + /* Same as ALIGN_TO but callable in constant contexts. */ #define CONST_ALIGN_TO(l, ali) \ __builtin_choose_expr( \ |