[CRIU] [PATCH] headers: Split */types.h headers

Pavel Emelyanov xemul at virtuozzo.com
Fri Oct 28 10:05:56 PDT 2016


From: Cyrill Gorcunov <gorcunov at openvz.org>

The 2nd big splitting patch -- move most of the code that is
infect-related and doesn't know about criu internals (like 
protobuf) out of types.h headers.

This is also big and fat patch, but it just moves the code
around. Applies on top of sigframe extracting patch.

Travis: https://travis-ci.org/xemul/criu/builds/171439595

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-and-ported-on-dev-by: Pavel Emelyanov <xemul at virtuozzo.com>

---
 criu/arch/aarch64/crtools.c                  |   2 +-
 criu/arch/aarch64/include/asm/infect-types.h |  57 ++++++++++
 criu/arch/aarch64/include/asm/types.h        |  45 --------
 criu/arch/aarch64/sigframe.c                 |   1 +
 criu/arch/arm/crtools.c                      |   2 +-
 criu/arch/arm/include/asm/infect-types.h     |  91 ++++++++++++++++
 criu/arch/arm/include/asm/types.h            |  83 --------------
 criu/arch/arm/sigframe.c                     |   1 +
 criu/arch/ppc64/crtools.c                    |   2 +-
 criu/arch/ppc64/include/asm/infect-types.h   | 110 +++++++++++++++++++
 criu/arch/ppc64/include/asm/types.h          |  80 --------------
 criu/arch/x86/crtools.c                      |   2 +-
 criu/arch/x86/include/asm/infect-types.h     | 157 +++++++++++++++++++++++++++
 criu/arch/x86/include/asm/types.h            | 146 +------------------------
 criu/arch/x86/restorer.c                     |   1 +
 criu/include/restore.h                       |   1 +
 criu/include/restorer.h                      |   2 +-
 criu/include/types.h                         |   1 +
 18 files changed, 427 insertions(+), 357 deletions(-)
 create mode 100644 criu/arch/aarch64/include/asm/infect-types.h
 create mode 100644 criu/arch/arm/include/asm/infect-types.h
 create mode 100644 criu/arch/ppc64/include/asm/infect-types.h
 create mode 100644 criu/arch/x86/include/asm/infect-types.h

diff --git a/criu/arch/aarch64/crtools.c b/criu/arch/aarch64/crtools.c
index 951ac75..515ab9a 100644
--- a/criu/arch/aarch64/crtools.c
+++ b/criu/arch/aarch64/crtools.c
@@ -3,7 +3,7 @@
 
 #include <linux/elf.h>
 
-#include "asm/types.h"
+#include "types.h"
 #include "asm/restorer.h"
 #include "common/compiler.h"
 #include "ptrace.h"
diff --git a/criu/arch/aarch64/include/asm/infect-types.h b/criu/arch/aarch64/include/asm/infect-types.h
new file mode 100644
index 0000000..7bc195b
--- /dev/null
+++ b/criu/arch/aarch64/include/asm/infect-types.h
@@ -0,0 +1,57 @@
+#ifndef UAPI_COMPEL_ASM_TYPES_H__
+#define UAPI_COMPEL_ASM_TYPES_H__
+
+#include <stdint.h>
+#include <signal.h>
+#include <sys/mman.h>
+#include <asm/ptrace.h>
+#include "common/page.h"
+
+#define SIGMAX			64
+#define SIGMAX_OLD		31
+
+/*
+ * Copied from the Linux kernel header arch/arm64/include/uapi/asm/ptrace.h
+ *
+ * A thread ARM CPU context
+ */
+
+typedef struct user_pt_regs		user_regs_struct_t;
+typedef struct user_fpsimd_state	user_fpregs_struct_t;
+
+#define REG_RES(r)			((uint64_t)(r).regs[0])
+#define REG_IP(r)			((uint64_t)(r).pc)
+#define REG_SYSCALL_NR(r)		((uint64_t)(r).regs[8])
+
+#define user_regs_native(pregs)		true
+
+/*
+ * Range for task size calculated from the following Linux kernel files:
+ *   arch/arm64/include/asm/memory.h
+ *   arch/arm64/Kconfig
+ *
+ * TODO: handle 32 bit tasks
+ */
+#define TASK_SIZE_MIN (1UL << 39)
+#define TASK_SIZE_MAX (1UL << 48)
+
+static inline unsigned long task_size(void)
+{
+	unsigned long task_size;
+
+	for (task_size = TASK_SIZE_MIN; task_size < TASK_SIZE_MAX; task_size <<= 1)
+		if (munmap((void *)task_size, page_size()))
+			break;
+	return task_size;
+}
+
+#define AT_VECTOR_SIZE 40
+
+typedef uint64_t auxv_t;
+typedef uint64_t tls_t;
+
+#define ARCH_SI_TRAP		TRAP_BRKPT
+
+#define __NR(syscall, compat)	__NR_##syscall
+
+#endif /* UAPI_COMPEL_ASM_TYPES_H__ */
diff --git a/criu/arch/aarch64/include/asm/types.h b/criu/arch/aarch64/include/asm/types.h
index d26baf4..17353ac 100644
--- a/criu/arch/aarch64/include/asm/types.h
+++ b/criu/arch/aarch64/include/asm/types.h
@@ -12,50 +12,8 @@
 
 #include "uapi/std/asm/syscall-types.h"
 
-#define SIGMAX			64
-#define SIGMAX_OLD		31
-
-/*
- * Copied from the Linux kernel header arch/arm64/include/uapi/asm/ptrace.h
- *
- * A thread ARM CPU context
- */
-
-typedef struct user_pt_regs user_regs_struct_t;
-typedef struct user_fpsimd_state user_fpregs_struct_t;
-
-
-#define REG_RES(r)		((u64)(r).regs[0])
-#define REG_IP(r)		((u64)(r).pc)
-#define REG_SYSCALL_NR(r)	((u64)(r).regs[8])
-
-#define user_regs_native(pregs)			true
 #define core_is_compat(core)			false
 
-/*
- * Range for task size calculated from the following Linux kernel files:
- *   arch/arm64/include/asm/memory.h
- *   arch/arm64/Kconfig
- *
- * TODO: handle 32 bit tasks
- */
-#define TASK_SIZE_MIN (1UL << 39)
-#define TASK_SIZE_MAX (1UL << 48)
-
-int munmap(void *addr, size_t length);
-
-static inline unsigned long task_size(void) {
-	unsigned long task_size;
-
-	for (task_size = TASK_SIZE_MIN; task_size < TASK_SIZE_MAX; task_size <<= 1)
-		if (munmap((void *)task_size, page_size()))
-			break;
-
-	return task_size;
-}
-
-#define AT_VECTOR_SIZE 40
-
 typedef UserAarch64RegsEntry UserRegsEntry;
 
 #define CORE_ENTRY__MARCH CORE_ENTRY__MARCH__AARCH64
@@ -64,9 +22,6 @@ typedef UserAarch64RegsEntry UserRegsEntry;
 
 #define TI_SP(core) ((core)->ti_aarch64->gpregs->sp)
 
-typedef uint64_t auxv_t;
-typedef uint64_t tls_t;
-
 static inline void *decode_pointer(uint64_t v) { return (void*)v; }
 static inline uint64_t encode_pointer(void *p) { return (uint64_t)p; }
 
diff --git a/criu/arch/aarch64/sigframe.c b/criu/arch/aarch64/sigframe.c
index 63e6524..e8d9952 100644
--- a/criu/arch/aarch64/sigframe.c
+++ b/criu/arch/aarch64/sigframe.c
@@ -1,4 +1,5 @@
 #include "asm/types.h"
+#include "asm/infect-types.h"
 #include "asm/sigframe.h"
 
 int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe,
diff --git a/criu/arch/arm/crtools.c b/criu/arch/arm/crtools.c
index 71438ac..51b6b06 100644
--- a/criu/arch/arm/crtools.c
+++ b/criu/arch/arm/crtools.c
@@ -1,7 +1,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "asm/types.h"
+#include "types.h"
 #include "asm/restorer.h"
 #include "common/compiler.h"
 #include "ptrace.h"
diff --git a/criu/arch/arm/include/asm/infect-types.h b/criu/arch/arm/include/asm/infect-types.h
new file mode 100644
index 0000000..1df9f68
--- /dev/null
+++ b/criu/arch/arm/include/asm/infect-types.h
@@ -0,0 +1,91 @@
+#ifndef UAPI_COMPEL_ASM_TYPES_H__
+#define UAPI_COMPEL_ASM_TYPES_H__
+
+#include <stdint.h>
+#include <sys/mman.h>
+#include "common/page.h"
+
+#define SIGMAX			64
+#define SIGMAX_OLD		31
+
+/*
+ * Copied from the Linux kernel header arch/arm/include/asm/ptrace.h
+ *
+ * A thread ARM CPU context
+ */
+
+typedef struct {
+	long			uregs[18];
+} user_regs_struct_t;
+
+typedef struct user_vfp		user_fpregs_struct_t;
+
+#define ARM_cpsr		uregs[16]
+#define ARM_pc			uregs[15]
+#define ARM_lr			uregs[14]
+#define ARM_sp			uregs[13]
+#define ARM_ip			uregs[12]
+#define ARM_fp			uregs[11]
+#define ARM_r10			uregs[10]
+#define ARM_r9			uregs[9]
+#define ARM_r8			uregs[8]
+#define ARM_r7			uregs[7]
+#define ARM_r6			uregs[6]
+#define ARM_r5			uregs[5]
+#define ARM_r4			uregs[4]
+#define ARM_r3			uregs[3]
+#define ARM_r2			uregs[2]
+#define ARM_r1			uregs[1]
+#define ARM_r0			uregs[0]
+#define ARM_ORIG_r0		uregs[17]
+
+
+/* Copied from arch/arm/include/asm/user.h */
+
+struct user_vfp {
+	unsigned long long	fpregs[32];
+	unsigned long		fpscr;
+};
+
+struct user_vfp_exc {
+	unsigned long		fpexc;
+	unsigned long		fpinst;
+	unsigned long		fpinst2;
+};
+
+#define REG_RES(regs)		((regs).ARM_r0)
+#define REG_IP(regs)		((regs).ARM_pc)
+#define REG_SYSCALL_NR(regs)	((regs).ARM_r7)
+
+#define user_regs_native(pregs)	true
+
+/*
+ * Range for task size calculated from the following Linux kernel files:
+ *   arch/arm/include/asm/memory.h
+ *   arch/arm/Kconfig (PAGE_OFFSET values in Memory split section)
+ */
+#define TASK_SIZE_MIN		0x3f000000
+#define TASK_SIZE_MAX		0xbf000000
+#define SZ_1G			0x40000000
+
+static inline unsigned long task_size(void)
+{
+	unsigned long task_size;
+
+	for (task_size = TASK_SIZE_MIN; task_size < TASK_SIZE_MAX; task_size += SZ_1G)
+		if (munmap((void *)task_size, page_size()))
+			break;
+
+	return task_size;
+}
+
+#define AT_VECTOR_SIZE		40
+
+typedef uint32_t auxv_t;
+typedef uint32_t tls_t;
+
+#define ARCH_SI_TRAP		TRAP_BRKPT
+
+#define __NR(syscall, compat)	__NR_##syscall
+
+#endif /* UAPI_COMPEL_ASM_TYPES_H__ */
diff --git a/criu/arch/arm/include/asm/types.h b/criu/arch/arm/include/asm/types.h
index 806c980..e4dfd2c 100644
--- a/criu/arch/arm/include/asm/types.h
+++ b/criu/arch/arm/include/asm/types.h
@@ -11,88 +11,8 @@
 
 #include "uapi/std/asm/syscall-types.h"
 
-#define SIGMAX			64
-#define SIGMAX_OLD		31
-
-#define MAJOR(dev)		((dev)>>8)
-#define MINOR(dev)		((dev) & 0xff)
-
-/*
- * Copied from the Linux kernel header arch/arm/include/asm/ptrace.h
- *
- * A thread ARM CPU context
- */
-
-typedef struct {
-        long uregs[18];
-} user_regs_struct_t;
-
-typedef struct user_vfp user_fpregs_struct_t;
-
-#define ARM_cpsr        uregs[16]
-#define ARM_pc          uregs[15]
-#define ARM_lr          uregs[14]
-#define ARM_sp          uregs[13]
-#define ARM_ip          uregs[12]
-#define ARM_fp          uregs[11]
-#define ARM_r10         uregs[10]
-#define ARM_r9          uregs[9]
-#define ARM_r8          uregs[8]
-#define ARM_r7          uregs[7]
-#define ARM_r6          uregs[6]
-#define ARM_r5          uregs[5]
-#define ARM_r4          uregs[4]
-#define ARM_r3          uregs[3]
-#define ARM_r2          uregs[2]
-#define ARM_r1          uregs[1]
-#define ARM_r0          uregs[0]
-#define ARM_ORIG_r0     uregs[17]
-
-
-/* Copied from arch/arm/include/asm/user.h */
-
-struct user_vfp {
-	unsigned long long fpregs[32];
-	unsigned long fpscr;
-};
-
-struct user_vfp_exc {
-        unsigned long   fpexc;
-	unsigned long   fpinst;
-	unsigned long   fpinst2;
-};
-
-#define REG_RES(regs) ((regs).ARM_r0)
-#define REG_IP(regs)  ((regs).ARM_pc)
-#define REG_SYSCALL_NR(regs) ((regs).ARM_r7)
-
-#define user_regs_native(pregs)			true
 #define core_is_compat(core)			false
 
-/*
- * Range for task size calculated from the following Linux kernel files:
- *   arch/arm/include/asm/memory.h
- *   arch/arm/Kconfig (PAGE_OFFSET values in Memory split section)
- */
-#define TASK_SIZE_MIN 0x3f000000
-#define TASK_SIZE_MAX 0xbf000000
-#define SZ_1G 0x40000000
-
-int munmap(void *addr, size_t length);
-
-static inline unsigned long task_size(void)
-{
-	unsigned long task_size;
-
-	for (task_size = TASK_SIZE_MIN; task_size < TASK_SIZE_MAX; task_size += SZ_1G)
-		if (munmap((void *)task_size, page_size()))
-			break;
-
-	return task_size;
-}
-
-#define AT_VECTOR_SIZE 40
-
 typedef UserArmRegsEntry UserRegsEntry;
 
 #define CORE_ENTRY__MARCH CORE_ENTRY__MARCH__ARM
@@ -101,9 +21,6 @@ typedef UserArmRegsEntry UserRegsEntry;
 
 #define TI_SP(core) ((core)->ti_arm->gpregs->sp)
 
-typedef u32 auxv_t;
-typedef u32 tls_t;
-
 static inline void *decode_pointer(u64 v) { return (void*)(u32)v; }
 static inline u64 encode_pointer(void *p) { return (u32)p; }
 
diff --git a/criu/arch/arm/sigframe.c b/criu/arch/arm/sigframe.c
index 63e6524..e8d9952 100644
--- a/criu/arch/arm/sigframe.c
+++ b/criu/arch/arm/sigframe.c
@@ -1,4 +1,5 @@
 #include "asm/types.h"
+#include "asm/infect-types.h"
 #include "asm/sigframe.h"
 
 int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe,
diff --git a/criu/arch/ppc64/crtools.c b/criu/arch/ppc64/crtools.c
index a276019..d002a0a 100644
--- a/criu/arch/ppc64/crtools.c
+++ b/criu/arch/ppc64/crtools.c
@@ -5,7 +5,7 @@
 #include <asm/unistd.h>
 #include <sys/uio.h>
 
-#include "asm/types.h"
+#include "types.h"
 #include "asm/fpu.h"
 #include "asm/restorer.h"
 
diff --git a/criu/arch/ppc64/include/asm/infect-types.h b/criu/arch/ppc64/include/asm/infect-types.h
new file mode 100644
index 0000000..182c1fd
--- /dev/null
+++ b/criu/arch/ppc64/include/asm/infect-types.h
@@ -0,0 +1,110 @@
+#ifndef UAPI_COMPEL_ASM_TYPES_H__
+#define UAPI_COMPEL_ASM_TYPES_H__
+
+#include <stdbool.h>
+#include <signal.h>
+#include <stdint.h>
+
+#define SIGMAX_OLD	31
+#define SIGMAX		64
+
+/*
+ * Copied from kernel header arch/powerpc/include/uapi/asm/ptrace.h
+ */
+typedef struct {
+	unsigned long gpr[32];
+	unsigned long nip;
+	unsigned long msr;
+	unsigned long orig_gpr3;	/* Used for restarting system calls */
+	unsigned long ctr;
+	unsigned long link;
+	unsigned long xer;
+	unsigned long ccr;
+	unsigned long softe;		/* Soft enabled/disabled */
+	unsigned long trap;		/* Reason for being here */
+	/*
+	 * N.B. for critical exceptions on 4xx, the dar and dsisr
+	 * fields are overloaded to hold srr0 and srr1.
+	 */
+	unsigned long dar;		/* Fault registers */
+	unsigned long dsisr;		/* on 4xx/Book-E used for ESR */
+	unsigned long result;		/* Result of a system call */
+} user_regs_struct_t;
+
+#define NVSXREG	32
+
+#define USER_FPREGS_FL_FP	0x00001
+#define USER_FPREGS_FL_ALTIVEC	0x00002
+#define USER_FPREGS_FL_VSX	0x00004
+#define USER_FPREGS_FL_TM	0x00010
+
+#ifndef NT_PPC_TM_SPR
+# define NT_PPC_TM_CGPR		0x108		/* TM checkpointed GPR Registers */
+# define NT_PPC_TM_CFPR		0x109		/* TM checkpointed FPR Registers */
+# define NT_PPC_TM_CVMX		0x10a		/* TM checkpointed VMX Registers */
+# define NT_PPC_TM_CVSX		0x10b		/* TM checkpointed VSX Registers */
+# define NT_PPC_TM_SPR		0x10c		/* TM Special Purpose Registers */
+#endif
+
+#define MSR_TMA			(1UL<<34)	/* bit 29 Trans Mem state: Transactional */
+#define MSR_TMS			(1UL<<33)	/* bit 30 Trans Mem state: Suspended */
+#define MSR_TM			(1UL<<32)	/* bit 31 Trans Mem Available */
+#define MSR_VEC			(1UL<<25)
+#define MSR_VSX			(1UL<<23)
+
+#define MSR_TM_ACTIVE(x) ((((x) & MSR_TM) && ((x)&(MSR_TMA|MSR_TMS))) != 0)
+
+typedef struct {
+	uint64_t fpregs[NFPREG];
+	__vector128 vrregs[NVRREG];
+	uint64_t vsxregs[NVSXREG];
+
+	int flags;
+	struct tm_regs {
+		int flags;
+		struct {
+			uint64_t tfhar, texasr, tfiar;
+		} tm_spr_regs;
+		user_regs_struct_t regs;
+		uint64_t fpregs[NFPREG];
+		__vector128 vrregs[NVRREG];
+		uint64_t vsxregs[NVSXREG];
+	} tm;
+} user_fpregs_struct_t;
+
+#define REG_RES(regs)		((uint64_t)(regs).gpr[3])
+#define REG_IP(regs)		((uint64_t)(regs).nip)
+#define REG_SYSCALL_NR(regs)	((uint64_t)(regs).gpr[0])
+
+#define user_regs_native(pregs)	true
+
+/*
+ * Copied from the following kernel header files :
+ * 	include/linux/auxvec.h
+ *	arch/powerpc/include/uapi/asm/auxvec.h
+ *	include/linux/mm_types.h
+ */
+#define AT_VECTOR_SIZE_BASE	20
+#define AT_VECTOR_SIZE_ARCH	6
+#define AT_VECTOR_SIZE		(2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
+
+typedef uint64_t auxv_t;
+
+/* Not used but the structure parasite_dump_thread needs a tls_t field */
+typedef uint64_t tls_t;
+
+/*
+ * Copied for the Linux kernel arch/powerpc/include/asm/processor.h
+ *
+ * NOTE: 32bit tasks are not supported.
+ */
+#define TASK_SIZE_USER64	(0x0000400000000000UL)
+#define TASK_SIZE		TASK_SIZE_USER64
+
+static inline unsigned long task_size(void) { return TASK_SIZE; }
+
+#define ARCH_SI_TRAP TRAP_BRKPT
+
+#define __NR(syscall, compat)	__NR_##syscall
+
+#endif /* UAPI_COMPEL_ASM_TYPES_H__ */
diff --git a/criu/arch/ppc64/include/asm/types.h b/criu/arch/ppc64/include/asm/types.h
index 34661ba..25e2125 100644
--- a/criu/arch/ppc64/include/asm/types.h
+++ b/criu/arch/ppc64/include/asm/types.h
@@ -11,94 +11,14 @@
 
 #include "uapi/std/asm/syscall-types.h"
 
-#define SIGMAX_OLD	31
-#define SIGMAX		64
-
-/*
- * Copied from kernel header arch/powerpc/include/uapi/asm/ptrace.h
- */
-typedef struct {
-        unsigned long gpr[32];
-        unsigned long nip;
-        unsigned long msr;
-        unsigned long orig_gpr3;        /* Used for restarting system calls */
-        unsigned long ctr;
-        unsigned long link;
-        unsigned long xer;
-        unsigned long ccr;
-        unsigned long softe;            /* Soft enabled/disabled */
-        unsigned long trap;             /* Reason for being here */
-        /* N.B. for critical exceptions on 4xx, the dar and dsisr
-           fields are overloaded to hold srr0 and srr1. */
-        unsigned long dar;              /* Fault registers */
-        unsigned long dsisr;            /* on 4xx/Book-E used for ESR */
-        unsigned long result;           /* Result of a system call */
-} user_regs_struct_t;
-
-#define NVSXREG	32
-
-#define USER_FPREGS_FL_FP	0x00001
-#define USER_FPREGS_FL_ALTIVEC	0x00002
-#define USER_FPREGS_FL_VSX	0x00004
-#define USER_FPREGS_FL_TM	0x00010
-
-typedef struct {
-	uint64_t fpregs[NFPREG];
-	__vector128 vrregs[NVRREG];
-	uint64_t vsxregs[NVSXREG];
-
-	int flags;
-	struct tm_regs {
-		int flags;
-		struct {
-			uint64_t tfhar, texasr, tfiar;
-		} tm_spr_regs;
-		user_regs_struct_t regs;
-		uint64_t fpregs[NFPREG];
-		__vector128 vrregs[NVRREG];
-		uint64_t vsxregs[NVSXREG];
-	} tm;
-} user_fpregs_struct_t;
-
-
 typedef UserPpc64RegsEntry UserRegsEntry;
 
 #define CORE_ENTRY__MARCH	CORE_ENTRY__MARCH__PPC64
 
-#define REG_RES(regs)           ((u64)(regs).gpr[3])
-#define REG_IP(regs)            ((u64)(regs).nip)
-#define REG_SYSCALL_NR(regs)    ((u64)(regs).gpr[0])
-
-#define user_regs_native(pregs)			true
 #define core_is_compat(core)			false
 
 #define CORE_THREAD_ARCH_INFO(core) core->ti_ppc64
 
-/*
- * Copied from the following kernel header files :
- * 	include/linux/auxvec.h
- *	arch/powerpc/include/uapi/asm/auxvec.h
- *	include/linux/mm_types.h
- */
-#define AT_VECTOR_SIZE_BASE 20
-#define AT_VECTOR_SIZE_ARCH 6
-#define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
-
-typedef uint64_t auxv_t;
-
-/* Not used but the structure parasite_dump_thread needs a tls_t field */
-typedef uint64_t tls_t;
-
-/*
- * Copied for the Linux kernel arch/powerpc/include/asm/processor.h
- *
- * NOTE: 32bit tasks are not supported.
- */
-#define TASK_SIZE_USER64 (0x0000400000000000UL)
-#define TASK_SIZE TASK_SIZE_USER64
-
-static inline unsigned long task_size(void) { return TASK_SIZE; }
-
 static inline void *decode_pointer(uint64_t v) { return (void*)v; }
 static inline uint64_t encode_pointer(void *p) { return (uint64_t)p; }
 
diff --git a/criu/arch/x86/crtools.c b/criu/arch/x86/crtools.c
index 2b351f0..0b8055a 100644
--- a/criu/arch/x86/crtools.c
+++ b/criu/arch/x86/crtools.c
@@ -6,10 +6,10 @@
 #include <sys/syscall.h>
 #include <sys/auxv.h>
 
+#include "types.h"
 #include "asm/processor-flags.h"
 #include "asm/parasite-syscall.h"
 #include "asm/restorer.h"
-#include "asm/types.h"
 #include "asm/fpu.h"
 
 #include "cr_options.h"
diff --git a/criu/arch/x86/include/asm/infect-types.h b/criu/arch/x86/include/asm/infect-types.h
new file mode 100644
index 0000000..39ddcb3
--- /dev/null
+++ b/criu/arch/x86/include/asm/infect-types.h
@@ -0,0 +1,157 @@
+#ifndef UAPI_COMPEL_ASM_TYPES_H__
+#define UAPI_COMPEL_ASM_TYPES_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <signal.h>
+#include "common/page.h"
+#include "uapi/std/asm/syscall-types.h"
+
+#define SIGMAX			64
+#define SIGMAX_OLD		31
+
+typedef struct {
+	uint64_t	r15;
+	uint64_t	r14;
+	uint64_t	r13;
+	uint64_t	r12;
+	uint64_t	bp;
+	uint64_t	bx;
+	uint64_t	r11;
+	uint64_t	r10;
+	uint64_t	r9;
+	uint64_t	r8;
+	uint64_t	ax;
+	uint64_t	cx;
+	uint64_t	dx;
+	uint64_t	si;
+	uint64_t	di;
+	uint64_t	orig_ax;
+	uint64_t	ip;
+	uint64_t	cs;
+	uint64_t	flags;
+	uint64_t	sp;
+	uint64_t	ss;
+	uint64_t	fs_base;
+	uint64_t	gs_base;
+	uint64_t	ds;
+	uint64_t	es;
+	uint64_t	fs;
+	uint64_t	gs;
+} user_regs_struct64;
+
+typedef struct {
+	uint32_t	bx;
+	uint32_t	cx;
+	uint32_t	dx;
+	uint32_t	si;
+	uint32_t	di;
+	uint32_t	bp;
+	uint32_t	ax;
+	uint32_t	ds;
+	uint32_t	es;
+	uint32_t	fs;
+	uint32_t	gs;
+	uint32_t	orig_ax;
+	uint32_t	ip;
+	uint32_t	cs;
+	uint32_t	flags;
+	uint32_t	sp;
+	uint32_t	ss;
+} user_regs_struct32;
+
+#ifdef CONFIG_X86_64
+/*
+ * To be sure that we rely on inited reg->__is_native, this member
+ * is (short int) instead of initial (bool). The right way to
+ * check if regs are native or compat is to use user_regs_native() macro.
+ * This should cost nothing, as *usually* sizeof(bool) == sizeof(short)
+ */
+typedef struct {
+	union {
+		user_regs_struct64 native;
+		user_regs_struct32 compat;
+	};
+	short __is_native; /* use user_regs_native macro to check it */
+} user_regs_struct_t;
+
+#define NATIVE_MAGIC	0x0A
+#define COMPAT_MAGIC	0x0C
+
+static inline bool user_regs_native(user_regs_struct_t *pregs)
+{
+	return pregs->__is_native == NATIVE_MAGIC;
+}
+
+#define get_user_reg(pregs, name)			\
+	((user_regs_native(pregs))		?	\
+	 ((pregs)->native.name)			:	\
+	 ((pregs)->compat.name))
+
+#define set_user_reg(pregs, name, val)			\
+	((user_regs_native(pregs))		?	\
+	 ((pregs)->native.name = (val))		:	\
+	 ((pregs)->compat.name = (val)))
+
+#else /* CONFIG_X86_64 */
+
+typedef struct {
+	union {
+		user_regs_struct32 native;
+	};
+} user_regs_struct_t;
+
+#define user_regs_native(pregs)		true
+#define get_user_reg(pregs, name)	((pregs)->native.name)
+#define set_user_reg(pregs, name, val)	((pregs)->native.name = val)
+
+#endif /* CONFIG_X86_64 */
+
+typedef struct xsave_struct user_fpregs_struct_t;
+
+#ifdef CONFIG_X86_64
+# define TASK_SIZE	((1UL << 47) - PAGE_SIZE)
+#else
+/*
+ * Task size may be limited to 3G but we need a
+ * higher limit, because it's backward compatible.
+ */
+# define TASK_SIZE	(0xffffe000)
+#endif
+
+static inline unsigned long task_size(void) { return TASK_SIZE; }
+
+#define REG_RES(regs)		get_user_reg(&regs, ax)
+#define REG_IP(regs)		get_user_reg(&regs, ip)
+#define REG_SYSCALL_NR(regs)	get_user_reg(&regs, orig_ax)
+
+typedef uint64_t auxv_t;
+
+/*
+ * Linux preserves three TLS segments in GDT.
+ * Offsets in GDT differ between 32-bit and 64-bit machines.
+ * For 64-bit x86 those GDT offsets are the same
+ * for native and compat tasks.
+ */
+#define GDT_ENTRY_TLS_MIN		12
+#define GDT_ENTRY_TLS_MAX		14
+#define GDT_ENTRY_TLS_NUM		3
+typedef struct {
+	user_desc_t		desc[GDT_ENTRY_TLS_NUM];
+} tls_t;
+
+#define AT_VECTOR_SIZE 44
+
+#define __NR(syscall, compat)	((compat) ? __NR32_##syscall : __NR_##syscall)
+
+/*
+ * For x86_32 __NR_mmap inside the kernel represents old_mmap system
+ * call, but since we didn't use it yet lets go further and simply
+ * define own alias for __NR_mmap2 which would allow us to unify code
+ * between 32 and 64 bits version.
+ */
+#define __NR32_mmap __NR32_mmap2
+
+#define ARCH_SI_TRAP SI_KERNEL
+
+#endif /* UAPI_COMPEL_ASM_TYPES_H__ */
diff --git a/criu/arch/x86/include/asm/types.h b/criu/arch/x86/include/asm/types.h
index 41d3b64..9131307 100644
--- a/criu/arch/x86/include/asm/types.h
+++ b/criu/arch/x86/include/asm/types.h
@@ -14,90 +14,7 @@
 #include "common/bug.h"
 #include "images/core.pb-c.h"
 
-#define SIGMAX			64
-#define SIGMAX_OLD		31
-
-#define MAJOR(dev)		((dev)>>8)
-#define MINOR(dev)		((dev) & 0xff)
-
-typedef struct {
-	uint64_t	r15;
-	uint64_t	r14;
-	uint64_t	r13;
-	uint64_t	r12;
-	uint64_t	bp;
-	uint64_t	bx;
-	uint64_t	r11;
-	uint64_t	r10;
-	uint64_t	r9;
-	uint64_t	r8;
-	uint64_t	ax;
-	uint64_t	cx;
-	uint64_t	dx;
-	uint64_t	si;
-	uint64_t	di;
-	uint64_t	orig_ax;
-	uint64_t	ip;
-	uint64_t	cs;
-	uint64_t	flags;
-	uint64_t	sp;
-	uint64_t	ss;
-	uint64_t	fs_base;
-	uint64_t	gs_base;
-	uint64_t	ds;
-	uint64_t	es;
-	uint64_t	fs;
-	uint64_t	gs;
-} user_regs_struct64;
-
-typedef struct {
-	uint32_t	bx;
-	uint32_t	cx;
-	uint32_t	dx;
-	uint32_t	si;
-	uint32_t	di;
-	uint32_t	bp;
-	uint32_t	ax;
-	uint32_t	ds;
-	uint32_t	es;
-	uint32_t	fs;
-	uint32_t	gs;
-	uint32_t	orig_ax;
-	uint32_t	ip;
-	uint32_t	cs;
-	uint32_t	flags;
-	uint32_t	sp;
-	uint32_t	ss;
-} user_regs_struct32;
-
 #ifdef CONFIG_X86_64
-/*
- * To be sure that we rely on inited reg->__is_native, this member
- * is (short int) instead of initial (bool). The right way to
- * check if regs are native or compat is to use user_regs_native() macro.
- * This should cost nothing, as *usually* sizeof(bool) == sizeof(short)
- */
-typedef struct {
-	union {
-		user_regs_struct64 native;
-		user_regs_struct32 compat;
-	};
-	short __is_native; /* use user_regs_native macro to check it */
-} user_regs_struct_t;
-
-#define NATIVE_MAGIC	0x0A
-#define COMPAT_MAGIC	0x0C
-static inline bool user_regs_native(user_regs_struct_t *pregs)
-{
-	BUG_ON(pregs->__is_native != NATIVE_MAGIC &&
-		pregs->__is_native != COMPAT_MAGIC);
-	return pregs->__is_native == NATIVE_MAGIC;
-}
-
-#define get_user_reg(pregs, name) ((user_regs_native(pregs)) ?		\
-		((pregs)->native.name) : ((pregs)->compat.name))
-#define set_user_reg(pregs, name, val) ((user_regs_native(pregs)) ?	\
-		((pregs)->native.name = (val)) : ((pregs)->compat.name = (val)))
 static inline int core_is_compat(CoreEntry *c)
 {
 	switch (c->thread_info->gpregs->mode) {
@@ -109,72 +26,13 @@ static inline int core_is_compat(CoreEntry *c)
 			return -1;
 	}
 }
-#else /* !CONFIG_X86_64 */
-typedef struct {
-	union {
-		user_regs_struct32 native;
-	};
-} user_regs_struct_t;
+#else /* CONFIG_X86_64 */
 #define user_regs_native(pregs)		true
-#define get_user_reg(pregs, name)	((pregs)->native.name)
-#define set_user_reg(pregs, name, val)	((pregs)->native.name = val)
 static inline int core_is_compat(CoreEntry *c) { return 0; }
-#endif /* !CONFIG_X86_64 */
-
-#if 0
-typedef struct {
-	unsigned short	cwd;
-	unsigned short	swd;
-	unsigned short	twd;	/* Note this is not the same as
-				   the 32bit/x87/FSAVE twd */
-	unsigned short	fop;
-	u64		rip;
-	u64		rdp;
-	u32		mxcsr;
-	u32		mxcsr_mask;
-	u32		st_space[32];	/* 8*16 bytes for each FP-reg = 128 bytes */
-	u32		xmm_space[64];	/* 16*16 bytes for each XMM-reg = 256 bytes */
-	u32		padding[24];
-} user_fpregs_struct_t;
-#endif
-
-typedef struct xsave_struct user_fpregs_struct_t;
-
-#ifdef CONFIG_X86_64
-# define TASK_SIZE	((1UL << 47) - PAGE_SIZE)
-#else
-/*
- * Task size may be limited to 3G but we need a
- * higher limit, because it's backward compatible.
- */
-# define TASK_SIZE	(0xffffe000)
-#endif
-
-static inline unsigned long task_size(void) { return TASK_SIZE; }
-
-typedef u64 auxv_t;
-
-/*
- * Linux preserves three TLS segments in GDT.
- * Offsets in GDT differ between 32-bit and 64-bit machines.
- * For 64-bit x86 those GDT offsets are the same
- * for native and compat tasks.
- */
-#define GDT_ENTRY_TLS_MIN		12
-#define GDT_ENTRY_TLS_MAX		14
-#define GDT_ENTRY_TLS_NUM		3
-typedef struct {
-	user_desc_t desc[GDT_ENTRY_TLS_NUM];
-} tls_t;
-
-#define REG_RES(regs)		get_user_reg(&regs, ax)
-#define REG_IP(regs)		get_user_reg(&regs, ip)
-#define REG_SYSCALL_NR(regs)	get_user_reg(&regs, orig_ax)
+#endif /* CONFIG_X86_64 */
 
 #define CORE_ENTRY__MARCH CORE_ENTRY__MARCH__X86_64
 
-#define AT_VECTOR_SIZE 44
-
 #define CORE_THREAD_ARCH_INFO(core) core->thread_info
 
 typedef UserX86RegsEntry UserRegsEntry;
diff --git a/criu/arch/x86/restorer.c b/criu/arch/x86/restorer.c
index 0c07251..052d91a 100644
--- a/criu/arch/x86/restorer.c
+++ b/criu/arch/x86/restorer.c
@@ -1,6 +1,7 @@
 #include <asm/prctl.h>
 #include <unistd.h>
 
+#include "types.h"
 #include "restorer.h"
 #include "asm/restorer.h"
 #include "asm/fpu.h"
diff --git a/criu/include/restore.h b/criu/include/restore.h
index 6d878b4..7a1efcf 100644
--- a/criu/include/restore.h
+++ b/criu/include/restore.h
@@ -1,4 +1,5 @@
 #ifndef __CR_INC_RESTORE_H__
 #define __CR_INC_RESTORE_H__
+#include "types.h"
 #include "asm/restore.h"
 #endif
diff --git a/criu/include/restorer.h b/criu/include/restorer.h
index 4ef520e..cce0995 100644
--- a/criu/include/restorer.h
+++ b/criu/include/restorer.h
@@ -5,6 +5,7 @@
 #include <limits.h>
 #include <sys/resource.h>
 
+#include "types.h"
 #include "int.h"
 #include "common/compiler.h"
 #include "asm/fpu.h"
@@ -12,7 +13,6 @@
 #include "util.h"
 #include "asm/restorer.h"
 #include "config.h"
-
 #include "posix-timer.h"
 #include "timerfd.h"
 #include "shmem.h"
diff --git a/criu/include/types.h b/criu/include/types.h
index c55993a..36f2408 100644
--- a/criu/include/types.h
+++ b/criu/include/types.h
@@ -1,4 +1,5 @@
 #ifndef __CR_INC_TYPES_H__
 #define __CR_INC_TYPES_H__
+#include "asm/infect-types.h"
 #include "asm/types.h"
 #endif
-- 
2.1.4



More information about the CRIU mailing list