Commit ae41bc9d authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

restore: Add restore_core_args facility

More convenient instead of manual offset calculations.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent efdb52e3
......@@ -1221,25 +1221,31 @@ static int restore_all_tasks(pid_t pid)
static void restorer_test(pid_t pid)
{
restorer_fcall_t restorer_fcall;
struct restore_core_args *args;
char path[64];
void *args_rip;
void *exec_mem;
long ret;
/* VMA we need to run restorer code */
exec_mem = mmap(0, RESTORER_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, 0, 0);
if (exec_mem == MAP_FAILED) {
pr_err("Can't mmap exec\n");
return;
}
/* Restorer content at the new location */
memcpy(exec_mem, &restorer, RESTORER_SIZE);
restorer_fcall = exec_mem;
restorer_fcall(RESTORER_CMD__GET_ARG_OFFSET);
args_rip = (void *)restorer_fcall(RESTORER_CMD__GET_ARG_OFFSET);
/*
* Pass arguments and run a command.
*/
snprintf(path, sizeof(path), "core-%d.img", pid);
strcpy(args_rip, path);
args = (struct restore_core_args *)restorer_fcall(RESTORER_CMD__GET_ARG_OFFSET);
args->self_entry = exec_mem;
args->self_size = RESTORER_SIZE;
strcpy(args->core_path, path);
ret = restorer_fcall(RESTORER_CMD__RESTORE_CORE);
pr_info("RESTORER_CMD__RESTORE_CORE: %lx\n", ret);
......
......@@ -20,6 +20,12 @@ enum {
RESTORER_CMD__MAX,
};
struct restore_core_args {
void *self_entry; /* restorer placed at */
long self_size; /* size for restorer granted */
char core_path[0]; /* path to a core file */
};
struct rt_sigframe {
char *pretcode;
struct ucontext uc;
......
......@@ -76,18 +76,21 @@ long restorer(long cmd)
*/
case RESTORER_CMD__RESTORE_CORE:
{
char *core_path;
struct restore_core_args *args;
int fd_core;
struct core_entry core_entry;
struct vma_entry vma_entry;
u64 va;
struct rt_sigframe *frame;
lea_args_off(core_path);
lea_args_off(args);
write_string(core_path);
write_string(args->core_path);
write_string("\n");
fd_core = sys_open(core_path, O_RDONLY, CR_FD_PERM);
fd_core = sys_open(args->core_path, O_RDONLY, CR_FD_PERM);
if (fd_core < 0)
return fd_core;
......
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