misc: Update several macros
diff --git a/common/lib/part.h b/common/lib/part.h
index e092a17b..f5230fae 100644
--- a/common/lib/part.h
+++ b/common/lib/part.h
@@ -74,7 +74,7 @@ struct volume *volume_get_by_bios_drive(int drive);
bool volume_read(struct volume *part, void *buffer, uint64_t loc, uint64_t count);
-#define volume_iterate_parts(_VOLUME_, _BODY_) ({ \
+#define volume_iterate_parts(_VOLUME_, _BODY_) do { \
struct volume *_VOLUME = _VOLUME_; \
if (_VOLUME->pxe) { \
do { \
@@ -101,6 +101,6 @@ bool volume_read(struct volume *part, void *buffer, uint64_t loc, uint64_t count
_BODY_ \
} \
} \
-})
+} while (0)
#endif
diff --git a/common/lib/print.h b/common/lib/print.h
index 8ceb95a1..30012338 100644
--- a/common/lib/print.h
+++ b/common/lib/print.h
@@ -9,6 +9,8 @@ extern bool verbose;
void print(const char *fmt, ...);
void vprint(const char *fmt, va_list args);
-#define printv(FMT, ...) ({ if (verbose) print(FMT, ##__VA_ARGS__); })
+#define printv(FMT, ...) do { \
+ if (verbose) print(FMT, ##__VA_ARGS__); \
+} while (0)
#endif
diff --git a/common/protos/multiboot2.c b/common/protos/multiboot2.c
index 28985fd7..a9c5b1a5 100644
--- a/common/protos/multiboot2.c
+++ b/common/protos/multiboot2.c
@@ -57,7 +57,9 @@ static size_t get_multiboot2_info_size(
ALIGN_UP(sizeof(struct multiboot_tag), MULTIBOOT_TAG_ALIGN); // end
}
-#define append_tag(P, TAG) ({ (P) += ALIGN_UP((TAG)->size, MULTIBOOT_TAG_ALIGN); })
+#define append_tag(P, TAG) do { \
+ (P) += ALIGN_UP((TAG)->size, MULTIBOOT_TAG_ALIGN); \
+} while (0)
noreturn void multiboot2_load(char *config, char* cmdline) {
struct file_handle *kernel_file;
diff --git a/common/sys/cpu.h b/common/sys/cpu.h
index d36487b1..80b46305 100644
--- a/common/sys/cpu.h
+++ b/common/sys/cpu.h
@@ -164,57 +164,56 @@ inline void delay(uint64_t cycles) {
}
#define rdrand(type) ({ \
- type ret; \
+ type rdrand__ret; \
asm volatile ( \
"1: " \
"rdrand %0;" \
"jnc 1b;" \
- : "=r" (ret) \
+ : "=r" (rdrand__ret) \
); \
- ret; \
+ rdrand__ret; \
})
#define rdseed(type) ({ \
- type ret; \
+ type rdseed__ret; \
asm volatile ( \
"1: " \
"rdseed %0;" \
"jnc 1b;" \
- : "=r" (ret) \
+ : "=r" (rdseed__ret) \
); \
- ret; \
+ rdseed__ret; \
})
-#define write_cr(reg, val) ({ \
+#define write_cr(reg, val) do { \
asm volatile ("mov %0, %%cr" reg :: "r" (val) : "memory"); \
-})
+} while (0)
#define read_cr(reg) ({ \
- size_t cr; \
- asm volatile ("mov %%cr" reg ", %0" : "=r" (cr) :: "memory"); \
- cr; \
+ size_t read_cr__cr; \
+ asm volatile ("mov %%cr" reg ", %0" : "=r" (read_cr__cr) :: "memory"); \
+ read_cr__cr; \
})
#define locked_read(var) ({ \
- typeof(*var) ret = 0; \
+ typeof(*var) locked_read__ret = 0; \
asm volatile ( \
"lock xadd %0, %1" \
- : "+r" (ret) \
+ : "+r" (locked_read__ret) \
: "m" (*(var)) \
: "memory" \
); \
- ret; \
+ locked_read__ret; \
})
-#define locked_write(var, val) ({ \
- typeof(*var) ret = val; \
+#define locked_write(var, val) do { \
+ __auto_type locked_write__ret = val; \
asm volatile ( \
"lock xchg %0, %1" \
- : "+r" ((ret)) \
+ : "+r" ((locked_write__ret)) \
: "m" (*(var)) \
: "memory" \
); \
- ret; \
-})
+} while (0)
#endif
