[CRIU] [PATCH 4/7] parasite: Introduce generic syscall-calling function
Pavel Emelyanov
xemul at parallels.com
Mon Dec 17 15:30:43 EST 2012
This one calls a syscon on seized task. Existing mmap/munmap
just use one.
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
include/parasite-syscall.h | 8 +++++
parasite-syscall.c | 67 +++++++++++++++++++++++--------------------
2 files changed, 44 insertions(+), 31 deletions(-)
diff --git a/include/parasite-syscall.h b/include/parasite-syscall.h
index 3e960af..4ef6ed9 100644
--- a/include/parasite-syscall.h
+++ b/include/parasite-syscall.h
@@ -59,4 +59,12 @@ struct pstree_item;
extern int parasite_init_threads_seized(struct parasite_ctl *ctl, struct pstree_item *item);
extern int parasite_fini_threads_seized(struct parasite_ctl *ctl, struct pstree_item *item);
+int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
+ unsigned long arg1,
+ unsigned long arg2,
+ unsigned long arg3,
+ unsigned long arg4,
+ unsigned long arg5,
+ unsigned long arg6);
+
#endif /* PARASITE_SYSCALL_H_ */
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 98d2e86..7375afd 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -244,50 +244,55 @@ static int parasite_execute(unsigned int cmd, struct parasite_ctl *ctl)
return parasite_execute_by_pid(cmd, ctl, ctl->pid);
}
-static void *mmap_seized(struct parasite_ctl *ctl,
- void *addr, size_t length, int prot,
- int flags, int fd, off_t offset)
+int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
+ unsigned long arg1,
+ unsigned long arg2,
+ unsigned long arg3,
+ unsigned long arg4,
+ unsigned long arg5,
+ unsigned long arg6)
{
user_regs_struct_t regs = ctl->regs_orig;
- void *map = NULL;
- int ret;
+ int err;
- regs.ax = (unsigned long)__NR_mmap; /* mmap */
- regs.di = (unsigned long)addr; /* @addr */
- regs.si = (unsigned long)length; /* @length */
- regs.dx = (unsigned long)prot; /* @prot */
- regs.r10 = (unsigned long)flags; /* @flags */
- regs.r8 = (unsigned long)fd; /* @fd */
- regs.r9 = (unsigned long)offset; /* @offset */
+ regs.ax = (unsigned long)nr;
+ regs.di = arg1;
+ regs.si = arg2;
+ regs.dx = arg3;
+ regs.r10 = arg4;
+ regs.r8 = arg5;
+ regs.r9 = arg6;
parasite_setup_regs(ctl->syscall_ip, ®s);
+ err = __parasite_execute(ctl, ctl->pid, ®s);
+ if (err)
+ return err;
- ret = __parasite_execute(ctl, ctl->pid, ®s);
- if (ret)
- goto err;
-
- if ((long)regs.ax > 0)
- map = (void *)regs.ax;
-err:
- return map;
+ *ret = regs.ax;
+ return 0;
}
-static int munmap_seized(struct parasite_ctl *ctl, void *addr, size_t length)
+static void *mmap_seized(struct parasite_ctl *ctl,
+ void *addr, size_t length, int prot,
+ int flags, int fd, off_t offset)
{
- user_regs_struct_t regs = ctl->regs_orig;
- int ret;
+ unsigned long map;
+ int err;
- regs.ax = (unsigned long)__NR_munmap; /* mmap */
- regs.di = (unsigned long)addr; /* @addr */
- regs.si = (unsigned long)length; /* @length */
+ err = syscall_seized(ctl, __NR_mmap, &map,
+ (unsigned long)addr, length, prot, flags, fd, offset);
+ if (err < 0 || (long)map < 0)
+ map = 0;
- parasite_setup_regs(ctl->syscall_ip, ®s);
+ return (void *)map;
+}
- ret = __parasite_execute(ctl, ctl->pid, ®s);
- if (!ret)
- ret = (int)regs.ax;
+static int munmap_seized(struct parasite_ctl *ctl, void *addr, size_t length)
+{
+ unsigned long x;
- return ret;
+ return syscall_seized(ctl, __NR_munmap, &x,
+ (unsigned long)addr, length, 0, 0, 0, 0);
}
static int gen_parasite_saddr(struct sockaddr_un *saddr, int key)
--
1.7.1
More information about the CRIU
mailing list