git: 8b19d28d68a3 - main - stand: Create MOD_ALIGN macro and use it everywhere
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 16 Sep 2022 15:53:53 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=8b19d28d68a396b0263e3c13a559a31f70eb3b1d
commit 8b19d28d68a396b0263e3c13a559a31f70eb3b1d
Author: Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-09-16 15:08:37 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2022-09-16 15:18:56 +0000
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
---
stand/common/metadata.c | 7 ++++---
stand/efi/loader/bootinfo.c | 9 +++++----
stand/i386/libi386/bootinfo32.c | 7 ++++---
stand/i386/libi386/bootinfo64.c | 7 ++++---
stand/userboot/userboot/bootinfo32.c | 7 ++++---
stand/userboot/userboot/bootinfo64.c | 7 ++++---
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 06b131aac521..c3184a1e84d5 100644
--- a/stand/efi/loader/bootinfo.c
+++ b/stand/efi/loader/bootinfo.c
@@ -180,6 +180,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) \
@@ -192,7 +193,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)
@@ -204,7 +205,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)
@@ -214,8 +215,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) { \