diff options
Diffstat (limited to 'common/mem.h')
-rw-r--r-- | common/mem.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/common/mem.h b/common/mem.h index d24ec0b50b09..0c83b70dec2f 100644 --- a/common/mem.h +++ b/common/mem.h @@ -212,6 +212,18 @@ p2roundup(size_t n) return (n); } +/* + * is_aligned -- + * Determine whether the program can safely read an object with an + * alignment requirement from ptr. + * + * See also: https://clang.llvm.org/docs/LanguageExtensions.html#alignment-builtins + */ +static __inline int +is_aligned(void *ptr, size_t alignment) { + return ((uintptr_t)ptr % alignment) == 0; +} + /* Additional TAILQ helper. */ #define TAILQ_ENTRY_ISVALID(elm, field) \ ((elm)->field.tqe_prev != NULL) |