Commit 0133a23a authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

restore: Add opening core file

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent f8c46a5d
...@@ -1218,11 +1218,13 @@ static int restore_all_tasks(pid_t pid) ...@@ -1218,11 +1218,13 @@ 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) static void restorer_test(pid_t pid)
{ {
restorer_fcall_t restorer_fcall; restorer_fcall_t restorer_fcall;
char path[64];
void *args_rip; void *args_rip;
void *exec_mem; void *exec_mem;
long ret;
exec_mem = mmap(0, RESTORER_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, 0, 0); exec_mem = mmap(0, RESTORER_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, 0, 0);
if (exec_mem == MAP_FAILED) { if (exec_mem == MAP_FAILED) {
...@@ -1236,8 +1238,11 @@ static void restorer_test(void) ...@@ -1236,8 +1238,11 @@ static void restorer_test(void)
args_rip = (void *)restorer_fcall(RESTORER_CMD__GET_ARG_OFFSET); args_rip = (void *)restorer_fcall(RESTORER_CMD__GET_ARG_OFFSET);
strcpy(args_rip, "Hello from restorer!\n"); snprintf(path, sizeof(path), "core-%d.img", pid);
restorer_fcall(RESTORER_CMD__PR_ARG_STRING); strcpy(args_rip, path);
ret = restorer_fcall(RESTORER_CMD__RESTORE_CORE);
pr_info("RESTORER_CMD__RESTORE_CORE: %lx\n", ret);
exit(0); exit(0);
...@@ -1245,7 +1250,7 @@ static void restorer_test(void) ...@@ -1245,7 +1250,7 @@ static void restorer_test(void)
int cr_restore_tasks(pid_t pid, struct cr_options *opts) int cr_restore_tasks(pid_t pid, struct cr_options *opts)
{ {
restorer_test(); restorer_test(pid);
if (opts->leader_only) if (opts->leader_only)
return restore_one_task(pid); return restore_one_task(pid);
......
...@@ -13,8 +13,12 @@ ...@@ -13,8 +13,12 @@
#include "util.h" #include "util.h"
#include "image.h" #include "image.h"
#include "crtools.h"
#include "restorer.h" #include "restorer.h"
#define get_rt_sigframe_addr(stack) \
(struct rt_sigframe *)(stack - sizeof(long))
#define lea_args_off(p) \ #define lea_args_off(p) \
do { \ do { \
asm volatile( \ asm volatile( \
...@@ -25,6 +29,16 @@ ...@@ -25,6 +29,16 @@
: "memory"); \ : "memory"); \
} while (0) } while (0)
static void always_inline write_string(char *str)
{
int len = 0;
while (str[len])
len++;
sys_write(1, str, len);
}
long restorer(long cmd) long restorer(long cmd)
{ {
long ret; long ret;
...@@ -64,6 +78,20 @@ long restorer(long cmd) ...@@ -64,6 +78,20 @@ long restorer(long cmd)
*/ */
case RESTORER_CMD__RESTORE_CORE: case RESTORER_CMD__RESTORE_CORE:
{ {
char *core_path;
int fd_core;
struct core_entry core_entry;
struct rt_sigframe *frame;
lea_args_off(core_path);
write_string(core_path);
write_string("\n");
fd_core = sys_open(core_path, O_RDONLY, CR_FD_PERM);
return fd_core;
/* /*
* Unmap all but self, note that we reply on * Unmap all but self, note that we reply on
* caller that it has placed this execution * caller that it has placed this execution
......
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