From 03a9c6b0b7328ea573c19fb40a580cc57bab4975 Mon Sep 17 00:00:00 2001 From: Alexander Kartashov Date: Fri, 11 Oct 2013 10:47:58 +0400 Subject: [PATCH] parasite-syscall: use the ptrace requests PTRACE_(GET|SET)REGSET to retrieve and set CPU registers This patch introduces the routines ptrace_get_gpregs() and ptrace_set_gpregs() that wrap the ptrace interface to get and set CPU registers respectively. The motivation is to make the CRIU code be compatible with architectures that don't support the PTRACE_GETREGS and PTRACE_SETREGS ptrace calls --- the requests PTRACE_GETREGSET and PTRACE_SETREGSET are implemented instead. Signed-off-by: Alexander Kartashov Signed-off-by: Pavel Emelyanov --- include/ptrace.h | 5 +++++ parasite-syscall.c | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/ptrace.h b/include/ptrace.h index 61c3b6a7e..3bcc95163 100644 --- a/include/ptrace.h +++ b/include/ptrace.h @@ -27,6 +27,11 @@ struct ptrace_peeksiginfo_args { #define PTRACE_PEEKSIGINFO_SHARED (1 << 0) #endif +#ifndef PTRACE_GETREGSET +# define PTRACE_GETREGSET 0x4204 +# define PTRACE_SETREGSET 0x4205 +#endif + #define PTRACE_GETSIGMASK 0x420a #define PTRACE_SETSIGMASK 0x420b diff --git a/parasite-syscall.c b/parasite-syscall.c index b3644394a..e67b1c3e6 100644 --- a/parasite-syscall.c +++ b/parasite-syscall.c @@ -30,6 +30,7 @@ #include #include +#include #include "asm/parasite-syscall.h" #include "asm/dump.h" @@ -67,12 +68,20 @@ static struct vma_area *get_vma_by_ip(struct list_head *vma_area_list, unsigned static inline int ptrace_get_regs(int pid, user_regs_struct_t *regs) { - return ptrace(PTRACE_GETREGS, pid, NULL, regs); + struct iovec iov; + + iov.iov_base = regs; + iov.iov_len = sizeof(user_regs_struct_t); + return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov); } static inline int ptrace_set_regs(int pid, user_regs_struct_t *regs) { - return ptrace(PTRACE_SETREGS, pid, NULL, regs); + struct iovec iov; + + iov.iov_base = regs; + iov.iov_len = sizeof(user_regs_struct_t); + return ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov); } static int get_thread_ctx(int pid, struct thread_ctx *ctx)