[CRIU] [PATCH 3/7] compel: Reserve memory for thread sas

Cyrill Gorcunov gorcunov at openvz.org
Mon Mar 13 09:52:15 PDT 2017


Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 compel/include/infect-priv.h | 4 ++++
 compel/src/lib/infect.c      | 7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/compel/include/infect-priv.h b/compel/include/infect-priv.h
index 45e7409980d0..892099eaf245 100644
--- a/compel/include/infect-priv.h
+++ b/compel/include/infect-priv.h
@@ -2,6 +2,7 @@
 #define __COMPEL_INFECT_PRIV_H__
 
 #include <stdbool.h>
+#include <signal.h>
 
 #define BUILTIN_SYSCALL_SIZE	8
 
@@ -29,6 +30,8 @@ struct parasite_ctl {
 	struct rt_sigframe	*sigframe;
 	struct rt_sigframe	*rsigframe;				/* address in a parasite */
 
+	stack_t			*thread_sas;
+	stack_t			*r_thread_sas;				/* per-thread sas storage (shared) */
 	void			*r_thread_stack;			/* stack for non-leader threads (shared) */
 
 	unsigned long		parasite_ip;				/* service routine start ip */
@@ -45,6 +48,7 @@ struct parasite_thread_ctl {
 	int			tid;
 	struct parasite_ctl	*ctl;
 	struct thread_ctx	th;
+	stack_t			sas;
 };
 
 #define MEMFD_FNAME	"CRIUMFD"
diff --git a/compel/src/lib/infect.c b/compel/src/lib/infect.c
index c34452fd6f12..68d86d3d809f 100644
--- a/compel/src/lib/infect.c
+++ b/compel/src/lib/infect.c
@@ -863,7 +863,7 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l
 	map_exchange_size = parasite_size;
 	map_exchange_size += RESTORE_STACK_SIGFRAME + PARASITE_STACK_SIZE;
 	if (nr_threads > 1)
-		map_exchange_size += PARASITE_STACK_SIZE;
+		map_exchange_size += PARASITE_STACK_SIZE + sizeof(stack_t);
 
 	ret = compel_map_exchange(ctl, map_exchange_size);
 	if (ret)
@@ -890,6 +890,9 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l
 	ctl->rstack = ctl->remote_map + p;
 
 	if (nr_threads > 1) {
+		p += sizeof(stack_t);
+		ctl->r_thread_sas = ctl->remote_map + p;
+		ctl->thread_sas = ctl->local_map + p;
 		p += PARASITE_STACK_SIZE;
 		ctl->r_thread_stack = ctl->remote_map + p;
 	}
@@ -914,7 +917,7 @@ struct parasite_thread_ctl *compel_prepare_thread(struct parasite_ctl *ctl, int
 {
 	struct parasite_thread_ctl *tctl;
 
-	tctl = xmalloc(sizeof(*tctl));
+	tctl = xzalloc(sizeof(*tctl));
 	if (tctl) {
 		if (prepare_thread(pid, &tctl->th)) {
 			xfree(tctl);
-- 
2.7.4



More information about the CRIU mailing list