[CRIU] [PATCH 09/22] restorer: moved the routine restore_gpregs() to the file arch/x86/restorer.c
Alexander Kartashov
alekskartashov at parallels.com
Thu Dec 27 01:51:00 EST 2012
Signed-off-by: Alexander Kartashov <alekskartashov at parallels.com>
---
arch/x86/include/asm/restorer.h | 2 ++
arch/x86/restorer.c | 54 +++++++++++++++++++++++++++++++++++++++
pie/restorer.c | 49 ++---------------------------------
3 files changed, 58 insertions(+), 47 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 e233651..a4e8366 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/restorer.c b/pie/restorer.c
index 337577a..299657a 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -27,6 +27,8 @@
#include "creds.pb-c.h"
+#include "asm/restorer.h"
+
#define sys_prctl_safe(opcode, val1, val2, val3) \
({ \
long __ret = sys_prctl(opcode, val1, val2, val3, 0); \
@@ -157,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