Commit 168d8cf1 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

restore: restorer is finally alive

No real restore code yet, but at least it
produce message ;)
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 791f2c8c
......@@ -26,6 +26,7 @@
#include "image.h"
#include "util.h"
#include "syscall.h"
#include "restorer.h"
#include "crtools.h"
......@@ -1231,7 +1232,7 @@ static void restorer_test(pid_t pid)
restorer_fcall = restorer;
exec_len = restorer_fcall(RESTORER_CMD__GET_SELF_LEN) - (long)restorer;
args_offset = restorer_fcall(RESTORER_CMD__GET_ARG_OFFSET) - (long)restorer;
exec_len = (exec_len + 8) & ~7;
exec_len = round_up(exec_len, 16);
/* VMA we need to run restorer code */
exec_mem = mmap(0, exec_len + RESTORER_STACK_SIZE,
......@@ -1255,8 +1256,10 @@ static void restorer_test(pid_t pid)
memcpy(exec_start, &restorer, exec_len);
restorer_fcall = exec_start;
pr_info("exec_mem: %lx exec_start: %lx exec_len: %lx args_offset: %lx\n",
exec_mem, exec_start, exec_len, args_offset);
/*
* Stack pointer in a middle of allocated stack zone.
*/
new_sp = (long)exec_mem + RESTORER_STACK_MIDDLE;
/*
* Pass arguments and run a command.
......@@ -1267,31 +1270,22 @@ static void restorer_test(pid_t pid)
args->self_size = exec_len;
strcpy(args->core_path, path);
/*
* An indirect call to restorer, note it never resturns
* and restoreing core is extremely destructive.
*/
asm volatile(
"movq %%rsp, %0 \t\n"
"movq %4, %%rax \t\n"
"movq %3, %%rbx \t\n"
"movl $3, %%edi \t\n"
"movq %%rbx, %%rsp \t\n"
"pushq $0 \t\n"
// "callq *%%rax \t\n"
"movq %%rbx, %1 \t\n"
"movq %%rax, %2 \t\n"
: "=g"(old_sp), "=g"(new_sp), "=g"(new_ip)
: "g"(exec_mem), "g"(exec_start)
"movq %0, %%rbx \t\n"
"movq %1, %%rax \t\n"
"movl $"__stringify(RESTORER_CMD__RESTORE_CORE)", %%edi \t\n"
"movq %%rbx, %%rsp \t\n"
"callq *%%rax \t\n"
:
: "g"(new_sp), "g"(exec_start)
: "rsp", "rdi", "rbx", "rax", "memory");
pr_info("old_sp: %lx new_sp: %lx new_ip: %lx\n",
old_sp, new_sp, new_ip);
pr_info("exec_mem: %lx exec_start: %lx\n",
exec_mem, exec_start);
ret = restorer_fcall(RESTORER_CMD__RESTORE_CORE);
pr_info("RESTORER_CMD__RESTORE_CORE: %lx\n", ret);
exit(0);
/* Just to be sure */
sys_exit(0);
}
int cr_restore_tasks(pid_t pid, struct cr_options *opts)
......
......@@ -6,20 +6,18 @@
#include "image.h"
#define RESTORER_ARGS_SIZE 512
#define RESTORER_STACK_SIZE (16 << 10)
#define RESTORER_STACK_MIDDLE (16 << 10)
#define RESTORER_STACK_SIZE (RESTORER_STACK_MIDDLE * 2)
long restorer(long cmd);
typedef long (*restorer_fcall_t) (long cmd);
enum {
RESTORER_CMD__NONE,
RESTORER_CMD__GET_ARG_OFFSET,
RESTORER_CMD__GET_SELF_LEN,
RESTORER_CMD__PR_ARG_STRING,
RESTORER_CMD__RESTORE_CORE,
RESTORER_CMD__MAX,
};
#define RESTORER_CMD__NONE 0
#define RESTORER_CMD__GET_ARG_OFFSET 1
#define RESTORER_CMD__GET_SELF_LEN 2
#define RESTORER_CMD__PR_ARG_STRING 3
#define RESTORER_CMD__RESTORE_CORE 4
struct restore_core_args {
void *self_entry; /* restorer placed at */
......
......@@ -89,7 +89,9 @@ self_len_end:
u64 va;
struct rt_sigframe *frame;
char msg[] = {'I', '\'', 'm', '!', '\n', 0};
write_string(msg);
sys_exit(0);
lea_args_off(args);
......
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