aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2022-09-16 15:08:37 +0000
committerWarner Losh <imp@FreeBSD.org>2023-01-24 21:49:34 +0000
commit9bc956361bccb51a1349f4c903bfe1462f3b16cf (patch)
treec18c03873c7653b754c7f950a7610e89255786e8
parentcf96360237eada5ff5626832b4fb09c0e8b1b63f (diff)
downloadsrc-9bc956361bccb51a1349f4c903bfe1462f3b16cf.tar.gz
src-9bc956361bccb51a1349f4c903bfe1462f3b16cf.zip
stand: Create MOD_ALIGN macro and use it everywhere
To further reduce the differences between the different MOD_xxx macros, use MOD_ALIGN to do the proper alignment for the given use. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D36570 (cherry picked from commit 8b19d28d68a396b0263e3c13a559a31f70eb3b1d)
-rw-r--r--stand/common/metadata.c7
-rw-r--r--stand/efi/loader/bootinfo.c9
-rw-r--r--stand/i386/libi386/bootinfo32.c7
-rw-r--r--stand/i386/libi386/bootinfo64.c7
-rw-r--r--stand/userboot/userboot/bootinfo32.c7
-rw-r--r--stand/userboot/userboot/bootinfo64.c7
6 files changed, 25 insertions, 19 deletions
diff --git a/stand/common/metadata.c b/stand/common/metadata.c
index a9c81added02..cb92537d1ce2 100644
--- a/stand/common/metadata.c
+++ b/stand/common/metadata.c
@@ -111,6 +111,7 @@ md_copyenv(vm_offset_t addr)
static int align;
+#define MOD_ALIGN(l) roundup(l, align)
#define COPY32(v, a, c) { \
uint32_t x = (v); \
if (c) \
@@ -123,7 +124,7 @@ static int align;
COPY32(strlen(s) + 1, a, c) \
if (c) \
archsw.arch_copyin(s, a, strlen(s) + 1);\
- a += roundup(strlen(s) + 1, align); \
+ a += MOD_ALIGN(strlen(s) + 1); \
}
#define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c)
@@ -135,7 +136,7 @@ static int align;
COPY32(sizeof(s), a, c); \
if (c) \
archsw.arch_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), align); \
+ a += MOD_ALIGN(sizeof(s)); \
}
#define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c)
@@ -146,7 +147,7 @@ static int align;
COPY32(mm->md_size, a, c); \
if (c) \
archsw.arch_copyin(mm->md_data, a, mm->md_size);\
- a += roundup(mm->md_size, align); \
+ a += MOD_ALIGN(mm->md_size); \
}
#define MOD_END(a, c) { \
diff --git a/stand/efi/loader/bootinfo.c b/stand/efi/loader/bootinfo.c
index 7f1a2f840f78..542f15a471d9 100644
--- a/stand/efi/loader/bootinfo.c
+++ b/stand/efi/loader/bootinfo.c
@@ -182,6 +182,7 @@ bi_copyenv(vm_offset_t start)
* MOD_SIZE sizeof(size_t) module size
* MOD_METADATA (variable) type-specific metadata
*/
+#define MOD_ALIGN(l) roundup(l, sizeof(u_long))
#define COPY32(v, a, c) { \
uint32_t x = (v); \
if (c) \
@@ -194,7 +195,7 @@ bi_copyenv(vm_offset_t start)
COPY32(strlen(s) + 1, a, c); \
if (c) \
archsw.arch_copyin(s, a, strlen(s) + 1); \
- a += roundup(strlen(s) + 1, sizeof(u_long)); \
+ a += MOD_ALIGN(strlen(s) + 1); \
}
#define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c)
@@ -206,7 +207,7 @@ bi_copyenv(vm_offset_t start)
COPY32(sizeof(s), a, c); \
if (c) \
archsw.arch_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), sizeof(u_long)); \
+ a += MOD_ALIGN(sizeof(s)); \
}
#define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c)
@@ -216,8 +217,8 @@ bi_copyenv(vm_offset_t start)
COPY32(MODINFO_METADATA | mm->md_type, a, c); \
COPY32(mm->md_size, a, c); \
if (c) \
- archsw.arch_copyin(mm->md_data, a, mm->md_size); \
- a += roundup(mm->md_size, sizeof(u_long)); \
+ archsw.arch_copyin(mm->md_data, a, mm->md_size); \
+ a += MOD_ALIGN(mm->md_size); \
}
#define MOD_END(a, c) { \
diff --git a/stand/i386/libi386/bootinfo32.c b/stand/i386/libi386/bootinfo32.c
index dd919d0fad93..207fe9a3fde8 100644
--- a/stand/i386/libi386/bootinfo32.c
+++ b/stand/i386/libi386/bootinfo32.c
@@ -59,6 +59,7 @@ static struct bootinfo bi;
* MOD_SIZE sizeof(size_t) module size
* MOD_METADATA (variable) type-specific metadata
*/
+#define MOD_ALIGN(l) roundup(l, sizeof(u_long))
#define COPY32(v, a, c) { \
uint32_t x = (v); \
if (c) \
@@ -71,7 +72,7 @@ static struct bootinfo bi;
COPY32(strlen(s) + 1, a, c); \
if (c) \
archsw.arch_copyin(s, a, strlen(s) + 1); \
- a += roundup(strlen(s) + 1, sizeof(u_long));\
+ a += MOD_ALIGN(strlen(s) + 1); \
}
#define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c)
@@ -83,7 +84,7 @@ static struct bootinfo bi;
COPY32(sizeof(s), a, c); \
if (c) \
archsw.arch_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), sizeof(u_long)); \
+ a += MOD_ALIGN(sizeof(s)); \
}
#define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c)
@@ -94,7 +95,7 @@ static struct bootinfo bi;
COPY32(mm->md_size, a, c); \
if (c) \
archsw.arch_copyin(mm->md_data, a, mm->md_size); \
- a += roundup(mm->md_size, sizeof(u_long));\
+ a += MOD_ALIGN(mm->md_size); \
}
#define MOD_END(a, c) { \
diff --git a/stand/i386/libi386/bootinfo64.c b/stand/i386/libi386/bootinfo64.c
index 1e06c229ec30..e088c27347be 100644
--- a/stand/i386/libi386/bootinfo64.c
+++ b/stand/i386/libi386/bootinfo64.c
@@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$");
* MOD_SIZE sizeof(size_t) module size
* MOD_METADATA (variable) type-specific metadata
*/
+#define MOD_ALIGN(l) roundup(l, sizeof(uint64_t))
#define COPY32(v, a, c) { \
uint32_t x = (v); \
if (c) \
@@ -72,7 +73,7 @@ __FBSDID("$FreeBSD$");
COPY32(strlen(s) + 1, a, c); \
if (c) \
archsw.arch_copyin(s, a, strlen(s) + 1); \
- a += roundup(strlen(s) + 1, sizeof(uint64_t));\
+ a += MOD_ALIGN(strlen(s) + 1); \
}
#define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c)
@@ -84,7 +85,7 @@ __FBSDID("$FreeBSD$");
COPY32(sizeof(s), a, c); \
if (c) \
archsw.arch_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), sizeof(uint64_t)); \
+ a += MOD_ALIGN(sizeof(s)); \
}
#define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c)
@@ -95,7 +96,7 @@ __FBSDID("$FreeBSD$");
COPY32(mm->md_size, a, c); \
if (c) \
archsw.arch_copyin(mm->md_data, a, mm->md_size); \
- a += roundup(mm->md_size, sizeof(uint64_t));\
+ a += MOD_ALIGN(mm->md_size); \
}
#define MOD_END(a, c) { \
diff --git a/stand/userboot/userboot/bootinfo32.c b/stand/userboot/userboot/bootinfo32.c
index 26376709e899..bd2729927349 100644
--- a/stand/userboot/userboot/bootinfo32.c
+++ b/stand/userboot/userboot/bootinfo32.c
@@ -58,6 +58,7 @@ static struct bootinfo bi;
* MOD_SIZE sizeof(size_t) module size
* MOD_METADATA (variable) type-specific metadata
*/
+#define MOD_ALIGN(l) roundup(l, sizeof(uint32_t))
#define COPY32(v, a, c) { \
uint32_t x = (v); \
if (c) \
@@ -70,7 +71,7 @@ static struct bootinfo bi;
COPY32(strlen(s) + 1, a, c); \
if (c) \
archsw.arch_copyin(s, a, strlen(s) + 1);\
- a += roundup(strlen(s) + 1, sizeof(uint32_t));\
+ a += MOD_ALIGN(strlen(s) + 1); \
}
#define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c)
@@ -82,7 +83,7 @@ static struct bootinfo bi;
COPY32(sizeof(s), a, c); \
if (c) \
archsw.arch_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), sizeof(uint32_t)); \
+ a += MOD_ALIGN(sizeof(s)); \
}
#define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c)
@@ -93,7 +94,7 @@ static struct bootinfo bi;
COPY32(mm->md_size, a, c); \
if (c) \
archsw.arch_copyin(mm->md_data, a, mm->md_size);\
- a += roundup(mm->md_size, sizeof(uint32_t));\
+ a += MOD_ALIGN(mm->md_size); \
}
#define MOD_END(a, c) { \
diff --git a/stand/userboot/userboot/bootinfo64.c b/stand/userboot/userboot/bootinfo64.c
index f2713adf5513..5fffb04d8d75 100644
--- a/stand/userboot/userboot/bootinfo64.c
+++ b/stand/userboot/userboot/bootinfo64.c
@@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
* MOD_SIZE sizeof(size_t) module size
* MOD_METADATA (variable) type-specific metadata
*/
+#define MOD_ALIGN(l) roundup(l, sizeof(uint64_t))
#define COPY32(v, a, c) { \
uint32_t x = (v); \
if (c) \
@@ -67,7 +68,7 @@ __FBSDID("$FreeBSD$");
COPY32(strlen(s) + 1, a, c); \
if (c) \
archsw.arch_copyin(s, a, strlen(s) + 1);\
- a += roundup(strlen(s) + 1, sizeof(uint64_t));\
+ a += MOD_ALIGN(strlen(s) + 1); \
}
#define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c)
@@ -79,7 +80,7 @@ __FBSDID("$FreeBSD$");
COPY32(sizeof(s), a, c); \
if (c) \
archsw.arch_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), sizeof(uint64_t)); \
+ a += MOD_ALIGN(sizeof(s)); \
}
#define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c)
@@ -90,7 +91,7 @@ __FBSDID("$FreeBSD$");
COPY32(mm->md_size, a, c); \
if (c) \
archsw.arch_copyin(mm->md_data, a, mm->md_size);\
- a += roundup(mm->md_size, sizeof(uint64_t));\
+ a += MOD_ALIGN(mm->md_size); \
}
#define MOD_END(a, c) { \