[CRIU] [PATCH 1/8] signals: dump alternate stack as misc parameters

Andrey Vagin avagin at openvz.org
Thu Jul 11 05:46:48 EDT 2013


The initilization stage is not good for that, because it can fail.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c          |  3 +++
 include/parasite.h | 10 +++++++++-
 parasite-syscall.c | 10 ----------
 pie/parasite.c     |  8 ++++----
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index ceee96f..9a7d756 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -668,6 +668,9 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
 	core_put_tls(core, misc->tls);
 	CORE_THREAD_ARCH_INFO(core)->clear_tid_addr = encode_pointer(misc->tid_addr);
 
+	BUG_ON(!core->thread_core->sas);
+	copy_sas(core->thread_core->sas, &misc->sas);
+
 	ret = pb_write_one(fd_core, core, PB_CORE);
 	if (ret < 0)
 		goto err;
diff --git a/include/parasite.h b/include/parasite.h
index 0fbdd2c..334e31d 100644
--- a/include/parasite.h
+++ b/include/parasite.h
@@ -71,7 +71,6 @@ struct parasite_init_args {
 	k_rtsigset_t		sig_blocked;
 
 	struct rt_sigframe	*sigframe;
-	stack_t			sas;
 };
 
 struct parasite_log_args {
@@ -150,6 +149,8 @@ struct parasite_dump_misc {
 	u32 pgid;
 	u32 tls;
 	u32 umask;
+
+	stack_t			sas;
 };
 
 #define PARASITE_MAX_GROUPS	(PAGE_SIZE / sizeof(unsigned int) - 2 * sizeof(unsigned))
@@ -168,6 +169,13 @@ struct parasite_dump_thread {
 	stack_t			sas;
 };
 
+static inline void copy_sas(ThreadSasEntry *dst, const stack_t *src)
+{
+	dst->ss_sp = encode_pointer(src->ss_sp);
+	dst->ss_size = (u64)src->ss_size;
+	dst->ss_flags = src->ss_flags;
+}
+
 #define PARASITE_MAX_FDS	(PAGE_SIZE / sizeof(int))
 
 struct parasite_drain_fd {
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 2ca90f6..79dc7cd 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -370,13 +370,6 @@ static int parasite_set_logfd(struct parasite_ctl *ctl, pid_t pid)
 	return 0;
 }
 
-static void copy_sas(ThreadSasEntry *dst, stack_t *src)
-{
-	dst->ss_sp = encode_pointer(src->ss_sp);
-	dst->ss_size = (u64)src->ss_size;
-	dst->ss_flags = src->ss_flags;
-}
-
 static int parasite_init(struct parasite_ctl *ctl, pid_t pid, struct pstree_item *item)
 {
 	static int ssock = -1;
@@ -428,9 +421,6 @@ static int parasite_init(struct parasite_ctl *ctl, pid_t pid, struct pstree_item
 	ctl->sig_blocked = args->sig_blocked;
 	ctl->use_sig_blocked = true;
 
-	BUG_ON(!item->core[0]->thread_core->sas);
-	copy_sas(item->core[0]->thread_core->sas, &args->sas);
-
 	sock = accept(ssock, NULL, 0);
 	if (sock < 0) {
 		pr_perror("Can't accept connection to the transport socket");
diff --git a/pie/parasite.c b/pie/parasite.c
index 125305e..eb5186d 100644
--- a/pie/parasite.c
+++ b/pie/parasite.c
@@ -149,6 +149,10 @@ static int dump_misc(struct parasite_dump_misc *args)
 	args->umask = sys_umask(0);
 	sys_umask(args->umask); /* never fails */
 
+	ret = sys_sigaltstack(NULL, &args->sas);
+	if (ret)
+		return ret;
+
 	ret = sys_prctl(PR_GET_TID_ADDRESS, (unsigned long) &args->tid_addr, 0, 0, 0);
 
 	return ret;
@@ -250,10 +254,6 @@ static int init(struct parasite_init_args *args)
 	if (ret)
 		return -1;
 
-	ret = sys_sigaltstack(NULL, &args->sas);
-	if (ret)
-		goto err;
-
 	tsock = sys_socket(PF_UNIX, SOCK_STREAM, 0);
 	if (tsock < 0) {
 		ret = tsock;
-- 
1.8.3.1



More information about the CRIU mailing list