[CRIU] [PATCH 1/3] rst: Don't allocate page for child stack (v2)

Pavel Emelyanov xemul at parallels.com
Mon Sep 15 11:05:21 PDT 2014


When clone-ing kids we can set their stack on current, as
it will anyway be COW-ed later. One thing to note -- we do
need to reserve some space on the stack for glibc's arguments
and retcode allocation. 128 bytes should be enough for 16
pointers while clone has 5 arguments.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-restore.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 4d5ccd5..cad1b7c 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -945,7 +945,11 @@ static int restore_one_task(int pid, CoreEntry *core)
 
 /* All arguments should be above stack, because it grows down */
 struct cr_clone_arg {
-	char stack[PAGE_SIZE] __attribute__((aligned (8)));
+	/*
+	 * Reserve some space for clone() to locate arguments
+	 * and retcode in this place
+	 */
+	char stack[128] __attribute__((aligned (8)));
 	char stack_ptr[0];
 	struct pstree_item *item;
 	unsigned long clone_flags;
@@ -993,8 +997,8 @@ static void maybe_clone_parent(struct pstree_item *item,
 
 static inline int fork_with_pid(struct pstree_item *item)
 {
-	int ret = -1, fd;
 	struct cr_clone_arg ca;
+	int ret = -1, fd;
 	pid_t pid = item->pid.virt;
 
 	if (item->state != TASK_HELPER) {
@@ -1037,6 +1041,8 @@ static inline int fork_with_pid(struct pstree_item *item)
 	ca.item = item;
 	ca.clone_flags = item->rst->clone_flags;
 
+	BUG_ON(ca.clone_flags & CLONE_VM);
+
 	pr_info("Forking task with %d pid (flags 0x%lx)\n", pid, ca.clone_flags);
 
 	if (!(ca.clone_flags & CLONE_NEWPID)) {
-- 
1.8.4.2




More information about the CRIU mailing list