Commit 53c611b6 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

dump,restore: Use rt_sigaction_t for sys_sigaction

Since we operate with syscalls directly we are
to convert signal's structures between image and
kernel formats, without intermediate glibc layer.

Note this involves chaging sa_entry::flags to u64
(since it's long int value in kernel).
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 8557e39b
...@@ -1052,11 +1052,11 @@ static int open_pipe(int pid, struct pipe_entry *e, int *pipes_fd) ...@@ -1052,11 +1052,11 @@ static int open_pipe(int pid, struct pipe_entry *e, int *pipes_fd)
static int prepare_sigactions(int pid) static int prepare_sigactions(int pid)
{ {
u32 type = 0; rt_sigaction_t act, oact;
int fd_sigact, ret; int fd_sigact, ret;
int sig, i;
struct sigaction act, oact;
struct sa_entry e; struct sa_entry e;
u32 type = 0;
int sig, i;
fd_sigact = open_fmt_ro(FMT_FNAME_SIGACTS, pid); fd_sigact = open_fmt_ro(FMT_FNAME_SIGACTS, pid);
if (fd_sigact < 0) { if (fd_sigact < 0) {
...@@ -1081,13 +1081,11 @@ static int prepare_sigactions(int pid) ...@@ -1081,13 +1081,11 @@ static int prepare_sigactions(int pid)
goto err; goto err;
} }
BUILD_BUG_ON(sizeof(e.mask) != sizeof(act.sa_mask)); ASSIGN_TYPED(act.rt_sa_handler, e.sigaction);
ASSIGN_TYPED(act.rt_sa_flags, e.flags);
act.sa_sigaction = (void *)(long)e.sigaction; ASSIGN_TYPED(act.rt_sa_restorer, e.restorer);
act.sa_flags = (int)e.flags;
act.sa_restorer = (void *)(long)e.restorer;
memcpy(&act.sa_mask, &e.mask, sizeof(act.sa_mask)); memcpy(&act.rt_sa_mask, &e.mask, sizeof(act.rt_sa_mask));
/* /*
* A pure syscall is used, because glibc * A pure syscall is used, because glibc
......
...@@ -90,7 +90,7 @@ struct page_entry { ...@@ -90,7 +90,7 @@ struct page_entry {
struct sa_entry { struct sa_entry {
u64 sigaction; u64 sigaction;
u8 mask[128]; u8 mask[128];
u32 flags; u64 flags;
u64 restorer; u64 restorer;
} __packed; } __packed;
......
...@@ -154,9 +154,9 @@ static always_inline long sys_open(const char *filename, unsigned long flags, un ...@@ -154,9 +154,9 @@ static always_inline long sys_open(const char *filename, unsigned long flags, un
struct sigaction; struct sigaction;
static always_inline long sys_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) static always_inline long sys_sigaction(int signum, const rt_sigaction_t *act, rt_sigaction_t *oldact)
{ {
return syscall4(__NR_rt_sigaction, signum, (unsigned long) act, (unsigned long) oldact, sizeof(rt_sigset_t)); return syscall4(__NR_rt_sigaction, signum, (unsigned long)act, (unsigned long)oldact, sizeof(rt_sigset_t));
} }
static always_inline long sys_close(int fd) static always_inline long sys_close(int fd)
......
...@@ -98,6 +98,19 @@ typedef struct { ...@@ -98,6 +98,19 @@ typedef struct {
unsigned long sig[1]; unsigned long sig[1];
} rt_sigset_t; } rt_sigset_t;
typedef void rt_signalfn_t(int);
typedef rt_signalfn_t *rt_sighandler_t;
typedef void rt_restorefn_t(void);
typedef rt_restorefn_t *rt_sigrestore_t;
typedef struct {
rt_sighandler_t rt_sa_handler;
unsigned long rt_sa_flags;
rt_sigrestore_t rt_sa_restorer;
rt_sigset_t rt_sa_mask;
} rt_sigaction_t;
typedef struct { typedef struct {
unsigned int entry_number; unsigned int entry_number;
unsigned int base_addr; unsigned int base_addr;
...@@ -180,6 +193,8 @@ typedef struct { ...@@ -180,6 +193,8 @@ typedef struct {
#endif /* CONFIG_X86_64 */ #endif /* CONFIG_X86_64 */
#define ASSIGN_TYPED(a,b) a = (typeof(a))b
#ifndef PAGE_SIZE #ifndef PAGE_SIZE
# define PAGE_SIZE 4096 # define PAGE_SIZE 4096
#endif #endif
......
...@@ -226,7 +226,7 @@ err: ...@@ -226,7 +226,7 @@ err:
static int dump_sigact(parasite_args_cmd_dumpsigacts_t *args) static int dump_sigact(parasite_args_cmd_dumpsigacts_t *args)
{ {
parasite_status_t *st = &args->status; parasite_status_t *st = &args->status;
struct sigaction act; rt_sigaction_t act;
struct sa_entry e; struct sa_entry e;
int fd, sig; int fd, sig;
...@@ -254,13 +254,11 @@ static int dump_sigact(parasite_args_cmd_dumpsigacts_t *args) ...@@ -254,13 +254,11 @@ static int dump_sigact(parasite_args_cmd_dumpsigacts_t *args)
goto err_close; goto err_close;
} }
BUILD_BUG_ON(sizeof(e.mask) != sizeof(act.sa_mask)); ASSIGN_TYPED(e.sigaction, act.rt_sa_handler);
ASSIGN_TYPED(e.flags, act.rt_sa_flags);
ASSIGN_TYPED(e.restorer, act.rt_sa_restorer);
e.sigaction = (u64)act.sa_sigaction; inline_memcpy(&e.mask, &act.rt_sa_mask, sizeof(e.mask));
e.flags = (u32)act.sa_flags;
e.restorer = (u64)act.sa_restorer;
inline_memcpy(&e.mask, &act.sa_mask, sizeof(e.mask));
ret = sys_write(fd, &e, sizeof(e)); ret = sys_write(fd, &e, sizeof(e));
if (ret != sizeof(e)) { if (ret != sizeof(e)) {
......
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