Commit e37c1562 authored by Alexander Kartashov's avatar Alexander Kartashov Committed by Pavel Emelyanov

restorer: wrapped the assembly code calling sys_clone into the macro RUN_CLONE_RESTORE_FN.

Signed-off-by: 's avatarAlexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 1e5635da
......@@ -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);
......
......@@ -638,41 +638,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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment