[CRIU] [PATCH 15/44] restorer: moved the routine restore_gpregs() to the file arch/x86/restorer.c.

Alexander Kartashov alekskartashov at parallels.com
Mon Jan 7 10:04:44 EST 2013


Signed-off-by: Alexander Kartashov <alekskartashov at parallels.com>
---
 arch/x86/include/asm/restorer.h |    2 ++
 arch/x86/restorer.c             |   54 +++++++++++++++++++++++++++++++++++++++
 pie/Makefile                    |    3 ++-
 pie/restorer.c                  |   47 ----------------------------------
 4 files changed, 58 insertions(+), 48 deletions(-)
 create mode 100644 arch/x86/restorer.c

diff --git a/arch/x86/include/asm/restorer.h b/arch/x86/include/asm/restorer.h
index 7d8c8aa..6f9bdae 100644
--- a/arch/x86/include/asm/restorer.h
+++ b/arch/x86/include/asm/restorer.h
@@ -71,4 +71,6 @@ struct rt_sigframe {
 	/* fp state follows here */
 };
 
+int restore_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r);
+
 #endif
diff --git a/arch/x86/restorer.c b/arch/x86/restorer.c
new file mode 100644
index 0000000..599ab8c
--- /dev/null
+++ b/arch/x86/restorer.c
@@ -0,0 +1,54 @@
+#include <unistd.h>
+
+#include "restorer.h"
+#include "asm/restorer.h"
+
+#include "syscall.h"
+#include "log.h"
+
+int restore_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r)
+{
+	long ret;
+	unsigned long fsgs_base;
+
+#define CPREG1(d)	f->uc.uc_mcontext.d = r->d
+#define CPREG2(d, s)	f->uc.uc_mcontext.d = r->s
+
+	CPREG1(r8);
+	CPREG1(r9);
+	CPREG1(r10);
+	CPREG1(r11);
+	CPREG1(r12);
+	CPREG1(r13);
+	CPREG1(r14);
+	CPREG1(r15);
+	CPREG2(rdi, di);
+	CPREG2(rsi, si);
+	CPREG2(rbp, bp);
+	CPREG2(rbx, bx);
+	CPREG2(rdx, dx);
+	CPREG2(rax, ax);
+	CPREG2(rcx, cx);
+	CPREG2(rsp, sp);
+	CPREG2(rip, ip);
+	CPREG2(eflags, flags);
+	CPREG1(cs);
+	CPREG1(gs);
+	CPREG1(fs);
+
+	fsgs_base = r->fs_base;
+	ret = sys_arch_prctl(ARCH_SET_FS, fsgs_base);
+	if (ret) {
+		pr_info("SET_FS fail %ld\n", ret);
+		return -1;
+	}
+
+	fsgs_base = r->gs_base;
+	ret = sys_arch_prctl(ARCH_SET_GS, fsgs_base);
+	if (ret) {
+		pr_info("SET_GS fail %ld\n", ret);
+		return -1;
+	}
+
+	return 0;
+}
diff --git a/pie/Makefile b/pie/Makefile
index 197ea4a..c77c847 100644
--- a/pie/Makefile
+++ b/pie/Makefile
@@ -4,6 +4,7 @@ CFLAGS		+=  -fpie  -Wa,--noexecstack -fno-strict-aliasing
 GEN-OFFSETS	:= gen-offsets.sh
 
 PASM-OBJS	+= $(ARCH_DIR)/parasite-head.o
+RESTORER-ARCH-OBJS := $(ARCH_DIR)/restorer.o
 
 PARASITE	+= parasite.bin.o parasite.bin
 RESTORER	:= restorer.bin.o restorer.bin
@@ -16,7 +17,7 @@ ASMFLAGS	:= -D__ASSEMBLY__
 LIB-OBJS	= log-simple.o blob-util-net.o $(SYSCALL-LIB)
 
 $(PARASITE): $(LIB-OBJS) $(PASM-OBJS) $(PIELDS)
-$(RESTORER): $(LIB-OBJS) $(PIELDS)
+$(RESTORER): $(LIB-OBJS) $(RESTORER-ARCH-OBJS) $(PIELDS)
 
 $(PIELDS): $(PIELDS).in
 	$(E) "  GEN     " $@
diff --git a/pie/restorer.c b/pie/restorer.c
index 8b011a8..299657a 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -159,53 +159,6 @@ static int restore_fpu(struct rt_sigframe *sigframe, struct thread_restore_args
 	return 0;
 }
 
-static int restore_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r)
-{
-	long ret;
-	unsigned long fsgs_base;
-
-#define CPREG1(d)	f->uc.uc_mcontext.d = r->d
-#define CPREG2(d, s)	f->uc.uc_mcontext.d = r->s
-
-	CPREG1(r8);
-	CPREG1(r9);
-	CPREG1(r10);
-	CPREG1(r11);
-	CPREG1(r12);
-	CPREG1(r13);
-	CPREG1(r14);
-	CPREG1(r15);
-	CPREG2(rdi, di);
-	CPREG2(rsi, si);
-	CPREG2(rbp, bp);
-	CPREG2(rbx, bx);
-	CPREG2(rdx, dx);
-	CPREG2(rax, ax);
-	CPREG2(rcx, cx);
-	CPREG2(rsp, sp);
-	CPREG2(rip, ip);
-	CPREG2(eflags, flags);
-	CPREG1(cs);
-	CPREG1(gs);
-	CPREG1(fs);
-
-	fsgs_base = r->fs_base;
-	ret = sys_arch_prctl(ARCH_SET_FS, fsgs_base);
-	if (ret) {
-		pr_info("SET_FS fail %ld\n", ret);
-		return -1;
-	}
-
-	fsgs_base = r->gs_base;
-	ret = sys_arch_prctl(ARCH_SET_GS, fsgs_base);
-	if (ret) {
-		pr_info("SET_GS fail %ld\n", ret);
-		return -1;
-	}
-
-	return 0;
-}
-
 static int restore_thread_common(struct rt_sigframe *sigframe,
 		struct thread_restore_args *args)
 {
-- 
1.7.10.4



More information about the CRIU mailing list