[CRIU] [PATCH 30/38] compel: Move sigframe from criu to compel

Cyrill Gorcunov gorcunov at openvz.org
Tue Oct 11 09:04:20 PDT 2016


Some criu specific helpers are still sitting in criu folder.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 .../aarch64/src/lib/include/compel/asm/sigframe.h  |  51 +++++
 .../arch/arm/src/lib/include/compel/asm/sigframe.h |  85 ++++++++
 .../ppc64/src/lib/include/compel/asm/sigframe.h    |  66 ++++++
 .../arch/x86/src/lib/include/compel/asm/sigframe.h | 231 +++++++++++++++++++++
 compel/include/compel/sigframe-common.h            |  56 +++++
 criu/Makefile                                      |   1 +
 criu/Makefile.crtools                              |   1 +
 criu/arch/aarch64/include/asm/restorer.h           |  49 +----
 criu/arch/arm/include/asm/restorer.h               |  79 +------
 criu/arch/ppc64/include/asm/restorer.h             |  59 +-----
 criu/arch/x86/include/asm/restorer.h               | 104 ----------
 criu/include/sigframe.h                            |  42 +---
 12 files changed, 495 insertions(+), 329 deletions(-)
 create mode 100644 compel/arch/aarch64/src/lib/include/compel/asm/sigframe.h
 create mode 100644 compel/arch/arm/src/lib/include/compel/asm/sigframe.h
 create mode 100644 compel/arch/ppc64/src/lib/include/compel/asm/sigframe.h
 create mode 100644 compel/arch/x86/src/lib/include/compel/asm/sigframe.h
 create mode 100644 compel/include/compel/sigframe-common.h

diff --git a/compel/arch/aarch64/src/lib/include/compel/asm/sigframe.h b/compel/arch/aarch64/src/lib/include/compel/asm/sigframe.h
new file mode 100644
index 000000000000..f0ecf844ad8c
--- /dev/null
+++ b/compel/arch/aarch64/src/lib/include/compel/asm/sigframe.h
@@ -0,0 +1,51 @@
+#ifndef COMPEL_ASM_SIGFRAME_H__
+#define COMPEL_ASM_SIGFRAME_H__
+
+#include <asm/sigcontext.h>
+#include <sys/ucontext.h>
+
+#include <stdint.h>
+
+/* Copied from the kernel header arch/arm64/include/uapi/asm/sigcontext.h */
+
+#define FPSIMD_MAGIC			0x46508001
+
+typedef struct fpsimd_context		fpu_state_t;
+
+struct aux_context {
+	struct fpsimd_context		fpsimd;
+	/* additional context to be added before "end" */
+	struct _aarch64_ctx		end;
+};
+
+// XXX: the idetifier rt_sigcontext is expected to be struct by the CRIU code
+#define rt_sigcontext			sigcontext
+
+#include "compel/sigframe-common.h"
+
+/* Copied from the kernel source arch/arm64/kernel/signal.c */
+
+struct rt_sigframe {
+	siginfo_t			info;
+	struct ucontext			uc;
+	uint64_t			fp;
+	uint64_t			lr;
+};
+
+#define ARCH_RT_SIGRETURN(new_sp, rt_sigframe)					\
+	asm volatile(								\
+			"mov sp, %0					\n"	\
+			"mov x8, #"__stringify(__NR_rt_sigreturn)"	\n"	\
+			"svc #0						\n"	\
+			:							\
+			: "r"(new_sp)						\
+			: "sp", "x8", "memory")
+
+#define RT_SIGFRAME_UC(rt_sigframe)		(&rt_sigframe->uc)
+#define RT_SIGFRAME_REGIP(rt_sigframe)		((long unsigned int)(rt_sigframe)->uc.uc_mcontext.pc)
+#define RT_SIGFRAME_HAS_FPU(rt_sigframe)	(1)
+#define RT_SIGFRAME_AUX_CONTEXT(rt_sigframe)	((struct aux_context*)&(rt_sigframe)->uc.uc_mcontext.__reserved)
+#define RT_SIGFRAME_FPU(rt_sigframe)		(&RT_SIGFRAME_AUX_CONTEXT(rt_sigframe)->fpsimd)
+#define RT_SIGFRAME_OFFSET(rt_sigframe)		0
+
+#endif /* COMPEL_ASM_SIGFRAME_H__ */
diff --git a/compel/arch/arm/src/lib/include/compel/asm/sigframe.h b/compel/arch/arm/src/lib/include/compel/asm/sigframe.h
new file mode 100644
index 000000000000..2b054cce1db8
--- /dev/null
+++ b/compel/arch/arm/src/lib/include/compel/asm/sigframe.h
@@ -0,0 +1,85 @@
+#ifndef COMPEL_ASM_SIGFRAME_H__
+#define COMPEL_ASM_SIGFRAME_H__
+
+#include "compiler.h"
+
+/* Copied from the Linux kernel header arch/arm/include/asm/sigcontext.h */
+
+struct rt_sigcontext {
+	unsigned long		trap_no;
+	unsigned long		error_code;
+	unsigned long		oldmask;
+	unsigned long		arm_r0;
+	unsigned long		arm_r1;
+	unsigned long		arm_r2;
+	unsigned long		arm_r3;
+	unsigned long		arm_r4;
+	unsigned long		arm_r5;
+	unsigned long		arm_r6;
+	unsigned long		arm_r7;
+	unsigned long		arm_r8;
+	unsigned long		arm_r9;
+	unsigned long		arm_r10;
+	unsigned long		arm_fp;
+	unsigned long		arm_ip;
+	unsigned long		arm_sp;
+	unsigned long		arm_lr;
+	unsigned long		arm_pc;
+	unsigned long		arm_cpsr;
+	unsigned long		fault_address;
+};
+
+/* Copied from the Linux kernel header arch/arm/include/asm/ucontext.h */
+
+#define VFP_MAGIC		0x56465001
+#define VFP_STORAGE_SIZE	sizeof(struct vfp_sigframe)
+
+struct vfp_sigframe {
+	unsigned long		magic;
+	unsigned long		size;
+	struct user_vfp		ufp;
+	struct user_vfp_exc	ufp_exc;
+};
+
+typedef struct vfp_sigframe	fpu_state_t;
+
+struct aux_sigframe {
+	/*
+	struct crunch_sigframe  crunch;
+	struct iwmmxt_sigframe  iwmmxt;
+	*/
+
+	struct vfp_sigframe	vfp;
+	unsigned long		end_magic;
+} __aligned(8);
+
+#include "compel/sigframe-common.h"
+
+struct sigframe {
+	struct rt_ucontext	uc;
+	unsigned long		retcode[2];
+};
+
+struct rt_sigframe {
+	struct rt_siginfo	info;
+	struct sigframe		sig;
+};
+
+
+#define ARCH_RT_SIGRETURN(new_sp, rt_sigframe)				\
+	asm volatile(							\
+		     "mov %%sp, %0				    \n"	\
+		     "mov %%r7,  #"__stringify(__NR_rt_sigreturn)"  \n" \
+		     "svc #0					    \n"	\
+		     :							\
+		     : "r"(new_sp)					\
+		     : "sp","memory")
+
+#define RT_SIGFRAME_UC(rt_sigframe)		(&rt_sigframe->sig.uc)
+#define RT_SIGFRAME_REGIP(rt_sigframe)		(rt_sigframe)->sig.uc.uc_mcontext.arm_ip
+#define RT_SIGFRAME_HAS_FPU(rt_sigframe)	1
+#define RT_SIGFRAME_AUX_SIGFRAME(rt_sigframe)	((struct aux_sigframe *)&(rt_sigframe)->sig.uc.uc_regspace)
+#define RT_SIGFRAME_FPU(rt_sigframe)		(&RT_SIGFRAME_AUX_SIGFRAME(rt_sigframe)->vfp)
+#define RT_SIGFRAME_OFFSET(rt_sigframe)		0
+
+#endif /* COMPEL_ASM_SIGFRAME_H__ */
diff --git a/compel/arch/ppc64/src/lib/include/compel/asm/sigframe.h b/compel/arch/ppc64/src/lib/include/compel/asm/sigframe.h
new file mode 100644
index 000000000000..37f2a0f0e703
--- /dev/null
+++ b/compel/arch/ppc64/src/lib/include/compel/asm/sigframe.h
@@ -0,0 +1,66 @@
+#ifndef COMPEL_ASM_SIGFRAME_H__
+#define COMPEL_ASM_SIGFRAME_H__
+
+#include <asm/ptrace.h>
+#include <asm/elf.h>
+#include <asm/types.h>
+
+/*
+ * sigcontext structure defined in file
+ *	/usr/include/powerpc64le-linux-gnu/bits/sigcontext.h,
+ * included from /usr/include/signal.h
+ *
+ * Kernel definition can be found in arch/powerpc/include/uapi/asm/sigcontext.h
+ */
+#include <signal.h>
+
+// XXX: the idetifier rt_sigcontext is expected to be struct by the CRIU code
+#define rt_sigcontext sigcontext
+
+#include "compel/sigframe-common.h"
+
+#define RT_SIGFRAME_OFFSET(rt_sigframe)	0
+
+/* Copied from the Linux kernel header arch/powerpc/include/asm/ptrace.h */
+#define USER_REDZONE_SIZE		512
+
+/* Copied from the Linux kernel source file arch/powerpc/kernel/signal_64.c */
+#define TRAMP_SIZE			6
+
+/*
+ * ucontext defined in /usr/include/powerpc64le-linux-gnu/sys/ucontext.h
+ */
+struct rt_sigframe {
+        /* sys_rt_sigreturn requires the ucontext be the first field */
+        struct ucontext			uc;
+        struct ucontext			uc_transact; /* Transactional state	 */
+        unsigned long			_unused[2];
+        unsigned int			tramp[TRAMP_SIZE];
+        struct rt_siginfo		*pinfo;
+        void				*puc;
+        struct rt_siginfo		info;
+        /* New 64 bit little-endian ABI allows redzone of 512 bytes below sp */
+        char				abigap[USER_REDZONE_SIZE];
+} __aligned(16);
+
+#define ARCH_RT_SIGRETURN(new_sp, rt_sigframe)			\
+        asm volatile(						\
+		"mr 1, %0 \n"					\
+		"li 0, "__stringify(__NR_rt_sigreturn)" \n"	\
+		"sc \n"						\
+		:						\
+		: "r"(new_sp)					\
+		: "1", "memory")
+
+#if _CALL_ELF != 2
+# error Only supporting ABIv2.
+#else
+# define FRAME_MIN_SIZE_PARM		96
+#endif
+
+#define RT_SIGFRAME_UC(rt_sigframe)		(&(rt_sigframe)->uc)
+#define RT_SIGFRAME_REGIP(rt_sigframe)		((long unsigned int)(rt_sigframe)->uc.uc_mcontext.gp_regs[PT_NIP])
+#define RT_SIGFRAME_HAS_FPU(rt_sigframe)	(1)
+#define RT_SIGFRAME_FPU(rt_sigframe)		(&(rt_sigframe)->uc.uc_mcontext)
+
+#endif /* COMPEL_ASM_SIGFRAME_H__ */
diff --git a/compel/arch/x86/src/lib/include/compel/asm/sigframe.h b/compel/arch/x86/src/lib/include/compel/asm/sigframe.h
new file mode 100644
index 000000000000..dd5513f5916e
--- /dev/null
+++ b/compel/arch/x86/src/lib/include/compel/asm/sigframe.h
@@ -0,0 +1,231 @@
+#ifndef COMPEL_ASM_SIGFRAME_H__
+#define COMPEL_ASM_SIGFRAME_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "compiler.h"
+#include "compel/asm/fpu.h"
+
+#define SIGFRAME_MAX_OFFSET 8
+
+struct rt_sigcontext {
+	unsigned long			r8;
+	unsigned long			r9;
+	unsigned long			r10;
+	unsigned long			r11;
+	unsigned long			r12;
+	unsigned long			r13;
+	unsigned long			r14;
+	unsigned long			r15;
+	unsigned long			rdi;
+	unsigned long			rsi;
+	unsigned long			rbp;
+	unsigned long			rbx;
+	unsigned long			rdx;
+	unsigned long			rax;
+	unsigned long			rcx;
+	unsigned long			rsp;
+	unsigned long			rip;
+	unsigned long			eflags;
+	unsigned short			cs;
+	unsigned short			gs;
+	unsigned short			fs;
+	unsigned short			ss;
+	unsigned long			err;
+	unsigned long			trapno;
+	unsigned long			oldmask;
+	unsigned long			cr2;
+	void				*fpstate;
+	unsigned long			reserved1[8];
+};
+
+struct rt_sigcontext_32 {
+	uint32_t			gs;
+	uint32_t			fs;
+	uint32_t			es;
+	uint32_t			ds;
+	uint32_t			di;
+	uint32_t			si;
+	uint32_t			bp;
+	uint32_t			sp;
+	uint32_t			bx;
+	uint32_t			dx;
+	uint32_t			cx;
+	uint32_t			ax;
+	uint32_t			trapno;
+	uint32_t			err;
+	uint32_t			ip;
+	uint32_t			cs;
+	uint32_t			flags;
+	uint32_t			sp_at_signal;
+	uint32_t			ss;
+
+	uint32_t			fpstate;
+	uint32_t			oldmask;
+	uint32_t			cr2;
+};
+
+#include "compel/sigframe-common.h"
+
+/*
+ * XXX: move declarations to generic sigframe.h or sigframe-compat.h
+ *      when (if) other architectures will support compatible C/R
+ */
+
+typedef uint32_t			compat_uptr_t;
+typedef uint32_t			compat_size_t;
+typedef uint32_t			compat_sigset_word;
+
+#define _COMPAT_NSIG			64
+#define _COMPAT_NSIG_BPW		32
+#define _COMPAT_NSIG_WORDS		(_COMPAT_NSIG / _COMPAT_NSIG_BPW)
+
+typedef struct {
+	compat_sigset_word		sig[_COMPAT_NSIG_WORDS];
+} compat_sigset_t;
+
+typedef struct compat_siginfo {
+	int				si_signo;
+	int				si_errno;
+	int				si_code;
+	int				_pad[128/sizeof(int) - 3];
+} compat_siginfo_t;
+
+#ifdef CONFIG_X86_32
+# define rt_sigframe_ia32		rt_sigframe
+#endif
+
+typedef struct compat_sigaltstack {
+	compat_uptr_t			ss_sp;
+	int				ss_flags;
+	compat_size_t			ss_size;
+} compat_stack_t;
+
+struct ucontext_ia32 {
+	unsigned int			uc_flags;
+	unsigned int			uc_link;
+	compat_stack_t			uc_stack;
+	struct rt_sigcontext_32		uc_mcontext;
+	k_rtsigset_t			uc_sigmask; /* mask last for extensibility */
+};
+
+struct rt_sigframe_ia32 {
+	u32				pretcode;
+	s32				sig;
+	u32				pinfo;
+	u32				puc;
+#ifdef CONFIG_X86_64
+	compat_siginfo_t		info;
+#else
+	struct rt_siginfo		info;
+#endif
+	struct ucontext_ia32		uc;
+	char				retcode[8];
+
+	/* fp state follows here */
+	fpu_state_t			fpu_state;
+};
+
+#ifdef CONFIG_X86_64
+struct rt_sigframe_64 {
+	char				*pretcode;
+	struct rt_ucontext		uc;
+	struct rt_siginfo		info;
+
+	/* fp state follows here */
+	fpu_state_t			fpu_state;
+};
+
+struct rt_sigframe {
+	union {
+		struct rt_sigframe_ia32	compat;
+		struct rt_sigframe_64	native;
+	};
+	bool				is_native;
+};
+
+#define RT_SIGFRAME_UC_SIGMASK(rt_sigframe)				\
+	((rt_sigframe->is_native)			?		\
+	(&rt_sigframe->native.uc.uc_sigmask)		:		\
+	(&rt_sigframe->compat.uc.uc_sigmask))
+
+#define RT_SIGFRAME_REGIP(rt_sigframe)					\
+	((rt_sigframe->is_native)			?		\
+	(rt_sigframe)->native.uc.uc_mcontext.rip	:		\
+	(rt_sigframe)->compat.uc.uc_mcontext.ip)
+
+#define RT_SIGFRAME_FPU(rt_sigframe)					\
+	((rt_sigframe->is_native)			?		\
+	(&(rt_sigframe)->native.fpu_state)		:		\
+	 (&(rt_sigframe)->compat.fpu_state))
+
+#define RT_SIGFRAME_HAS_FPU(rt_sigframe)	(RT_SIGFRAME_FPU(rt_sigframe)->has_fpu)
+
+/*
+ * Sigframe offset is different for native/compat tasks.
+ * Offsets calculations one may see at kernel:
+ * - compatible is in sys32_rt_sigreturn at arch/x86/ia32/ia32_signal.c
+ * - native is in sys_rt_sigreturn at arch/x86/kernel/signal.c
+ */
+#define RT_SIGFRAME_OFFSET(rt_sigframe)		((rt_sigframe->is_native) ? 8 : 4 )
+
+#define USER32_CS		0x23
+
+#define ARCH_RT_SIGRETURN_NATIVE(new_sp)				\
+	asm volatile(							\
+		     "movq %0, %%rax				    \n"	\
+		     "movq %%rax, %%rsp				    \n"	\
+		     "movl $"__stringify(__NR_rt_sigreturn)", %%eax \n" \
+		     "syscall					    \n"	\
+		     :							\
+		     : "r"(new_sp)					\
+		     : "rax","rsp","memory")
+
+#define ARCH_RT_SIGRETURN_COMPAT(new_sp)				\
+	asm volatile(							\
+		"pushq $"__stringify(USER32_CS)"		\n"	\
+		"pushq $1f					\n"	\
+		"lretq						\n"	\
+		"1:						\n"	\
+		".code32					\n"	\
+		"movl %%edi, %%esp				\n"	\
+		"movl $"__stringify(__NR32_rt_sigreturn)",%%eax	\n"	\
+		"int $0x80					\n"	\
+		".code64					\n"	\
+		:							\
+		: "rdi"(new_sp)						\
+		: "eax","esp","memory")
+
+#define ARCH_RT_SIGRETURN(new_sp, rt_sigframe)				\
+do {									\
+	if ((rt_sigframe)->is_native)					\
+		ARCH_RT_SIGRETURN_NATIVE(new_sp);			\
+	else								\
+		ARCH_RT_SIGRETURN_COMPAT(new_sp);			\
+} while (0)
+
+#else /* CONFIG_X86_64 */
+
+#define ARCH_RT_SIGRETURN(new_sp, rt_sigframe)				\
+	asm volatile(							\
+		     "movl %0, %%eax				    \n"	\
+		     "movl %%eax, %%esp				    \n"	\
+		     "movl $"__stringify(__NR_rt_sigreturn)", %%eax \n" \
+		     "int $0x80					    \n"	\
+		     :							\
+		     : "r"(new_sp)					\
+		     : "eax","esp","memory")
+
+#define RT_SIGFRAME_UC(rt_sigframe)		(&rt_sigframe->uc)
+#define RT_SIGFRAME_OFFSET(rt_sigframe)		4
+#define RT_SIGFRAME_REGIP(rt_sigframe)					\
+	(unsigned long)(rt_sigframe)->uc.uc_mcontext.ip
+#define RT_SIGFRAME_FPU(rt_sigframe)		(&(rt_sigframe)->fpu_state)
+#define RT_SIGFRAME_HAS_FPU(rt_sigframe)	(RT_SIGFRAME_FPU(rt_sigframe)->has_fpu)
+#define kdat_compat_sigreturn_test()		0
+
+#endif /* CONFIG_X86_64 */
+
+
+#endif /* COMPEL_ASM_SIGFRAME_H__ */
diff --git a/compel/include/compel/sigframe-common.h b/compel/include/compel/sigframe-common.h
new file mode 100644
index 000000000000..bce05c410136
--- /dev/null
+++ b/compel/include/compel/sigframe-common.h
@@ -0,0 +1,56 @@
+/*
+ * Don't include it directly but use "arch-sigframe.h" instead.
+ */
+#ifndef COMPEL_SIGFRAME_COMMON_H__
+#define COMPEL_SIGFRAME_COMMON_H__
+
+#include "compiler.h"
+
+#ifndef COMPEL_ASM_SIGFRAME_H__
+# error "Direct inclusion is forbidden"
+#endif
+
+struct rt_sigframe;
+
+#ifndef SIGFRAME_MAX_OFFSET
+# define SIGFRAME_MAX_OFFSET		RT_SIGFRAME_OFFSET(0)
+#endif
+
+/* sigframe should be aligned on 64 byte for x86 and 8 bytes for arm */
+#define RESTORE_STACK_SIGFRAME		\
+	ALIGN(sizeof(struct rt_sigframe) + SIGFRAME_MAX_OFFSET, 64)
+
+#ifndef __ARCH_SI_PREAMBLE_SIZE
+# define __ARCH_SI_PREAMBLE_SIZE	(3 * sizeof(int))
+#endif
+
+#define SI_MAX_SIZE	128
+
+#ifndef SI_PAD_SIZE
+# define SI_PAD_SIZE			((SI_MAX_SIZE - __ARCH_SI_PREAMBLE_SIZE) / sizeof(int))
+#endif
+
+typedef struct rt_siginfo {
+	int	si_signo;
+	int	si_errno;
+	int	si_code;
+	int	_pad[SI_PAD_SIZE];
+} rt_siginfo_t;
+
+typedef struct rt_sigaltstack {
+	void	*ss_sp;
+	int	ss_flags;
+	size_t	ss_size;
+} rt_stack_t;
+
+struct rt_ucontext {
+	unsigned long		uc_flags;
+	struct rt_ucontext	*uc_link;
+	rt_stack_t		uc_stack;
+	struct rt_sigcontext	uc_mcontext;
+	k_rtsigset_t		uc_sigmask;	/* mask last for extensibility */
+	int                     __unused[32 - (sizeof (k_rtsigset_t) / sizeof (int))];
+	unsigned long           uc_regspace[128] __aligned(8);
+};
+
+#endif /* COMPEL_SIGFRAME_COMMON_H__ */
diff --git a/criu/Makefile b/criu/Makefile
index 19af713a3c87..35d7c7373f0b 100644
--- a/criu/Makefile
+++ b/criu/Makefile
@@ -19,6 +19,7 @@ ccflags-y		+= -I/usr/include/libnl3
 ccflags-y		+= -iquote compel/plugins/include
 ccflags-y		+= -iquote compel/include
 ccflags-y		+= -iquote compel/arch/$(ARCH)/plugins/std
+ccflags-y		+= -iquote compel/arch/$(ARCH)/src/lib/include
 
 export ccflags-y
 
diff --git a/criu/Makefile.crtools b/criu/Makefile.crtools
index 8b6535c26679..c27faa9fecb1 100644
--- a/criu/Makefile.crtools
+++ b/criu/Makefile.crtools
@@ -2,6 +2,7 @@ ccflags-y		+= -iquote criu/$(ARCH)
 ccflags-y		+= -iquote compel/plugins/include
 ccflags-y		+= -iquote compel/include
 ccflags-y		+= -iquote compel/arch/$(ARCH)/plugins/std
+ccflags-y		+= -iquote compel/arch/$(ARCH)/src/lib/include
 
 obj-y			+= infect.o
 obj-y			+= infect-rpc.o
diff --git a/criu/arch/aarch64/include/asm/restorer.h b/criu/arch/aarch64/include/asm/restorer.h
index 80f358c46a42..6bde5f0344d2 100644
--- a/criu/arch/aarch64/include/asm/restorer.h
+++ b/criu/arch/aarch64/include/asm/restorer.h
@@ -7,45 +7,7 @@
 #include "asm/types.h"
 #include "images/core.pb-c.h"
 
-/* Copied from the kernel header arch/arm64/include/uapi/asm/sigcontext.h */
-
-#define FPSIMD_MAGIC    0x46508001
-
-typedef struct fpsimd_context fpu_state_t;
-
-
-struct aux_context {
-	struct fpsimd_context fpsimd;
-	/* additional context to be added before "end" */
-	struct _aarch64_ctx end;
-};
-
-
-// XXX: the idetifier rt_sigcontext is expected to be struct by the CRIU code
-#define rt_sigcontext sigcontext
-
-
-#include "sigframe.h"
-
-
-/* Copied from the kernel source arch/arm64/kernel/signal.c */
-
-struct rt_sigframe {
-	siginfo_t info;
-	struct ucontext uc;
-	u64 fp;
-	u64 lr;
-};
-
-
-#define ARCH_RT_SIGRETURN(new_sp, rt_sigframe)					\
-	asm volatile(								\
-			"mov sp, %0					\n"	\
-			"mov x8, #"__stringify(__NR_rt_sigreturn)"	\n"	\
-			"svc #0						\n"	\
-			:							\
-			: "r"(new_sp)						\
-			: "sp", "x8", "memory")
+#include "compel/asm/sigframe.h"
 
 #define RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid,		\
 			     thread_args, clone_restore_fn)			\
@@ -90,17 +52,8 @@ struct rt_sigframe {
 			: "sp", "x0", "memory")
 
 
-#define RT_SIGFRAME_UC(rt_sigframe) (&rt_sigframe->uc)
-#define RT_SIGFRAME_REGIP(rt_sigframe) ((long unsigned int)(rt_sigframe)->uc.uc_mcontext.pc)
-#define RT_SIGFRAME_HAS_FPU(rt_sigframe) (1)
-#define RT_SIGFRAME_AUX_CONTEXT(rt_sigframe)				\
-	((struct aux_context*)&(rt_sigframe)->uc.uc_mcontext.__reserved)
-#define RT_SIGFRAME_FPU(rt_sigframe)					\
-	(&RT_SIGFRAME_AUX_CONTEXT(rt_sigframe)->fpsimd)
-#define RT_SIGFRAME_OFFSET(rt_sigframe) 0
 #define kdat_compat_sigreturn_test()			0
 
-
 int restore_gpregs(struct rt_sigframe *f, UserAarch64RegsEntry *r);
 int restore_nonsigframe_gpregs(UserAarch64RegsEntry *r);
 
diff --git a/criu/arch/arm/include/asm/restorer.h b/criu/arch/arm/include/asm/restorer.h
index 305311799e9a..fcf4c1473de3 100644
--- a/criu/arch/arm/include/asm/restorer.h
+++ b/criu/arch/arm/include/asm/restorer.h
@@ -4,78 +4,9 @@
 #include "asm/types.h"
 #include "images/core.pb-c.h"
 
-/* Copied from the Linux kernel header arch/arm/include/asm/sigcontext.h */
-
-struct rt_sigcontext {
-	unsigned long trap_no;
-	unsigned long error_code;
-	unsigned long oldmask;
-	unsigned long arm_r0;
-	unsigned long arm_r1;
-	unsigned long arm_r2;
-	unsigned long arm_r3;
-	unsigned long arm_r4;
-	unsigned long arm_r5;
-	unsigned long arm_r6;
-	unsigned long arm_r7;
-	unsigned long arm_r8;
-	unsigned long arm_r9;
-	unsigned long arm_r10;
-	unsigned long arm_fp;
-	unsigned long arm_ip;
-	unsigned long arm_sp;
-	unsigned long arm_lr;
-	unsigned long arm_pc;
-	unsigned long arm_cpsr;
-	unsigned long fault_address;
-};
-
-/* Copied from the Linux kernel header arch/arm/include/asm/ucontext.h */
-
-#define VFP_MAGIC               0x56465001
-#define VFP_STORAGE_SIZE        sizeof(struct vfp_sigframe)
-
-struct vfp_sigframe {
-	unsigned long           magic;
-	unsigned long           size;
-	struct user_vfp         ufp;
-	struct user_vfp_exc     ufp_exc;
-};
-
-typedef struct vfp_sigframe fpu_state_t;
-
-struct aux_sigframe {
-	/*
-	struct crunch_sigframe  crunch;
-        struct iwmmxt_sigframe  iwmmxt;
-	*/
-
-	struct vfp_sigframe     vfp;
-	unsigned long           end_magic;
-} __attribute__((__aligned__(8)));
-
+#include "compel/asm/sigframe.h"
 #include "sigframe.h"
 
-struct sigframe {
-	struct rt_ucontext uc;
-	unsigned long retcode[2];
-};
-
-struct rt_sigframe {
-	struct rt_siginfo info;
-	struct sigframe sig;
-};
-
-
-#define ARCH_RT_SIGRETURN(new_sp, rt_sigframe)				\
-	asm volatile(							\
-		     "mov %%sp, %0				    \n"	\
-		     "mov %%r7,  #"__stringify(__NR_rt_sigreturn)"  \n" \
-		     "svc #0					    \n"	\
-		     :							\
-		     : "r"(new_sp)					\
-		     : "sp","memory")
-
 #define RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid,	\
 			     thread_args, clone_restore_fn)		\
 	asm volatile(							\
@@ -123,14 +54,6 @@ struct rt_sigframe {
 		     : "memory")
 
 
-#define RT_SIGFRAME_UC(rt_sigframe) (&rt_sigframe->sig.uc)
-#define RT_SIGFRAME_REGIP(rt_sigframe) (rt_sigframe)->sig.uc.uc_mcontext.arm_ip
-#define RT_SIGFRAME_HAS_FPU(rt_sigframe) 1
-#define RT_SIGFRAME_AUX_SIGFRAME(rt_sigframe)				\
-	((struct aux_sigframe *)&(rt_sigframe)->sig.uc.uc_regspace)
-#define RT_SIGFRAME_FPU(rt_sigframe)					\
-	(&RT_SIGFRAME_AUX_SIGFRAME(rt_sigframe)->vfp)
-#define RT_SIGFRAME_OFFSET(rt_sigframe) 0
 #define kdat_compat_sigreturn_test()			0
 
 
diff --git a/criu/arch/ppc64/include/asm/restorer.h b/criu/arch/ppc64/include/asm/restorer.h
index 6b6135cdaf19..dc7be1b17de9 100644
--- a/criu/arch/ppc64/include/asm/restorer.h
+++ b/criu/arch/ppc64/include/asm/restorer.h
@@ -1,66 +1,13 @@
 #ifndef __CR_ASM_RESTORER_H__
 #define __CR_ASM_RESTORER_H__
 
-#include <asm/ptrace.h>
-#include <asm/elf.h>
-#include <asm/types.h>
-
-/*
- * sigcontext structure defined in file
- *	/usr/include/powerpc64le-linux-gnu/bits/sigcontext.h,
- * included from /usr/include/signal.h
- *
- * Kernel definition can be found in arch/powerpc/include/uapi/asm/sigcontext.h
- */
-#include <signal.h>
-
-// XXX: the idetifier rt_sigcontext is expected to be struct by the CRIU code
-#define rt_sigcontext sigcontext
-
-#include "sigframe.h"
-#define RT_SIGFRAME_OFFSET(rt_sigframe) 0
-
-/* Copied from the Linux kernel header arch/powerpc/include/asm/ptrace.h */
-#define USER_REDZONE_SIZE       512
-
-/* Copied from the Linux kernel source file arch/powerpc/kernel/signal_64.c */
-#define TRAMP_SIZE      	6
-
-/*
- * ucontext defined in /usr/include/powerpc64le-linux-gnu/sys/ucontext.h
- */
-struct rt_sigframe {
-        /* sys_rt_sigreturn requires the ucontext be the first field */
-        struct ucontext uc;
-        struct ucontext uc_transact;  	/* Transactional state	 */
-        unsigned long _unused[2];
-        unsigned int tramp[TRAMP_SIZE];
-        struct rt_siginfo *pinfo;
-        void *puc;
-        struct rt_siginfo info;
-        /* New 64 bit little-endian ABI allows redzone of 512 bytes below sp */
-        char abigap[USER_REDZONE_SIZE];
-} __attribute__ ((aligned (16)));
-
-#define ARCH_RT_SIGRETURN(new_sp, rt_sigframe)			\
-        asm volatile(						\
-		"mr 1, %0 \n"					\
-		"li 0, "__stringify(__NR_rt_sigreturn)" \n"	\
-		"sc \n"						\
-		:						\
-		: "r"(new_sp)					\
-		: "1", "memory")
+#include "compel/asm/sigframe.h"
 
 /*
  * Clone trampoline
  *
  * See glibc sysdeps/powerpc/powerpc64/sysdep.h for FRAME_MIN_SIZE defines
  */
-#if _CALL_ELF != 2
-#error Only supporting ABIv2.
-#else
-#define FRAME_MIN_SIZE_PARM     96
-#endif
 #define RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid, 	\
 			     thread_args, clone_restore_fn)		\
 	asm volatile( 							\
@@ -95,10 +42,6 @@ struct rt_sigframe {
 		  "r"(&thread_args[i])		/* %6 */		\
 		: "memory","0","3","4","5","6","7","14","15")
 
-#define RT_SIGFRAME_UC(rt_sigframe) (&(rt_sigframe)->uc)
-#define RT_SIGFRAME_REGIP(rt_sigframe) ((long unsigned int)(rt_sigframe)->uc.uc_mcontext.gp_regs[PT_NIP])
-#define RT_SIGFRAME_HAS_FPU(rt_sigframe) (1)
-#define RT_SIGFRAME_FPU(rt_sigframe) (&(rt_sigframe)->uc.uc_mcontext)
 #define kdat_compat_sigreturn_test()			0
 
 int restore_gpregs(struct rt_sigframe *f, UserPpc64RegsEntry *r);
diff --git a/criu/arch/x86/include/asm/restorer.h b/criu/arch/x86/include/asm/restorer.h
index 944c54751ed9..0b4d44584b71 100644
--- a/criu/arch/x86/include/asm/restorer.h
+++ b/criu/arch/x86/include/asm/restorer.h
@@ -29,95 +29,7 @@ static inline int
 arch_compat_rt_sigaction(void *stack, int sig, void *act) { return -1; }
 #endif
 
-struct rt_sigframe_ia32 {
-	u32			pretcode;
-	s32			sig;
-	u32			pinfo;
-	u32			puc;
 #ifdef CONFIG_X86_64
-	compat_siginfo_t	info;
-#else
-	struct rt_siginfo	info;
-#endif
-	struct ucontext_ia32	uc;
-	char			retcode[8];
-
-	/* fp state follows here */
-	fpu_state_t		fpu_state;
-};
-
-#ifdef CONFIG_X86_64
-struct rt_sigframe_64 {
-	char			*pretcode;
-	struct rt_ucontext	uc;
-	struct rt_siginfo	info;
-
-	/* fp state follows here */
-	fpu_state_t		fpu_state;
-};
-
-struct rt_sigframe {
-	union {
-		struct rt_sigframe_ia32	compat;
-		struct rt_sigframe_64	native;
-	};
-	bool is_native;
-};
-
-#define RT_SIGFRAME_UC_SIGMASK(rt_sigframe) ((rt_sigframe->is_native) ?	\
-	(&rt_sigframe->native.uc.uc_sigmask) :				\
-	(&rt_sigframe->compat.uc.uc_sigmask))
-
-#define RT_SIGFRAME_REGIP(rt_sigframe) ((rt_sigframe->is_native) ?	\
-	(rt_sigframe)->native.uc.uc_mcontext.rip :			\
-	(rt_sigframe)->compat.uc.uc_mcontext.ip)
-
-#define RT_SIGFRAME_FPU(rt_sigframe)	((rt_sigframe->is_native) ?	\
-	(&(rt_sigframe)->native.fpu_state) : (&(rt_sigframe)->compat.fpu_state))
-#define RT_SIGFRAME_HAS_FPU(rt_sigframe) (RT_SIGFRAME_FPU(rt_sigframe)->has_fpu)
-
-/*
- * Sigframe offset is different for native/compat tasks.
- * Offsets calculations one may see at kernel:
- * - compatible is in sys32_rt_sigreturn at arch/x86/ia32/ia32_signal.c
- * - native is in sys_rt_sigreturn at arch/x86/kernel/signal.c
- */
-#define RT_SIGFRAME_OFFSET(rt_sigframe)	((rt_sigframe->is_native) ? 8 : 4 )
-
-#define USER32_CS		0x23
-
-#define ARCH_RT_SIGRETURN_NATIVE(new_sp)				\
-	asm volatile(							\
-		     "movq %0, %%rax				    \n"	\
-		     "movq %%rax, %%rsp				    \n"	\
-		     "movl $"__stringify(__NR_rt_sigreturn)", %%eax \n" \
-		     "syscall					    \n"	\
-		     :							\
-		     : "r"(new_sp)					\
-		     : "rax","rsp","memory")
-
-#define ARCH_RT_SIGRETURN_COMPAT(new_sp)				\
-	asm volatile(							\
-		"pushq $"__stringify(USER32_CS)"		\n"	\
-		"pushq $1f					\n"	\
-		"lretq						\n"	\
-		"1:						\n"	\
-		".code32					\n"	\
-		"movl %%edi, %%esp				\n"	\
-		"movl $"__stringify(__NR32_rt_sigreturn)",%%eax	\n"	\
-		"int $0x80					\n"	\
-		".code64					\n"	\
-		:							\
-		: "rdi"(new_sp)						\
-		: "eax","esp","memory")
-
-#define ARCH_RT_SIGRETURN(new_sp, rt_sigframe)				\
-do {									\
-	if ((rt_sigframe)->is_native)					\
-		ARCH_RT_SIGRETURN_NATIVE(new_sp);			\
-	else								\
-		ARCH_RT_SIGRETURN_COMPAT(new_sp);			\
-} while (0)
 
 #define RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid,      \
 			     thread_args, clone_restore_fn)             \
@@ -173,16 +85,6 @@ do {									\
 extern int kdat_compat_sigreturn_test(void);
 #else /* !CONFIG_X86_64 */
 
-#define ARCH_RT_SIGRETURN(new_sp, rt_sigframe)				\
-	asm volatile(							\
-		     "movl %0, %%eax				    \n"	\
-		     "movl %%eax, %%esp				    \n"	\
-		     "movl $"__stringify(__NR_rt_sigreturn)", %%eax \n" \
-		     "int $0x80					    \n"	\
-		     :							\
-		     : "r"(new_sp)					\
-		     : "eax","esp","memory")
-
 #define RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid,      \
 			     thread_args, clone_restore_fn)             \
 	(void)ret;							\
@@ -201,12 +103,6 @@ extern int kdat_compat_sigreturn_test(void);
 		     : "r"(ret)					\
 		     : "memory")
 
-#define RT_SIGFRAME_UC(rt_sigframe) (&rt_sigframe->uc)
-#define RT_SIGFRAME_OFFSET(rt_sigframe)	4
-#define RT_SIGFRAME_REGIP(rt_sigframe)					\
-	(unsigned long)(rt_sigframe)->uc.uc_mcontext.ip
-#define RT_SIGFRAME_FPU(rt_sigframe) (&(rt_sigframe)->fpu_state)
-#define RT_SIGFRAME_HAS_FPU(rt_sigframe) (RT_SIGFRAME_FPU(rt_sigframe)->has_fpu)
 #define kdat_compat_sigreturn_test()			0
 #endif /* !CONFIG_X86_64 */
 
diff --git a/criu/include/sigframe.h b/criu/include/sigframe.h
index 1bb0fb9cab80..877097c0c386 100644
--- a/criu/include/sigframe.h
+++ b/criu/include/sigframe.h
@@ -8,47 +8,7 @@
 #include "asm/types.h"
 #include "images/core.pb-c.h"
 
-struct rt_sigframe;
-
-#ifndef SIGFRAME_MAX_OFFSET
-#define SIGFRAME_MAX_OFFSET RT_SIGFRAME_OFFSET(0)
-#endif
-
-/* sigframe should be aligned on 64 byte for x86 and 8 bytes for arm */
-#define RESTORE_STACK_SIGFRAME						\
-	ALIGN(sizeof(struct rt_sigframe) + SIGFRAME_MAX_OFFSET, 64)
-
-#ifndef __ARCH_SI_PREAMBLE_SIZE
-#define __ARCH_SI_PREAMBLE_SIZE	(3 * sizeof(int))
-#endif
-
-#define SI_MAX_SIZE	128
-#ifndef SI_PAD_SIZE
-#define SI_PAD_SIZE	((SI_MAX_SIZE - __ARCH_SI_PREAMBLE_SIZE) / sizeof(int))
-#endif
-
-typedef struct rt_siginfo {
-	int	si_signo;
-	int	si_errno;
-	int	si_code;
-	int	_pad[SI_PAD_SIZE];
-} rt_siginfo_t;
-
-typedef struct rt_sigaltstack {
-	void	*ss_sp;
-	int	ss_flags;
-	size_t	ss_size;
-} rt_stack_t;
-
-struct rt_ucontext {
-	unsigned long		uc_flags;
-	struct rt_ucontext	*uc_link;
-	rt_stack_t		uc_stack;
-	struct rt_sigcontext	uc_mcontext;
-	k_rtsigset_t		uc_sigmask;	/* mask last for extensibility */
-	int                     __unused[32 - (sizeof (k_rtsigset_t) / sizeof (int))];
-	unsigned long           uc_regspace[128] __attribute__((__aligned__(8)));
-};
+#include "compel/asm/sigframe.h"
 
 extern int construct_sigframe(struct rt_sigframe *sigframe,
 			      struct rt_sigframe *rsigframe,
-- 
2.7.4



More information about the CRIU mailing list