Commit 63e08215 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

restore: Add restorer test

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 0fe80627
...@@ -67,6 +67,7 @@ OBJS += util.o ...@@ -67,6 +67,7 @@ OBJS += util.o
OBJS += rbtree.o OBJS += rbtree.o
OBJS += elf.o OBJS += elf.o
OBJS += seize.o OBJS += seize.o
OBJS += restorer.o
DEPS := $(patsubst %.o,%.d,$(OBJS)) DEPS := $(patsubst %.o,%.d,$(OBJS))
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "image.h" #include "image.h"
#include "util.h" #include "util.h"
#include "restorer.h"
#include "crtools.h" #include "crtools.h"
...@@ -1217,8 +1218,35 @@ static int restore_all_tasks(pid_t pid) ...@@ -1217,8 +1218,35 @@ static int restore_all_tasks(pid_t pid)
return restore_root_task(path, pstree_fd); return restore_root_task(path, pstree_fd);
} }
static void restorer_test(void)
{
restorer_fcall_t restorer_fcall;
void *args_rip;
void *exec_mem;
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;
}
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);
strcpy(args_rip, "Hello from restorer!\n");
restorer_fcall(RESTORER_CMD__PR_ARG_STRING);
exit(0);
}
int cr_restore_tasks(pid_t pid, struct cr_options *opts) int cr_restore_tasks(pid_t pid, struct cr_options *opts)
{ {
restorer_test();
if (opts->leader_only) if (opts->leader_only)
return restore_one_task(pid); return restore_one_task(pid);
return restore_all_tasks(pid); return restore_all_tasks(pid);
......
#ifndef CR_RESTORER_H__
#define CR_RESTORER_H__
#include "image.h"
#define RESTORER_ARGS_SIZE 512
#define RESTORER_SIZE 4096
long restorer(long cmd);
typedef long (*restorer_fcall_t) (long cmd);
enum {
RESTORER_CMD__NONE,
RESTORER_CMD__GET_ARG_OFFSET,
RESTORER_CMD__PR_ARG_STRING,
RESTORER_CMD__MAX,
};
#endif /* CR_RESTORER_H__ */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "compiler.h"
#include "types.h"
#include "syscall.h"
#include "util.h"
#include "image.h"
#include "restorer.h"
long restorer(long cmd)
{
long ret;
asm volatile(
"jmp 1f \n\t"
"restore_args__: \n\t"
".skip "__stringify(RESTORER_ARGS_SIZE)",0 \n\t"
"1: \n\t"
:
:
: "memory");
switch (cmd) {
case RESTORER_CMD__PR_ARG_STRING:
{
char *str = NULL;
int size = 0;
asm volatile(
"leaq restore_args__(%%rip), %%rax \n\t"
"movq %%rax, %0 \n\t"
: "=m"(str)
:
: "memory");
while (str[size])
size++;
sys_write(1, str, size);
}
break;
case RESTORER_CMD__GET_ARG_OFFSET:
asm volatile(
"leaq restore_args__(%%rip), %%rax \n\t"
"movq %%rax, %0 \n\t"
: "=m"(ret)
:
: "memory");
break;
}
asm volatile(".align "__stringify(RESTORER_SIZE));
return ret;
}
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