[CRIU] [PATCH 18/44] restorer: wrapped the assembly code calling sys_clone into the macro RUN_CLONE_RESTORE_FN.
Alexander Kartashov
alekskartashov at parallels.com
Mon Jan 7 10:04:47 EST 2013
Signed-off-by: Alexander Kartashov <alekskartashov at parallels.com>
---
arch/x86/include/asm/restorer.h | 38 ++++++++++++++++++++++++++++++++++++++
pie/restorer.c | 37 ++-----------------------------------
2 files changed, 40 insertions(+), 35 deletions(-)
diff --git a/arch/x86/include/asm/restorer.h b/arch/x86/include/asm/restorer.h
index 6867ccc..8d0708d 100644
--- a/arch/x86/include/asm/restorer.h
+++ b/arch/x86/include/asm/restorer.h
@@ -82,6 +82,44 @@ struct rt_sigframe {
: "r"(new_sp) \
: "rax","rsp","memory")
+#define RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid, \
+ thread_args, clone_restore_fn) \
+ asm volatile( \
+ "clone_emul: \n" \
+ "movq %2, %%rsi \n" \
+ "subq $16, %%rsi \n" \
+ "movq %6, %%rdi \n" \
+ "movq %%rdi, 8(%%rsi) \n" \
+ "movq %5, %%rdi \n" \
+ "movq %%rdi, 0(%%rsi) \n" \
+ "movq %1, %%rdi \n" \
+ "movq %3, %%rdx \n" \
+ "movq %4, %%r10 \n" \
+ "movl $"__stringify(__NR_clone)", %%eax \n" \
+ "syscall \n" \
+ \
+ "testq %%rax,%%rax \n" \
+ "jz thread_run \n" \
+ \
+ "movq %%rax, %0 \n" \
+ "jmp clone_end \n" \
+ \
+ "thread_run: \n" \
+ "xorq %%rbp, %%rbp \n" \
+ "popq %%rax \n" \
+ "popq %%rdi \n" \
+ "callq *%%rax \n" \
+ \
+ "clone_end: \n" \
+ : "=r"(ret) \
+ : "g"(clone_flags), \
+ "g"(new_sp), \
+ "g"(&parent_tid), \
+ "g"(&thread_args[i].pid), \
+ "g"(clone_restore_fn), \
+ "g"(&thread_args[i]) \
+ : "rax", "rdi", "rsi", "rdx", "r10", "memory")
+
int restore_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r);
diff --git a/pie/restorer.c b/pie/restorer.c
index adf7af0..69e056c 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -629,41 +629,8 @@ long __export_restore_task(struct task_restore_core_args *args)
* thread will run with own stack and we must not
* have any additional instructions... oh, dear...
*/
- asm volatile(
- "clone_emul: \n"
- "movq %2, %%rsi \n"
- "subq $16, %%rsi \n"
- "movq %6, %%rdi \n"
- "movq %%rdi, 8(%%rsi) \n"
- "movq %5, %%rdi \n"
- "movq %%rdi, 0(%%rsi) \n"
- "movq %1, %%rdi \n"
- "movq %3, %%rdx \n"
- "movq %4, %%r10 \n"
- "movl $"__stringify(__NR_clone)", %%eax \n"
- "syscall \n"
-
- "testq %%rax,%%rax \n"
- "jz thread_run \n"
-
- "movq %%rax, %0 \n"
- "jmp clone_end \n"
-
- "thread_run: \n" /* new stack here */
- "xorq %%rbp, %%rbp \n" /* clear ABI frame pointer */
- "popq %%rax \n" /* clone_restore_fn -- restore_thread */
- "popq %%rdi \n" /* arguments */
- "callq *%%rax \n"
-
- "clone_end: \n"
- : "=r"(ret)
- : "g"(clone_flags),
- "g"(new_sp),
- "g"(&parent_tid),
- "g"(&thread_args[i].pid),
- "g"(args->clone_restore_fn),
- "g"(&thread_args[i])
- : "rax", "rdi", "rsi", "rdx", "r10", "memory");
+
+ RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid, thread_args, args->clone_restore_fn);
}
ret = sys_flock(fd, LOCK_UN);
--
1.7.10.4
More information about the CRIU
mailing list