[CRIU] [PATCH] compiler: add ASSIGN_TYPED and ASSIGN_MEMBER

Dmitry Safonov dsafonov at virtuozzo.com
Fri Jun 17 07:47:55 PDT 2016


Looks like it's the most appropriate place for those hooks.
Didn't know about those helpers - maybe I should have used
them in my code more widely instead of casts.

Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 criu/arch/aarch64/include/asm/types.h | 3 ---
 criu/arch/arm/include/asm/types.h     | 3 ---
 criu/arch/ppc64/include/asm/types.h   | 3 ---
 criu/arch/x86/include/asm/types.h     | 3 ---
 criu/include/compiler.h               | 3 +++
 5 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/criu/arch/aarch64/include/asm/types.h b/criu/arch/aarch64/include/asm/types.h
index 203b44ab363f..71db6daa3c3b 100644
--- a/criu/arch/aarch64/include/asm/types.h
+++ b/criu/arch/aarch64/include/asm/types.h
@@ -54,9 +54,6 @@ typedef struct {
 typedef struct user_pt_regs user_regs_struct_t;
 
 
-#define ASSIGN_TYPED(a, b) do { a = (typeof(a))b; } while (0)
-#define ASSIGN_MEMBER(a,b,m) do { ASSIGN_TYPED((a)->m, (b)->m); } while (0)
-
 #define REG_RES(regs)		((u64)(regs).regs[0])
 #define REG_IP(regs)		((u64)(regs).pc)
 #define REG_SYSCALL_NR(regs)	((u64)(regs).regs[8])
diff --git a/criu/arch/arm/include/asm/types.h b/criu/arch/arm/include/asm/types.h
index 87f4c3c817d1..fcebaff7ba3b 100644
--- a/criu/arch/arm/include/asm/types.h
+++ b/criu/arch/arm/include/asm/types.h
@@ -89,9 +89,6 @@ struct user_vfp_exc {
 	unsigned long   fpinst2;
 };
 
-#define ASSIGN_TYPED(a, b) do { a = (typeof(a))b; } while (0)
-#define ASSIGN_MEMBER(a,b,m) do { ASSIGN_TYPED((a)->m, (b)->m); } while (0)
-
 #define REG_RES(regs) ((regs).ARM_r0)
 #define REG_IP(regs)  ((regs).ARM_pc)
 #define REG_SYSCALL_NR(regs) ((regs).ARM_r7)
diff --git a/criu/arch/ppc64/include/asm/types.h b/criu/arch/ppc64/include/asm/types.h
index fed09c465888..a668ed15a529 100644
--- a/criu/arch/ppc64/include/asm/types.h
+++ b/criu/arch/ppc64/include/asm/types.h
@@ -72,9 +72,6 @@ typedef UserPpc64RegsEntry UserRegsEntry;
 
 #define CORE_ENTRY__MARCH	CORE_ENTRY__MARCH__PPC64
 
-#define ASSIGN_TYPED(a, b) do { a = (typeof(a))b; } while (0)
-#define ASSIGN_MEMBER(a,b,m) do { ASSIGN_TYPED((a)->m, (b)->m); } while (0)
-
 #define REG_RES(regs)           ((u64)(regs).gpr[3])
 #define REG_IP(regs)            ((u64)(regs).nip)
 #define REG_SYSCALL_NR(regs)    ((u64)(regs).gpr[0])
diff --git a/criu/arch/x86/include/asm/types.h b/criu/arch/x86/include/asm/types.h
index 75621a7d046e..7c0239bd772d 100644
--- a/criu/arch/x86/include/asm/types.h
+++ b/criu/arch/x86/include/asm/types.h
@@ -165,9 +165,6 @@ typedef struct {
 	u32		padding[24];
 } user_fpregs_struct_t;
 
-#define ASSIGN_TYPED(a, b) do { a = (typeof(a))b; } while (0)
-#define ASSIGN_MEMBER(a,b,m) do { ASSIGN_TYPED((a)->m, (b)->m); } while (0)
-
 #ifdef CONFIG_X86_64
 # define TASK_SIZE	((1UL << 47) - PAGE_SIZE)
 #else
diff --git a/criu/include/compiler.h b/criu/include/compiler.h
index 6bce93562a48..235413070add 100644
--- a/criu/include/compiler.h
+++ b/criu/include/compiler.h
@@ -10,6 +10,9 @@
 #define ARRAY_SIZE(x)		(sizeof(x) / sizeof((x)[0]))
 #define BUILD_BUG_ON(condition)	((void)sizeof(char[1 - 2*!!(condition)]))
 
+#define ASSIGN_TYPED(a, b)	do { (a) = (typeof(a))(b); } while (0)
+#define ASSIGN_MEMBER(a, b, m)	do { ASSIGN_TYPED((a)->m, (b)->m); } while (0)
+
 #define __stringify_1(x...)	#x
 #define __stringify(x...)	__stringify_1(x)
 
-- 
2.8.3



More information about the CRIU mailing list