[CRIU] [PATCHv2 2/2] ia32: Add compatible sigmask to sigframe
Dmitry Safonov
dima at arista.com
Wed Apr 10 04:06:35 MSK 2019
It has a different alignment - rework ugly macro RT_SIGFRAME_UC_SIGMASK
into helpers.
Fixes: #666
Signed-off-by: Dmitry Safonov <dima at arista.com>
---
.../src/lib/include/uapi/asm/sigframe.h | 5 +++
.../arm/src/lib/include/uapi/asm/sigframe.h | 5 +++
.../ppc64/src/lib/include/uapi/asm/sigframe.h | 5 +++
.../s390/src/lib/include/uapi/asm/sigframe.h | 6 +++
.../x86/src/lib/include/uapi/asm/sigframe.h | 38 ++++++++++++++++---
compel/arch/x86/src/lib/infect.c | 2 +-
compel/src/lib/infect.c | 11 +-----
criu/sigframe.c | 12 +-----
8 files changed, 58 insertions(+), 26 deletions(-)
diff --git a/compel/arch/aarch64/src/lib/include/uapi/asm/sigframe.h b/compel/arch/aarch64/src/lib/include/uapi/asm/sigframe.h
index 6b9317b040cb..d99da3ab6272 100644
--- a/compel/arch/aarch64/src/lib/include/uapi/asm/sigframe.h
+++ b/compel/arch/aarch64/src/lib/include/uapi/asm/sigframe.h
@@ -61,4 +61,9 @@ struct cr_sigcontext {
#define RT_SIGFRAME_FPU(rt_sigframe) (&RT_SIGFRAME_AUX_CONTEXT(rt_sigframe)->fpsimd)
#define RT_SIGFRAME_OFFSET(rt_sigframe) 0
+#define rt_sigframe_erase_sigset(sigframe) \
+ memset(&sigframe->uc.uc_sigmask, 0, sizeof(k_rtsigset_t))
+#define rt_sigframe_copy_sigset(from, sigframe) \
+ memcpy(&sigframe->uc.uc_sigmask, from, sizeof(k_rtsigset_t))
+
#endif /* UAPI_COMPEL_ASM_SIGFRAME_H__ */
diff --git a/compel/arch/arm/src/lib/include/uapi/asm/sigframe.h b/compel/arch/arm/src/lib/include/uapi/asm/sigframe.h
index b90c0f659090..524d632b77b4 100644
--- a/compel/arch/arm/src/lib/include/uapi/asm/sigframe.h
+++ b/compel/arch/arm/src/lib/include/uapi/asm/sigframe.h
@@ -82,4 +82,9 @@ struct rt_sigframe {
#define RT_SIGFRAME_FPU(rt_sigframe) (&RT_SIGFRAME_AUX_SIGFRAME(rt_sigframe)->vfp)
#define RT_SIGFRAME_OFFSET(rt_sigframe) 0
+#define rt_sigframe_erase_sigset(sigframe) \
+ memset(&sigframe->uc.uc_sigmask, 0, sizeof(k_rtsigset_t))
+#define rt_sigframe_copy_sigset(from, sigframe) \
+ memcpy(&sigframe->uc.uc_sigmask, from, sizeof(k_rtsigset_t))
+
#endif /* UAPI_COMPEL_ASM_SIGFRAME_H__ */
diff --git a/compel/arch/ppc64/src/lib/include/uapi/asm/sigframe.h b/compel/arch/ppc64/src/lib/include/uapi/asm/sigframe.h
index 6f8b6ec54840..d591dbee065c 100644
--- a/compel/arch/ppc64/src/lib/include/uapi/asm/sigframe.h
+++ b/compel/arch/ppc64/src/lib/include/uapi/asm/sigframe.h
@@ -63,6 +63,11 @@ struct rt_sigframe {
#define RT_SIGFRAME_HAS_FPU(rt_sigframe) (1)
#define RT_SIGFRAME_FPU(rt_sigframe) (&(rt_sigframe)->uc.uc_mcontext)
+#define rt_sigframe_erase_sigset(sigframe) \
+ memset(&sigframe->uc.uc_sigmask, 0, sizeof(k_rtsigset_t))
+#define rt_sigframe_copy_sigset(from, sigframe) \
+ memcpy(&sigframe->uc.uc_sigmask, from, sizeof(k_rtsigset_t))
+
#define MSR_TMA (1UL<<34) /* bit 29 Trans Mem state: Transactional */
#define MSR_TMS (1UL<<33) /* bit 30 Trans Mem state: Suspended */
#define MSR_TM (1UL<<32) /* bit 31 Trans Mem Available */
diff --git a/compel/arch/s390/src/lib/include/uapi/asm/sigframe.h b/compel/arch/s390/src/lib/include/uapi/asm/sigframe.h
index 47c39f642f0e..503646eb2bb4 100644
--- a/compel/arch/s390/src/lib/include/uapi/asm/sigframe.h
+++ b/compel/arch/s390/src/lib/include/uapi/asm/sigframe.h
@@ -7,6 +7,7 @@
#include <signal.h>
#include <stdint.h>
+#include <string.h>
// XXX: the identifier rt_sigcontext is expected to be struct by the CRIU code
#define rt_sigcontext sigcontext
@@ -72,4 +73,9 @@ struct rt_sigframe {
#define RT_SIGFRAME_REGIP(rt_sigframe) (rt_sigframe)->uc.uc_mcontext.regs.psw.addr
#define RT_SIGFRAME_HAS_FPU(rt_sigframe) (1)
+#define rt_sigframe_erase_sigset(sigframe) \
+ memset(&sigframe->uc.uc_sigmask, 0, sizeof(k_rtsigset_t))
+#define rt_sigframe_copy_sigset(from, sigframe) \
+ memcpy(&sigframe->uc.uc_sigmask, from, sizeof(k_rtsigset_t))
+
#endif /* UAPI_COMPEL_ASM_SIGFRAME_H__ */
diff --git a/compel/arch/x86/src/lib/include/uapi/asm/sigframe.h b/compel/arch/x86/src/lib/include/uapi/asm/sigframe.h
index 768fb61ab7b8..51ca023f7759 100644
--- a/compel/arch/x86/src/lib/include/uapi/asm/sigframe.h
+++ b/compel/arch/x86/src/lib/include/uapi/asm/sigframe.h
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <stdbool.h>
+#include <string.h>
#include <compel/asm/fpu.h>
#include <compel/plugins/std/syscall-codes.h>
@@ -75,6 +76,7 @@ struct rt_sigcontext_32 {
typedef uint32_t compat_uptr_t;
typedef uint32_t compat_size_t;
+typedef uint32_t compat_sigset_word;
typedef struct compat_siginfo {
int si_signo;
@@ -89,12 +91,20 @@ typedef struct compat_sigaltstack {
compat_size_t ss_size;
} compat_stack_t;
+#define _COMPAT_NSIG 64
+#define _COMPAT_NSIG_BPW 32
+#define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
+
+typedef struct {
+ compat_sigset_word sig[_COMPAT_NSIG_WORDS];
+} compat_sigset_t;
+
struct ucontext_ia32 {
unsigned int uc_flags;
unsigned int uc_link;
compat_stack_t uc_stack;
struct rt_sigcontext_32 uc_mcontext;
- k_rtsigset_t uc_sigmask; /* mask last for extensibility */
+ compat_sigset_t uc_sigmask; /* mask last for extensibility */
};
struct rt_sigframe_ia32 {
@@ -127,10 +137,28 @@ struct rt_sigframe {
bool is_native;
};
-#define RT_SIGFRAME_UC_SIGMASK(rt_sigframe) \
- ((rt_sigframe->is_native) ? \
- (&rt_sigframe->native.uc.uc_sigmask) : \
- ((k_rtsigset_t *)(void *)&rt_sigframe->compat.uc.uc_sigmask))
+static inline
+void rt_sigframe_copy_sigset(struct rt_sigframe *to, k_rtsigset_t *from)
+{
+ size_t sz = sizeof(k_rtsigset_t);
+
+ BUILD_BUG_ON(sz != sizeof(compat_sigset_t));
+ if (to->is_native)
+ memcpy(&to->native.uc.uc_sigmask, from, sz);
+ else
+ memcpy(&to->compat.uc.uc_sigmask, from, sz);
+}
+
+static inline
+void rt_sigframe_erase_sigset(struct rt_sigframe *sigframe)
+{
+ size_t sz = sizeof(k_rtsigset_t);
+
+ if (sigframe->is_native)
+ memset(&sigframe->native.uc.uc_sigmask, 0, sz);
+ else
+ memset(&sigframe->compat.uc.uc_sigmask, 0, sz);
+}
#define RT_SIGFRAME_REGIP(rt_sigframe) \
((rt_sigframe->is_native) ? \
diff --git a/compel/arch/x86/src/lib/infect.c b/compel/arch/x86/src/lib/infect.c
index cb3e7759ae60..e76f7787d88c 100644
--- a/compel/arch/x86/src/lib/infect.c
+++ b/compel/arch/x86/src/lib/infect.c
@@ -116,7 +116,7 @@ void compel_convert_from_fxsr(struct user_i387_ia32_struct *env,
struct i387_fxsave_struct *fxsave)
{
struct fpxreg *from = (struct fpxreg *)&fxsave->st_space[0];
- struct fpreg *to = (struct fpreg *)&env->st_space[0];
+ struct fpreg *to = (struct fpreg *)env->st_space;
int i;
env->cwd = fxsave->cwd | 0xffff0000u;
diff --git a/compel/src/lib/infect.c b/compel/src/lib/infect.c
index b7db6cf9705d..09c2c53f9700 100644
--- a/compel/src/lib/infect.c
+++ b/compel/src/lib/infect.c
@@ -1130,15 +1130,9 @@ static int save_regs_plain(void *to, user_regs_struct_t *r, user_fpregs_struct_t
return 0;
}
-#ifndef RT_SIGFRAME_UC_SIGMASK
-#define RT_SIGFRAME_UC_SIGMASK(sigframe) \
- (k_rtsigset_t*)(void *)&RT_SIGFRAME_UC(sigframe)->uc_sigmask
-#endif
-
static int make_sigframe_plain(void *from, struct rt_sigframe *f, struct rt_sigframe *rtf, k_rtsigset_t *b)
{
struct plain_regs_struct *prs = from;
- k_rtsigset_t *blk_sigset;
/*
* Make sure it's zeroified.
@@ -1148,11 +1142,8 @@ static int make_sigframe_plain(void *from, struct rt_sigframe *f, struct rt_sigf
if (sigreturn_prep_regs_plain(f, &prs->regs, &prs->fpregs))
return -1;
- blk_sigset = RT_SIGFRAME_UC_SIGMASK(f);
if (b)
- memcpy(blk_sigset, b, sizeof(k_rtsigset_t));
- else
- memset(blk_sigset, 0, sizeof(k_rtsigset_t));
+ rt_sigframe_copy_sigset(f, b);
if (RT_SIGFRAME_HAS_FPU(f)) {
if (sigreturn_prep_fpu_frame_plain(f, rtf))
diff --git a/criu/sigframe.c b/criu/sigframe.c
index 2b5ae7658912..b8798efc376b 100644
--- a/criu/sigframe.c
+++ b/criu/sigframe.c
@@ -18,18 +18,11 @@ static inline void setup_sas(struct rt_sigframe* sigframe, ThreadSasEntry *sas)
}
#endif
-#ifndef RT_SIGFRAME_UC_SIGMASK
-#define RT_SIGFRAME_UC_SIGMASK(sigframe) \
- (k_rtsigset_t*)&RT_SIGFRAME_UC(sigframe)->uc_sigmask
-#endif
-
int construct_sigframe(struct rt_sigframe *sigframe,
struct rt_sigframe *rsigframe,
k_rtsigset_t *blkset,
CoreEntry *core)
{
- k_rtsigset_t *blk_sigset;
-
/*
* Copy basic register set in the first place: this will set
* rt_sigframe type: native/compat.
@@ -37,11 +30,10 @@ int construct_sigframe(struct rt_sigframe *sigframe,
if (restore_gpregs(sigframe, CORE_THREAD_ARCH_INFO(core)->gpregs))
return -1;
- blk_sigset = RT_SIGFRAME_UC_SIGMASK(sigframe);
if (blkset)
- memcpy(blk_sigset, blkset, sizeof(k_rtsigset_t));
+ rt_sigframe_copy_sigset(sigframe, blkset);
else
- memset(blk_sigset, 0, sizeof(k_rtsigset_t));
+ rt_sigframe_erase_sigset(sigframe);
if (restore_fpu(sigframe, core))
return -1;
--
2.21.0
More information about the CRIU
mailing list