macro: introduce several helper functions for alignment

Some of them are not used in this commit, but will be used later.
This commit is contained in:
Yu Watanabe
2023-10-19 18:31:44 +09:00
parent d54c0f37d8
commit 2977904cad
4 changed files with 237 additions and 3 deletions
+6 -3
View File
@@ -12,9 +12,12 @@
#include "memory-util-fundamental.h"
size_t page_size(void) _pure_;
#define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
#define PAGE_ALIGN_DOWN(l) ((l) & ~(page_size() - 1))
#define PAGE_OFFSET(l) ((l) & (page_size() - 1))
#define PAGE_ALIGN(l) ALIGN_TO(l, page_size())
#define PAGE_ALIGN_U64(l) ALIGN_TO_U64(l, page_size())
#define PAGE_ALIGN_DOWN(l) ALIGN_DOWN(l, page_size())
#define PAGE_ALIGN_DOWN_U64(l) ALIGN_DOWN_U64(l, page_size())
#define PAGE_OFFSET(l) ALIGN_OFFSET(l, page_size())
#define PAGE_OFFSET_U64(l) ALIGN_OFFSET_U64(l, page_size())
/* Normal memcpy() requires src to be nonnull. We do nothing if n is 0. */
static inline void *memcpy_safe(void *dst, const void *src, size_t n) {