Skip to contentSkip to conversation

cr: deal with signals

PATCH In review Alexey Dobriyan 1 participant 1 message Apr 10, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 24/30 cr: deal with signals

Dump signal_struct, sighand_struct.

FIXME: correstly restore, check everything

---

 include/linux/cr.h     |   28 ++++
 include/linux/signal.h |    1 
 kernel/cr/Makefile     |    1 
 kernel/cr/cpt-sys.c    |   12 +
 kernel/cr/cr-signal.c  |  301 +++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/cr/cr-task.c    |   14 ++
 kernel/cr/cr.h         |   19 +++
 kernel/fork.c          |    2 
 8 files changed, 377 insertions(+), 1 deletion(-)
include/linux/cr.h +28 -0
@@ -42,6 +42,8 @@ struct cr_object_header {
 #define CR_OBJ_FILES_STRUCT	11
 #define CR_OBJ_FD		12
 #define CR_OBJ_FS_STRUCT	13
+#define CR_OBJ_SIGNAL_STRUCT	14
+#define CR_OBJ_SIGHAND_STRUCT	15
 	__u32	cr_type;	/* object type */
 	__u32	cr_len;		/* object length in bytes including header */
 } __packed;
@@ -66,6 +68,12 @@ struct cr_image_task_struct {
 	cr_pos_t	cr_pos_files;
 	cr_pos_t	cr_pos_nsproxy;
 
+	cr_pos_t	cr_pos_signal;
+	cr_pos_t	cr_pos_sighand;
+	__u8		cr_blocked[16];
+	__u8		cr_real_blocked[16];
+	__u8		cr_saved_sigmask[16];
+
 	__u8		cr_comm[16];
 
 	/* Native arch of task, one of CR_ARCH_*. */
@@ -233,6 +241,26 @@ struct cr_image_vma_content {
 	/* __u8 cr_data[cr_nr_pages * cr_page_size]; */
 } __packed;
 
+struct cr_image_signal_struct {
+	struct cr_object_header cr_hdr;
+
+	struct {
+		__u64	cr_rlim_cur;
+		__u64	cr_rlim_max;
+	} cr_rlim[16];
+} __packed;
+
+struct cr_image_sighand_struct {
+	struct cr_object_header cr_hdr;
+
+	struct {
+		__u64	cr_sa_handler;
+		__u64	cr_sa_flags;
+		__u64	cr_sa_restorer;
+		__u8	cr_sa_mask[16];
+	} cr_sa[128];
+} __packed;
+
 struct cr_image_fs_struct {
 	struct cr_object_header cr_hdr;
 
include/linux/signal.h +1 -0
@@ -243,6 +243,7 @@ struct pt_regs;
 extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
 extern void exit_signals(struct task_struct *tsk);
 
+extern struct kmem_cache *signal_cachep;
 extern struct kmem_cache *sighand_cachep;
 
 int unhandled_signal(struct task_struct *tsk, int sig);
kernel/cr/Makefile +1 -0
@@ -6,6 +6,7 @@ cr-y += cr-fs.o
 cr-y += cr-mm.o
 cr-y += cr-nsproxy.o
 cr-y += cr-pid.o
+cr-y += cr-signal.o
 cr-y += cr-task.o
 cr-y += cr-uts.o
 cr-$(CONFIG_X86_32) += cr-x86_32.o
kernel/cr/cpt-sys.c +12 -0
@@ -86,6 +86,12 @@ static int cr_collect(struct cr_context *ctx)
 	rv = cr_collect_all_fs_struct(ctx);
 	if (rv < 0)
 		return rv;
+	rv = cr_collect_all_signal_struct(ctx);
+	if (rv < 0)
+		return rv;
+	rv = cr_collect_all_sighand_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = cr_collect_all_pid(ctx);
 	if (rv < 0)
 		return rv;
@@ -140,6 +146,12 @@ static int cr_dump(struct cr_context *ctx)
 	rv = cr_dump_all_uts_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = cr_dump_all_sighand_struct(ctx);
+	if (rv < 0)
+		return rv;
+	rv = cr_dump_all_signal_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = cr_dump_all_mm_struct(ctx);
 	if (rv < 0)
 		return rv;

new file mode 100644

kernel/cr/cr-signal.c new file +301 -0

301 lines not on this page · raw message

kernel/cr/cr-task.c +14 -0
@@ -132,6 +132,14 @@ static int cr_dump_task_struct(struct cr_context *ctx, struct cr_object *obj)
 	tmp = cr_find_obj_by_ptr(ctx, tsk->files, CR_CTX_FILES_STRUCT);
 	i->cr_pos_files = tmp->o_pos;
 
+	tmp = cr_find_obj_by_ptr(ctx, tsk->signal, CR_CTX_SIGNAL_STRUCT);
+	i->cr_pos_signal = tmp->o_pos;
+	tmp = cr_find_obj_by_ptr(ctx, tsk->sighand, CR_CTX_SIGHAND_STRUCT);
+	i->cr_pos_sighand = tmp->o_pos;
+	cr_dump_sigset(i->cr_blocked, &tsk->blocked);
+	cr_dump_sigset(i->cr_real_blocked, &tsk->real_blocked);
+	cr_dump_sigset(i->cr_saved_sigmask, &tsk->saved_sigmask);
+
 	BUILD_BUG_ON(TASK_COMM_LEN != 16);
 	strlcpy((char *)i->cr_comm, (const char *)tsk->comm, sizeof(i->cr_comm));
 
@@ -196,6 +204,12 @@ static int task_struct_restorer(void *_tsk_ctx)
 	rv = cr_restore_pid(ctx, i);
 	if (rv < 0)
 		goto out;
+	rv = cr_restore_sighand_struct(ctx, i->cr_pos_sighand);
+	if (rv < 0)
+		goto out;
+	cr_restore_sigset(&tsk->blocked, i->cr_blocked);
+	cr_restore_sigset(&tsk->real_blocked, i->cr_real_blocked);
+	cr_restore_sigset(&tsk->saved_sigmask, i->cr_saved_sigmask);
 
 	rv = 0;
 out:
kernel/cr/cr.h +19 -0
@@ -29,6 +29,8 @@ enum cr_context_obj_type {
 	CR_CTX_NSPROXY,
 	CR_CTX_PID,
 	CR_CTX_PID_NS,
+	CR_CTX_SIGHAND_STRUCT,
+	CR_CTX_SIGNAL_STRUCT,
 	CR_CTX_TASK_STRUCT,
 	CR_CTX_UTS_NS,
 	NR_CR_CTX_TYPES
@@ -72,6 +74,17 @@ static inline void __user *cr_restore_ptr(__u64 ptr)
 	return (void __user *)(unsigned long)ptr;
 }
 
+static inline void cr_dump_sigset(__u8 *cr_image_sigset, sigset_t *sig)
+{
+	BUILD_BUG_ON(sizeof(sigset_t) > 16);
+	memcpy(cr_image_sigset, sig, sizeof(sigset_t));
+}
+
+static inline void cr_restore_sigset(sigset_t *sig, __u8 *cr_image_sigset)
+{
+	memcpy(sig, cr_image_sigset, sizeof(sigset_t));
+}
+
 int cr_collect_all_files_struct(struct cr_context *ctx);
 int cr_collect_all_file(struct cr_context *ctx);
 int cr_collect_all_fs_struct(struct cr_context *ctx);
@@ -79,6 +92,8 @@ int cr_collect_all_mm_struct(struct cr_context *ctx);
 int cr_collect_all_nsproxy(struct cr_context *ctx);
 int cr_collect_all_pid_ns(struct cr_context *ctx);
 int cr_collect_all_pid(struct cr_context *ctx);
+int cr_collect_all_sighand_struct(struct cr_context *ctx);
+int cr_collect_all_signal_struct(struct cr_context *ctx);
 int cr_collect_all_task_struct(struct cr_context *ctx);
 int cr_collect_all_uts_ns(struct cr_context *ctx);
 
@@ -89,6 +104,8 @@ int cr_dump_all_mm_struct(struct cr_context *ctx);
 int cr_dump_all_nsproxy(struct cr_context *ctx);
 int cr_dump_all_pid_ns(struct cr_context *ctx);
 int cr_dump_all_pid(struct cr_context *ctx);
+int cr_dump_all_sighand_struct(struct cr_context *ctx);
+int cr_dump_all_signal_struct(struct cr_context *ctx);
 int cr_dump_all_task_struct(struct cr_context *ctx);
 int cr_dump_all_uts_ns(struct cr_context *ctx);
 
@@ -99,6 +116,8 @@ int cr_restore_mm_struct(struct cr_context *ctx, loff_t pos);
 int cr_restore_nsproxy(struct cr_context *ctx, loff_t pos);
 int cr_restore_pid_ns(struct cr_context *ctx, loff_t pos);
 int cr_restore_pid(struct cr_context *ctx, struct cr_image_task_struct *i);
+int cr_restore_sighand_struct(struct cr_context *ctx, loff_t pos);
+int cr_restore_signal_struct(struct cr_context *ctx, loff_t pos);
 int cr_restore_task_struct(struct cr_context *ctx, loff_t pos);
 int cr_restore_uts_ns(struct cr_context *ctx, loff_t pos);
 
kernel/fork.c +1 -1
@@ -120,7 +120,7 @@ static inline void free_thread_info(struct thread_info *ti)
 #endif
 
 /* SLAB cache for signal_struct structures (tsk->signal) */
-static struct kmem_cache *signal_cachep;
+struct kmem_cache *signal_cachep;
 
 /* SLAB cache for sighand_struct structures (tsk->sighand) */
 struct kmem_cache *sighand_cachep;